mirror of https://github.com/apache/jclouds.git
issue #1401: labs is now at https://github.com/jclouds/jclouds-labs
This commit is contained in:
parent
bd0f44fb74
commit
0fab297e0c
|
@ -1,10 +0,0 @@
|
|||
Jclouds Abiquo Provider
|
||||
=======================
|
||||
|
||||
This is the jclouds Abiquo provider. It enables compute features for the Abiquo cloud platform.
|
||||
|
||||
Detailed information about the Abiquo REST API can be found in the
|
||||
[Abiquo documentation page](http://community.abiquo.com).
|
||||
|
||||
If you find any issue in the provider api, please submit it to the [Bug tracking system](http://jira.abiquo.com/browse/ABIQUOJC) and we will do our best to fix it.
|
||||
|
|
@ -1,226 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.jclouds.labs</groupId>
|
||||
<artifactId>jclouds-labs-project</artifactId>
|
||||
<version>1.7.0-SNAPSHOT</version>
|
||||
<relativePath>../project/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>abiquo</artifactId>
|
||||
<name>jclouds Abiquo api</name>
|
||||
<description>jclouds components to access an implementation of Abiquo</description>
|
||||
<packaging>bundle</packaging>
|
||||
|
||||
<properties>
|
||||
<abiquomodel.version>2.2.0.1</abiquomodel.version>
|
||||
<abiquoam.version>2.1.2.1</abiquoam.version>
|
||||
<test.abiquo.endpoint>http://localhost/api</test.abiquo.endpoint>
|
||||
<test.abiquo.identity>FIXME</test.abiquo.identity>
|
||||
<test.abiquo.credential>FIXME</test.abiquo.credential>
|
||||
<test.abiquo.api-version />
|
||||
<test.abiquo.build-version />
|
||||
<jclouds.osgi.export>org.jclouds.abiquo*;version="${project.version}"</jclouds.osgi.export>
|
||||
<jclouds.osgi.import>
|
||||
org.jclouds.labs*;version="${project.version}",
|
||||
org.jclouds*;version="${jclouds.version}",
|
||||
*
|
||||
</jclouds.osgi.import>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<version>${jclouds.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${jclouds.version}</version>
|
||||
</dependency>
|
||||
<!-- Abiquo -->
|
||||
<dependency>
|
||||
<groupId>com.abiquo</groupId>
|
||||
<artifactId>api-model-transport</artifactId>
|
||||
<version>${abiquomodel.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.uncommons</groupId>
|
||||
<artifactId>reportng</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.abiquo</groupId>
|
||||
<artifactId>am-model</artifactId>
|
||||
<version>${abiquoam.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.uncommons</groupId>
|
||||
<artifactId>reportng</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- Required for class SyndLink (imported form RESTLink) : TODO remove this dependency -->
|
||||
<dependency>
|
||||
<groupId>org.apache.wink</groupId>
|
||||
<artifactId>wink-common</artifactId>
|
||||
<version>1.1-incubating</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.xml.stream</groupId>
|
||||
<artifactId>stax-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- Test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<version>${jclouds.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${jclouds.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.driver</groupId>
|
||||
<artifactId>jclouds-sshj</artifactId>
|
||||
<version>${jclouds.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.driver</groupId>
|
||||
<artifactId>jclouds-slf4j</artifactId>
|
||||
<version>${jclouds.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>src/test/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
<exclude>**/*LiveApiTest.java</exclude>
|
||||
<exclude>**/*LiveUcsTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>live</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<test.abiquo.identity>${test.abiquo.idenfity}</test.abiquo.identity>
|
||||
<test.abiquo.credential>${test.abiquo.credential}</test.abiquo.credential>
|
||||
<test.abiquo.api-version>${test.abiquo.api-version}</test.abiquo.api-version>
|
||||
<test.abiquo.build-version>${test.abiquo.build-version}</test.abiquo.build-version>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>api</id>
|
||||
<build>
|
||||
<filters>
|
||||
<filter>src/test/resources/filters/filters.properties</filter>
|
||||
</filters>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- Infrastructure tests must not be executed in parallel.
|
||||
They modify concurrently the same infrastructure resources. -->
|
||||
<threadCount>1</threadCount>
|
||||
<excludes>
|
||||
<exclude>none</exclude>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/*LiveApiTest.java</include>
|
||||
</includes>
|
||||
<systemPropertyVariables>
|
||||
<test.abiquo.identity>${test.abiquo.identity}</test.abiquo.identity>
|
||||
<test.abiquo.credential>${test.abiquo.credential}</test.abiquo.credential>
|
||||
<test.abiquo.api-version>${test.abiquo.api-version}</test.abiquo.api-version>
|
||||
<test.abiquo.build-version>${test.abiquo.build-version}</test.abiquo.build-version>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo;
|
||||
|
||||
import org.jclouds.abiquo.features.AdminApi;
|
||||
import org.jclouds.abiquo.features.CloudApi;
|
||||
import org.jclouds.abiquo.features.ConfigApi;
|
||||
import org.jclouds.abiquo.features.EnterpriseApi;
|
||||
import org.jclouds.abiquo.features.EventApi;
|
||||
import org.jclouds.abiquo.features.InfrastructureApi;
|
||||
import org.jclouds.abiquo.features.PricingApi;
|
||||
import org.jclouds.abiquo.features.TaskApi;
|
||||
import org.jclouds.abiquo.features.VirtualMachineTemplateApi;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Abiquo.
|
||||
*
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/API+Reference">
|
||||
* http://community.abiquo.com/display/ABI20/API+Reference</a>
|
||||
* @see AbiquoAsyncApi
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public interface AbiquoApi {
|
||||
/**
|
||||
* Provides synchronous access to Admin features.
|
||||
*/
|
||||
@Delegate
|
||||
AdminApi getAdminApi();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Infrastructure features.
|
||||
*/
|
||||
@Delegate
|
||||
InfrastructureApi getInfrastructureApi();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Cloud features.
|
||||
*/
|
||||
@Delegate
|
||||
CloudApi getCloudApi();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Apps library features.
|
||||
*/
|
||||
@Delegate
|
||||
VirtualMachineTemplateApi getVirtualMachineTemplateApi();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Enterprise features.
|
||||
*/
|
||||
@Delegate
|
||||
EnterpriseApi getEnterpriseApi();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to configuration features.
|
||||
*/
|
||||
@Delegate
|
||||
ConfigApi getConfigApi();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to task asynchronous features.
|
||||
*/
|
||||
@Delegate
|
||||
TaskApi getTaskApi();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Event features.
|
||||
*/
|
||||
@Delegate
|
||||
EventApi getEventApi();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Pricing features.
|
||||
*/
|
||||
@Delegate
|
||||
PricingApi getPricingApi();
|
||||
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo;
|
||||
import static org.jclouds.Constants.PROPERTY_MAX_REDIRECTS;
|
||||
import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY;
|
||||
import static org.jclouds.abiquo.config.AbiquoProperties.CREDENTIAL_IS_TOKEN;
|
||||
import static org.jclouds.reflect.Reflection2.typeToken;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.abiquo.compute.config.AbiquoComputeServiceContextModule;
|
||||
import org.jclouds.abiquo.config.AbiquoRestClientModule;
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.concurrent.config.ScheduledExecutorServiceModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.internal.BaseRestApiMetadata;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ApiMetadata} for Abiquo API.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class AbiquoApiMetadata extends BaseRestApiMetadata {
|
||||
|
||||
/** The token describing the rest api context. */
|
||||
public static TypeToken<RestContext<AbiquoApi, AbiquoAsyncApi>> CONTEXT_TOKEN = new TypeToken<RestContext<AbiquoApi, AbiquoAsyncApi>>() {
|
||||
private static final long serialVersionUID = -2098594161943130770L;
|
||||
};
|
||||
|
||||
public AbiquoApiMetadata() {
|
||||
this(new Builder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromApiMetadata(this);
|
||||
}
|
||||
|
||||
protected AbiquoApiMetadata(Builder builder) {
|
||||
super(builder);
|
||||
}
|
||||
|
||||
public static Properties defaultProperties() {
|
||||
Properties properties = BaseRestApiMetadata.defaultProperties();
|
||||
// By default redirects will be handled in the domain objects
|
||||
properties.setProperty(PROPERTY_MAX_REDIRECTS, "0");
|
||||
// The default polling delay between AsyncTask monitor requests
|
||||
properties.setProperty(ASYNC_TASK_MONITOR_DELAY, "5000");
|
||||
// By default the provided credential is not a token
|
||||
properties.setProperty(CREDENTIAL_IS_TOKEN, "false");
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static class Builder extends BaseRestApiMetadata.Builder<Builder> {
|
||||
private static final String DOCUMENTATION_ROOT = "http://community.abiquo.com/display/ABI"
|
||||
+ CharMatcher.DIGIT.retainFrom(AbiquoAsyncApi.API_VERSION);
|
||||
|
||||
protected Builder() {
|
||||
super(AbiquoApi.class, AbiquoAsyncApi.class);
|
||||
id("abiquo")
|
||||
.name("Abiquo API")
|
||||
.identityName("API Username")
|
||||
.credentialName("API Password")
|
||||
.documentation(URI.create(DOCUMENTATION_ROOT + "/API+Reference"))
|
||||
.defaultEndpoint("http://localhost/api")
|
||||
.version(AbiquoAsyncApi.API_VERSION)
|
||||
.buildVersion(AbiquoAsyncApi.BUILD_VERSION)
|
||||
.view(typeToken(AbiquoContext.class))
|
||||
.defaultProperties(AbiquoApiMetadata.defaultProperties())
|
||||
.defaultModules(
|
||||
ImmutableSet.<Class<? extends Module>> of(AbiquoRestClientModule.class,
|
||||
AbiquoComputeServiceContextModule.class, ScheduledExecutorServiceModule.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbiquoApiMetadata build() {
|
||||
return new AbiquoApiMetadata(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Builder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo;
|
||||
|
||||
import org.jclouds.abiquo.features.AdminAsyncApi;
|
||||
import org.jclouds.abiquo.features.CloudAsyncApi;
|
||||
import org.jclouds.abiquo.features.ConfigAsyncApi;
|
||||
import org.jclouds.abiquo.features.EnterpriseAsyncApi;
|
||||
import org.jclouds.abiquo.features.EventAsyncApi;
|
||||
import org.jclouds.abiquo.features.InfrastructureAsyncApi;
|
||||
import org.jclouds.abiquo.features.PricingAsyncApi;
|
||||
import org.jclouds.abiquo.features.TaskAsyncApi;
|
||||
import org.jclouds.abiquo.features.VirtualMachineTemplateAsyncApi;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
import com.abiquo.model.transport.SingleResourceTransportDto;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Abiquo via their REST API.
|
||||
*
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/API+Reference">
|
||||
* http://community.abiquo.com/display/ABI20/API+Reference</a>
|
||||
* @see InfrastructureAsyncApi
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public interface AbiquoAsyncApi {
|
||||
/**
|
||||
* The version of the supported Abiquo API.
|
||||
*/
|
||||
public static final String API_VERSION = SingleResourceTransportDto.API_VERSION;
|
||||
|
||||
/**
|
||||
* The supported build version of the Abiquo Api.
|
||||
*/
|
||||
public static final String BUILD_VERSION = "7bbfe95-158721b";
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Admin features.
|
||||
*/
|
||||
@Delegate
|
||||
AdminAsyncApi getAdminApi();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Infrastructure features.
|
||||
*/
|
||||
@Delegate
|
||||
InfrastructureAsyncApi getInfrastructureApi();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Cloud features.
|
||||
*/
|
||||
@Delegate
|
||||
CloudAsyncApi getCloudApi();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Apps library features.
|
||||
*/
|
||||
@Delegate
|
||||
VirtualMachineTemplateAsyncApi getVirtualMachineTemplateApi();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Enterprise features.
|
||||
*/
|
||||
@Delegate
|
||||
EnterpriseAsyncApi getEnterpriseApi();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to configuration features.
|
||||
*/
|
||||
@Delegate
|
||||
ConfigAsyncApi getConfigApi();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to task asynchronous features.
|
||||
*/
|
||||
@Delegate
|
||||
TaskAsyncApi getTaskApi();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Event features.
|
||||
*/
|
||||
@Delegate
|
||||
EventAsyncApi getEventApi();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Pricing features.
|
||||
*/
|
||||
@Delegate
|
||||
PricingAsyncApi getPricingApi();
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo;
|
||||
|
||||
import org.jclouds.abiquo.features.services.AdministrationService;
|
||||
import org.jclouds.abiquo.features.services.CloudService;
|
||||
import org.jclouds.abiquo.features.services.EventService;
|
||||
import org.jclouds.abiquo.features.services.MonitoringService;
|
||||
import org.jclouds.abiquo.features.services.PricingService;
|
||||
import org.jclouds.abiquo.features.services.SearchService;
|
||||
import org.jclouds.abiquo.internal.AbiquoContextImpl;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* Abiquo {@link ComputeServiceContext} implementation to expose high level
|
||||
* Abiquo functionalities.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@ImplementedBy(AbiquoContextImpl.class)
|
||||
public interface AbiquoContext extends ComputeServiceContext {
|
||||
/**
|
||||
* Returns the Abiquo API context, providing direct access to the Abiquo Rest
|
||||
* API.
|
||||
*
|
||||
* @return The Abiquo API context.
|
||||
*/
|
||||
RestContext<AbiquoApi, AbiquoAsyncApi> getApiContext();
|
||||
|
||||
/**
|
||||
* Returns the administration service.
|
||||
* <p>
|
||||
* This service provides an entry point to infrastructure administration
|
||||
* tasks.
|
||||
*/
|
||||
AdministrationService getAdministrationService();
|
||||
|
||||
/**
|
||||
* Returns the cloud service.
|
||||
* <p>
|
||||
* This service provides an entry point to cloud management tasks.
|
||||
*/
|
||||
CloudService getCloudService();
|
||||
|
||||
/**
|
||||
* Returns the search service.
|
||||
* <p>
|
||||
* This service provides an entry point to listing and filtering tasks.
|
||||
*/
|
||||
SearchService getSearchService();
|
||||
|
||||
/**
|
||||
* Returns the monitoring service.
|
||||
* <p>
|
||||
* This service provides an entry point to asynchronous task monitoring
|
||||
* tasks.
|
||||
*/
|
||||
MonitoringService getMonitoringService();
|
||||
|
||||
/**
|
||||
* Returns the event service.
|
||||
* <p>
|
||||
* This service provides an entry point to event management tasks.
|
||||
*/
|
||||
EventService getEventService();
|
||||
|
||||
/**
|
||||
* Returns the pricing service.
|
||||
* <p>
|
||||
* This service provides an entry point to pricing management tasks.
|
||||
*/
|
||||
PricingService getPricingService();
|
||||
}
|
|
@ -1,180 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo;
|
||||
|
||||
import static com.google.common.base.Throwables.getCausalChain;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
||||
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.jclouds.Fallback;
|
||||
import org.jclouds.abiquo.domain.exception.AbiquoException;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* fallbacks common to abiquo
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public final class AbiquoFallbacks {
|
||||
private AbiquoFallbacks() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an Abiquo Exception on not found errors.
|
||||
*/
|
||||
public static final class PropagateAbiquoExceptionOnNotFoundOr4xx implements Fallback<Object> {
|
||||
@Override
|
||||
public ListenableFuture<Object> create(Throwable from) throws Exception {
|
||||
return immediateFuture(createOrPropagate(from));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createOrPropagate(Throwable from) throws Exception {
|
||||
Throwable exception = find(getCausalChain(from), isNotFoundAndHasAbiquoException(from), null);
|
||||
throw propagate(exception == null ? from : exception.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>null</code> on 303 response codes when requesting a task.
|
||||
*/
|
||||
public static final class NullOn303 implements Fallback<Object> {
|
||||
@Override
|
||||
public ListenableFuture<Object> create(Throwable from) throws Exception {
|
||||
return immediateFuture(createOrPropagate(from));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createOrPropagate(Throwable from) throws Exception {
|
||||
Throwable exception = find(getCausalChain(from), hasResponse(from), null);
|
||||
|
||||
if (exception != null) {
|
||||
HttpResponseException responseException = (HttpResponseException) exception;
|
||||
HttpResponse response = responseException.getResponse();
|
||||
|
||||
if (response != null && response.getStatusCode() == Status.SEE_OTHER.getStatusCode()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
throw propagate(from);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return false on service error exceptions.
|
||||
*/
|
||||
public static final class FalseOn5xx implements Fallback<Boolean> {
|
||||
@Override
|
||||
public ListenableFuture<Boolean> create(Throwable from) throws Exception {
|
||||
return immediateFuture(createOrPropagate(from));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean createOrPropagate(Throwable from) throws Exception {
|
||||
Throwable exception = find(getCausalChain(from), hasResponse(from), null);
|
||||
|
||||
if (exception != null) {
|
||||
HttpResponseException responseException = (HttpResponseException) exception;
|
||||
HttpResponse response = responseException.getResponse();
|
||||
|
||||
if (response != null && response.getStatusCode() >= 500 && response.getStatusCode() < 600) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
throw propagate(from);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return false on service error exceptions.
|
||||
*/
|
||||
public static final class FalseIfNotAvailable implements Fallback<Boolean> {
|
||||
@Override
|
||||
public ListenableFuture<Boolean> create(Throwable from) throws Exception {
|
||||
return immediateFuture(createOrPropagate(from));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean createOrPropagate(Throwable from) throws Exception {
|
||||
Throwable exception = find(getCausalChain(from), isNotAvailableException(from), null);
|
||||
|
||||
if (exception != null) {
|
||||
if (exception instanceof HttpResponseException) {
|
||||
HttpResponseException responseException = (HttpResponseException) exception;
|
||||
HttpResponse response = responseException.getResponse();
|
||||
|
||||
if (response != null && response.getStatusCode() >= 500 && response.getStatusCode() < 600) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Will enter here when exception is a ResourceNotFoundException
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
throw propagate(from);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Predicate<Throwable> isNotFoundAndHasAbiquoException(final Throwable exception) {
|
||||
return new Predicate<Throwable>() {
|
||||
@Override
|
||||
public boolean apply(final Throwable input) {
|
||||
return input instanceof ResourceNotFoundException && input.getCause() instanceof AbiquoException;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Predicate<Throwable> isNotAvailableException(final Throwable exception) {
|
||||
return new Predicate<Throwable>() {
|
||||
@Override
|
||||
public boolean apply(final Throwable input) {
|
||||
boolean notAvailable = input instanceof HttpResponseException
|
||||
&& ((HttpResponseException) input).getResponse() != null;
|
||||
|
||||
notAvailable |= input instanceof ResourceNotFoundException;
|
||||
|
||||
return notAvailable;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Predicate<Throwable> hasResponse(final Throwable exception) {
|
||||
return new Predicate<Throwable>() {
|
||||
@Override
|
||||
public boolean apply(final Throwable input) {
|
||||
return input instanceof HttpResponseException && ((HttpResponseException) input).getResponse() != null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
|
||||
/**
|
||||
* Appends the parameter value to the end of the request URI.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class AppendToPath implements Binder {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
// Append the parameter to the request URI
|
||||
String valueToAppend = getValue(request, checkNotNull(input, "input"));
|
||||
URI path = URI.create(request.getEndpoint().toString() + "/" + valueToAppend);
|
||||
return (R) request.toBuilder().endpoint(path).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value that will be appended to the request URI.
|
||||
*/
|
||||
protected <R extends HttpRequest> String getValue(final R request, final Object input) {
|
||||
return input.toString();
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
|
||||
/**
|
||||
* Binds the given link to the uri.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
@Singleton
|
||||
public class BindLinkToPath extends BindToPath {
|
||||
|
||||
@Override
|
||||
protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof RESTLink, "this binder is only valid for RESTLink objects");
|
||||
|
||||
return ((RESTLink) input).getHref();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
/**
|
||||
* Binds the given link to the uri and the Accept header.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindLinkToPathAndAcceptHeader extends BindLinkToPath {
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
R updatedRequest = super.bindToRequest(request, input);
|
||||
return addHeader(updatedRequest, HttpHeaders.ACCEPT, ((RESTLink) input).getType());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@VisibleForTesting
|
||||
<R extends HttpRequest> R addHeader(final R request, final String header, final String value) {
|
||||
return (R) request.toBuilder().replaceHeader(HttpHeaders.ACCEPT, checkNotNull(value, "value")).build();
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToXMLPayload;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.LinksDto;
|
||||
import com.abiquo.model.transport.SingleResourceTransportDto;
|
||||
|
||||
/**
|
||||
* Bind multiple objects to the payload of the request as a list of links.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public abstract class BindRefsToPayload extends BindToXMLPayload {
|
||||
@Inject
|
||||
public BindRefsToPayload(final XMLParser xmlParser) {
|
||||
super(xmlParser);
|
||||
}
|
||||
|
||||
protected abstract String getRelToUse(final Object input);
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof SingleResourceTransportDto[],
|
||||
"this binder is only valid for SingleResourceTransportDto arrays");
|
||||
|
||||
SingleResourceTransportDto[] dtos = (SingleResourceTransportDto[]) input;
|
||||
LinksDto refs = new LinksDto();
|
||||
|
||||
for (SingleResourceTransportDto dto : dtos) {
|
||||
RESTLink editLink = checkNotNull(dto.getEditLink(), "entity must have an edit link");
|
||||
|
||||
// Do not add repeated references
|
||||
if (refs.searchLinkByHref(editLink.getHref()) == null) {
|
||||
refs.addLink(new RESTLink(getRelToUse(input), editLink.getHref()));
|
||||
}
|
||||
}
|
||||
|
||||
return super.bindToRequest(request, refs);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.rest.annotations.EndpointLink;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.rest.binders.BindException;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.SingleResourceTransportDto;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Binds the given object to the path..
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindToPath implements Binder {
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests");
|
||||
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
|
||||
checkState(gRequest.getInvocation().getArgs() != null, "args should be initialized at this point");
|
||||
|
||||
// Update the request URI with the configured link URI
|
||||
String newEndpoint = getNewEndpoint(gRequest, input);
|
||||
return bindToPath(request, newEndpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the new endpoint to use.
|
||||
*
|
||||
* @param gRequest
|
||||
* The request.
|
||||
* @param input
|
||||
* The input parameter.
|
||||
* @return The new endpoint to use.
|
||||
*/
|
||||
protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) {
|
||||
SingleResourceTransportDto dto = checkValidInput(input);
|
||||
return getLinkToUse(gRequest, dto).getHref();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link to be used to build the request URI.
|
||||
*
|
||||
* @param request
|
||||
* The current request.
|
||||
* @param payload
|
||||
* The object containing the link.
|
||||
* @return The link to be used to build the request URI.
|
||||
*/
|
||||
static RESTLink getLinkToUse(final GeneratedHttpRequest request, final SingleResourceTransportDto payload) {
|
||||
int argIndex = request.getInvocation().getArgs().indexOf(payload);
|
||||
Annotation[] annotations = request.getInvocation().getInvokable().getParameters().get(argIndex).getAnnotations();
|
||||
|
||||
EndpointLink linkName = (EndpointLink) Iterables.find(Arrays.asList(annotations),
|
||||
Predicates.instanceOf(EndpointLink.class), null);
|
||||
|
||||
if (linkName == null) {
|
||||
throw new BindException(request, "Expected a EndpointLink annotation but not found in the parameter");
|
||||
}
|
||||
|
||||
return checkNotNull(payload.searchLink(linkName.value()), "No link was found in object with rel: " + linkName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the given link to the request URI.
|
||||
*
|
||||
* @param request
|
||||
* The request to modify.
|
||||
* @param endpoint
|
||||
* The endpoint to use as the request URI.
|
||||
* @return The updated request.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static <R extends HttpRequest> R bindToPath(final R request, final String endpoint) {
|
||||
// Preserve current query parameters
|
||||
String newEndpoint = endpoint + getParameterString(request);
|
||||
|
||||
// Replace the URI with the edit link in the DTO
|
||||
URI path = URI.create(newEndpoint);
|
||||
return (R) request.toBuilder().endpoint(path).build();
|
||||
}
|
||||
|
||||
protected static SingleResourceTransportDto checkValidInput(final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof SingleResourceTransportDto,
|
||||
"this binder is only valid for SingleResourceTransportDto objects");
|
||||
|
||||
return (SingleResourceTransportDto) input;
|
||||
}
|
||||
|
||||
protected static <R extends HttpRequest> String getParameterString(final R request) {
|
||||
String endpoint = request.getEndpoint().toString();
|
||||
|
||||
int query = endpoint.indexOf('?');
|
||||
|
||||
if (query == -1) {
|
||||
// No parameters
|
||||
return "";
|
||||
} else {
|
||||
// Only request parameters
|
||||
return endpoint.substring(query);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToXMLPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.abiquo.model.transport.SingleResourceTransportDto;
|
||||
|
||||
/**
|
||||
* Binds the given object to the payload and extracts the path parameters from
|
||||
* the edit link.
|
||||
* <p>
|
||||
* This method should be used in {@link PUT} methods to automatically extract
|
||||
* the path parameters from the edit link of the updated object.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindToXMLPayloadAndPath extends BindToXMLPayload {
|
||||
@Inject
|
||||
public BindToXMLPayloadAndPath(final XMLParser xmlParser) {
|
||||
super(xmlParser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object payload) {
|
||||
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests");
|
||||
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
|
||||
checkState(gRequest.getInvocation().getArgs() != null, "args should be initialized at this point");
|
||||
|
||||
// Update the request URI with the configured link URI
|
||||
String newEndpoint = getNewEndpoint(gRequest, payload);
|
||||
R updatedRequest = BindToPath.bindToPath(request, newEndpoint);
|
||||
|
||||
// Add the payload
|
||||
return super.bindToRequest(updatedRequest, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the new endpoint to use.
|
||||
*
|
||||
* @param gRequest
|
||||
* The request.
|
||||
* @param input
|
||||
* The input parameter.
|
||||
* @return The new endpoint to use.
|
||||
*/
|
||||
protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) {
|
||||
SingleResourceTransportDto dto = BindToPath.checkValidInput(input);
|
||||
return BindToPath.getLinkToUse(gRequest, dto).getHref();
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.cloud;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.binders.BindRefsToPayload;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
/**
|
||||
* Bind multiple {@link DiskManagementDto} objects to the payload of the request
|
||||
* as a list of links.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindHardDiskRefsToPayload extends BindRefsToPayload {
|
||||
@Inject
|
||||
public BindHardDiskRefsToPayload(final XMLParser xmlParser) {
|
||||
super(xmlParser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRelToUse(final Object input) {
|
||||
return "disk";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToXMLPayload;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.LinksDto;
|
||||
import com.abiquo.server.core.infrastructure.network.AbstractIpDto;
|
||||
|
||||
/**
|
||||
* Bind the link reference to an {@link AbstractIpDto} object into the payload.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindIpRefToPayload extends BindToXMLPayload {
|
||||
@Inject
|
||||
public BindIpRefToPayload(final XMLParser xmlParser) {
|
||||
super(xmlParser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof AbstractIpDto,
|
||||
"this binder is only valid for AbstractIpDto objects");
|
||||
|
||||
AbstractIpDto ip = (AbstractIpDto) input;
|
||||
RESTLink selfLink = checkNotNull(ip.searchLink("self"), "AbstractIpDto must have an self link");
|
||||
|
||||
LinksDto refs = new LinksDto();
|
||||
refs.addLink(new RESTLink(selfLink.getTitle(), selfLink.getHref()));
|
||||
|
||||
return super.bindToRequest(request, refs);
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.domain.util.LinkUtils;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToXMLPayload;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.LinksDto;
|
||||
import com.abiquo.server.core.infrastructure.network.AbstractIpDto;
|
||||
|
||||
/**
|
||||
* Bind the link reference to an {@link AbstractIpDto} object into the payload.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindIpRefsToPayload extends BindToXMLPayload {
|
||||
@Inject
|
||||
public BindIpRefsToPayload(final XMLParser xmlParser) {
|
||||
super(xmlParser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof AbstractIpDto[],
|
||||
"this binder is only valid for AbstractIpDto arrays");
|
||||
|
||||
AbstractIpDto[] ips = (AbstractIpDto[]) input;
|
||||
LinksDto refs = new LinksDto();
|
||||
|
||||
for (AbstractIpDto ip : ips) {
|
||||
RESTLink selfLink = checkNotNull(LinkUtils.getSelfLink(ip), "AbstractIpDto must have an edit or self link");
|
||||
if (refs.searchLinkByHref(selfLink.getHref()) == null) {
|
||||
RESTLink ref = new RESTLink(selfLink.getTitle(), selfLink.getHref());
|
||||
ref.setType(selfLink.getType());
|
||||
refs.addLink(ref);
|
||||
}
|
||||
}
|
||||
|
||||
return super.bindToRequest(request, refs);
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.abiquo.binders.BindToPath;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto;
|
||||
|
||||
/**
|
||||
* Binds the move volume action to the request endpoint.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class BindMoveVolumeToPath extends BindToPath {
|
||||
|
||||
@Override
|
||||
protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof VolumeManagementDto,
|
||||
"this binder is only valid for VolumeManagementDto objects");
|
||||
|
||||
VolumeManagementDto volume = (VolumeManagementDto) input;
|
||||
RESTLink editLink = checkNotNull(volume.getEditLink(), "VolumeManagementDto must have an edit link");
|
||||
|
||||
return editLink.getHref() + "/action/move";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToXMLPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.LinksDto;
|
||||
import com.abiquo.server.core.cloud.VirtualMachineDto;
|
||||
import com.abiquo.server.core.infrastructure.network.VLANNetworkDto;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Bind multiple objects to the payload of the request as a list of links.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindNetworkConfigurationRefToPayload extends BindToXMLPayload {
|
||||
@Inject
|
||||
public BindNetworkConfigurationRefToPayload(final XMLParser xmlParser) {
|
||||
super(xmlParser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests");
|
||||
checkArgument(checkNotNull(input, "input") instanceof VLANNetworkDto,
|
||||
"this binder is only valid for VLANNetworkDto");
|
||||
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
|
||||
checkState(gRequest.getInvocation().getArgs() != null, "args should be initialized at this point");
|
||||
|
||||
VLANNetworkDto network = (VLANNetworkDto) input;
|
||||
VirtualMachineDto vm = (VirtualMachineDto) Iterables.find(gRequest.getInvocation().getArgs(),
|
||||
Predicates.instanceOf(VirtualMachineDto.class));
|
||||
|
||||
RESTLink configLink = checkNotNull(vm.searchLink("configurations"), "missing required link");
|
||||
|
||||
LinksDto dto = new LinksDto();
|
||||
dto.addLink(new RESTLink("network_configuration", configLink.getHref() + "/" + network.getId()));
|
||||
|
||||
return super.bindToRequest(request, dto);
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToXMLPayload;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.LinksDto;
|
||||
import com.abiquo.server.core.infrastructure.network.VLANNetworkDto;
|
||||
|
||||
/**
|
||||
* Bind the link reference to an {@link VLANNetworkDto} object into the payload.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindNetworkRefToPayload extends BindToXMLPayload {
|
||||
@Inject
|
||||
public BindNetworkRefToPayload(final XMLParser xmlParser) {
|
||||
super(xmlParser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof VLANNetworkDto,
|
||||
"this binder is only valid for VLANNetworkDto objects");
|
||||
|
||||
VLANNetworkDto network = (VLANNetworkDto) input;
|
||||
RESTLink editLink = checkNotNull(network.getEditLink(), "VLANNetworkDto must have an edit link");
|
||||
|
||||
LinksDto refs = new LinksDto();
|
||||
switch (network.getType()) {
|
||||
case INTERNAL:
|
||||
refs.addLink(new RESTLink("internalnetwork", editLink.getHref()));
|
||||
break;
|
||||
case EXTERNAL:
|
||||
refs.addLink(new RESTLink("externalnetwork", editLink.getHref()));
|
||||
break;
|
||||
case PUBLIC:
|
||||
refs.addLink(new RESTLink("publicnetwork", editLink.getHref()));
|
||||
break;
|
||||
case UNMANAGED:
|
||||
refs.addLink(new RESTLink("unmanagednetwork", editLink.getHref()));
|
||||
break;
|
||||
default:
|
||||
// TODO: EXTERNAL_UNMANAGED network type
|
||||
throw new IllegalArgumentException("Unsupported network type");
|
||||
}
|
||||
|
||||
return super.bindToRequest(request, refs);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToXMLPayload;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.abiquo.model.enumerator.NetworkType;
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.LinksDto;
|
||||
import com.abiquo.server.core.infrastructure.network.VLANNetworkDto;
|
||||
|
||||
/**
|
||||
* Bind the link reference to an {@link AbstractIpDto} object into the payload.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindUnmanagedIpRefToPayload extends BindToXMLPayload {
|
||||
@Inject
|
||||
public BindUnmanagedIpRefToPayload(final XMLParser xmlParser) {
|
||||
super(xmlParser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof VLANNetworkDto,
|
||||
"this binder is only valid for VLANNetworkDto objects");
|
||||
|
||||
VLANNetworkDto network = (VLANNetworkDto) input;
|
||||
checkArgument(network.getType() == NetworkType.UNMANAGED, "this binder is only valid for UNMANAGED networks");
|
||||
|
||||
RESTLink ipsLink = checkNotNull(network.searchLink("ips"), "VLANNetworkDto must have an ips link");
|
||||
|
||||
LinksDto refs = new LinksDto();
|
||||
refs.addLink(new RESTLink("unmanagedip", ipsLink.getHref()));
|
||||
|
||||
return super.bindToRequest(request, refs);
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToXMLPayload;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.LinksDto;
|
||||
import com.abiquo.server.core.cloud.VirtualDatacenterDto;
|
||||
|
||||
/**
|
||||
* Bind multiple {@link VolumeManagementDto} objects to the payload of the
|
||||
* request as a list of links.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindVirtualDatacenterRefToPayload extends BindToXMLPayload {
|
||||
@Inject
|
||||
public BindVirtualDatacenterRefToPayload(final XMLParser xmlParser) {
|
||||
super(xmlParser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof VirtualDatacenterDto,
|
||||
"this binder is only valid for VirtualDatacenterDto objects");
|
||||
|
||||
VirtualDatacenterDto vdc = (VirtualDatacenterDto) input;
|
||||
RESTLink editLink = checkNotNull(vdc.getEditLink(), "VirtualDatacenterDto must have an edit link");
|
||||
LinksDto refs = new LinksDto();
|
||||
refs.addLink(new RESTLink("virtualdatacenter", editLink.getHref()));
|
||||
|
||||
return super.bindToRequest(request, refs);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.cloud;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.binders.BindRefsToPayload;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
/**
|
||||
* Bind multiple {@link VolumeManagementDto} objects to the payload of the
|
||||
* request as a list of links.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindVolumeRefsToPayload extends BindRefsToPayload {
|
||||
@Inject
|
||||
public BindVolumeRefsToPayload(final XMLParser xmlParser) {
|
||||
super(xmlParser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRelToUse(final Object input) {
|
||||
return "volume";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.infrastructure;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.binders.AppendToPath;
|
||||
import org.jclouds.abiquo.functions.infrastructure.ParseMachineId;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
|
||||
/**
|
||||
* Append the {@link Machine} id to the request URI.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class AppendMachineIdToPath extends AppendToPath {
|
||||
private ParseMachineId parser;
|
||||
|
||||
@Inject
|
||||
public AppendMachineIdToPath(final ParseMachineId parser) {
|
||||
super();
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <R extends HttpRequest> String getValue(final R request, final Object input) {
|
||||
return parser.apply(input);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.infrastructure;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.binders.AppendToPath;
|
||||
import org.jclouds.abiquo.functions.infrastructure.ParseRemoteServiceType;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
|
||||
/**
|
||||
* Append the {@link RemoteServiceType} service to the request URI.
|
||||
* <p>
|
||||
* This method assumes that the input object is a {@link RemoteServiceType}
|
||||
* enumeration.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class AppendRemoteServiceTypeToPath extends AppendToPath {
|
||||
private ParseRemoteServiceType parser;
|
||||
|
||||
@Inject
|
||||
public AppendRemoteServiceTypeToPath(final ParseRemoteServiceType parser) {
|
||||
super();
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <R extends HttpRequest> String getValue(final R request, final Object input) {
|
||||
return parser.apply(input);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.infrastructure;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.binders.BindToPath;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
/**
|
||||
* Binds the given link to the uri appends the supported devices action path.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindSupportedDevicesLinkToPath extends BindToPath {
|
||||
|
||||
@Override
|
||||
protected String getNewEndpoint(final GeneratedHttpRequest gRequest, final Object input) {
|
||||
return super.getNewEndpoint(gRequest, input) + "/action/supported";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.infrastructure.ucs;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.LogicServerDto;
|
||||
|
||||
/**
|
||||
* Binds logic server query parameters to request. This method assumes that the
|
||||
* input object is a {@link LogicServerDto}.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindLogicServerParameters implements Binder {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof LogicServerDto,
|
||||
"this binder is only valid for LogicServerDto objects");
|
||||
|
||||
LogicServerDto server = (LogicServerDto) input;
|
||||
|
||||
return (R) request.toBuilder().addQueryParam("lsName", checkNotNull(server.getName(), "server.name")).build();
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.binders.infrastructure.ucs;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.OrganizationDto;
|
||||
|
||||
/**
|
||||
* Binds organization query parameters to request. This method assumes that the
|
||||
* input object is a {@link OrganizationDto}.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindOrganizationParameters implements Binder {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof OrganizationDto,
|
||||
"this binder is only valid for OrganizationDto objects");
|
||||
|
||||
OrganizationDto org = (OrganizationDto) input;
|
||||
|
||||
return (R) request.toBuilder().addQueryParam("org", checkNotNull(org.getDn(), "org.dn")).build();
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.compute.config;
|
||||
|
||||
import org.jclouds.abiquo.compute.functions.DatacenterToLocation;
|
||||
import org.jclouds.abiquo.compute.functions.VirtualDatacenterToLocation;
|
||||
import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateToImage;
|
||||
import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateInVirtualDatacenterToHardware;
|
||||
import org.jclouds.abiquo.compute.functions.VirtualMachineToNodeMetadata;
|
||||
import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions;
|
||||
import org.jclouds.abiquo.compute.strategy.AbiquoComputeServiceAdapter;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
|
||||
import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Abiquo Compute service configuration module.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class AbiquoComputeServiceContextModule
|
||||
extends
|
||||
ComputeServiceAdapterContextModule<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter> {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(
|
||||
new TypeLiteral<ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>>() {
|
||||
}).to(AbiquoComputeServiceAdapter.class);
|
||||
bind(new TypeLiteral<Function<VirtualMachine, NodeMetadata>>() {
|
||||
}).to(VirtualMachineToNodeMetadata.class);
|
||||
bind(new TypeLiteral<Function<VirtualMachineTemplate, Image>>() {
|
||||
}).to(VirtualMachineTemplateToImage.class);
|
||||
bind(new TypeLiteral<Function<VirtualMachineTemplateInVirtualDatacenter, Hardware>>() {
|
||||
}).to(VirtualMachineTemplateInVirtualDatacenterToHardware.class);
|
||||
bind(new TypeLiteral<Function<Datacenter, Location>>() {
|
||||
}).to(DatacenterToLocation.class);
|
||||
bind(new TypeLiteral<Function<VirtualDatacenter, Location>>() {
|
||||
}).to(VirtualDatacenterToLocation.class);
|
||||
bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON);
|
||||
bind(TemplateOptions.class).to(AbiquoTemplateOptions.class);
|
||||
install(new LocationsFromComputeServiceAdapterModule<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>() {
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.compute.functions;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Converts a {@link Datacenter} to a {@link Location} one.
|
||||
* <p>
|
||||
* Physical datacenters will be considered regions.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class DatacenterToLocation implements Function<Datacenter, Location> {
|
||||
|
||||
@Override
|
||||
public Location apply(final Datacenter datacenter) {
|
||||
LocationBuilder builder = new LocationBuilder();
|
||||
builder.id(datacenter.getId().toString());
|
||||
builder.description(datacenter.getName() + " [" + datacenter.getLocation() + "]");
|
||||
builder.metadata(ImmutableMap.<String, Object> of());
|
||||
builder.scope(LocationScope.REGION);
|
||||
builder.iso3166Codes(ImmutableSet.<String> of());
|
||||
|
||||
builder.parent(new LocationBuilder().scope(LocationScope.PROVIDER).id("abiquo").description("abiquo").build());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Converts a {@link VirtualDatacenter} to a {@link Location} one.
|
||||
* <p>
|
||||
* Virtual datacenters will be considered zones, since images will be deployed
|
||||
* in a virtual datacenter. Each zone will be scoped into a physical datacenter
|
||||
* (region).
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class VirtualDatacenterToLocation implements Function<VirtualDatacenter, Location> {
|
||||
private final Function<Datacenter, Location> datacenterToLocation;
|
||||
|
||||
private final Supplier<Map<Integer, Datacenter>> regionMap;
|
||||
|
||||
@Inject
|
||||
public VirtualDatacenterToLocation(final Function<Datacenter, Location> datacenterToLocation,
|
||||
@Memoized final Supplier<Map<Integer, Datacenter>> regionMap) {
|
||||
this.datacenterToLocation = checkNotNull(datacenterToLocation, "datacenterToLocation");
|
||||
this.regionMap = checkNotNull(regionMap, "regionMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location apply(final VirtualDatacenter vdc) {
|
||||
LocationBuilder builder = new LocationBuilder();
|
||||
builder.id(vdc.getId().toString());
|
||||
builder.description(vdc.getName());
|
||||
builder.metadata(ImmutableMap.<String, Object> of());
|
||||
builder.scope(LocationScope.ZONE);
|
||||
builder.iso3166Codes(ImmutableSet.<String> of());
|
||||
|
||||
Datacenter parent = regionMap.get().get(vdc.unwrap().getIdFromLink(ParentLinkName.DATACENTER));
|
||||
builder.parent(datacenterToLocation.apply(parent));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.compute.functions;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata.Status;
|
||||
|
||||
import com.abiquo.server.core.cloud.VirtualMachineState;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Converts a {@link VirtualMachineState} object to a {@link Status} one.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class VirtualMachineStateToNodeState implements Function<VirtualMachineState, Status> {
|
||||
|
||||
@Override
|
||||
public Status apply(final VirtualMachineState state) {
|
||||
switch (state) {
|
||||
case ALLOCATED:
|
||||
case LOCKED:
|
||||
case CONFIGURED:
|
||||
case NOT_ALLOCATED:
|
||||
return Status.PENDING;
|
||||
case ON:
|
||||
return Status.RUNNING;
|
||||
case OFF:
|
||||
case PAUSED:
|
||||
return Status.SUSPENDED;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
return Status.UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.Volume;
|
||||
import org.jclouds.compute.domain.VolumeBuilder;
|
||||
import org.jclouds.compute.predicates.ImagePredicates;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Transforms a {@link VirtualMachineTemplate} into an {@link Hardware}.
|
||||
* <p>
|
||||
* Each {@link Image} ({@link VirtualMachineTemplate}) will have one
|
||||
* {@link Hardware} entity for each zone (scoped to a virtualization technology)
|
||||
* supported by the image.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class VirtualMachineTemplateInVirtualDatacenterToHardware implements
|
||||
Function<VirtualMachineTemplateInVirtualDatacenter, Hardware> {
|
||||
/** The default core speed, 2.0Ghz. */
|
||||
public static final double DEFAULT_CORE_SPEED = 2.0;
|
||||
|
||||
private final Function<VirtualDatacenter, Location> virtualDatacenterToLocation;
|
||||
|
||||
@Inject
|
||||
public VirtualMachineTemplateInVirtualDatacenterToHardware(
|
||||
final Function<VirtualDatacenter, Location> virtualDatacenterToLocation) {
|
||||
this.virtualDatacenterToLocation = checkNotNull(virtualDatacenterToLocation, "virtualDatacenterToLocation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hardware apply(final VirtualMachineTemplateInVirtualDatacenter templateInVirtualDatacenter) {
|
||||
VirtualMachineTemplate template = templateInVirtualDatacenter.getTemplate();
|
||||
VirtualDatacenter virtualDatacenter = templateInVirtualDatacenter.getZone();
|
||||
|
||||
HardwareBuilder builder = new HardwareBuilder();
|
||||
builder.providerId(template.getId().toString());
|
||||
builder.id(template.getId().toString() + "/" + virtualDatacenter.getId());
|
||||
builder.uri(template.getURI());
|
||||
|
||||
builder.name(template.getName());
|
||||
builder.processor(new Processor(template.getCpuRequired(), DEFAULT_CORE_SPEED));
|
||||
builder.ram(template.getRamRequired());
|
||||
|
||||
// Location information
|
||||
builder.location(virtualDatacenterToLocation.apply(virtualDatacenter));
|
||||
builder.hypervisor(virtualDatacenter.getHypervisorType().name());
|
||||
builder.supportsImage(ImagePredicates.idEquals(template.getId().toString()));
|
||||
|
||||
VolumeBuilder volumeBuilder = new VolumeBuilder();
|
||||
volumeBuilder.bootDevice(true);
|
||||
volumeBuilder.size(toGb(template.getHdRequired()));
|
||||
volumeBuilder.type(Volume.Type.LOCAL);
|
||||
volumeBuilder.durable(false);
|
||||
builder.volume(volumeBuilder.build());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static float toGb(final long bytes) {
|
||||
return bytes / (float) (1024 * 1024 * 1024);
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.Image.Status;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* Transforms a {@link VirtualMachineTemplate} into an {@link Image}.
|
||||
* <p>
|
||||
* Images are scoped to a region (physical datacenter).
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class VirtualMachineTemplateToImage implements Function<VirtualMachineTemplate, Image> {
|
||||
private final Function<Datacenter, Location> datacenterToLocation;
|
||||
|
||||
private final Supplier<Map<Integer, Datacenter>> regionMap;
|
||||
|
||||
@Inject
|
||||
public VirtualMachineTemplateToImage(final Function<Datacenter, Location> datacenterToLocation,
|
||||
@Memoized final Supplier<Map<Integer, Datacenter>> regionMap) {
|
||||
this.datacenterToLocation = checkNotNull(datacenterToLocation, "datacenterToLocation");
|
||||
this.regionMap = checkNotNull(regionMap, "regionMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image apply(final VirtualMachineTemplate template) {
|
||||
ImageBuilder builder = new ImageBuilder();
|
||||
builder.ids(template.getId().toString());
|
||||
builder.name(template.getName());
|
||||
builder.description(template.getDescription());
|
||||
|
||||
// Location information
|
||||
Datacenter region = regionMap.get().get(template.unwrap().getIdFromLink(ParentLinkName.DATACENTER));
|
||||
builder.location(datacenterToLocation.apply(region));
|
||||
|
||||
// Only conversions have a status
|
||||
builder.status(Status.AVAILABLE);
|
||||
builder.backendStatus(Status.AVAILABLE.name()); // Abiquo images do not
|
||||
// have a status
|
||||
|
||||
RESTLink downloadLink = template.unwrap().searchLink("diskfile");
|
||||
builder.uri(downloadLink == null ? null : URI.create(downloadLink.getHref()));
|
||||
|
||||
// TODO: Operating system not implemented in Abiquo Templates
|
||||
// TODO: Image credentials still not present in Abiquo template metadata
|
||||
// Will be added in Abiquo 2.4:
|
||||
// http://jira.abiquo.com/browse/ABICLOUDPREMIUM-3647
|
||||
builder.operatingSystem(OperatingSystem.builder().description(template.getName()).build());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.network.Ip;
|
||||
import org.jclouds.abiquo.domain.network.PrivateIp;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.abiquo.server.core.cloud.VirtualMachineState;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* Links a {@link VirtualMachine} object to a {@link NodeMetadata} one.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, NodeMetadata> {
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final VirtualMachineTemplateToImage virtualMachineTemplateToImage;
|
||||
|
||||
private final VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware;
|
||||
|
||||
private final VirtualMachineStateToNodeState virtualMachineStateToNodeState;
|
||||
|
||||
private final Function<VirtualDatacenter, Location> virtualDatacenterToLocation;
|
||||
|
||||
@Inject
|
||||
public VirtualMachineToNodeMetadata(final VirtualMachineTemplateToImage virtualMachineTemplateToImage,
|
||||
final VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware,
|
||||
final VirtualMachineStateToNodeState virtualMachineStateToNodeState,
|
||||
final Function<VirtualDatacenter, Location> virtualDatacenterToLocation) {
|
||||
this.virtualMachineTemplateToImage = checkNotNull(virtualMachineTemplateToImage, "virtualMachineTemplateToImage");
|
||||
this.virtualMachineTemplateToHardware = checkNotNull(virtualMachineTemplateToHardware,
|
||||
"virtualMachineTemplateToHardware");
|
||||
this.virtualMachineStateToNodeState = checkNotNull(virtualMachineStateToNodeState,
|
||||
"virtualMachineStateToNodeState");
|
||||
this.virtualDatacenterToLocation = checkNotNull(virtualDatacenterToLocation, "virtualDatacenterToLocation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata apply(final VirtualMachine vm) {
|
||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||
builder.ids(vm.getId().toString());
|
||||
builder.uri(vm.getURI());
|
||||
builder.name(vm.getNameLabel());
|
||||
builder.group(vm.getVirtualAppliance().getName());
|
||||
|
||||
// TODO: Node credentials still not present in Abiquo template metadata
|
||||
// Will be added in Abiquo 2.4:
|
||||
// http://jira.abiquo.com/browse/ABICLOUDPREMIUM-3647
|
||||
|
||||
// Location details
|
||||
VirtualDatacenter vdc = vm.getVirtualDatacenter();
|
||||
builder.location(virtualDatacenterToLocation.apply(vdc));
|
||||
|
||||
// Image details
|
||||
VirtualMachineTemplate template = vm.getTemplate();
|
||||
Image image = virtualMachineTemplateToImage.apply(template);
|
||||
builder.imageId(image.getId().toString());
|
||||
builder.operatingSystem(image.getOperatingSystem());
|
||||
|
||||
// Hardware details
|
||||
Hardware defaultHardware = virtualMachineTemplateToHardware.apply(new VirtualMachineTemplateInVirtualDatacenter(
|
||||
template, vdc));
|
||||
|
||||
Hardware hardware = HardwareBuilder
|
||||
.fromHardware(defaultHardware)
|
||||
.ram(vm.getRam())
|
||||
.processors(
|
||||
Lists.newArrayList(new Processor(vm.getCpu(),
|
||||
VirtualMachineTemplateInVirtualDatacenterToHardware.DEFAULT_CORE_SPEED))) //
|
||||
.build();
|
||||
|
||||
builder.hardware(hardware);
|
||||
|
||||
// Networking configuration
|
||||
List<Ip<?, ?>> nics = vm.listAttachedNics();
|
||||
builder.privateAddresses(ips(filter(nics, Predicates.instanceOf(PrivateIp.class))));
|
||||
builder.publicAddresses(ips(filter(nics, Predicates.not(Predicates.instanceOf(PrivateIp.class)))));
|
||||
|
||||
// Node state
|
||||
VirtualMachineState state = vm.getState();
|
||||
builder.status(virtualMachineStateToNodeState.apply(state));
|
||||
builder.backendStatus(state.name());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static Iterable<String> ips(final Iterable<Ip<?, ?>> nics) {
|
||||
return transform(nics, new Function<Ip<?, ?>, String>() {
|
||||
@Override
|
||||
public String apply(final Ip<?, ?> nic) {
|
||||
return nic.getIp();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.compute.options;
|
||||
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
|
||||
/**
|
||||
* Contains options supported by the
|
||||
* {@link ComputeService#createNodesInGroup(String, int, TemplateOptions)} and
|
||||
* {@link ComputeService#createNodesInGroup(String, int, TemplateOptions)}
|
||||
* operations on the <em>Abiquo</em> provider.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class AbiquoTemplateOptions extends TemplateOptions implements Cloneable {
|
||||
public static final AbiquoTemplateOptions NONE = new AbiquoTemplateOptions();
|
||||
|
||||
private Integer overrideCores;
|
||||
|
||||
private Integer overrideRam;
|
||||
|
||||
private String vncPassword;
|
||||
|
||||
@Override
|
||||
public TemplateOptions clone() {
|
||||
AbiquoTemplateOptions options = new AbiquoTemplateOptions();
|
||||
copyTo(options);
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyTo(final TemplateOptions to) {
|
||||
super.copyTo(to);
|
||||
if (to instanceof AbiquoTemplateOptions) {
|
||||
AbiquoTemplateOptions options = AbiquoTemplateOptions.class.cast(to);
|
||||
options.overrideCores(overrideCores);
|
||||
options.overrideRam(overrideRam);
|
||||
options.vncPassword(vncPassword);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the number of cores set by the hardware profile.
|
||||
*
|
||||
* @return The template options with the number of cores.
|
||||
*/
|
||||
public AbiquoTemplateOptions overrideCores(final Integer overrideCores) {
|
||||
this.overrideCores = overrideCores;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getOverrideCores() {
|
||||
return overrideCores;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the amount of ram set by the hardware profile.
|
||||
*
|
||||
* @return The template options with the amount of ram.
|
||||
*/
|
||||
public AbiquoTemplateOptions overrideRam(final Integer overrideRam) {
|
||||
this.overrideRam = overrideRam;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getOverrideRam() {
|
||||
return overrideRam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the VNC password to access the virtual machine.
|
||||
* <p>
|
||||
* By default virtual machines does not have VNC access password protected.
|
||||
*
|
||||
* @return The template options with the VNC password.
|
||||
*/
|
||||
public AbiquoTemplateOptions vncPassword(final String vncPassword) {
|
||||
this.vncPassword = vncPassword;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getVncPassword() {
|
||||
return vncPassword;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
/**
|
||||
* @see AbiquoTemplateOptions#overrideCores(int)
|
||||
*/
|
||||
public static AbiquoTemplateOptions overrideCores(final Integer overrideCores) {
|
||||
AbiquoTemplateOptions options = new AbiquoTemplateOptions();
|
||||
return options.overrideCores(overrideCores);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbiquoTemplateOptions#overrideRam(int)
|
||||
*/
|
||||
public static AbiquoTemplateOptions overrideRam(final Integer overrideRam) {
|
||||
AbiquoTemplateOptions options = new AbiquoTemplateOptions();
|
||||
return options.overrideRam(overrideRam);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbiquoTemplateOptions#vncPassword(String)
|
||||
*/
|
||||
public static AbiquoTemplateOptions vncPassword(final String vncPassword) {
|
||||
AbiquoTemplateOptions options = new AbiquoTemplateOptions();
|
||||
return options.vncPassword(vncPassword);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,259 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.concat;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.enterprise.Enterprise;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.domain.network.PublicIp;
|
||||
import org.jclouds.abiquo.features.services.AdministrationService;
|
||||
import org.jclouds.abiquo.features.services.CloudService;
|
||||
import org.jclouds.abiquo.features.services.MonitoringService;
|
||||
import org.jclouds.abiquo.monitor.VirtualMachineMonitor;
|
||||
import org.jclouds.abiquo.predicates.cloud.VirtualAppliancePredicates;
|
||||
import org.jclouds.abiquo.predicates.cloud.VirtualMachineTemplatePredicates;
|
||||
import org.jclouds.abiquo.predicates.network.IpPredicates;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.cloud.VirtualMachineState;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Defines the connection between the {@link AbiquoApi} implementation and the
|
||||
* jclouds {@link ComputeService}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class AbiquoComputeServiceAdapter
|
||||
implements
|
||||
ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter> {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private final AdministrationService adminService;
|
||||
|
||||
private final CloudService cloudService;
|
||||
|
||||
private final MonitoringService monitoringService;
|
||||
|
||||
private final FindCompatibleVirtualDatacenters compatibleVirtualDatacenters;
|
||||
|
||||
private final Supplier<Map<Integer, Datacenter>> regionMap;
|
||||
|
||||
@Inject
|
||||
public AbiquoComputeServiceAdapter(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final AdministrationService adminService, final CloudService cloudService,
|
||||
final MonitoringService monitoringService,
|
||||
final FindCompatibleVirtualDatacenters compatibleVirtualDatacenters,
|
||||
@Memoized final Supplier<Map<Integer, Datacenter>> regionMap) {
|
||||
this.context = checkNotNull(context, "context");
|
||||
this.adminService = checkNotNull(adminService, "adminService");
|
||||
this.cloudService = checkNotNull(cloudService, "cloudService");
|
||||
this.monitoringService = checkNotNull(monitoringService, "monitoringService");
|
||||
this.compatibleVirtualDatacenters = checkNotNull(compatibleVirtualDatacenters, "compatibleVirtualDatacenters");
|
||||
this.regionMap = checkNotNull(regionMap, "regionMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeAndInitialCredentials<VirtualMachine> createNodeWithGroupEncodedIntoName(final String tag,
|
||||
final String name, final Template template) {
|
||||
AbiquoTemplateOptions options = template.getOptions().as(AbiquoTemplateOptions.class);
|
||||
Enterprise enterprise = adminService.getCurrentEnterprise();
|
||||
|
||||
// Get the region where the template is available
|
||||
Datacenter datacenter = regionMap.get().get(Integer.valueOf(template.getImage().getLocation().getId()));
|
||||
|
||||
// Load the template
|
||||
VirtualMachineTemplate virtualMachineTemplate = enterprise.getTemplateInRepository(datacenter,
|
||||
Integer.valueOf(template.getImage().getId()));
|
||||
|
||||
// Get the zone where the template will be deployed
|
||||
VirtualDatacenter vdc = cloudService.getVirtualDatacenter(Integer.valueOf(template.getHardware().getLocation()
|
||||
.getId()));
|
||||
|
||||
// Load the virtual appliance or create it if it does not exist
|
||||
VirtualAppliance vapp = vdc.findVirtualAppliance(VirtualAppliancePredicates.name(tag));
|
||||
if (vapp == null) {
|
||||
vapp = VirtualAppliance.builder(context, vdc).name(tag).build();
|
||||
vapp.save();
|
||||
}
|
||||
|
||||
Integer overrideCores = options.getOverrideCores();
|
||||
Integer overrideRam = options.getOverrideRam();
|
||||
|
||||
VirtualMachine vm = VirtualMachine.builder(context, vapp, virtualMachineTemplate) //
|
||||
.nameLabel(name) //
|
||||
.cpu(overrideCores != null ? overrideCores : totalCores(template.getHardware())) //
|
||||
.ram(overrideRam != null ? overrideRam : template.getHardware().getRam()) //
|
||||
.password(options.getVncPassword()) // Can be null
|
||||
.build();
|
||||
|
||||
vm.save();
|
||||
|
||||
// Once the virtual machine is created, override the default network
|
||||
// settings if needed
|
||||
// If no public ip is available in the virtual datacenter, the virtual
|
||||
// machine will be assigned by default an ip address in the default
|
||||
// private VLAN for the virtual datacenter
|
||||
PublicIp publicIp = vdc.findPurchasedPublicIp(IpPredicates.<PublicIp> notUsed());
|
||||
if (publicIp != null) {
|
||||
List<PublicIp> ips = Lists.newArrayList();
|
||||
ips.add(publicIp);
|
||||
vm.setNics(ips);
|
||||
}
|
||||
|
||||
// This is an async operation, but jclouds already waits until the node is
|
||||
// RUNNING, so there is no need to block here
|
||||
vm.deploy();
|
||||
|
||||
return new NodeAndInitialCredentials<VirtualMachine>(vm, vm.getId().toString(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<VirtualMachineTemplateInVirtualDatacenter> listHardwareProfiles() {
|
||||
// In Abiquo, images are scoped to a region (physical datacenter), and
|
||||
// hardware profiles are scoped to a zone (a virtual datacenter in the
|
||||
// region, with a concrete virtualization technology)
|
||||
|
||||
return concat(transform(listImages(),
|
||||
new Function<VirtualMachineTemplate, Iterable<VirtualMachineTemplateInVirtualDatacenter>>() {
|
||||
@Override
|
||||
public Iterable<VirtualMachineTemplateInVirtualDatacenter> apply(final VirtualMachineTemplate template) {
|
||||
Iterable<VirtualDatacenter> compatibleZones = compatibleVirtualDatacenters.execute(template);
|
||||
|
||||
return transform(compatibleZones,
|
||||
new Function<VirtualDatacenter, VirtualMachineTemplateInVirtualDatacenter>() {
|
||||
@Override
|
||||
public VirtualMachineTemplateInVirtualDatacenter apply(final VirtualDatacenter vdc) {
|
||||
return new VirtualMachineTemplateInVirtualDatacenter(template, vdc);
|
||||
}
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<VirtualMachineTemplate> listImages() {
|
||||
Enterprise enterprise = adminService.getCurrentEnterprise();
|
||||
return enterprise.listTemplates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualMachineTemplate getImage(final String id) {
|
||||
Enterprise enterprise = adminService.getCurrentEnterprise();
|
||||
return enterprise.findTemplate(VirtualMachineTemplatePredicates.id(Integer.valueOf(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<VirtualDatacenter> listLocations() {
|
||||
return cloudService.listVirtualDatacenters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualMachine getNode(final String id) {
|
||||
return cloudService.findVirtualMachine(vmId(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyNode(final String id) {
|
||||
VirtualMachine vm = getNode(id);
|
||||
vm.delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebootNode(final String id) {
|
||||
VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor();
|
||||
VirtualMachine vm = getNode(id);
|
||||
vm.reboot();
|
||||
monitor.awaitState(VirtualMachineState.ON, vm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeNode(final String id) {
|
||||
VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor();
|
||||
VirtualMachine vm = getNode(id);
|
||||
vm.changeState(VirtualMachineState.ON);
|
||||
monitor.awaitState(VirtualMachineState.ON, vm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suspendNode(final String id) {
|
||||
VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor();
|
||||
VirtualMachine vm = getNode(id);
|
||||
vm.changeState(VirtualMachineState.PAUSED);
|
||||
monitor.awaitState(VirtualMachineState.PAUSED, vm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<VirtualMachine> listNodes() {
|
||||
return cloudService.listVirtualMachines();
|
||||
}
|
||||
|
||||
private static Predicate<VirtualMachine> vmId(final String id) {
|
||||
return new Predicate<VirtualMachine>() {
|
||||
@Override
|
||||
public boolean apply(final VirtualMachine input) {
|
||||
return Integer.valueOf(id).equals(input.getId());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static int totalCores(final Hardware hardware) {
|
||||
double cores = 0;
|
||||
for (Processor processor : hardware.getProcessors()) {
|
||||
cores += processor.getCores();
|
||||
}
|
||||
return Double.valueOf(cores).intValue();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.compute.strategy;
|
||||
|
||||
import org.jclouds.abiquo.compute.strategy.internal.FindCompatibleVirtualDatacentersForImageAndConversions;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* Finds all virtual datacenters where the given {@link VirtualMachineTemplate}
|
||||
* can be deployed.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@ImplementedBy(FindCompatibleVirtualDatacentersForImageAndConversions.class)
|
||||
public interface FindCompatibleVirtualDatacenters {
|
||||
Iterable<VirtualDatacenter> execute(VirtualMachineTemplate template);
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.abiquo.compute.strategy.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
|
||||
import static org.jclouds.abiquo.predicates.cloud.VirtualDatacenterPredicates.compatibleWithTemplateOrConversions;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.compute.strategy.FindCompatibleVirtualDatacenters;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.features.services.CloudService;
|
||||
import org.jclouds.abiquo.predicates.cloud.VirtualDatacenterPredicates;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.DatacenterDto;
|
||||
|
||||
/**
|
||||
* Default implementation for the {@link FindCompatibleVirtualDatacenters}
|
||||
* strategy.
|
||||
* <p>
|
||||
* This strategy assumes that the datacenter will have different hypervisor
|
||||
* technologies, and images will have conversions to each of them.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class FindCompatibleVirtualDatacentersForImageAndConversions implements FindCompatibleVirtualDatacenters {
|
||||
private final RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private final CloudService cloudService;
|
||||
|
||||
@Inject
|
||||
public FindCompatibleVirtualDatacentersForImageAndConversions(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final CloudService cloudService) {
|
||||
this.context = checkNotNull(context, "context");
|
||||
this.cloudService = checkNotNull(cloudService, "cloudService");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<VirtualDatacenter> execute(final VirtualMachineTemplate template) {
|
||||
// Build the transport object with the available information to avoid
|
||||
// making an unnecessary call to the target API (we only need the id of
|
||||
// the datacenter, and it is present in the link).
|
||||
DatacenterDto datacenterDto = new DatacenterDto();
|
||||
datacenterDto.setId(template.unwrap().getIdFromLink(ParentLinkName.DATACENTER_REPOSITORY));
|
||||
Datacenter datacenter = wrap(context, Datacenter.class, datacenterDto);
|
||||
|
||||
Iterable<VirtualDatacenter> vdcs = cloudService.listVirtualDatacenters(VirtualDatacenterPredicates
|
||||
.datacenter(datacenter));
|
||||
|
||||
return filter(vdcs, compatibleWithTemplateOrConversions(template));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.abiquo.compute.strategy.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.compute.strategy.FindCompatibleVirtualDatacenters;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.features.services.CloudService;
|
||||
import org.jclouds.abiquo.predicates.cloud.VirtualDatacenterPredicates;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.HypervisorType;
|
||||
import com.abiquo.server.core.infrastructure.DatacenterDto;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
/**
|
||||
* Implementation for the {@link FindCompatibleVirtualDatacenters} strategy to
|
||||
* be used in homogeneous datacenters.
|
||||
* <p>
|
||||
* For providers that only have one hypervisor technology in the physical
|
||||
* datacenter and use compatible images, there is no need to check if the images
|
||||
* have conversions to other formats.
|
||||
* <p>
|
||||
* This strategy will only consider the base disk format of the image.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class FindCompatibleVirtualDatacentersForImageBaseFormat implements FindCompatibleVirtualDatacenters {
|
||||
private final RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private final CloudService cloudService;
|
||||
|
||||
@Inject
|
||||
public FindCompatibleVirtualDatacentersForImageBaseFormat(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final CloudService cloudService) {
|
||||
this.context = checkNotNull(context, "context");
|
||||
this.cloudService = checkNotNull(cloudService, "cloudService");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<VirtualDatacenter> execute(final VirtualMachineTemplate template) {
|
||||
// Build the transport object with the available information to avoid
|
||||
// making an unnecessary call to the target API (we only need the id of
|
||||
// the datacenter, and it is present in the link).
|
||||
DatacenterDto datacenterDto = new DatacenterDto();
|
||||
datacenterDto.setId(template.unwrap().getIdFromLink(ParentLinkName.DATACENTER_REPOSITORY));
|
||||
Datacenter datacenter = wrap(context, Datacenter.class, datacenterDto);
|
||||
|
||||
Iterable<VirtualDatacenter> vdcs = cloudService.listVirtualDatacenters(VirtualDatacenterPredicates
|
||||
.datacenter(datacenter));
|
||||
|
||||
return filter(vdcs, new Predicate<VirtualDatacenter>() {
|
||||
@Override
|
||||
public boolean apply(final VirtualDatacenter vdc) {
|
||||
HypervisorType type = vdc.getHypervisorType();
|
||||
return type.isCompatible(template.getDiskFormatType());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.config;
|
||||
|
||||
/**
|
||||
* The Abiquo Edition (Community or Enterprise).
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public enum AbiquoEdition {
|
||||
ENTERPRISE, COMMUNITY;
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.config;
|
||||
|
||||
/**
|
||||
* Configuration properties and constants used in Abiquo connections.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public interface AbiquoProperties {
|
||||
/**
|
||||
* Boolean property indicating if the provided credential is an api token.
|
||||
* <p>
|
||||
* Default value: false
|
||||
*/
|
||||
public static final String CREDENTIAL_IS_TOKEN = "abiquo.credential-is-token";
|
||||
|
||||
/**
|
||||
* The delay (in ms) used between requests by the {@link MonitoringService}
|
||||
* when monitoring asynchronous task state.
|
||||
* <p>
|
||||
* Default value: 5000 ms
|
||||
*/
|
||||
public static final String ASYNC_TASK_MONITOR_DELAY = "abiquo.monitor-delay";
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.config;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.enterprise.Enterprise;
|
||||
import org.jclouds.abiquo.domain.enterprise.User;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.features.AdminApi;
|
||||
import org.jclouds.abiquo.features.AdminAsyncApi;
|
||||
import org.jclouds.abiquo.features.CloudApi;
|
||||
import org.jclouds.abiquo.features.CloudAsyncApi;
|
||||
import org.jclouds.abiquo.features.ConfigApi;
|
||||
import org.jclouds.abiquo.features.ConfigAsyncApi;
|
||||
import org.jclouds.abiquo.features.EnterpriseApi;
|
||||
import org.jclouds.abiquo.features.EnterpriseAsyncApi;
|
||||
import org.jclouds.abiquo.features.EventApi;
|
||||
import org.jclouds.abiquo.features.EventAsyncApi;
|
||||
import org.jclouds.abiquo.features.InfrastructureApi;
|
||||
import org.jclouds.abiquo.features.InfrastructureAsyncApi;
|
||||
import org.jclouds.abiquo.features.PricingApi;
|
||||
import org.jclouds.abiquo.features.PricingAsyncApi;
|
||||
import org.jclouds.abiquo.features.TaskApi;
|
||||
import org.jclouds.abiquo.features.TaskAsyncApi;
|
||||
import org.jclouds.abiquo.features.VirtualMachineTemplateApi;
|
||||
import org.jclouds.abiquo.features.VirtualMachineTemplateAsyncApi;
|
||||
import org.jclouds.abiquo.handlers.AbiquoErrorHandler;
|
||||
import org.jclouds.abiquo.rest.internal.AbiquoHttpAsyncClient;
|
||||
import org.jclouds.abiquo.rest.internal.AbiquoHttpClient;
|
||||
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.Utils;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Configures the Abiquo connection.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@ConfiguresRestClient
|
||||
public class AbiquoRestClientModule extends RestClientModule<AbiquoApi, AbiquoAsyncApi> {
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder() //
|
||||
.put(InfrastructureApi.class, InfrastructureAsyncApi.class) //
|
||||
.put(EnterpriseApi.class, EnterpriseAsyncApi.class) //
|
||||
.put(AdminApi.class, AdminAsyncApi.class) //
|
||||
.put(ConfigApi.class, ConfigAsyncApi.class) //
|
||||
.put(CloudApi.class, CloudAsyncApi.class) //
|
||||
.put(VirtualMachineTemplateApi.class, VirtualMachineTemplateAsyncApi.class) //
|
||||
.put(TaskApi.class, TaskAsyncApi.class) //
|
||||
.put(EventApi.class, EventAsyncApi.class) //
|
||||
.put(PricingApi.class, PricingAsyncApi.class) //
|
||||
.build();
|
||||
|
||||
public AbiquoRestClientModule() {
|
||||
super(DELEGATE_MAP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bindHttpApi(binder(), AbiquoHttpClient.class, AbiquoHttpAsyncClient.class);
|
||||
bind(Utils.class).to(ExtendedUtils.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindErrorHandlers() {
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(AbiquoErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(AbiquoErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(AbiquoErrorHandler.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
public Supplier<User> getCurrentUser(final AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) final long seconds, final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, new Supplier<User>() {
|
||||
@Override
|
||||
public User get() {
|
||||
return wrap(context, User.class, context.getApi().getAdminApi().getCurrentUser());
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
public Supplier<Enterprise> getCurrentEnterprise(final AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) final long seconds, @Memoized final Supplier<User> currentUser) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
new Supplier<Enterprise>() {
|
||||
@Override
|
||||
public Enterprise get() {
|
||||
return currentUser.get().getEnterprise();
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
public Supplier<Map<Integer, Datacenter>> getAvailableRegionsIndexedById(
|
||||
final AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) final long seconds, @Memoized final Supplier<Enterprise> currentEnterprise) {
|
||||
Supplier<Map<Integer, Datacenter>> availableRegionsMapSupplier = Suppliers.compose(
|
||||
new Function<List<Datacenter>, Map<Integer, Datacenter>>() {
|
||||
@Override
|
||||
public Map<Integer, Datacenter> apply(final List<Datacenter> datacenters) {
|
||||
// Index available regions by id
|
||||
return Maps.uniqueIndex(datacenters, new Function<Datacenter, Integer>() {
|
||||
@Override
|
||||
public Integer apply(final Datacenter input) {
|
||||
return input.getId();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, new Supplier<List<Datacenter>>() {
|
||||
@Override
|
||||
public List<Datacenter> get() {
|
||||
// Get the list of regions available for the user's tenant
|
||||
return currentEnterprise.get().listAllowedDatacenters();
|
||||
}
|
||||
});
|
||||
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
availableRegionsMapSupplier, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.transport.SingleResourceWithLimitsDto;
|
||||
|
||||
/**
|
||||
* This class is used to decorate transport objects that have limits with high
|
||||
* level functionality.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public abstract class DomainWithLimitsWrapper<T extends SingleResourceWithLimitsDto> extends DomainWrapper<T> {
|
||||
|
||||
protected DomainWithLimitsWrapper(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final T target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public int getCpuCountHardLimit() {
|
||||
return target.getCpuCountHardLimit();
|
||||
}
|
||||
|
||||
public int getCpuCountSoftLimit() {
|
||||
return target.getCpuCountSoftLimit();
|
||||
}
|
||||
|
||||
public long getHdHardLimitInMb() {
|
||||
return target.getHdHardLimitInMb();
|
||||
}
|
||||
|
||||
public long getHdSoftLimitInMb() {
|
||||
return target.getHdSoftLimitInMb();
|
||||
}
|
||||
|
||||
public long getPublicIpsHard() {
|
||||
return target.getPublicIpsHard();
|
||||
}
|
||||
|
||||
public long getPublicIpsSoft() {
|
||||
return target.getPublicIpsSoft();
|
||||
}
|
||||
|
||||
public int getRamHardLimitInMb() {
|
||||
return target.getRamHardLimitInMb();
|
||||
}
|
||||
|
||||
public int getRamSoftLimitInMb() {
|
||||
return target.getRamSoftLimitInMb();
|
||||
}
|
||||
|
||||
public long getStorageHard() {
|
||||
return target.getStorageHard();
|
||||
}
|
||||
|
||||
public long getStorageSoft() {
|
||||
return target.getStorageSoft();
|
||||
}
|
||||
|
||||
public long getVlansHard() {
|
||||
return target.getVlansHard();
|
||||
}
|
||||
|
||||
public long getVlansSoft() {
|
||||
return target.getVlansSoft();
|
||||
}
|
||||
|
||||
public void setCpuCountHardLimit(final int cpuCountHardLimit) {
|
||||
target.setCpuCountHardLimit(cpuCountHardLimit);
|
||||
}
|
||||
|
||||
public void setCpuCountLimits(final int softLimit, final int hardLimit) {
|
||||
target.setCpuCountLimits(softLimit, hardLimit);
|
||||
}
|
||||
|
||||
public void setCpuCountSoftLimit(final int cpuCountSoftLimit) {
|
||||
target.setCpuCountSoftLimit(cpuCountSoftLimit);
|
||||
}
|
||||
|
||||
public void setHdHardLimitInMb(final long hdHardLimitInMb) {
|
||||
target.setHdHardLimitInMb(hdHardLimitInMb);
|
||||
}
|
||||
|
||||
public void setHdLimitsInMb(final long softLimit, final long hardLimit) {
|
||||
target.setHdLimitsInMb(softLimit, hardLimit);
|
||||
}
|
||||
|
||||
public void setHdSoftLimitInMb(final long hdSoftLimitInMb) {
|
||||
target.setHdSoftLimitInMb(hdSoftLimitInMb);
|
||||
}
|
||||
|
||||
public void setPublicIPLimits(final long softLimit, final long hardLimit) {
|
||||
target.setPublicIPLimits(softLimit, hardLimit);
|
||||
}
|
||||
|
||||
public void setPublicIpsHard(final long publicIpsHard) {
|
||||
target.setPublicIpsHard(publicIpsHard);
|
||||
}
|
||||
|
||||
public void setPublicIpsSoft(final long publicIpsSoft) {
|
||||
target.setPublicIpsSoft(publicIpsSoft);
|
||||
}
|
||||
|
||||
public void setRamHardLimitInMb(final int ramHardLimitInMb) {
|
||||
target.setRamHardLimitInMb(ramHardLimitInMb);
|
||||
}
|
||||
|
||||
public void setRamLimitsInMb(final int softLimit, final int hardLimit) {
|
||||
target.setRamLimitsInMb(softLimit, hardLimit);
|
||||
}
|
||||
|
||||
public void setRamSoftLimitInMb(final int ramSoftLimitInMb) {
|
||||
target.setRamSoftLimitInMb(ramSoftLimitInMb);
|
||||
}
|
||||
|
||||
public void setStorageHard(final long storageHard) {
|
||||
target.setStorageHard(storageHard);
|
||||
}
|
||||
|
||||
public void setStorageLimits(final long softLimit, final long hardLimit) {
|
||||
target.setStorageLimits(softLimit, hardLimit);
|
||||
}
|
||||
|
||||
public void setStorageSoft(final long storageSoft) {
|
||||
target.setStorageSoft(storageSoft);
|
||||
}
|
||||
|
||||
public void setVlansHard(final long vlansHard) {
|
||||
target.setVlansHard(vlansHard);
|
||||
}
|
||||
|
||||
public void setVlansLimits(final long softLimit, final long hardLimit) {
|
||||
target.setVlansLimits(softLimit, hardLimit);
|
||||
}
|
||||
|
||||
public void setVlansSoft(final long vlansSoft) {
|
||||
target.setVlansSoft(vlansSoft);
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain;
|
||||
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.task.AsyncTask;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.transport.SingleResourceTransportDto;
|
||||
import com.abiquo.server.core.task.TaskDto;
|
||||
import com.abiquo.server.core.task.TasksDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.common.primitives.Longs;
|
||||
|
||||
/**
|
||||
* This class is used to decorate transport objects that are owners of some
|
||||
* {@link TaskDto}
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public abstract class DomainWithTasksWrapper<T extends SingleResourceTransportDto> extends DomainWrapper<T> {
|
||||
|
||||
protected DomainWithTasksWrapper(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final T target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
public List<AsyncTask> listTasks() {
|
||||
TasksDto result = context.getApi().getTaskApi().listTasks(target);
|
||||
List<AsyncTask> tasks = wrap(context, AsyncTask.class, result.getCollection());
|
||||
|
||||
// Return the most recent task first
|
||||
Collections.sort(tasks, new Ordering<AsyncTask>() {
|
||||
@Override
|
||||
public int compare(final AsyncTask left, final AsyncTask right) {
|
||||
return Longs.compare(left.getTimestamp(), right.getTimestamp());
|
||||
}
|
||||
}.reverse());
|
||||
|
||||
return tasks;
|
||||
}
|
||||
|
||||
public List<AsyncTask> listTasks(final Predicate<AsyncTask> filter) {
|
||||
return ImmutableList.copyOf(filter(listTasks(), filter));
|
||||
}
|
||||
|
||||
public AsyncTask findTask(final Predicate<AsyncTask> filter) {
|
||||
return Iterables.getFirst(filter(listTasks(), filter), null);
|
||||
}
|
||||
}
|
|
@ -1,240 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.concat;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.reflect.Reflection2.constructor;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.exception.WrapperException;
|
||||
import org.jclouds.abiquo.domain.task.AsyncTask;
|
||||
import org.jclouds.abiquo.domain.util.LinkUtils;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.AcceptedRequestDto;
|
||||
import com.abiquo.model.transport.SingleResourceTransportDto;
|
||||
import com.abiquo.model.transport.WrapperDto;
|
||||
import com.abiquo.server.core.task.TaskDto;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* This class is used to decorate transport objects with high level
|
||||
* functionality.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public abstract class DomainWrapper<T extends SingleResourceTransportDto> {
|
||||
/** The rest context. */
|
||||
protected RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
/** The wrapped object. */
|
||||
protected T target;
|
||||
|
||||
protected DomainWrapper(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final T target) {
|
||||
super();
|
||||
this.context = checkNotNull(context, "context");
|
||||
this.target = checkNotNull(target, "target");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URI that identifies the transport object
|
||||
*
|
||||
* @return The URI identifying the transport object
|
||||
*/
|
||||
public URI getURI() {
|
||||
RESTLink link = LinkUtils.getSelfLink(target);
|
||||
return link == null ? null : URI.create(link.getHref());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wrapped object.
|
||||
*/
|
||||
public T unwrap() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the state of the current object.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void refresh() {
|
||||
RESTLink link = checkNotNull(LinkUtils.getSelfLink(target), ValidationErrors.MISSING_REQUIRED_LINK + " edit/self");
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<T> parser = new ParseXMLWithJAXB<T>(utils.getXml(),
|
||||
TypeLiteral.get((Class<T>) target.getClass()));
|
||||
|
||||
target = parser.apply(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the ID of the parent resource from the given link.
|
||||
*
|
||||
* @param parentLinkRel
|
||||
* The link to the parent resource.
|
||||
* @return The ID of the parent resource.
|
||||
*/
|
||||
protected Integer getParentId(final String parentLinkRel) {
|
||||
return target.getIdFromLink(parentLinkRel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps an object in the given wrapper class.
|
||||
*/
|
||||
public static <T extends SingleResourceTransportDto, W extends DomainWrapper<T>> W wrap(
|
||||
final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Class<W> wrapperClass, final T target) {
|
||||
if (target == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Invokable<W, W> cons = constructor(wrapperClass, RestContext.class, target.getClass());
|
||||
return cons.invoke(null, context, target);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new WrapperException(wrapperClass, target, e.getTargetException());
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new WrapperException(wrapperClass, target, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a collection of objects to the given wrapper class.
|
||||
*/
|
||||
public static <T extends SingleResourceTransportDto, W extends DomainWrapper<T>> List<W> wrap(
|
||||
final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Class<W> wrapperClass, final Iterable<T> targets) {
|
||||
if (targets == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ImmutableList.copyOf(transform(targets, new Function<T, W>() {
|
||||
@Override
|
||||
public W apply(final T input) {
|
||||
return wrap(context, wrapperClass, input);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unwrap a collection of objects.
|
||||
*/
|
||||
public static <T extends SingleResourceTransportDto, W extends DomainWrapper<T>> List<T> unwrap(
|
||||
final Iterable<W> targets) {
|
||||
return ImmutableList.copyOf(transform(targets, new Function<W, T>() {
|
||||
@Override
|
||||
public T apply(final W input) {
|
||||
return input.unwrap();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update or creates a link of "target" with the uri of a link from "source".
|
||||
*/
|
||||
protected <T1 extends SingleResourceTransportDto, T2 extends SingleResourceTransportDto> void updateLink(
|
||||
final T1 target, final String targetLinkRel, final T2 source, final String sourceLinkRel) {
|
||||
RESTLink parent = null;
|
||||
|
||||
checkNotNull(source.searchLink(sourceLinkRel), ValidationErrors.MISSING_REQUIRED_LINK);
|
||||
|
||||
// Insert
|
||||
if ((parent = target.searchLink(targetLinkRel)) == null) {
|
||||
target.addLink(new RESTLink(targetLinkRel, source.searchLink(sourceLinkRel).getHref()));
|
||||
}
|
||||
// Replace
|
||||
else {
|
||||
parent.setHref(source.searchLink(sourceLinkRel).getHref());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Join a collection of {@link WrapperDto} objects in a single collection
|
||||
* with all the elements of each wrapper object.
|
||||
*/
|
||||
public static <T extends SingleResourceTransportDto> Iterable<T> join(
|
||||
final Iterable<? extends WrapperDto<T>> collection) {
|
||||
return concat(transform(collection, new Function<WrapperDto<T>, Collection<T>>() {
|
||||
@Override
|
||||
public Collection<T> apply(WrapperDto<T> input) {
|
||||
return input.getCollection();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to get an {@link AsyncTask} given an
|
||||
* {@link AcceptedRequestDto}.
|
||||
*
|
||||
* @param acceptedRequest
|
||||
* The accepted request dto.
|
||||
* @return The async task.
|
||||
*/
|
||||
protected AsyncTask getTask(final AcceptedRequestDto<String> acceptedRequest) {
|
||||
RESTLink taskLink = acceptedRequest.getStatusLink();
|
||||
checkNotNull(taskLink, ValidationErrors.MISSING_REQUIRED_LINK + AsyncTask.class);
|
||||
|
||||
// This will return null on untrackable tasks
|
||||
TaskDto task = context.getApi().getTaskApi().getTask(taskLink);
|
||||
return wrap(context, AsyncTask.class, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to get all {@link AsyncTask} related to an
|
||||
* {@link AcceptedRequestDto}.
|
||||
*
|
||||
* @param acceptedRequest
|
||||
* The accepted request dto.
|
||||
* @return The async task array.
|
||||
*/
|
||||
protected AsyncTask[] getTasks(final AcceptedRequestDto<String> acceptedRequest) {
|
||||
List<AsyncTask> tasks = Lists.newArrayList();
|
||||
|
||||
for (RESTLink link : acceptedRequest.getLinks()) {
|
||||
// This will return null on untrackable tasks
|
||||
TaskDto task = context.getApi().getTaskApi().getTask(link);
|
||||
if (task != null) {
|
||||
tasks.add(wrap(context, AsyncTask.class, task));
|
||||
}
|
||||
}
|
||||
|
||||
AsyncTask[] taskArr = new AsyncTask[tasks.size()];
|
||||
return tasks.toArray(taskArr);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.builder;
|
||||
|
||||
/**
|
||||
* Base class for all builders that represent limits.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @param <T>
|
||||
* The type of the target builder.
|
||||
*/
|
||||
public abstract class LimitsBuilder<T extends LimitsBuilder<T>> {
|
||||
/** The default limits for enterprises (unlimited). */
|
||||
protected static final int DEFAULT_LIMITS = 0;
|
||||
|
||||
protected Integer ramSoftLimitInMb = DEFAULT_LIMITS;
|
||||
|
||||
protected Integer ramHardLimitInMb = DEFAULT_LIMITS;
|
||||
|
||||
protected Integer cpuCountSoftLimit = DEFAULT_LIMITS;
|
||||
|
||||
protected Integer cpuCountHardLimit = DEFAULT_LIMITS;
|
||||
|
||||
protected Long hdSoftLimitInMb = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
protected Long hdHardLimitInMb = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
protected Long storageSoft = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
protected Long storageHard = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
protected Long vlansSoft = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
protected Long vlansHard = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
protected Long publicIpsSoft = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
protected Long publicIpsHard = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T ramLimits(final int soft, final int hard) {
|
||||
this.ramSoftLimitInMb = soft;
|
||||
this.ramHardLimitInMb = hard;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T cpuCountLimits(final int soft, final int hard) {
|
||||
this.cpuCountSoftLimit = soft;
|
||||
this.cpuCountHardLimit = hard;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T hdLimitsInMb(final long soft, final long hard) {
|
||||
this.hdSoftLimitInMb = soft;
|
||||
this.hdHardLimitInMb = hard;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T storageLimits(final long soft, final long hard) {
|
||||
this.storageSoft = soft;
|
||||
this.storageHard = hard;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T vlansLimits(final long soft, final long hard) {
|
||||
this.vlansSoft = soft;
|
||||
this.vlansHard = hard;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T publicIpsLimits(final long soft, final long hard) {
|
||||
this.publicIpsSoft = soft;
|
||||
this.publicIpsHard = hard;
|
||||
return (T) this;
|
||||
}
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWithTasksWrapper;
|
||||
import org.jclouds.abiquo.domain.task.AsyncTask;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.ConversionState;
|
||||
import com.abiquo.model.enumerator.DiskFormatType;
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.appslibrary.ConversionDto;
|
||||
import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link ConversionDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/Conversion+Resource">
|
||||
* http://community.abiquo.com/display/ABI20/Conversion+Resource</a>
|
||||
*/
|
||||
public class Conversion extends DomainWithTasksWrapper<ConversionDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Conversion(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final ConversionDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Machine+Template+Resource"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Machine+Template+
|
||||
* Resource</a>
|
||||
*/
|
||||
public VirtualMachineTemplate getVirtualMachineTemplate() {
|
||||
RESTLink link = checkNotNull(target.searchLink(ParentLinkName.VIRTUAL_MACHINE_TEMPLATE),
|
||||
ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.VIRTUAL_MACHINE_TEMPLATE);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<VirtualMachineTemplateDto> parser = new ParseXMLWithJAXB<VirtualMachineTemplateDto>(
|
||||
utils.getXml(), TypeLiteral.get(VirtualMachineTemplateDto.class));
|
||||
|
||||
return wrap(context, VirtualMachineTemplate.class, parser.apply(response));
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new BPM task to regenerate a failed conversion.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Conversion+Resource#ConversionResource-UpdateConversion"
|
||||
* > http://community.abiquo.com/display/ABI20/Conversion+Resource#
|
||||
* ConversionResource- UpdateConversion</a>
|
||||
* @return The task reference to track its progress
|
||||
*/
|
||||
public AsyncTask restartFailedConversion() {
|
||||
return getVirtualMachineTemplate().requestConversion(getTargetFormat());
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public String getSourcePath() {
|
||||
return target.getSourcePath();
|
||||
}
|
||||
|
||||
public ConversionState getState() {
|
||||
return target.getState();
|
||||
}
|
||||
|
||||
public String getTargetPath() {
|
||||
return target.getTargetPath();
|
||||
}
|
||||
|
||||
public Long getTargetSizeInBytes() {
|
||||
return target.getTargetSizeInBytes();
|
||||
}
|
||||
|
||||
public DiskFormatType getSourceFormat() {
|
||||
return target.getSourceFormat();
|
||||
}
|
||||
|
||||
public DiskFormatType getTargetFormat() {
|
||||
return target.getTargetFormat();
|
||||
}
|
||||
|
||||
public Date getStartTimestamp() {
|
||||
return target.getStartTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Conversion [sourcePath=" + getSourcePath() + ", sourceFormat=" + getSourceFormat() + ", targetPath="
|
||||
+ getTargetPath() + ", targetFormat=" + getTargetFormat() + ", targetSizeInBytes=" + getTargetSizeInBytes()
|
||||
+ ", startTimestamp=" + getStartTimestamp() + ", state=" + getState() + "]";
|
||||
}
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.cloud.VirtualDatacenterDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.DiskManagementDto;
|
||||
|
||||
/**
|
||||
* Represents a disk attached to a virtual machine.
|
||||
* <p>
|
||||
* This disks will be created when a virtual machine is deployed, and will be
|
||||
* destroyed when it is undeployed. If there is a need to use persistent
|
||||
* storage, a persistent {@link Volume} should be used instead.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/Hard+Disks+Resource">
|
||||
* http://community.abiquo.com/display/ABI20/Hard+Disks+Resource</a>
|
||||
*/
|
||||
public class HardDisk extends DomainWrapper<DiskManagementDto> {
|
||||
/** The virtual datacenter where the hard disk belongs. */
|
||||
private VirtualDatacenter virtualDatacenter;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected HardDisk(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final DiskManagementDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* Creates the hard disk in the selected virtual datacenter.
|
||||
* <p>
|
||||
* Once the hard disk has been created it can be attached to a virtual
|
||||
* machine of the virtual datacenter.
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getCloudApi().createHardDisk(virtualDatacenter.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the hard disk.
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getCloudApi().deleteHardDisk(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* Gets the virtual datacenter where the hard disk belongs to.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-RetrieveaVirtualDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource# VirtualDatacenterResource-RetrieveaVirtualDatacenter</a>
|
||||
*/
|
||||
public VirtualDatacenter getVirtualDatacenter() {
|
||||
Integer virtualDatacenterId = target.getIdFromLink(ParentLinkName.VIRTUAL_DATACENTER);
|
||||
VirtualDatacenterDto dto = context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId);
|
||||
virtualDatacenter = wrap(context, VirtualDatacenter.class, dto);
|
||||
return virtualDatacenter;
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final VirtualDatacenter virtualDatacenter) {
|
||||
return new Builder(context, virtualDatacenter);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private Long sizeInMb;
|
||||
|
||||
private VirtualDatacenter virtualDatacenter;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final VirtualDatacenter virtualDatacenter) {
|
||||
super();
|
||||
checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + VirtualDatacenter.class);
|
||||
this.context = context;
|
||||
this.virtualDatacenter = virtualDatacenter;
|
||||
}
|
||||
|
||||
public Builder sizeInMb(final long sizeInMb) {
|
||||
this.sizeInMb = sizeInMb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HardDisk build() {
|
||||
DiskManagementDto dto = new DiskManagementDto();
|
||||
dto.setSizeInMb(sizeInMb);
|
||||
|
||||
HardDisk hardDisk = new HardDisk(context, dto);
|
||||
hardDisk.virtualDatacenter = virtualDatacenter;
|
||||
|
||||
return hardDisk;
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods. Since a hard disk cannot be edited, setters are not
|
||||
// visible
|
||||
|
||||
/**
|
||||
* Returns the id of the hard disk.
|
||||
*/
|
||||
public Integer getId() {
|
||||
// TODO: DiskManagementDto does not have an id field
|
||||
return target.getEditLink() == null ? null : target.getIdFromLink("edit");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the hard disk in MB.
|
||||
*/
|
||||
public Long getSizeInMb() {
|
||||
return target.getSizeInMb();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sequence number of the hard disk.
|
||||
* <p>
|
||||
* It will be computed when attaching the hard disk to a virtual machine and
|
||||
* will determine the attachment order of the disk in the virtual machine.
|
||||
*/
|
||||
public Integer getSequence() {
|
||||
return target.getSequence();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HardDisk [id=" + getId() + ", sizeInMb=" + getSizeInMb() + ", sequence=" + getSequence() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,382 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions;
|
||||
import org.jclouds.abiquo.domain.enterprise.Enterprise;
|
||||
import org.jclouds.abiquo.domain.task.AsyncTask;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.transport.AcceptedRequestDto;
|
||||
import com.abiquo.server.core.cloud.VirtualApplianceDto;
|
||||
import com.abiquo.server.core.cloud.VirtualApplianceState;
|
||||
import com.abiquo.server.core.cloud.VirtualApplianceStateDto;
|
||||
import com.abiquo.server.core.cloud.VirtualDatacenterDto;
|
||||
import com.abiquo.server.core.cloud.VirtualMachineTaskDto;
|
||||
import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto;
|
||||
import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto;
|
||||
import com.abiquo.server.core.enterprise.EnterpriseDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Represents a virtual appliance.
|
||||
* <p>
|
||||
* A virtual appliance is a logic container for virtual machines that together
|
||||
* make an appliance.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource</a>
|
||||
*/
|
||||
public class VirtualAppliance extends DomainWrapper<VirtualApplianceDto> {
|
||||
/** The virtual datacenter where the virtual appliance belongs. */
|
||||
private VirtualDatacenter virtualDatacenter;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected VirtualAppliance(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final VirtualApplianceDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* Deletes the virtual appliance.
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getCloudApi().deleteVirtualAppliance(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the virtual appliance in the selected virtual datacenter.
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getCloudApi().createVirtualAppliance(virtualDatacenter.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the virtual appliance information when some of its properties have
|
||||
* changed.
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getCloudApi().updateVirtualAppliance(target);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* Gets the virtual datacenter where the virtual appliance belongs to.
|
||||
*
|
||||
* @return The virtual datacenter where the virtual appliance belongs to.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-RetrieveaVirtualDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource# VirtualDatacenterResource-RetrieveaVirtualDatacenter</a>
|
||||
*/
|
||||
public VirtualDatacenter getVirtualDatacenter() {
|
||||
Integer virtualDatacenterId = target.getIdFromLink(ParentLinkName.VIRTUAL_DATACENTER);
|
||||
VirtualDatacenterDto dto = context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId);
|
||||
virtualDatacenter = wrap(context, VirtualDatacenter.class, dto);
|
||||
return virtualDatacenter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the enterprise where the virtual appliance belongs to.
|
||||
*
|
||||
* @return The enterprise where the virtual appliance belongs to.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource-RetrieveaEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/Enterprise+Resource#
|
||||
* EnterpriseResource- RetrieveaEnterprise</a>
|
||||
*/
|
||||
public Enterprise getEnterprise() {
|
||||
Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE);
|
||||
EnterpriseDto dto = context.getApi().getEnterpriseApi().getEnterprise(enterpriseId);
|
||||
return wrap(context, Enterprise.class, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current state of the virtual appliance.
|
||||
*
|
||||
* @return The current state of the virtual appliance.
|
||||
*/
|
||||
public VirtualApplianceState getState() {
|
||||
VirtualApplianceStateDto stateDto = context.getApi().getCloudApi().getVirtualApplianceState(target);
|
||||
return stateDto.getPower();
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
/**
|
||||
* Gets the list of virtual machines in the virtual appliance.
|
||||
*
|
||||
* @return The list of virtual machines in the virtual appliance.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI18/Virtual+Machine+Resource#VirtualMachineResource-RetrievethelistofVirtualMachines."
|
||||
* > http://community.abiquo.com/display/ABI18/Virtual+Machine+Resource#
|
||||
* VirtualMachineResource -RetrievethelistofVirtualMachines.</a>
|
||||
*/
|
||||
public List<VirtualMachine> listVirtualMachines() {
|
||||
return listVirtualMachines(VirtualMachineOptions.builder().disablePagination().build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of virtual machines in the virtual appliance.
|
||||
*
|
||||
* @return The list of virtual machines in the virtual appliance.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI18/Virtual+Machine+Resource#VirtualMachineResource-RetrievethelistofVirtualMachines."
|
||||
* > http://community.abiquo.com/display/ABI18/Virtual+Machine+Resource#
|
||||
* VirtualMachineResource -RetrievethelistofVirtualMachines.</a>
|
||||
*/
|
||||
public List<VirtualMachine> listVirtualMachines(final VirtualMachineOptions options) {
|
||||
VirtualMachinesWithNodeExtendedDto vms = context.getApi().getCloudApi().listVirtualMachines(target, options);
|
||||
return wrap(context, VirtualMachine.class, vms.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of virtual machines in the virtual appliance matching the
|
||||
* given filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The list of virtual machines in the virtual appliance matching the
|
||||
* given filter.
|
||||
*/
|
||||
public List<VirtualMachine> listVirtualMachines(final Predicate<VirtualMachine> filter) {
|
||||
return ImmutableList.copyOf(filter(listVirtualMachines(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single virtual machine in the virtual appliance matching the given
|
||||
* filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The virtual machine or <code>null</code> if none matched the given
|
||||
* filter.
|
||||
*/
|
||||
public VirtualMachine findVirtualMachine(final Predicate<VirtualMachine> filter) {
|
||||
return Iterables.getFirst(filter(listVirtualMachines(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a concrete virtual machine in the virtual appliance.
|
||||
*
|
||||
* @param id
|
||||
* The id of the virtual machine.
|
||||
* @return The requested virtual machine.
|
||||
*/
|
||||
public VirtualMachine getVirtualMachine(final Integer id) {
|
||||
VirtualMachineWithNodeExtendedDto vm = context.getApi().getCloudApi().getVirtualMachine(target, id);
|
||||
return wrap(context, VirtualMachine.class, vm);
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/**
|
||||
* Deploys the virtual appliance.
|
||||
* <p>
|
||||
* This method will start the deployment of all the virtual machines in the
|
||||
* virtual appliance, and will return an {@link AsyncTask} reference for each
|
||||
* deployment operation. The deployment will finish when all individual tasks
|
||||
* finish.
|
||||
*
|
||||
* @return The list of tasks corresponding to the deploy process of each
|
||||
* virtual machine in the appliance.
|
||||
*/
|
||||
public AsyncTask[] deploy() {
|
||||
return deploy(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploys the virtual appliance.
|
||||
* <p>
|
||||
* This method will start the deployment of all the virtual machines in the
|
||||
* virtual appliance, and will return an {@link AsyncTask} reference for each
|
||||
* deploy operation. The deployment will finish when all individual tasks
|
||||
* finish.
|
||||
*
|
||||
* @param forceEnterpriseSoftLimits
|
||||
* Boolean indicating if the deployment must be executed even if
|
||||
* the enterprise soft limits are reached.
|
||||
* @return The list of tasks corresponding to the deploy process of each
|
||||
* virtual machine in the appliance.
|
||||
*/
|
||||
public AsyncTask[] deploy(final boolean forceEnterpriseSoftLimits) {
|
||||
VirtualMachineTaskDto force = new VirtualMachineTaskDto();
|
||||
force.setForceEnterpriseSoftLimits(forceEnterpriseSoftLimits);
|
||||
|
||||
AcceptedRequestDto<String> response = context.getApi().getCloudApi().deployVirtualAppliance(unwrap(), force);
|
||||
|
||||
return getTasks(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undeploys the virtual appliance.
|
||||
* <p>
|
||||
* This method will start the undeploy of all the virtual machines in the
|
||||
* virtual appliance, and will return an {@link AsyncTask} reference for each
|
||||
* undeploy operation. The undeploy will finish when all individual tasks
|
||||
* finish.
|
||||
*
|
||||
* @return The list of tasks corresponding to the undeploy process of each
|
||||
* virtual machine in the appliance.
|
||||
*/
|
||||
public AsyncTask[] undeploy() {
|
||||
return undeploy(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undeploys the virtual appliance.
|
||||
* <p>
|
||||
* This method will start the undeploy of all the virtual machines in the
|
||||
* virtual appliance, and will return an {@link AsyncTask} reference for each
|
||||
* undeploy operation. The undeploy will finish when all individual tasks
|
||||
* finish.
|
||||
*
|
||||
* @param forceUndeploy
|
||||
* Boolean flag to force the undeploy even if the virtual appliance
|
||||
* contains imported virtual machines.
|
||||
* @return The list of tasks corresponding to the undeploy process of each
|
||||
* virtual machine in the appliance.
|
||||
*/
|
||||
public AsyncTask[] undeploy(final boolean forceUndeploy) {
|
||||
VirtualMachineTaskDto force = new VirtualMachineTaskDto();
|
||||
force.setForceUndeploy(forceUndeploy);
|
||||
|
||||
AcceptedRequestDto<String> response = context.getApi().getCloudApi().undeployVirtualAppliance(unwrap(), force);
|
||||
|
||||
return getTasks(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String message with the price info of the virtual appliance.
|
||||
*
|
||||
* @return The price of the virtual appliance
|
||||
*/
|
||||
public String getPrice() {
|
||||
return context.getApi().getCloudApi().getVirtualAppliancePrice(target);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final VirtualDatacenter virtualDatacenter) {
|
||||
return new Builder(context, virtualDatacenter);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private String name;
|
||||
|
||||
private VirtualDatacenter virtualDatacenter;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final VirtualDatacenter virtualDatacenter) {
|
||||
super();
|
||||
checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + VirtualDatacenter.class);
|
||||
this.virtualDatacenter = virtualDatacenter;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualDatacenter(final VirtualDatacenter virtualDatacenter) {
|
||||
checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + VirtualDatacenter.class);
|
||||
this.virtualDatacenter = virtualDatacenter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VirtualAppliance build() {
|
||||
VirtualApplianceDto dto = new VirtualApplianceDto();
|
||||
dto.setName(name);
|
||||
|
||||
VirtualAppliance virtualAppliance = new VirtualAppliance(context, dto);
|
||||
virtualAppliance.virtualDatacenter = virtualDatacenter;
|
||||
|
||||
return virtualAppliance;
|
||||
}
|
||||
|
||||
public static Builder fromVirtualAppliance(final VirtualAppliance in) {
|
||||
return VirtualAppliance.builder(in.context, in.virtualDatacenter).name(in.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public int getError() {
|
||||
return target.getError();
|
||||
}
|
||||
|
||||
public int getHighDisponibility() {
|
||||
return target.getHighDisponibility();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public int getPublicApp() {
|
||||
return target.getPublicApp();
|
||||
}
|
||||
|
||||
public void setHighDisponibility(final int highDisponibility) {
|
||||
target.setHighDisponibility(highDisponibility);
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public void setPublicApp(final int publicApp) {
|
||||
target.setPublicApp(publicApp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VirtualAppliance [id=" + getId() + ", name=" + getName() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,629 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWithLimitsWrapper;
|
||||
import org.jclouds.abiquo.domain.builder.LimitsBuilder;
|
||||
import org.jclouds.abiquo.domain.cloud.options.VirtualMachineTemplateOptions;
|
||||
import org.jclouds.abiquo.domain.enterprise.Enterprise;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Tier;
|
||||
import org.jclouds.abiquo.domain.network.ExternalNetwork;
|
||||
import org.jclouds.abiquo.domain.network.Network;
|
||||
import org.jclouds.abiquo.domain.network.PrivateIp;
|
||||
import org.jclouds.abiquo.domain.network.PrivateNetwork;
|
||||
import org.jclouds.abiquo.domain.network.PublicIp;
|
||||
import org.jclouds.abiquo.domain.network.options.IpOptions;
|
||||
import org.jclouds.abiquo.predicates.infrastructure.DatacenterPredicates;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.HypervisorType;
|
||||
import com.abiquo.model.enumerator.NetworkType;
|
||||
import com.abiquo.model.enumerator.StatefulInclusion;
|
||||
import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto;
|
||||
import com.abiquo.server.core.cloud.VirtualApplianceDto;
|
||||
import com.abiquo.server.core.cloud.VirtualAppliancesDto;
|
||||
import com.abiquo.server.core.cloud.VirtualDatacenterDto;
|
||||
import com.abiquo.server.core.infrastructure.network.PublicIpsDto;
|
||||
import com.abiquo.server.core.infrastructure.network.VLANNetworkDto;
|
||||
import com.abiquo.server.core.infrastructure.network.VLANNetworksDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.DiskManagementDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.DisksManagementDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.TierDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.TiersDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.VolumesManagementDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Represents a virtual datacenter.
|
||||
* <p>
|
||||
* Virtual datacenters expose a set of compute, storage and networking resources
|
||||
* that can be consumed by the tenants.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource">
|
||||
* http
|
||||
* ://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource</a>
|
||||
*/
|
||||
public class VirtualDatacenter extends DomainWithLimitsWrapper<VirtualDatacenterDto> {
|
||||
/** The enterprise where the rack belongs. */
|
||||
private Enterprise enterprise;
|
||||
|
||||
/** The datacenter where the virtual datacenter will be deployed. */
|
||||
private Datacenter datacenter;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected VirtualDatacenter(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final VirtualDatacenterDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* Delete the virtual datacenter.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-DeleteanexistingVirtualDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource#
|
||||
* VirtualDatacenterResource-DeleteanexistingVirtualDatacenter</a>
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getCloudApi().deleteVirtualDatacenter(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the virtual datacenter.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-CreateanewVirtualDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource# VirtualDatacenterResource-CreateanewVirtualDatacenter</a>
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getCloudApi().createVirtualDatacenter(target, datacenter.unwrap(), enterprise.unwrap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the virtual datacenter information when some of its properties
|
||||
* have changed.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-UpdatesanexistingVirtualDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource#
|
||||
* VirtualDatacenterResource-UpdatesanexistingVirtualDatacenter</a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getCloudApi().updateVirtualDatacenter(target);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* Gets the datacenter where this virtual datacenter is assigned.
|
||||
*
|
||||
* @return The datacenter where this virtual datacenter is assigned.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Datacenter+Resource#DatacenterResource-RetrieveaDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Datacenter+Resource#
|
||||
* DatacenterResource- RetrieveaDatacenter</a>
|
||||
*/
|
||||
public Datacenter getDatacenter() {
|
||||
Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER);
|
||||
datacenter = getEnterprise().findAllowedDatacenter(DatacenterPredicates.id(datacenterId));
|
||||
return datacenter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the enterprise that owns this virtual datacenter.
|
||||
*
|
||||
* @return The enterprise that owns this virtual datacenter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource-RetrieveanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/Enterprise+Resource#
|
||||
* EnterpriseResource- RetrieveanEnterprise</a>
|
||||
*/
|
||||
public Enterprise getEnterprise() {
|
||||
Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE);
|
||||
enterprise = wrap(context, Enterprise.class, context.getApi().getEnterpriseApi().getEnterprise(enterpriseId));
|
||||
return enterprise;
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
/**
|
||||
* Lists all the virtual appliances in the virtual datacenter.
|
||||
*
|
||||
* @return The list of virtual appliances in the virtual datacenter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource#VirtualApplianceResource-RetrievethelistofVirtualAppliances"
|
||||
* >http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource
|
||||
* # VirtualApplianceResource-RetrievethelistofVirtualAppliances</a>
|
||||
*/
|
||||
public List<VirtualAppliance> listVirtualAppliances() {
|
||||
VirtualAppliancesDto vapps = context.getApi().getCloudApi().listVirtualAppliances(target);
|
||||
return wrap(context, VirtualAppliance.class, vapps.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all the virtual appliances in the virtual datacenter that match the
|
||||
* given filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The list of virtual appliances in the virtual datacenter that
|
||||
* match the given filter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource#VirtualApplianceResource-RetrievethelistofVirtualAppliances"
|
||||
* >http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource
|
||||
* # VirtualApplianceResource-RetrievethelistofVirtualAppliances</a>
|
||||
*/
|
||||
public List<VirtualAppliance> listVirtualAppliances(final Predicate<VirtualAppliance> filter) {
|
||||
return ImmutableList.copyOf(filter(listVirtualAppliances(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first virtual appliance in the virtual datacenter that match the
|
||||
* given filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return the first virtual appliance in the virtual datacenter that match
|
||||
* the given filter or <code>null</code> if none is found.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource#VirtualApplianceResource-RetrievethelistofVirtualAppliances"
|
||||
* >http://community.abiquo.com/display/ABI20/Virtual+Appliance+Resource
|
||||
* # VirtualApplianceResource-RetrievethelistofVirtualAppliances</a>
|
||||
*/
|
||||
public VirtualAppliance findVirtualAppliance(final Predicate<VirtualAppliance> filter) {
|
||||
return Iterables.getFirst(filter(listVirtualAppliances(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the virtual appliance with the given id in the current virtual
|
||||
* datacenter.
|
||||
*
|
||||
* @param id
|
||||
* The id of the virtual appliance to get.
|
||||
* @return The virtual appliance.
|
||||
*/
|
||||
public VirtualAppliance getVirtualAppliance(final Integer id) {
|
||||
VirtualApplianceDto vapp = context.getApi().getCloudApi().getVirtualAppliance(target, id);
|
||||
return wrap(context, VirtualAppliance.class, vapp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists the storage tiers that are available to the virtual datacenter.
|
||||
*
|
||||
* @return The list of storage tiers that are available to the virtual
|
||||
* datacenter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-Retrieveenabledtiers"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource# VirtualDatacenterResource-Retrieveenabledtiers</a>
|
||||
*/
|
||||
public List<Tier> listStorageTiers() {
|
||||
TiersDto tiers = context.getApi().getCloudApi().listStorageTiers(target);
|
||||
return wrap(context, Tier.class, tiers.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists the storage tiers that are available to the virtual datacenter and
|
||||
* match the given filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The list of storage tiers that are available to the virtual
|
||||
* datacenter and match the given filter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-Retrieveenabledtiers"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource# VirtualDatacenterResource-Retrieveenabledtiers</a>
|
||||
*/
|
||||
public List<Tier> listStorageTiers(final Predicate<Tier> filter) {
|
||||
return ImmutableList.copyOf(filter(listStorageTiers(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first the storage tier that is available to the virtual
|
||||
* datacenter and matches the given filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The first the storage tier that is available to the virtual
|
||||
* datacenter and matches the given filter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-Retrieveenabledtiers"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource# VirtualDatacenterResource-Retrieveenabledtiers</a>
|
||||
*/
|
||||
public Tier findStorageTier(final Predicate<Tier> filter) {
|
||||
return Iterables.getFirst(filter(listStorageTiers(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the storage tier with the given id from the current virtual
|
||||
* datacenter.
|
||||
*
|
||||
* @param id
|
||||
* The id of the storage tier.
|
||||
* @return The storage tier.
|
||||
*/
|
||||
public Tier getStorageTier(final Integer id) {
|
||||
TierDto tier = context.getApi().getCloudApi().getStorageTier(target, id);
|
||||
return wrap(context, Tier.class, tier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all persistent volumes in the virtual datacenter.
|
||||
*
|
||||
* @return The list of all persistent volumes in the virtual datacenter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Volume+Resource#VolumeResource-Retrievethelistofvolumes"
|
||||
* > http://community.abiquo.com/display/ABI20/Volume+Resource#
|
||||
* VolumeResource- Retrievethelistofvolumes</a>
|
||||
*/
|
||||
public List<Volume> listVolumes() {
|
||||
VolumesManagementDto volumes = context.getApi().getCloudApi().listVolumes(target);
|
||||
return wrap(context, Volume.class, volumes.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all persistent volumes in the virtual datacenter that match the
|
||||
* given filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The list of all persistent volumes in the virtual datacenter that
|
||||
* match the given filter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Volume+Resource#VolumeResource-Retrievethelistofvolumes"
|
||||
* > http://community.abiquo.com/display/ABI20/Volume+Resource#
|
||||
* VolumeResource- Retrievethelistofvolumes</a>
|
||||
*/
|
||||
public List<Volume> listVolumes(final Predicate<Volume> filter) {
|
||||
return ImmutableList.copyOf(filter(listVolumes(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first persistent volume in the virtual datacenter that matches
|
||||
* the given filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The first persistent volumes in the virtual datacenter that
|
||||
* matches the given filter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Volume+Resource#VolumeResource-Retrievethelistofvolumes"
|
||||
* > http://community.abiquo.com/display/ABI20/Volume+Resource#
|
||||
* VolumeResource- Retrievethelistofvolumes</a>
|
||||
*/
|
||||
public Volume findVolume(final Predicate<Volume> filter) {
|
||||
return Iterables.getFirst(filter(listVolumes(), filter), null);
|
||||
}
|
||||
|
||||
public Volume getVolume(final Integer id) {
|
||||
VolumeManagementDto volume = context.getApi().getCloudApi().getVolume(target, id);
|
||||
return wrap(context, Volume.class, volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Hard+Disks+Resource#HardDisksResource-GetthelistofHardDisksofaVirtualDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Hard+Disks+Resource#
|
||||
* HardDisksResource- GetthelistofHardDisksofaVirtualDatacenter</a>
|
||||
*/
|
||||
public List<HardDisk> listHardDisks() {
|
||||
DisksManagementDto hardDisks = context.getApi().getCloudApi().listHardDisks(target);
|
||||
return wrap(context, HardDisk.class, hardDisks.getCollection());
|
||||
}
|
||||
|
||||
public List<HardDisk> listHardDisks(final Predicate<HardDisk> filter) {
|
||||
return ImmutableList.copyOf(filter(listHardDisks(), filter));
|
||||
}
|
||||
|
||||
public HardDisk findHardDisk(final Predicate<HardDisk> filter) {
|
||||
return Iterables.getFirst(filter(listHardDisks(), filter), null);
|
||||
}
|
||||
|
||||
public HardDisk getHardDisk(final Integer id) {
|
||||
DiskManagementDto hardDisk = context.getApi().getCloudApi().getHardDisk(target, id);
|
||||
return wrap(context, HardDisk.class, hardDisk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-GetdefaultVLANusedbydefaultinVirtualDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource#
|
||||
* VirtualDatacenterResource-GetdefaultVLANusedbydefaultinVirtualDatacenter
|
||||
* </a>
|
||||
*/
|
||||
public Network<?> getDefaultNetwork() {
|
||||
VLANNetworkDto network = context.getApi().getCloudApi().getDefaultNetwork(target);
|
||||
return wrap(context, network.getType() == NetworkType.INTERNAL ? PrivateNetwork.class : ExternalNetwork.class,
|
||||
network);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Private+Network+Resource#PrivateNetworkResource-RetrievealistofPrivateNetworks"
|
||||
* > http://community.abiquo.com/display/ABI20/Private+Network+Resource#
|
||||
* PrivateNetworkResource -RetrievealistofPrivateNetworks</a>
|
||||
*/
|
||||
public List<PrivateNetwork> listPrivateNetworks() {
|
||||
VLANNetworksDto networks = context.getApi().getCloudApi().listPrivateNetworks(target);
|
||||
return wrap(context, PrivateNetwork.class, networks.getCollection());
|
||||
}
|
||||
|
||||
public List<PrivateNetwork> listPrivateNetworks(final Predicate<Network<PrivateIp>> filter) {
|
||||
return ImmutableList.copyOf(filter(listPrivateNetworks(), filter));
|
||||
}
|
||||
|
||||
public PrivateNetwork findPrivateNetwork(final Predicate<Network<PrivateIp>> filter) {
|
||||
return Iterables.getFirst(filter(listPrivateNetworks(), filter), null);
|
||||
}
|
||||
|
||||
public PrivateNetwork getPrivateNetwork(final Integer id) {
|
||||
VLANNetworkDto network = context.getApi().getCloudApi().getPrivateNetwork(target, id);
|
||||
return wrap(context, PrivateNetwork.class, network);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO needs to be in the wiki
|
||||
*/
|
||||
public List<VirtualMachineTemplate> listAvailableTemplates() {
|
||||
VirtualMachineTemplatesDto templates = context.getApi().getCloudApi().listAvailableTemplates(target);
|
||||
|
||||
return wrap(context, VirtualMachineTemplate.class, templates.getCollection());
|
||||
}
|
||||
|
||||
public List<VirtualMachineTemplate> listAvailableTemplates(final VirtualMachineTemplateOptions options) {
|
||||
VirtualMachineTemplatesDto templates = context.getApi().getCloudApi().listAvailableTemplates(target, options);
|
||||
|
||||
return wrap(context, VirtualMachineTemplate.class, templates.getCollection());
|
||||
}
|
||||
|
||||
public List<VirtualMachineTemplate> listAvailableTemplates(final Predicate<VirtualMachineTemplate> filter) {
|
||||
return ImmutableList.copyOf(filter(listAvailableTemplates(), filter));
|
||||
}
|
||||
|
||||
public VirtualMachineTemplate findAvailableTemplate(final Predicate<VirtualMachineTemplate> filter) {
|
||||
return Iterables.getFirst(filter(listAvailableTemplates(), filter), null);
|
||||
}
|
||||
|
||||
public VirtualMachineTemplate getAvailableTemplate(final Integer id) {
|
||||
VirtualMachineTemplatesDto templates = context.getApi().getCloudApi()
|
||||
.listAvailableTemplates(target, VirtualMachineTemplateOptions.builder().idTemplate(id).build());
|
||||
|
||||
return templates.getCollection().isEmpty() ? null : //
|
||||
wrap(context, VirtualMachineTemplate.class, templates.getCollection().get(0));
|
||||
}
|
||||
|
||||
public VirtualMachineTemplate getAvailablePersistentTemplate(final Integer id) {
|
||||
VirtualMachineTemplatesDto templates = context
|
||||
.getApi()
|
||||
.getCloudApi()
|
||||
.listAvailableTemplates(target,
|
||||
VirtualMachineTemplateOptions.builder().idTemplate(id).persistent(StatefulInclusion.ALL).build());
|
||||
|
||||
return templates.getCollection().isEmpty() ? null : //
|
||||
wrap(context, VirtualMachineTemplate.class, templates.getCollection().get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-ListofPublicIPstopurchasebyVirtualDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource#
|
||||
* VirtualDatacenterResource-ListofPublicIPstopurchasebyVirtualDatacenter
|
||||
* </a>
|
||||
*/
|
||||
public List<PublicIp> listAvailablePublicIps() {
|
||||
IpOptions options = IpOptions.builder().build();
|
||||
|
||||
PublicIpsDto ips = context.getApi().getCloudApi().listAvailablePublicIps(target, options);
|
||||
|
||||
return wrap(context, PublicIp.class, ips.getCollection());
|
||||
}
|
||||
|
||||
public List<PublicIp> listAvailablePublicIps(final Predicate<PublicIp> filter) {
|
||||
return ImmutableList.copyOf(filter(listAvailablePublicIps(), filter));
|
||||
}
|
||||
|
||||
public PublicIp findAvailablePublicIp(final Predicate<PublicIp> filter) {
|
||||
return Iterables.getFirst(filter(listAvailablePublicIps(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-ListofpurchasedPublicIPsbyVirtualDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource#
|
||||
* VirtualDatacenterResource-ListofpurchasedPublicIPsbyVirtualDatacenter
|
||||
* </a>
|
||||
*/
|
||||
public List<PublicIp> listPurchasedPublicIps() {
|
||||
IpOptions options = IpOptions.builder().build();
|
||||
|
||||
PublicIpsDto ips = context.getApi().getCloudApi().listPurchasedPublicIps(target, options);
|
||||
|
||||
return wrap(context, PublicIp.class, ips.getCollection());
|
||||
}
|
||||
|
||||
public List<PublicIp> listPurchasedPublicIps(final Predicate<PublicIp> filter) {
|
||||
return ImmutableList.copyOf(filter(listPurchasedPublicIps(), filter));
|
||||
}
|
||||
|
||||
public PublicIp findPurchasedPublicIp(final Predicate<PublicIp> filter) {
|
||||
return Iterables.getFirst(filter(listPurchasedPublicIps(), filter), null);
|
||||
}
|
||||
|
||||
public void purchasePublicIp(final PublicIp ip) {
|
||||
checkNotNull(ip.unwrap().searchLink("purchase"), ValidationErrors.MISSING_REQUIRED_LINK);
|
||||
context.getApi().getCloudApi().purchasePublicIp(ip.unwrap());
|
||||
}
|
||||
|
||||
public void releasePublicIp(final PublicIp ip) {
|
||||
checkNotNull(ip.unwrap().searchLink("release"), ValidationErrors.MISSING_REQUIRED_LINK);
|
||||
context.getApi().getCloudApi().releasePublicIp(ip.unwrap());
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
public void setDefaultNetwork(final Network<?> network) {
|
||||
context.getApi().getCloudApi().setDefaultNetwork(target, network.unwrap());
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Datacenter datacenter,
|
||||
final Enterprise enterprise) {
|
||||
return new Builder(context, datacenter, enterprise);
|
||||
}
|
||||
|
||||
public static class Builder extends LimitsBuilder<Builder> {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private String name;
|
||||
|
||||
private HypervisorType hypervisorType;
|
||||
|
||||
private Enterprise enterprise;
|
||||
|
||||
private Datacenter datacenter;
|
||||
|
||||
private PrivateNetwork network;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Datacenter datacenter,
|
||||
final Enterprise enterprise) {
|
||||
super();
|
||||
checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class);
|
||||
this.datacenter = datacenter;
|
||||
checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class);
|
||||
this.enterprise = enterprise;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hypervisorType(final HypervisorType hypervisorType) {
|
||||
this.hypervisorType = hypervisorType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder datacenter(final Datacenter datacenter) {
|
||||
checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class);
|
||||
this.datacenter = datacenter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder enterprise(final Enterprise enterprise) {
|
||||
checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class);
|
||||
this.enterprise = enterprise;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder network(final PrivateNetwork network) {
|
||||
checkNotNull(network, ValidationErrors.NULL_RESOURCE + PrivateNetwork.class);
|
||||
this.network = network;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VirtualDatacenter build() {
|
||||
VirtualDatacenterDto dto = new VirtualDatacenterDto();
|
||||
dto.setName(name);
|
||||
dto.setRamLimitsInMb(ramSoftLimitInMb, ramHardLimitInMb);
|
||||
dto.setCpuCountLimits(cpuCountSoftLimit, cpuCountHardLimit);
|
||||
dto.setHdLimitsInMb(hdSoftLimitInMb, hdHardLimitInMb);
|
||||
dto.setStorageLimits(storageSoft, storageHard);
|
||||
dto.setVlansLimits(vlansSoft, vlansHard);
|
||||
dto.setPublicIPLimits(publicIpsSoft, publicIpsHard);
|
||||
dto.setName(name);
|
||||
dto.setHypervisorType(hypervisorType);
|
||||
dto.setVlan(network.unwrap());
|
||||
|
||||
VirtualDatacenter virtualDatacenter = new VirtualDatacenter(context, dto);
|
||||
virtualDatacenter.datacenter = datacenter;
|
||||
virtualDatacenter.enterprise = enterprise;
|
||||
|
||||
return virtualDatacenter;
|
||||
}
|
||||
|
||||
public static Builder fromVirtualDatacenter(final VirtualDatacenter in) {
|
||||
return VirtualDatacenter.builder(in.context, in.datacenter, in.enterprise).name(in.getName())
|
||||
.ramLimits(in.getRamSoftLimitInMb(), in.getRamHardLimitInMb())
|
||||
.cpuCountLimits(in.getCpuCountSoftLimit(), in.getCpuCountHardLimit())
|
||||
.hdLimitsInMb(in.getHdSoftLimitInMb(), in.getHdHardLimitInMb())
|
||||
.storageLimits(in.getStorageSoft(), in.getStorageHard())
|
||||
.vlansLimits(in.getVlansSoft(), in.getVlansHard())
|
||||
.publicIpsLimits(in.getPublicIpsSoft(), in.getPublicIpsHard()).hypervisorType(in.getHypervisorType());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public HypervisorType getHypervisorType() {
|
||||
return target.getHypervisorType();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public void setHypervisorType(final HypervisorType hypervisorType) {
|
||||
target.setHypervisorType(hypervisorType);
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VirtualDatacenter [id=" + getId() + ", type=" + getHypervisorType() + ", name=" + getName() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,899 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWithTasksWrapper;
|
||||
import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions;
|
||||
import org.jclouds.abiquo.domain.enterprise.Enterprise;
|
||||
import org.jclouds.abiquo.domain.network.Ip;
|
||||
import org.jclouds.abiquo.domain.network.Network;
|
||||
import org.jclouds.abiquo.domain.network.UnmanagedNetwork;
|
||||
import org.jclouds.abiquo.domain.task.AsyncTask;
|
||||
import org.jclouds.abiquo.domain.util.LinkUtils;
|
||||
import org.jclouds.abiquo.features.services.MonitoringService;
|
||||
import org.jclouds.abiquo.monitor.VirtualMachineMonitor;
|
||||
import org.jclouds.abiquo.predicates.LinkPredicates;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
|
||||
import org.jclouds.abiquo.strategy.cloud.ListAttachedNics;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.AcceptedRequestDto;
|
||||
import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto;
|
||||
import com.abiquo.server.core.cloud.VirtualApplianceDto;
|
||||
import com.abiquo.server.core.cloud.VirtualDatacenterDto;
|
||||
import com.abiquo.server.core.cloud.VirtualMachineState;
|
||||
import com.abiquo.server.core.cloud.VirtualMachineStateDto;
|
||||
import com.abiquo.server.core.cloud.VirtualMachineTaskDto;
|
||||
import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto;
|
||||
import com.abiquo.server.core.enterprise.EnterpriseDto;
|
||||
import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto;
|
||||
import com.abiquo.server.core.infrastructure.network.VMNetworkConfigurationDto;
|
||||
import com.abiquo.server.core.infrastructure.network.VMNetworkConfigurationsDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.DiskManagementDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.DisksManagementDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.DvdManagementDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.VolumesManagementDto;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link VirtualMachineWithNodeExtendedDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/VirtualMachineResource">
|
||||
* http://community.abiquo.com/display/ABI20/VirtualMachineResource</a>
|
||||
*/
|
||||
public class VirtualMachine extends DomainWithTasksWrapper<VirtualMachineWithNodeExtendedDto> {
|
||||
/** The virtual appliance where the virtual machine belongs. */
|
||||
private VirtualAppliance virtualAppliance;
|
||||
|
||||
/** The virtual machine template of the virtual machine. */
|
||||
private VirtualMachineTemplate template;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected VirtualMachine(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final VirtualMachineWithNodeExtendedDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* Delete the virtual machine.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/VirtualMachineResource#VirtualMachineResource-Deleteavirtualmachine"
|
||||
* > http://community.abiquo.com/display/ABI20/VirtualMachineResource#
|
||||
* VirtualMachineResource -Deleteavirtualmachine</a>
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getCloudApi().deleteVirtualMachine(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new virtual machine in Abiquo.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/VirtualMachineResource#VirtualMachineResource-Createavirtualmachine"
|
||||
* > http://community.abiquo.com/display/ABI20/VirtualMachineResource#
|
||||
* VirtualMachineResource-Createavirtualmachine</a>
|
||||
*/
|
||||
public void save() {
|
||||
checkNotNull(template, ValidationErrors.NULL_RESOURCE + VirtualMachineTemplate.class);
|
||||
checkNotNull(template.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + VirtualMachineTemplate.class);
|
||||
|
||||
this.updateLink(target, ParentLinkName.VIRTUAL_MACHINE_TEMPLATE, template.unwrap(), "edit");
|
||||
|
||||
target = context.getApi().getCloudApi().createVirtualMachine(virtualAppliance.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update virtual machine information in the server with the data from this
|
||||
* virtual machine. This is an asynchronous call. This method returns a
|
||||
* {@link org.jclouds.abiquo.domain.task.AsyncTask} object that keeps track
|
||||
* of the task completion. Please refer to the documentation for details.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/VirtualMachineResource#VirtualMachineResource-Modifyavirtualmachine"
|
||||
* > http://community.abiquo.com/display/ABI20/VirtualMachineResource#
|
||||
* VirtualMachineResource-Modifyavirtualmachine</a>
|
||||
* @see github: <a href=
|
||||
* "https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-example"
|
||||
* > https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-
|
||||
* example</a>
|
||||
* @return The task reference or <code>null</code> if the operation completed
|
||||
* synchronously.
|
||||
*/
|
||||
public AsyncTask update() {
|
||||
AcceptedRequestDto<String> taskRef = context.getApi().getCloudApi().updateVirtualMachine(target);
|
||||
return taskRef == null ? null : getTask(taskRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update virtual machine information in the server with the data from this
|
||||
* virtual machine. This is an asynchronous call. This method returns a
|
||||
* {@link org.jclouds.abiquo.domain.task.AsyncTask} object that keeps track
|
||||
* of the task completion. Please refer to the documentation for details.
|
||||
*
|
||||
* @param force
|
||||
* Force update.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/VirtualMachineResource#VirtualMachineResource-Modifyavirtualmachine"
|
||||
* > http://community.abiquo.com/display/ABI20/VirtualMachineResource#
|
||||
* VirtualMachineResource-Modifyavirtualmachine</a>
|
||||
* @see github: <a href=
|
||||
* "https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-example"
|
||||
* > https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-
|
||||
* example</a>
|
||||
* @return The task reference or <code>null</code> if the operation completed
|
||||
* synchronously.
|
||||
*/
|
||||
public AsyncTask update(final boolean force) {
|
||||
AcceptedRequestDto<String> taskRef = context.getApi().getCloudApi()
|
||||
.updateVirtualMachine(target, VirtualMachineOptions.builder().force(force).build());
|
||||
return taskRef == null ? null : getTask(taskRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the state of the virtual machine. This is an asynchronous call.
|
||||
* This method returns a {@link org.jclouds.abiquo.domain.task.AsyncTask}
|
||||
* object that keeps track of the task completion. Please refer to the
|
||||
* documentation for details.
|
||||
*
|
||||
* @param state
|
||||
* The new state of the virtual machine.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/VirtualMachineResource#VirtualMachineResource-Changethestateofavirtualmachine"
|
||||
* > http://community.abiquo.com/display/ABI20/VirtualMachineResource#
|
||||
* VirtualMachineResource-Changethestateofavirtualmachine</a>
|
||||
* @see github: <a href=
|
||||
* "https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-example"
|
||||
* > https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-
|
||||
* example</a>
|
||||
* @return The task reference or <code>null</code> if the operation completed
|
||||
* synchronously.
|
||||
*/
|
||||
public AsyncTask changeState(final VirtualMachineState state) {
|
||||
VirtualMachineStateDto dto = new VirtualMachineStateDto();
|
||||
dto.setState(state);
|
||||
|
||||
AcceptedRequestDto<String> taskRef = context.getApi().getCloudApi().changeVirtualMachineState(target, dto);
|
||||
|
||||
return getTask(taskRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the state of the virtual machine.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/VirtualMachineResource#VirtualMachineResource-Retrievethestateofthevirtualmachine"
|
||||
* > http://community.abiquo.com/display/ABI20/VirtualMachineResource#
|
||||
* VirtualMachineResource-Retrievethestateofthevirtualmachine</a>
|
||||
* @return Current state of the virtual machine.
|
||||
*/
|
||||
public VirtualMachineState getState() {
|
||||
VirtualMachineStateDto stateDto = context.getApi().getCloudApi().getVirtualMachineState(target);
|
||||
VirtualMachineState state = stateDto.getState();
|
||||
target.setState(state);
|
||||
target.setIdState(state.id());
|
||||
return state;
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* Retrieve the virtual appliance where this virtual machine is.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/VirtualApplianceResource#VirtualApplianceResource-Retrieveavirtualappliance"
|
||||
* > http://community.abiquo.com/display/ABI20/VirtualApplianceResource#
|
||||
* VirtualApplianceResource-Retrieveavirtualappliance</a>
|
||||
* @return The virtual appliance where this virtual machine is.
|
||||
*/
|
||||
public VirtualAppliance getVirtualAppliance() {
|
||||
RESTLink link = checkNotNull(target.searchLink(ParentLinkName.VIRTUAL_APPLIANCE),
|
||||
ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.VIRTUAL_APPLIANCE);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<VirtualApplianceDto> parser = new ParseXMLWithJAXB<VirtualApplianceDto>(utils.getXml(),
|
||||
TypeLiteral.get(VirtualApplianceDto.class));
|
||||
|
||||
return wrap(context, VirtualAppliance.class, parser.apply(response));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the virtual datacenter where this virtual machine is.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/VirtualDatacenterResource#VirtualDatacenterResource-Retireveavirtualdatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/VirtualDatacenterResource
|
||||
* # VirtualDatacenterResource-Retireveavirtualdatacenter</a>
|
||||
* @return The virtual datacenter where this virtual machine is.
|
||||
*/
|
||||
public VirtualDatacenter getVirtualDatacenter() {
|
||||
Integer virtualDatacenterId = target.getIdFromLink(ParentLinkName.VIRTUAL_DATACENTER);
|
||||
VirtualDatacenterDto dto = context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId);
|
||||
return wrap(context, VirtualDatacenter.class, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the enterprise of this virtual machine.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-RetrieveanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource- RetrieveanEnterprise</a>
|
||||
* @return Enterprise of this virtual machine.
|
||||
*/
|
||||
public Enterprise getEnterprise() {
|
||||
Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE);
|
||||
EnterpriseDto dto = context.getApi().getEnterpriseApi().getEnterprise(enterpriseId);
|
||||
return wrap(context, Enterprise.class, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the template of this virtual machine.
|
||||
*
|
||||
* @return Template of this virtual machine.
|
||||
*/
|
||||
public VirtualMachineTemplate getTemplate() {
|
||||
VirtualMachineTemplateDto dto = context.getApi().getCloudApi().getVirtualMachineTemplate(target);
|
||||
return wrap(context, VirtualMachineTemplate.class, dto);
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
public List<HardDisk> listAttachedHardDisks() {
|
||||
refresh();
|
||||
DisksManagementDto hardDisks = context.getApi().getCloudApi().listAttachedHardDisks(target);
|
||||
return wrap(context, HardDisk.class, hardDisks.getCollection());
|
||||
}
|
||||
|
||||
public List<HardDisk> listAttachedHardDisks(final Predicate<HardDisk> filter) {
|
||||
return ImmutableList.copyOf(filter(listAttachedHardDisks(), filter));
|
||||
}
|
||||
|
||||
public HardDisk findAttachedHardDisk(final Predicate<HardDisk> filter) {
|
||||
return Iterables.getFirst(filter(listAttachedHardDisks(), filter), null);
|
||||
}
|
||||
|
||||
public List<Volume> listAttachedVolumes() {
|
||||
refresh();
|
||||
VolumesManagementDto volumes = context.getApi().getCloudApi().listAttachedVolumes(target);
|
||||
return wrap(context, Volume.class, volumes.getCollection());
|
||||
}
|
||||
|
||||
public List<Volume> listAttachedVolumes(final Predicate<Volume> filter) {
|
||||
return ImmutableList.copyOf(filter(listAttachedVolumes(), filter));
|
||||
}
|
||||
|
||||
public Volume findAttachedVolume(final Predicate<Volume> filter) {
|
||||
return Iterables.getFirst(filter(listAttachedVolumes(), filter), null);
|
||||
}
|
||||
|
||||
public List<Ip<?, ?>> listAttachedNics() {
|
||||
// The strategy will refresh the vm. There is no need to do it here
|
||||
ListAttachedNics strategy = context.getUtils().getInjector().getInstance(ListAttachedNics.class);
|
||||
return ImmutableList.copyOf(strategy.execute(this));
|
||||
}
|
||||
|
||||
public List<Ip<?, ?>> listAttachedNics(final Predicate<Ip<?, ?>> filter) {
|
||||
return ImmutableList.copyOf(filter(listAttachedNics(), filter));
|
||||
}
|
||||
|
||||
public Ip<?, ?> findAttachedNic(final Predicate<Ip<?, ?>> filter) {
|
||||
return Iterables.getFirst(filter(listAttachedNics(), filter), null);
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
public AsyncTask deploy() {
|
||||
return deploy(false);
|
||||
}
|
||||
|
||||
public AsyncTask deploy(final boolean forceEnterpriseSoftLimits) {
|
||||
VirtualMachineTaskDto force = new VirtualMachineTaskDto();
|
||||
force.setForceEnterpriseSoftLimits(forceEnterpriseSoftLimits);
|
||||
|
||||
AcceptedRequestDto<String> response = context.getApi().getCloudApi().deployVirtualMachine(unwrap(), force);
|
||||
|
||||
return getTask(response);
|
||||
}
|
||||
|
||||
public AsyncTask undeploy() {
|
||||
return undeploy(false);
|
||||
}
|
||||
|
||||
public AsyncTask undeploy(final boolean forceUndeploy) {
|
||||
VirtualMachineTaskDto force = new VirtualMachineTaskDto();
|
||||
force.setForceUndeploy(forceUndeploy);
|
||||
|
||||
AcceptedRequestDto<String> response = context.getApi().getCloudApi().undeployVirtualMachine(unwrap(), force);
|
||||
|
||||
return getTask(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reboot a virtual machine. This is an asynchronous call. This method
|
||||
* returns a {@link org.jclouds.abiquo.domain.task.AsyncTask} object that
|
||||
* keeps track of the task completion. Please refer to the documentation for
|
||||
* details.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/VirtualMachineResource#VirtualMachineResource-Resetavirtualmachine"
|
||||
* > http://community.abiquo.com/display/ABI20/Rack+Resource#/
|
||||
* VirtualMachineResource#
|
||||
* VirtualMachineResource-Resetavirtualmachine</a>
|
||||
* @see github: <a href=
|
||||
* "https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-example"
|
||||
* > https://github.com/abiquo/jclouds-abiquo/wiki/Asynchronous-monitor-
|
||||
* example</a>
|
||||
* @return The task reference or <code>null</code> if the operation completed
|
||||
* synchronously.
|
||||
*/
|
||||
public AsyncTask reboot() {
|
||||
AcceptedRequestDto<String> response = context.getApi().getCloudApi().rebootVirtualMachine(unwrap());
|
||||
|
||||
return getTask(response);
|
||||
}
|
||||
|
||||
public AsyncTask attachHardDisks(final HardDisk... hardDisks) {
|
||||
List<HardDisk> expected = Lists.newArrayList(listAttachedHardDisks());
|
||||
expected.addAll(Arrays.asList(hardDisks));
|
||||
|
||||
HardDisk[] disks = new HardDisk[expected.size()];
|
||||
return setHardDisks(expected.toArray(disks));
|
||||
}
|
||||
|
||||
public AsyncTask detachAllHardDisks() {
|
||||
AcceptedRequestDto<String> taskRef = context.getApi().getCloudApi().detachAllHardDisks(target);
|
||||
return taskRef == null ? null : getTask(taskRef);
|
||||
}
|
||||
|
||||
public AsyncTask detachHardDisks(final HardDisk... hardDisks) {
|
||||
List<HardDisk> expected = Lists.newArrayList(listAttachedHardDisks());
|
||||
Iterables.removeIf(expected, hardDiskIdIn(hardDisks));
|
||||
|
||||
HardDisk[] disks = new HardDisk[expected.size()];
|
||||
return setHardDisks(expected.toArray(disks));
|
||||
}
|
||||
|
||||
public AsyncTask setHardDisks(final HardDisk... hardDisks) {
|
||||
AcceptedRequestDto<String> taskRef = context.getApi().getCloudApi()
|
||||
.replaceHardDisks(target, toHardDiskDto(hardDisks));
|
||||
return taskRef == null ? null : getTask(taskRef);
|
||||
}
|
||||
|
||||
public AsyncTask attachVolumes(final Volume... volumes) {
|
||||
List<Volume> expected = Lists.newArrayList(listAttachedVolumes());
|
||||
expected.addAll(Arrays.asList(volumes));
|
||||
|
||||
Volume[] vols = new Volume[expected.size()];
|
||||
return setVolumes(true, expected.toArray(vols));
|
||||
}
|
||||
|
||||
public AsyncTask detachAllVolumes() {
|
||||
AcceptedRequestDto<String> taskRef = context.getApi().getCloudApi().detachAllVolumes(target);
|
||||
return taskRef == null ? null : getTask(taskRef);
|
||||
}
|
||||
|
||||
public AsyncTask detachVolumes(final Volume... volumes) {
|
||||
List<Volume> expected = Lists.newArrayList(listAttachedVolumes());
|
||||
Iterables.removeIf(expected, volumeIdIn(volumes));
|
||||
|
||||
Volume[] vols = new Volume[expected.size()];
|
||||
return setVolumes(true, expected.toArray(vols));
|
||||
}
|
||||
|
||||
public AsyncTask setVolumes(final Boolean forceSoftLimits, final Volume... volumes) {
|
||||
AcceptedRequestDto<String> taskRef = context
|
||||
.getApi()
|
||||
.getCloudApi()
|
||||
.replaceVolumes(target, VirtualMachineOptions.builder().force(forceSoftLimits).build(),
|
||||
toVolumeDto(volumes));
|
||||
|
||||
return taskRef == null ? null : getTask(taskRef);
|
||||
}
|
||||
|
||||
public AsyncTask setVolumes(final Volume... volumes) {
|
||||
return setVolumes(true, volumes);
|
||||
}
|
||||
|
||||
public AsyncTask setNics(final List<? extends Ip<?, ?>> ips) {
|
||||
// By default the network of the first ip will be used as a gateway
|
||||
return setNics(ips != null && !ips.isEmpty() ? ips.get(0).getNetwork() : null, ips, null);
|
||||
}
|
||||
|
||||
public AsyncTask setNics(final List<? extends Ip<?, ?>> ips, final List<UnmanagedNetwork> unmanagedNetworks) {
|
||||
// By default the network of the first ip will be used as a gateway
|
||||
Network<?> gateway = null;
|
||||
if (ips != null && !ips.isEmpty()) {
|
||||
gateway = ips.get(0).getNetwork();
|
||||
} else if (unmanagedNetworks != null && !unmanagedNetworks.isEmpty()) {
|
||||
gateway = unmanagedNetworks.get(0);
|
||||
}
|
||||
|
||||
return setNics(gateway, ips, unmanagedNetworks);
|
||||
}
|
||||
|
||||
public AsyncTask setNics(final Network<?> gatewayNetwork, final List<? extends Ip<?, ?>> ips) {
|
||||
return setNics(gatewayNetwork, ips, null);
|
||||
}
|
||||
|
||||
public AsyncTask setNics(final Network<?> gatewayNetwork, final List<? extends Ip<?, ?>> ips,
|
||||
final List<UnmanagedNetwork> unmanagedNetworks) {
|
||||
// Remove the gateway configuration and the current nics
|
||||
Iterables.removeIf(target.getLinks(),
|
||||
Predicates.or(LinkPredicates.isNic(), LinkPredicates.rel(ParentLinkName.NETWORK_GATEWAY)));
|
||||
|
||||
// Add the given nics in the appropriate order
|
||||
int i = 0;
|
||||
if (ips != null) {
|
||||
for (i = 0; i < ips.size(); i++) {
|
||||
RESTLink source = LinkUtils.getSelfLink(ips.get(i).unwrap());
|
||||
RESTLink link = new RESTLink("nic" + i, source.getHref());
|
||||
link.setType(ips.get(i).unwrap().getBaseMediaType());
|
||||
target.addLink(link);
|
||||
}
|
||||
}
|
||||
|
||||
// Add unmanaged network references, if given
|
||||
if (unmanagedNetworks != null) {
|
||||
for (UnmanagedNetwork unmanaged : unmanagedNetworks) {
|
||||
RESTLink source = checkNotNull(unmanaged.unwrap().searchLink("ips"), ValidationErrors.MISSING_REQUIRED_LINK
|
||||
+ "ips");
|
||||
|
||||
RESTLink link = new RESTLink("nic" + i, source.getHref());
|
||||
link.setType(UnmanagedIpDto.BASE_MEDIA_TYPE);
|
||||
target.addLink(link);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
AsyncTask task = update(true);
|
||||
if (gatewayNetwork == null) {
|
||||
return task;
|
||||
}
|
||||
|
||||
// If there is a gateway network, we have to wait until the network
|
||||
// configuration links are
|
||||
// available
|
||||
if (task != null) {
|
||||
VirtualMachineState originalState = target.getState();
|
||||
VirtualMachineMonitor monitor = context.getUtils().getInjector().getInstance(MonitoringService.class)
|
||||
.getVirtualMachineMonitor();
|
||||
monitor.awaitState(originalState, this);
|
||||
}
|
||||
|
||||
// Set the new network configuration
|
||||
|
||||
// Refresh virtual machine, to get the new configuration links
|
||||
refresh();
|
||||
|
||||
VMNetworkConfigurationsDto configs = context.getApi().getCloudApi().listNetworkConfigurations(target);
|
||||
|
||||
Iterables.removeIf(target.getLinks(), LinkPredicates.rel(ParentLinkName.NETWORK_GATEWAY));
|
||||
for (VMNetworkConfigurationDto config : configs.getCollection()) {
|
||||
if (config.getGateway().equalsIgnoreCase(gatewayNetwork.getGateway())) {
|
||||
target.addLink(new RESTLink(ParentLinkName.NETWORK_GATEWAY, config.getEditLink().getHref()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return update(true);
|
||||
}
|
||||
|
||||
// TODO: Get current gateway network
|
||||
|
||||
public void setGatewayNetwork(final Network<?> network) {
|
||||
context.getApi().getCloudApi().setGatewayNetwork(target, network.unwrap());
|
||||
refresh(); // First refresh the target and its links
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the virtual machine is persistent.
|
||||
* <p>
|
||||
* Persistent virtual machines have the system disc in an external volume.
|
||||
* This way, when the virtual machine is undeployed, the contents of the
|
||||
* system disk remain in the storage device and the user can deploy the
|
||||
* virtual machine again without losing the data in the system disk.
|
||||
*
|
||||
* @return Boolean indicating if the virtual machine is persistent.
|
||||
*/
|
||||
public boolean isPersistent() {
|
||||
return getTemplate().unwrap().searchLink("volume") != null;
|
||||
}
|
||||
|
||||
public boolean hasDvd() {
|
||||
return target.getDvd() != null;
|
||||
}
|
||||
|
||||
public void attachDvd() {
|
||||
DvdManagementDto dvd = new DvdManagementDto();
|
||||
RESTLink link = new RESTLink("image", "");
|
||||
dvd.addLink(link);
|
||||
target.setDvd(dvd);
|
||||
}
|
||||
|
||||
public void detachDvd() {
|
||||
target.setDvd(null);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final VirtualAppliance virtualAppliance, final VirtualMachineTemplate template) {
|
||||
return new Builder(context, virtualAppliance, template);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private VirtualAppliance virtualAppliance;
|
||||
|
||||
private final VirtualMachineTemplate template;
|
||||
|
||||
private String nameLabel;
|
||||
|
||||
private String internalName;
|
||||
|
||||
private String description;
|
||||
|
||||
private Integer ram;
|
||||
|
||||
private Integer cpu;
|
||||
|
||||
private Integer vncPort;
|
||||
|
||||
private String vncAddress;
|
||||
|
||||
private Integer idState;
|
||||
|
||||
private Integer idType;
|
||||
|
||||
private String password;
|
||||
|
||||
private String keymap;
|
||||
|
||||
private String uuid;
|
||||
|
||||
private boolean dvd;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final VirtualAppliance virtualAppliance,
|
||||
final VirtualMachineTemplate template) {
|
||||
super();
|
||||
checkNotNull(virtualAppliance, ValidationErrors.NULL_RESOURCE + VirtualAppliance.class);
|
||||
this.virtualAppliance = virtualAppliance;
|
||||
this.template = template;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder nameLabel(final String nameLabel) {
|
||||
this.nameLabel = checkNotNull(nameLabel, "nameLabel must not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(final String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ram(final int ram) {
|
||||
this.ram = ram;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder cpu(final int cpu) {
|
||||
this.cpu = cpu;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder password(final String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder keymap(final String keymap) {
|
||||
this.keymap = keymap;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder dvd(final boolean dvd) {
|
||||
this.dvd = dvd;
|
||||
return this;
|
||||
}
|
||||
|
||||
// This methods are used only to build a builder from an existing
|
||||
// VirtualMachine but should
|
||||
// never be used by the user. This fields are set automatically by Abiquo
|
||||
|
||||
private Builder vncPort(final int vdrpPort) {
|
||||
this.vncPort = vdrpPort;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Builder vncAddress(final String vdrpIP) {
|
||||
this.vncAddress = vdrpIP;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Builder idState(final int idState) {
|
||||
this.idState = idState;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Builder idType(final int idType) {
|
||||
this.idType = idType;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Builder internalName(final String internalName) {
|
||||
this.internalName = internalName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualAppliance(final VirtualAppliance virtualAppliance) {
|
||||
checkNotNull(virtualAppliance, ValidationErrors.NULL_RESOURCE + VirtualAppliance.class);
|
||||
this.virtualAppliance = virtualAppliance;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VirtualMachine build() {
|
||||
VirtualMachineWithNodeExtendedDto dto = new VirtualMachineWithNodeExtendedDto();
|
||||
dto.setNodeName(checkNotNull(nameLabel, ValidationErrors.MISSING_REQUIRED_FIELD + "nameLabel"));
|
||||
dto.setDescription(description);
|
||||
dto.setHdInBytes(template.getHdRequired());
|
||||
dto.setVdrpIP(vncAddress);
|
||||
|
||||
if (cpu != null) {
|
||||
dto.setCpu(cpu);
|
||||
}
|
||||
|
||||
if (ram != null) {
|
||||
dto.setRam(ram);
|
||||
}
|
||||
|
||||
if (vncPort != null) {
|
||||
dto.setVdrpPort(vncPort);
|
||||
}
|
||||
|
||||
if (idState != null) {
|
||||
dto.setIdState(idState);
|
||||
}
|
||||
|
||||
if (idType != null) {
|
||||
dto.setIdType(idType);
|
||||
}
|
||||
|
||||
if (internalName != null) {
|
||||
dto.setName(internalName);
|
||||
}
|
||||
|
||||
dto.setPassword(password);
|
||||
dto.setKeymap(keymap);
|
||||
dto.setUuid(uuid);
|
||||
|
||||
// DVD
|
||||
if (dvd) {
|
||||
DvdManagementDto dvd = new DvdManagementDto();
|
||||
RESTLink link = new RESTLink("image", "");
|
||||
dvd.addLink(link);
|
||||
dto.setDvd(dvd);
|
||||
}
|
||||
|
||||
VirtualMachine virtualMachine = new VirtualMachine(context, dto);
|
||||
virtualMachine.virtualAppliance = virtualAppliance;
|
||||
virtualMachine.template = template;
|
||||
|
||||
return virtualMachine;
|
||||
}
|
||||
|
||||
public static Builder fromVirtualMachine(final VirtualMachine in) {
|
||||
return VirtualMachine.builder(in.context, in.virtualAppliance, in.template).internalName(in.getInternalName())
|
||||
.nameLabel(in.getNameLabel()).description(in.getDescription()).ram(in.getRam()).cpu(in.getCpu())
|
||||
.vncAddress(in.getVncAddress()).vncPort(in.getVncPort()).idState(in.getIdState()).idType(in.getIdType())
|
||||
.password(in.getPassword()).keymap(in.getKeymap()).dvd(in.hasDvd());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public int getCpu() {
|
||||
return target.getCpu();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
// Read-only field. This value is computed from the size of the Template
|
||||
public long getHdInBytes() {
|
||||
return target.getHdInBytes();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public int getIdState() {
|
||||
return target.getIdState();
|
||||
}
|
||||
|
||||
public int getIdType() {
|
||||
return target.getIdType();
|
||||
}
|
||||
|
||||
public String getNameLabel() {
|
||||
return target.getNodeName();
|
||||
}
|
||||
|
||||
public String getOwnerName() {
|
||||
return target.getUserName() + " " + target.getUserSurname();
|
||||
}
|
||||
|
||||
public String getInternalName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return target.getPassword();
|
||||
}
|
||||
|
||||
public int getRam() {
|
||||
return target.getRam();
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return target.getUuid();
|
||||
}
|
||||
|
||||
public String getVncAddress() {
|
||||
return target.getVdrpIP();
|
||||
}
|
||||
|
||||
public int getVncPort() {
|
||||
return target.getVdrpPort();
|
||||
}
|
||||
|
||||
public String getKeymap() {
|
||||
return target.getKeymap();
|
||||
}
|
||||
|
||||
public void setCpu(final int cpu) {
|
||||
target.setCpu(cpu);
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
target.setDescription(description);
|
||||
}
|
||||
|
||||
public void setNameLabel(final String nameLabel) {
|
||||
target.setNodeName(nameLabel);
|
||||
}
|
||||
|
||||
public void setPassword(final String password) {
|
||||
target.setPassword(password);
|
||||
}
|
||||
|
||||
public void setRam(final int ram) {
|
||||
target.setRam(ram);
|
||||
}
|
||||
|
||||
public void setKeymap(final String keymap) {
|
||||
target.setKeymap(keymap);
|
||||
}
|
||||
|
||||
private static VolumeManagementDto[] toVolumeDto(final Volume... volumes) {
|
||||
checkNotNull(volumes, "must provide at least one volume");
|
||||
|
||||
VolumeManagementDto[] dtos = new VolumeManagementDto[volumes.length];
|
||||
for (int i = 0; i < volumes.length; i++) {
|
||||
dtos[i] = volumes[i].unwrap();
|
||||
}
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
||||
private static DiskManagementDto[] toHardDiskDto(final HardDisk... hardDisks) {
|
||||
checkNotNull(hardDisks, "must provide at least one hard disk");
|
||||
|
||||
DiskManagementDto[] dtos = new DiskManagementDto[hardDisks.length];
|
||||
for (int i = 0; i < hardDisks.length; i++) {
|
||||
dtos[i] = hardDisks[i].unwrap();
|
||||
}
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
||||
private static Predicate<Volume> volumeIdIn(final Volume... volumes) {
|
||||
return new Predicate<Volume>() {
|
||||
List<Integer> ids = volumeIds(Arrays.asList(volumes));
|
||||
|
||||
@Override
|
||||
public boolean apply(final Volume input) {
|
||||
return ids.contains(input.getId());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Predicate<HardDisk> hardDiskIdIn(final HardDisk... hardDisks) {
|
||||
return new Predicate<HardDisk>() {
|
||||
List<Integer> ids = hardDisksIds(Arrays.asList(hardDisks));
|
||||
|
||||
@Override
|
||||
public boolean apply(final HardDisk input) {
|
||||
return ids.contains(input.getId());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static List<Integer> volumeIds(final List<Volume> volumes) {
|
||||
return Lists.transform(volumes, new Function<Volume, Integer>() {
|
||||
@Override
|
||||
public Integer apply(final Volume input) {
|
||||
return input.getId();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static List<Integer> hardDisksIds(final List<HardDisk> HardDisk) {
|
||||
return Lists.transform(HardDisk, new Function<HardDisk, Integer>() {
|
||||
@Override
|
||||
public Integer apply(final HardDisk input) {
|
||||
return input.getId();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VirtualMachine [id=" + getId() + ", state=" + target.getState().name() + ", cpu=" + getCpu()
|
||||
+ ", description=" + getDescription() + ", hdInBytes=" + getHdInBytes() + ", idType=" + getIdType()
|
||||
+ ", nameLabel=" + getNameLabel() + ", internalName=" + getInternalName() + ", password=" + getPassword()
|
||||
+ ", ram=" + getRam() + ", uuid=" + getUuid() + ", vncAddress=" + getVncAddress() + ", vncPort="
|
||||
+ getVncPort() + ", keymap=" + getKeymap() + ", dvd=" + hasDvd() + "]";
|
||||
}
|
||||
}
|
|
@ -1,380 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.domain.cloud.options.ConversionOptions;
|
||||
import org.jclouds.abiquo.domain.config.Category;
|
||||
import org.jclouds.abiquo.domain.config.CostCode;
|
||||
import org.jclouds.abiquo.domain.enterprise.Enterprise;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Tier;
|
||||
import org.jclouds.abiquo.domain.task.AsyncTask;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.ConversionState;
|
||||
import com.abiquo.model.enumerator.DiskFormatType;
|
||||
import com.abiquo.model.enumerator.HypervisorType;
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.AcceptedRequestDto;
|
||||
import com.abiquo.server.core.appslibrary.CategoryDto;
|
||||
import com.abiquo.server.core.appslibrary.ConversionDto;
|
||||
import com.abiquo.server.core.appslibrary.ConversionsDto;
|
||||
import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto;
|
||||
import com.abiquo.server.core.appslibrary.VirtualMachineTemplatePersistentDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto;
|
||||
import com.abiquo.server.core.pricing.CostCodeDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link VirtualMachineTemplateDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Machine+Template+Resource"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Virtual+Machine+Template+Resource
|
||||
* </a>
|
||||
*/
|
||||
public class VirtualMachineTemplate extends DomainWrapper<VirtualMachineTemplateDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected VirtualMachineTemplate(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final VirtualMachineTemplateDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
public void delete() {
|
||||
context.getApi().getVirtualMachineTemplateApi().deleteVirtualMachineTemplate(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
target = context.getApi().getVirtualMachineTemplateApi().updateVirtualMachineTemplate(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @param vdc
|
||||
* @param volume
|
||||
* @param persistentTemplateName
|
||||
* @param persistentVolumeName
|
||||
* @return
|
||||
*/
|
||||
public AsyncTask makePersistent(final VirtualDatacenter vdc, final Volume volume, final String persistentTemplateName) {
|
||||
RESTLink storageLink = volume.unwrap().getEditLink();
|
||||
storageLink.setRel("volume");
|
||||
return makePersistent(vdc, storageLink, persistentTemplateName, null);
|
||||
}
|
||||
|
||||
public AsyncTask makePersistent(final VirtualDatacenter vdc, final Tier tier, final String persistentTemplateName,
|
||||
final String persistentVolumeName) {
|
||||
// infrastructure
|
||||
RESTLink storageLink = tier.unwrap().getEditLink();
|
||||
if (storageLink == null) {
|
||||
// cloud
|
||||
storageLink = tier.unwrap().searchLink("self");
|
||||
}
|
||||
storageLink.setRel(ParentLinkName.TIER);
|
||||
return makePersistent(vdc, storageLink, persistentTemplateName, persistentVolumeName);
|
||||
}
|
||||
|
||||
private AsyncTask makePersistent(final VirtualDatacenter vdc, final RESTLink storageLink,
|
||||
final String persistentTemplateName, final String persistentVolumeName) {
|
||||
VirtualMachineTemplatePersistentDto persistentData = new VirtualMachineTemplatePersistentDto();
|
||||
persistentData.setPersistentTemplateName(persistentTemplateName);
|
||||
persistentData.setPersistentVolumeName(persistentVolumeName);
|
||||
RESTLink vdcLink = new RESTLink(ParentLinkName.VIRTUAL_DATACENTER, vdc.unwrap().getEditLink().getHref());
|
||||
RESTLink templateLink = new RESTLink(ParentLinkName.VIRTUAL_MACHINE_TEMPLATE, target.getEditLink().getHref());
|
||||
|
||||
persistentData.addLink(vdcLink);
|
||||
persistentData.addLink(storageLink);
|
||||
persistentData.addLink(templateLink);
|
||||
|
||||
// SCG:
|
||||
// A simple user should not have permissions to obtain a datacenter
|
||||
// repository, but at this
|
||||
// point we have the datacenter repository and enterprise ids in the own
|
||||
// target uri. So we
|
||||
// can obtain the path where do the POST
|
||||
// Assumption that to create a new object a user needs to get the parent
|
||||
// object cannot be
|
||||
// applied in this case
|
||||
String editUri = getURI().getPath();
|
||||
Pattern p = Pattern.compile("\\d+");
|
||||
Matcher m = p.matcher(editUri);
|
||||
m.find();
|
||||
Integer idEnt = new Integer(m.group());
|
||||
m.find();
|
||||
Integer idDcRepo = new Integer(m.group());
|
||||
|
||||
AcceptedRequestDto<String> response = context.getApi().getVirtualMachineTemplateApi()
|
||||
.createPersistentVirtualMachineTemplate(idEnt, idDcRepo, persistentData);
|
||||
|
||||
return getTask(response);
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Category+Resource#CategoryResource-Retrieveacategory"
|
||||
* > http://community.abiquo.com/display/ABI20/Category+Resource#
|
||||
* CategoryResource- Retrieveacategory</a>
|
||||
*/
|
||||
public Category getCategory() {
|
||||
Integer categoryId = target.getIdFromLink(ParentLinkName.CATEGORY);
|
||||
CategoryDto category = context.getApi().getConfigApi().getCategory(categoryId);
|
||||
return wrap(context, Category.class, category);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/Abiquo/Volume+Resource#VolumeResource-Retrieveavolume"
|
||||
* > http://community.abiquo.com/display/Abiquo/Volume+Resource#
|
||||
* VolumeResource- Retrieveavolume</a>
|
||||
*/
|
||||
public Volume getVolume() {
|
||||
if (this.isPersistent()) {
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse rp = checkNotNull(utils.getAbiquoHttpClient().get(target.searchLink("volume")), "volume");
|
||||
|
||||
ParseXMLWithJAXB<VolumeManagementDto> parser = new ParseXMLWithJAXB<VolumeManagementDto>(utils.getXml(),
|
||||
TypeLiteral.get(VolumeManagementDto.class));
|
||||
|
||||
VolumeManagementDto dto = parser.apply(rp);
|
||||
return new Volume(context, dto);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPersistent() {
|
||||
return target.searchLink("volume") != null;
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource-RetrieveanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/Enterprise+Resource#
|
||||
* EnterpriseResource- RetrieveanEnterprise</a>
|
||||
*/
|
||||
public Enterprise getEnterprise() {
|
||||
Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE);
|
||||
return wrap(context, Enterprise.class, context.getApi().getEnterpriseApi().getEnterprise(enterpriseId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Datacenter+Resource#DatacenterResource-RetrieveaDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Datacenter+Resource#
|
||||
* DatacenterResource- RetrieveaDatacenter</a>
|
||||
*/
|
||||
public Datacenter getDatacenter() {
|
||||
Integer repositoryId = target.getIdFromLink(ParentLinkName.DATACENTER_REPOSITORY);
|
||||
return wrap(context, Datacenter.class, context.getApi().getInfrastructureApi().getDatacenter(repositoryId));
|
||||
}
|
||||
|
||||
/**
|
||||
* List all the conversions for the virtual machine template.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Conversion+Resource#ConversionResource-ListConversions"
|
||||
* > http://community.abiquo.com/display/ABI20/Conversion+Resource#
|
||||
* ConversionResource- ListConversions</a>
|
||||
* @return all the conversions of the virtual machine template
|
||||
*/
|
||||
public List<Conversion> listConversions() {
|
||||
ConversionsDto convs = context.getApi().getVirtualMachineTemplateApi().listConversions(target);
|
||||
return wrap(context, Conversion.class, convs.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* List all the conversions for the virtual machine template matching the
|
||||
* given filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The list all the conversions for the virtual machine template
|
||||
* matching the given filter.
|
||||
*/
|
||||
public List<Conversion> listConversions(final Predicate<Conversion> filter) {
|
||||
return ImmutableList.copyOf(filter(listConversions(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single conversion in the virtual machine template matching the
|
||||
* given filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The conversion or <code>null</code> if none matched the given
|
||||
* filter.
|
||||
*/
|
||||
public Conversion findConversion(final Predicate<Conversion> filter) {
|
||||
return Iterables.getFirst(filter(listConversions(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* List conversions for a virtual machine template.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Conversion+Resource#ConversionResource-ListConversions"
|
||||
* > http://community.abiquo.com/display/ABI20/Conversion+Resource#
|
||||
* ConversionResource- ListConversions</a>
|
||||
* @param hypervisor
|
||||
* , Optionally filter conversions compatible with the provided
|
||||
* hypervisor
|
||||
* @param state
|
||||
* , Optionally filter conversions with the desired state
|
||||
* @return all the conversions of the virtual machine template applying the
|
||||
* constrains
|
||||
*/
|
||||
public List<Conversion> listConversions(final HypervisorType hypervisor, final ConversionState state) {
|
||||
ConversionsDto convs = context
|
||||
.getApi()
|
||||
.getVirtualMachineTemplateApi()
|
||||
.listConversions(target,
|
||||
ConversionOptions.builder().hypervisorType(hypervisor).conversionState(state).build());
|
||||
return wrap(context, Conversion.class, convs.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new conversion for a virtual machine template.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Conversion+Resource#ConversionResource-RequestConversion"
|
||||
* > http://community.abiquo.com/display/ABI20/Conversion+Resource#
|
||||
* ConversionResource- RequestConversion</a>
|
||||
* @param diskFormat
|
||||
* , desired target format for the request template
|
||||
* @return The task reference to track its progress
|
||||
*/
|
||||
public AsyncTask requestConversion(final DiskFormatType diskFormat) {
|
||||
ConversionDto request = new ConversionDto();
|
||||
request.setTargetFormat(diskFormat);
|
||||
|
||||
AcceptedRequestDto<String> taskRef = context.getApi().getVirtualMachineTemplateApi()
|
||||
.requestConversion(target, diskFormat, request);
|
||||
|
||||
return taskRef == null ? null : getTask(taskRef);
|
||||
}
|
||||
|
||||
public CostCode getCostCode() {
|
||||
Integer costcodeId = target.getIdFromLink(ParentLinkName.COST_CODE);
|
||||
CostCodeDto costcode = context.getApi().getPricingApi().getCostCode(costcodeId);
|
||||
return wrap(context, CostCode.class, costcode);
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public int getCpuRequired() {
|
||||
return target.getCpuRequired();
|
||||
}
|
||||
|
||||
public Date getCreationDate() {
|
||||
return target.getCreationDate();
|
||||
}
|
||||
|
||||
public String getCreationUser() {
|
||||
return target.getCreationUser();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
public long getDiskFileSize() {
|
||||
return target.getDiskFileSize();
|
||||
}
|
||||
|
||||
public DiskFormatType getDiskFormatType() {
|
||||
return DiskFormatType.valueOf(target.getDiskFormatType());
|
||||
}
|
||||
|
||||
public long getHdRequired() {
|
||||
return target.getHdRequired();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return target.getPath();
|
||||
}
|
||||
|
||||
public int getRamRequired() {
|
||||
return target.getRamRequired();
|
||||
}
|
||||
|
||||
public boolean isChefEnabled() {
|
||||
return target.isChefEnabled();
|
||||
}
|
||||
|
||||
public void setChefEnabled(final boolean chefEnabled) {
|
||||
target.setChefEnabled(chefEnabled);
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getIconUrl() {
|
||||
return target.getIconUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VirtualMachineTemplate [id=" + getId() + ", cpuRequired=" + getCpuRequired() + ", creationDate="
|
||||
+ getCreationDate() + ", creationUser=" + getCreationUser() + ", description=" + getDescription()
|
||||
+ ", diskFileSize=" + getDiskFileSize() + ", diskFormatType=" + getDiskFormatType() + ", hdRequired="
|
||||
+ getHdRequired() + ", name=" + getName() + ", path=" + getPath() + ", ramRequired=" + getRamRequired()
|
||||
+ ", chefEnabled=" + isChefEnabled() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.abiquo.domain.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Wrapper to hold the information of a virtual machine template scoped to a
|
||||
* concrete hypervisor type.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class VirtualMachineTemplateInVirtualDatacenter {
|
||||
private VirtualMachineTemplate template;
|
||||
|
||||
private VirtualDatacenter zone;
|
||||
|
||||
public VirtualMachineTemplateInVirtualDatacenter(final VirtualMachineTemplate template, final VirtualDatacenter zone) {
|
||||
super();
|
||||
this.template = checkNotNull(template, "template");
|
||||
this.zone = checkNotNull(zone, "zone");
|
||||
}
|
||||
|
||||
public VirtualMachineTemplate getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
public VirtualDatacenter getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Tier;
|
||||
import org.jclouds.abiquo.domain.task.AsyncTask;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.VolumeState;
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.model.transport.AcceptedRequestDto;
|
||||
import com.abiquo.server.core.cloud.VirtualDatacenterDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.TierDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link VolumeManagementDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/Volume+Resource">
|
||||
* http://community.abiquo.com/display/ABI20/Volume+Resource</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class Volume extends DomainWrapper<VolumeManagementDto> {
|
||||
/** The default state for volumes. */
|
||||
public static final VolumeState DEFAULT_STATE = VolumeState.DETACHED;
|
||||
|
||||
/** The virtual datacenter where the volume belongs. */
|
||||
private VirtualDatacenter virtualDatacenter;
|
||||
|
||||
/** The tier where the volume belongs. */
|
||||
private Tier tier;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Volume(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final VolumeManagementDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
public void delete() {
|
||||
context.getApi().getCloudApi().deleteVolume(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
target = context.getApi().getCloudApi().createVolume(virtualDatacenter.unwrap(), target);
|
||||
}
|
||||
|
||||
public AsyncTask update() {
|
||||
AcceptedRequestDto<String> taskRef = context.getApi().getCloudApi().updateVolume(target);
|
||||
return taskRef == null ? null : getTask(taskRef);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Virtual+Datacenter+Resource#VirtualDatacenterResource-RetrieveaVirtualDatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Virtual+Datacenter+
|
||||
* Resource# VirtualDatacenterResource-RetrieveaVirtualDatacenter</a>
|
||||
*/
|
||||
public VirtualDatacenter getVirtualDatacenter() {
|
||||
Integer virtualDatacenterId = target.getIdFromLink(ParentLinkName.VIRTUAL_DATACENTER);
|
||||
VirtualDatacenterDto dto = context.getApi().getCloudApi().getVirtualDatacenter(virtualDatacenterId);
|
||||
virtualDatacenter = wrap(context, VirtualDatacenter.class, dto);
|
||||
return virtualDatacenter;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO javadoc link
|
||||
*/
|
||||
public Tier getTier() {
|
||||
Integer tierId = target.getIdFromLink(ParentLinkName.TIER);
|
||||
TierDto dto = context.getApi().getCloudApi().getStorageTier(virtualDatacenter.unwrap(), tierId);
|
||||
tier = wrap(context, Tier.class, dto);
|
||||
return tier;
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/**
|
||||
* Move the volume to the given virtual datacenter.
|
||||
*
|
||||
* @param newVirtualDatacenter
|
||||
* The destination virtual datacenter.
|
||||
*/
|
||||
public void moveTo(final VirtualDatacenter newVirtualDatacenter) {
|
||||
target = context.getApi().getCloudApi().moveVolume(unwrap(), newVirtualDatacenter.unwrap());
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final VirtualDatacenter virtualDatacenter, final Tier tier) {
|
||||
return new Builder(context, virtualDatacenter, tier);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private Long sizeInMb;
|
||||
|
||||
private VirtualDatacenter virtualDatacenter;
|
||||
|
||||
private Tier tier;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final VirtualDatacenter virtualDatacenter,
|
||||
final Tier tier) {
|
||||
super();
|
||||
checkNotNull(virtualDatacenter, ValidationErrors.NULL_RESOURCE + VirtualDatacenter.class);
|
||||
checkNotNull(tier, ValidationErrors.NULL_RESOURCE + Tier.class);
|
||||
this.context = context;
|
||||
this.virtualDatacenter = virtualDatacenter;
|
||||
this.tier = tier;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(final String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder sizeInMb(final long sizeInMb) {
|
||||
this.sizeInMb = sizeInMb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Volume build() {
|
||||
VolumeManagementDto dto = new VolumeManagementDto();
|
||||
dto.setName(name);
|
||||
dto.setDescription(description);
|
||||
dto.setSizeInMB(sizeInMb);
|
||||
dto.setState(DEFAULT_STATE.name());
|
||||
|
||||
RESTLink link = tier.unwrap().searchLink("self");
|
||||
checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK);
|
||||
dto.addLink(new RESTLink("tier", link.getHref()));
|
||||
|
||||
Volume volume = new Volume(context, dto);
|
||||
volume.virtualDatacenter = virtualDatacenter;
|
||||
volume.tier = tier;
|
||||
|
||||
return volume;
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return target.getState();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public long getSizeInMB() {
|
||||
return target.getSizeInMB();
|
||||
}
|
||||
|
||||
public void setSizeInMB(final long sizeInMB) {
|
||||
target.setSizeInMB(sizeInMB);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
target.setDescription(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Volume [id=" + getId() + ", state=" + getState() + ", name=" + getName() + ", sizeInMB=" + getSizeInMB()
|
||||
+ ", description=" + getDescription() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.abiquo.model.enumerator.ConversionState;
|
||||
import com.abiquo.model.enumerator.HypervisorType;
|
||||
|
||||
/**
|
||||
* Available options to filter virtual machine template conversions
|
||||
*/
|
||||
public class ConversionOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
ConversionOptions options = new ConversionOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private HypervisorType hypervisorType;
|
||||
|
||||
private ConversionState conversionState;
|
||||
|
||||
/** Only conversions compatible with this hypervisor */
|
||||
public Builder hypervisorType(final HypervisorType hypervisorType) {
|
||||
this.hypervisorType = hypervisorType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Only conversions with the provided state */
|
||||
public Builder conversionState(final ConversionState conversionState) {
|
||||
this.conversionState = conversionState;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConversionOptions build() {
|
||||
ConversionOptions options = new ConversionOptions();
|
||||
|
||||
if (hypervisorType != null) {
|
||||
options.queryParameters.put("hypervisor", hypervisorType.name());
|
||||
}
|
||||
if (conversionState != null) {
|
||||
options.queryParameters.put("state", conversionState.name());
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query virtual appliances.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class VirtualApplianceOptions extends BaseHttpRequestOptions {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
VirtualApplianceOptions options = new VirtualApplianceOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private Boolean available;
|
||||
|
||||
public Builder available(final boolean available) {
|
||||
this.available = available;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VirtualApplianceOptions build() {
|
||||
VirtualApplianceOptions options = new VirtualApplianceOptions();
|
||||
|
||||
if (available != null) {
|
||||
options.queryParameters.put("available", String.valueOf(available));
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query virtual datacenters.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class VirtualDatacenterOptions extends BaseHttpRequestOptions {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
VirtualDatacenterOptions options = new VirtualDatacenterOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Integer datacenterId;
|
||||
|
||||
private Integer enterpriseId;
|
||||
|
||||
/**
|
||||
* Set the optional datacenter.
|
||||
*/
|
||||
public Builder datacenterId(final int datacenterId) {
|
||||
this.datacenterId = datacenterId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the optional enterprise.
|
||||
*/
|
||||
public Builder enterpriseId(final int enterpriseId) {
|
||||
this.enterpriseId = enterpriseId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VirtualDatacenterOptions build() {
|
||||
VirtualDatacenterOptions options = new VirtualDatacenterOptions();
|
||||
|
||||
if (datacenterId != null) {
|
||||
options.queryParameters.put("datacenter", datacenterId.toString());
|
||||
}
|
||||
|
||||
if (enterpriseId != null) {
|
||||
options.queryParameters.put("enterprise", enterpriseId.toString());
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud.options;
|
||||
|
||||
import org.jclouds.abiquo.domain.options.search.FilterOptions.BaseFilterOptionsBuilder;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query virtual machine.
|
||||
*
|
||||
* @author Alessia Prete
|
||||
*/
|
||||
public class VirtualMachineOptions extends BaseHttpRequestOptions {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
VirtualMachineOptions options = new VirtualMachineOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder extends BaseFilterOptionsBuilder<Builder> {
|
||||
private Boolean force;
|
||||
|
||||
public Builder force(final Boolean force) {
|
||||
this.force = force;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VirtualMachineOptions build() {
|
||||
VirtualMachineOptions options = new VirtualMachineOptions();
|
||||
|
||||
if (force != null) {
|
||||
options.queryParameters.put("force", String.valueOf(force));
|
||||
}
|
||||
|
||||
return addFilterOptions(options);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud.options;
|
||||
|
||||
import org.jclouds.abiquo.domain.config.Category;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.abiquo.model.enumerator.HypervisorType;
|
||||
import com.abiquo.model.enumerator.StatefulInclusion;
|
||||
|
||||
/**
|
||||
* Available options to query virtual machine templates.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class VirtualMachineTemplateOptions extends BaseHttpRequestOptions {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
VirtualMachineTemplateOptions options = new VirtualMachineTemplateOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private StatefulInclusion persistent;
|
||||
|
||||
private HypervisorType hypervisorType;
|
||||
|
||||
private Category category;
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private Integer idTemplate;
|
||||
|
||||
public Builder persistent(final StatefulInclusion persistent) {
|
||||
this.persistent = persistent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hypervisorType(final HypervisorType hypervisorType) {
|
||||
this.hypervisorType = hypervisorType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder category(final Category category) {
|
||||
this.category = category;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder categoryName(final String categoryName) {
|
||||
this.categoryName = categoryName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder idTemplate(final Integer idTemplate) {
|
||||
this.idTemplate = idTemplate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VirtualMachineTemplateOptions build() {
|
||||
VirtualMachineTemplateOptions options = new VirtualMachineTemplateOptions();
|
||||
|
||||
if (persistent != null) {
|
||||
options.queryParameters.put("stateful", persistent.name());
|
||||
}
|
||||
if (hypervisorType != null) {
|
||||
options.queryParameters.put("hypervisorTypeName", hypervisorType.name());
|
||||
}
|
||||
if (category != null) {
|
||||
options.queryParameters.put("categoryName", category.getName());
|
||||
}
|
||||
|
||||
if (category == null && categoryName != null) {
|
||||
options.queryParameters.put("categoryName", categoryName);
|
||||
}
|
||||
|
||||
if (idTemplate != null) {
|
||||
options.queryParameters.put("idTemplate", String.valueOf(idTemplate));
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.cloud.options;
|
||||
|
||||
import org.jclouds.abiquo.domain.options.search.FilterOptions.BaseFilterOptionsBuilder;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query volumes.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class VolumeOptions extends BaseHttpRequestOptions {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
VolumeOptions options = new VolumeOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder extends BaseFilterOptionsBuilder<Builder> {
|
||||
private Boolean onlyAvailable;
|
||||
|
||||
public Builder onlyAvailable(final boolean onlyAvailable) {
|
||||
this.onlyAvailable = onlyAvailable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VolumeOptions build() {
|
||||
VolumeOptions options = new VolumeOptions();
|
||||
|
||||
if (onlyAvailable != null) {
|
||||
options.queryParameters.put("available", String.valueOf(onlyAvailable));
|
||||
}
|
||||
|
||||
return addFilterOptions(options);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,169 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.appslibrary.CategoryDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link CategoryDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/Category+Resource">
|
||||
* http://community.abiquo.com/display/ABI20/Category+Resource</a>
|
||||
*/
|
||||
|
||||
public class Category extends DomainWrapper<CategoryDto> {
|
||||
/** The default value for the default category flag. */
|
||||
private static final boolean DEFAULT_DEFAULT_CATEGORY = false;
|
||||
|
||||
/** The default value for the erasable flag. */
|
||||
private static final boolean DEFAULT_ERASABLE = true;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder. This resource cannot be
|
||||
* created.
|
||||
*/
|
||||
private Category(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final CategoryDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Category+Resource#CategoryResource-Deleteacategory"
|
||||
* > http://community.abiquo.com/display/ABI20/Category+Resource#
|
||||
* CategoryResource-Deleteacategory</a>
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getConfigApi().deleteCategory(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Category+Resource#CategoryResource-Createacategory"
|
||||
* > http://community.abiquo.com/display/ABI20/Category+Resource#
|
||||
* CategoryResource-Createacategory</a>
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getConfigApi().createCategory(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Category+Resource#CategoryResource-Updateanexistingcategory"
|
||||
* > http://community.abiquo.com/display/ABI20/Category+Resource#
|
||||
* CategoryResource-Updateanexistingcategory</a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getConfigApi().updateCategory(target);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
return new Builder(context);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private String name;
|
||||
|
||||
private Boolean erasable = DEFAULT_ERASABLE;
|
||||
|
||||
private Boolean defaultCategory = DEFAULT_DEFAULT_CATEGORY;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder defaultCategory(final boolean defaultCategory) {
|
||||
this.defaultCategory = defaultCategory;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder erasable(final boolean erasable) {
|
||||
this.erasable = erasable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Category build() {
|
||||
CategoryDto dto = new CategoryDto();
|
||||
dto.setErasable(erasable);
|
||||
dto.setDefaultCategory(defaultCategory);
|
||||
dto.setName(name);
|
||||
Category category = new Category(context, dto);
|
||||
|
||||
return category;
|
||||
}
|
||||
|
||||
public static Builder fromCategory(final Category in) {
|
||||
Builder builder = Category.builder(in.context).name(in.getName()).erasable(in.isErasable())
|
||||
.defaultCategory(in.isDefaultCategory());
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public boolean isDefaultCategory() {
|
||||
return target.isDefaultCategory();
|
||||
}
|
||||
|
||||
public boolean isErasable() {
|
||||
return target.isErasable();
|
||||
}
|
||||
|
||||
public void setDefaultCategory(final boolean defaultCategory) {
|
||||
target.setDefaultCategory(defaultCategory);
|
||||
}
|
||||
|
||||
public void setErasable(final boolean erasable) {
|
||||
target.setErasable(erasable);
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.pricing.CostCodeCurrenciesDto;
|
||||
import com.abiquo.server.core.pricing.CostCodeCurrencyDto;
|
||||
import com.abiquo.server.core.pricing.CostCodeDto;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* A cost code is a kind of label where concrete prices can be assigned.
|
||||
* <p>
|
||||
* Cloud administrators can create several cost codes and assign a price to each
|
||||
* one, to have a flexible way to configure custom billings for each resource.
|
||||
* <p>
|
||||
* Cost codes can be assigned to {@link VirtualMachineTemplate}s and other
|
||||
* resources to provide pricing information about them.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Susana Acedo
|
||||
*/
|
||||
public class CostCode extends DomainWrapper<CostCodeDto> {
|
||||
|
||||
private List<CostCodePrice> defaultPrices;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder. This resource cannot be
|
||||
* created.
|
||||
*/
|
||||
private CostCode(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final CostCodeDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
public void delete() {
|
||||
context.getApi().getPricingApi().deleteCostCode(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
target = context.getApi().getPricingApi().createCostCode(target);
|
||||
|
||||
if (defaultPrices != null && !defaultPrices.isEmpty()) {
|
||||
CostCodeCurrenciesDto costcodecurrencies = new CostCodeCurrenciesDto();
|
||||
for (CostCodePrice ccp : defaultPrices) {
|
||||
CostCodeCurrencyDto costcodecurrency = new CostCodeCurrencyDto();
|
||||
Currency currency = ccp.getCurrency();
|
||||
|
||||
costcodecurrency.addLink(new RESTLink("currency", currency.unwrap().getEditLink().getHref()));
|
||||
costcodecurrency.setPrice(ccp.getPrice());
|
||||
costcodecurrencies.add(costcodecurrency);
|
||||
}
|
||||
context.getApi().getPricingApi().updateCostCodeCurrencies(getId(), costcodecurrencies);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void update() {
|
||||
target = context.getApi().getPricingApi().updateCostCode(target);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
return new Builder(context);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private List<CostCodePrice> defaultPrices = Lists.newArrayList();
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(final String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder defaultPrices(final List<CostCodePrice> prices) {
|
||||
this.defaultPrices.addAll(prices);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CostCode build() {
|
||||
CostCodeDto dto = new CostCodeDto();
|
||||
dto.setName(name);
|
||||
dto.setDescription(description);
|
||||
CostCode costcode = new CostCode(context, dto);
|
||||
costcode.setDefaultPrices(defaultPrices);
|
||||
return costcode;
|
||||
}
|
||||
|
||||
public static Builder fromCostCode(final CostCode in) {
|
||||
Builder builder = CostCode.builder(in.context).name(in.getName()).description(in.getDescription())
|
||||
.defaultPrices(in.getDefaultPrices());
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
target.setDescription(description);
|
||||
}
|
||||
|
||||
public List<CostCodePrice> getDefaultPrices() {
|
||||
return defaultPrices;
|
||||
}
|
||||
|
||||
public void setDefaultPrices(final List<CostCodePrice> defaultPrices) {
|
||||
this.defaultPrices = defaultPrices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CostCode [id=" + getId() + ", name=" + getName() + ", description=" + getDescription() + "]";
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.pricing.CostCodeCurrencyDto;
|
||||
|
||||
public class CostCodeCurrency extends DomainWrapper<CostCodeCurrencyDto> {
|
||||
|
||||
protected CostCodeCurrency(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final CostCodeCurrencyDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return target.getPrice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CostCodeCurrency [id=" + getId() + ", price=" + getPrice() + "]";
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Gives a price to a {@link CostCode}.
|
||||
*
|
||||
* @author Susana Acedo
|
||||
*/
|
||||
public class CostCodePrice {
|
||||
private Currency currency;
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
public CostCodePrice(final Currency currency, final BigDecimal price) {
|
||||
super();
|
||||
this.currency = currency;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Currency getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
public void setCurrency(final Currency currency) {
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(final BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CostCodePrice [currency=" + currency + ", price=" + price + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.pricing.CurrencyDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link CurrencyDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Susana Acedo
|
||||
*/
|
||||
public class Currency extends DomainWrapper<CurrencyDto> {
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder. This resource cannot be
|
||||
* created.
|
||||
*/
|
||||
private Currency(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final CurrencyDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
public void delete() {
|
||||
context.getApi().getPricingApi().deleteCurrency(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
target = context.getApi().getPricingApi().createCurrency(target);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
target = context.getApi().getPricingApi().updateCurrency(target);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
return new Builder(context);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private String name;
|
||||
|
||||
private String symbol;
|
||||
|
||||
private int digits;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder symbol(final String symbol) {
|
||||
this.symbol = symbol;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder digits(final int digits) {
|
||||
this.digits = digits;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Currency build() {
|
||||
CurrencyDto dto = new CurrencyDto();
|
||||
dto.setName(name);
|
||||
dto.setSymbol(symbol);
|
||||
dto.setDigits(digits);
|
||||
Currency currency = new Currency(context, dto);
|
||||
|
||||
return currency;
|
||||
}
|
||||
|
||||
public static Builder fromCurrency(final Currency in) {
|
||||
Builder builder = Currency.builder(in.context).name(in.getName()).symbol(in.getSymbol())
|
||||
.digits(in.getDigits());
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return target.getSymbol();
|
||||
}
|
||||
|
||||
public void setSymbol(final String symbol) {
|
||||
target.setSymbol(symbol);
|
||||
}
|
||||
|
||||
public int getDigits() {
|
||||
return target.getDigits();
|
||||
}
|
||||
|
||||
public void setDigits(final int digits) {
|
||||
target.setDigits(digits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Currency [id=" + getId() + ", name=" + getName() + ", symbol=" + getSymbol() + ", digits=" + getDigits()
|
||||
+ "]";
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.config.LicenseDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link LicenseDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class License extends DomainWrapper<LicenseDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected License(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final LicenseDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
public void remove() {
|
||||
context.getApi().getConfigApi().removeLicense(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
public void add() {
|
||||
target = context.getApi().getConfigApi().addLicense(target);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final String code) {
|
||||
return new Builder(context, code);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private String code;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final String code) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Builder code(final String code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public License build() {
|
||||
LicenseDto dto = new LicenseDto();
|
||||
dto.setCode(code);
|
||||
|
||||
License license = new License(context, dto);
|
||||
return license;
|
||||
}
|
||||
|
||||
public static Builder fromLicense(final License in) {
|
||||
return License.builder(in.context, in.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public String getCode() {
|
||||
return target.getCode();
|
||||
}
|
||||
|
||||
public String getCustomerId() {
|
||||
return target.getCustomerid();
|
||||
}
|
||||
|
||||
public String getEnabledIp() {
|
||||
return target.getEnabledip();
|
||||
}
|
||||
|
||||
public String getExpiration() {
|
||||
return target.getExpiration();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public Integer getNumCores() {
|
||||
return target.getNumcores();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "License [id=" + getId() + ", code=" + getCode() + ", customerId=" + getCustomerId() + ", enabledIp="
|
||||
+ getEnabledIp() + ", expiration=" + getExpiration() + ", numCores=" + getNumCores() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.pricing.PricingCostCodeDto;
|
||||
|
||||
/**
|
||||
* Associates a {@link CostCode} with a pricing template.
|
||||
*
|
||||
* @author Susana Acedo
|
||||
*/
|
||||
public class PricingCostCode extends DomainWrapper<PricingCostCodeDto> {
|
||||
private CostCode costcode;
|
||||
|
||||
private PricingTemplate pricingTemplate;
|
||||
|
||||
protected PricingCostCode(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final PricingCostCodeDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final PricingTemplate pricingtemplate, final CostCode costcode) {
|
||||
return new Builder(context, pricingtemplate, costcode);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private Integer id;
|
||||
|
||||
private PricingTemplate pricingTemplate;
|
||||
|
||||
private CostCode costcode;
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final PricingTemplate pricingTemplate,
|
||||
final CostCode costcode) {
|
||||
super();
|
||||
this.pricingTemplate = checkNotNull(pricingTemplate, ValidationErrors.NULL_RESOURCE + PricingTemplate.class);
|
||||
this.costcode = checkNotNull(costcode, ValidationErrors.NULL_RESOURCE + CostCode.class);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder price(final BigDecimal price) {
|
||||
this.price = price;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PricingCostCode build() {
|
||||
PricingCostCodeDto dto = new PricingCostCodeDto();
|
||||
dto.setId(id);
|
||||
dto.setPrice(price);
|
||||
|
||||
RESTLink link = costcode.unwrap().searchLink("edit");
|
||||
checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK);
|
||||
dto.addLink(new RESTLink("costcode", link.getHref()));
|
||||
|
||||
PricingCostCode pricingcostcode = new PricingCostCode(context, dto);
|
||||
pricingcostcode.pricingTemplate = pricingTemplate;
|
||||
pricingcostcode.costcode = costcode;
|
||||
|
||||
return pricingcostcode;
|
||||
}
|
||||
|
||||
public static Builder fromPricingCostCode(final PricingCostCode in) {
|
||||
return PricingCostCode.builder(in.context, in.pricingTemplate, in.costcode).price(in.getPrice());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return target.getPrice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PricingCostCode [id=" + getId() + ", price=" + getPrice() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,378 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.PricingPeriod;
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.pricing.PricingTemplateDto;
|
||||
|
||||
/**
|
||||
* A pricing template is a complete pricing schema that can be assigned to an
|
||||
* {@link Enterprise}.
|
||||
* <p>
|
||||
* This pricing schema will provide detailed billing information for each
|
||||
* resource consumed by the users of the enterprise.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Susana Acedo
|
||||
*/
|
||||
|
||||
public class PricingTemplate extends DomainWrapper<PricingTemplateDto> {
|
||||
|
||||
/** The currency used by the pricing template. */
|
||||
protected Currency currency;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder. This resource cannot be
|
||||
* created.
|
||||
*/
|
||||
private PricingTemplate(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final PricingTemplateDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
public void delete() {
|
||||
context.getApi().getPricingApi().deletePricingTemplate(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
target = context.getApi().getPricingApi().createPricingTemplate(target);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
target = context.getApi().getPricingApi().updatePricingTemplate(target);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Currency currency) {
|
||||
return new Builder(context, currency);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private Currency currency;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private BigDecimal hdGB;
|
||||
|
||||
private BigDecimal standingChargePeriod;
|
||||
|
||||
private BigDecimal vlan;
|
||||
|
||||
private PricingPeriod chargingPeriod;
|
||||
|
||||
private BigDecimal minimumChargePeriod;
|
||||
|
||||
private boolean showChangesBefore;
|
||||
|
||||
private boolean showMinimumCharge;
|
||||
|
||||
private PricingPeriod minimumCharge;
|
||||
|
||||
private BigDecimal publicIp;
|
||||
|
||||
private BigDecimal vcpu;
|
||||
|
||||
private BigDecimal memoryGB;
|
||||
|
||||
private boolean defaultTemplate;
|
||||
|
||||
private Date lastUpdate;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Currency currency) {
|
||||
super();
|
||||
this.currency = checkNotNull(currency, ValidationErrors.NULL_RESOURCE + Currency.class);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(final String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hdGB(final BigDecimal hdGB) {
|
||||
this.hdGB = hdGB;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder standingChargePeriod(final BigDecimal standingChargePeriod) {
|
||||
this.standingChargePeriod = standingChargePeriod;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder chargingPeriod(final PricingPeriod chargingPeriod) {
|
||||
this.chargingPeriod = chargingPeriod;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vlan(final BigDecimal vlan) {
|
||||
this.vlan = vlan;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder minimumChargePeriod(final BigDecimal minimumChargePeriod) {
|
||||
this.minimumChargePeriod = minimumChargePeriod;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder minimumCharge(final PricingPeriod minimumCharge) {
|
||||
this.minimumCharge = minimumCharge;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder showChangesBefore(final boolean showChangesBefore) {
|
||||
this.showChangesBefore = showChangesBefore;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder showMinimumCharge(final boolean showMinimumCharge) {
|
||||
this.showMinimumCharge = showMinimumCharge;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder publicIp(final BigDecimal publicIp) {
|
||||
this.publicIp = publicIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vcpu(final BigDecimal vcpu) {
|
||||
this.vcpu = vcpu;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder memoryGB(final BigDecimal memoryGB) {
|
||||
this.memoryGB = memoryGB;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder defaultTemplate(final boolean defaultTemplate) {
|
||||
this.defaultTemplate = defaultTemplate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lastUpdate(final Date lastUpdate) {
|
||||
this.lastUpdate = lastUpdate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder currency(final Currency currency) {
|
||||
this.currency = checkNotNull(currency, ValidationErrors.NULL_RESOURCE + Currency.class);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PricingTemplate build() {
|
||||
PricingTemplateDto dto = new PricingTemplateDto();
|
||||
dto.setName(name);
|
||||
dto.setDescription(description);
|
||||
dto.setHdGB(hdGB);
|
||||
dto.setStandingChargePeriod(standingChargePeriod);
|
||||
dto.setVlan(vlan);
|
||||
dto.setChargingPeriod(chargingPeriod.ordinal());
|
||||
dto.setMinimumCharge(minimumCharge.ordinal());
|
||||
dto.setMinimumChargePeriod(minimumChargePeriod);
|
||||
dto.setShowChangesBefore(showChangesBefore);
|
||||
dto.setShowMinimumCharge(showMinimumCharge);
|
||||
dto.setPublicIp(publicIp);
|
||||
dto.setVcpu(vcpu);
|
||||
dto.setMemoryGB(memoryGB);
|
||||
dto.setDefaultTemplate(defaultTemplate);
|
||||
dto.setLastUpdate(lastUpdate);
|
||||
|
||||
RESTLink link = currency.unwrap().searchLink("edit");
|
||||
checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK);
|
||||
dto.addLink(new RESTLink("currency", link.getHref()));
|
||||
|
||||
PricingTemplate pricingTemplate = new PricingTemplate(context, dto);
|
||||
pricingTemplate.currency = currency;
|
||||
|
||||
return pricingTemplate;
|
||||
}
|
||||
|
||||
public static Builder fromPricingTemplate(final PricingTemplate in) {
|
||||
Builder builder = PricingTemplate.builder(in.context, in.currency).name(in.getName())
|
||||
.description(in.getDescription()).hdGB(in.getHdGB()).standingChargePeriod(in.getStandingChargePeriod())
|
||||
.vcpu(in.getVlan()).chargingPeriod(in.getChargingPeriod()).minimumCharge(in.getMinimumCharge())
|
||||
.minimumChargePeriod(in.getMinimumChargePeriod()).showChangesBefore(in.isShowChangesBefore())
|
||||
.showMinimumCharge(in.isShowMinimumCharge()).publicIp(in.getPublicIp()).vcpu(in.getVcpu())
|
||||
.memoryGB(in.getMemoryGB()).defaultTemplate(in.isDefaultTemplate()).lastUpdate(in.getLastUpdate());
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
target.setDescription(description);
|
||||
}
|
||||
|
||||
public BigDecimal getHdGB() {
|
||||
return target.getHdGB();
|
||||
}
|
||||
|
||||
public void setHdGB(final BigDecimal hdGB) {
|
||||
target.setHdGB(hdGB);
|
||||
}
|
||||
|
||||
public BigDecimal getStandingChargePeriod() {
|
||||
return target.getStandingChargePeriod();
|
||||
}
|
||||
|
||||
public void setStandingChargePeriod(final BigDecimal standingChargePeriod) {
|
||||
target.setStandingChargePeriod(standingChargePeriod);
|
||||
}
|
||||
|
||||
public BigDecimal getVlan() {
|
||||
return target.getVlan();
|
||||
}
|
||||
|
||||
public void setVlan(final BigDecimal vlan) {
|
||||
target.getVlan();
|
||||
}
|
||||
|
||||
public BigDecimal getMinimumChargePeriod() {
|
||||
return target.getMinimumChargePeriod();
|
||||
}
|
||||
|
||||
public void setMinimumChargePeriod(final BigDecimal minimumChargePeriod) {
|
||||
target.setMinimumChargePeriod(minimumChargePeriod);
|
||||
}
|
||||
|
||||
public boolean isShowChangesBefore() {
|
||||
return target.isShowChangesBefore();
|
||||
}
|
||||
|
||||
public void setShowChangesBefore(final boolean showChangesBefore) {
|
||||
target.setShowChangesBefore(showChangesBefore);
|
||||
}
|
||||
|
||||
public boolean isShowMinimumCharge() {
|
||||
return target.isShowMinimumCharge();
|
||||
}
|
||||
|
||||
public void setShowMinimumCharge(final boolean showMinimumCharge) {
|
||||
target.setShowMinimumCharge(showMinimumCharge);
|
||||
}
|
||||
|
||||
public PricingPeriod getMinimumCharge() {
|
||||
return PricingPeriod.fromId(target.getMinimumCharge());
|
||||
}
|
||||
|
||||
public void setMinimumCharge(final PricingPeriod minimumCharge) {
|
||||
target.setMinimumCharge(minimumCharge.ordinal());
|
||||
}
|
||||
|
||||
public PricingPeriod getChargingPeriod() {
|
||||
return PricingPeriod.fromId(target.getChargingPeriod());
|
||||
}
|
||||
|
||||
public void setChargingPeriod(final PricingPeriod chargingPeriod) {
|
||||
target.setChargingPeriod(chargingPeriod.ordinal());
|
||||
}
|
||||
|
||||
public BigDecimal getPublicIp() {
|
||||
return target.getPublicIp();
|
||||
}
|
||||
|
||||
public void setPublicIp(final BigDecimal publicIp) {
|
||||
target.setPublicIp(publicIp);
|
||||
}
|
||||
|
||||
public BigDecimal getVcpu() {
|
||||
return target.getVcpu();
|
||||
}
|
||||
|
||||
public void setVcpu(final BigDecimal vcpu) {
|
||||
target.setVcpu(vcpu);
|
||||
}
|
||||
|
||||
public BigDecimal getMemoryGB() {
|
||||
return target.getMemoryGB();
|
||||
}
|
||||
|
||||
public void setMemoryGB(final BigDecimal memoryGB) {
|
||||
target.setMemoryGB(memoryGB);
|
||||
}
|
||||
|
||||
public boolean isDefaultTemplate() {
|
||||
return target.isDefaultTemplate();
|
||||
}
|
||||
|
||||
public void setDefaultTemplate(final boolean defaultTemplate) {
|
||||
target.setDefaultTemplate(defaultTemplate);
|
||||
}
|
||||
|
||||
public Date getLastUpdate() {
|
||||
return target.getLastUpdate();
|
||||
}
|
||||
|
||||
public void setLastUpdate(final Date lastUpdate) {
|
||||
target.setLastUpdate(lastUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PricingTemplate [id=" + getId() + ", name=" + getName() + ", description=" + getDescription()
|
||||
+ ", hdGB =" + getHdGB() + ", standingChargePeriod =" + getStandingChargePeriod() + ", vlan = " + getVlan()
|
||||
+ ", chargingPeriod =" + getChargingPeriod() + ", minimumChargePeriod=" + getMinimumChargePeriod()
|
||||
+ ", showChangesBefore =" + isShowChangesBefore() + ", showMinimumCharge= " + isShowMinimumCharge()
|
||||
+ ", minimumCharge = " + getMinimumCharge() + ", publicIp = " + getPublicIp() + ", vcpu =" + getVcpu()
|
||||
+ ", memoryGB= " + getMemoryGB() + ", defaultTemplate= " + isDefaultTemplate() + ", lastUpdate = "
|
||||
+ getLastUpdate() + "]";
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Tier;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.pricing.PricingTierDto;
|
||||
|
||||
/**
|
||||
* Associates an storage {@link Tier} with a {@link PricingTemplate}.
|
||||
*
|
||||
* @author Susana Acedo
|
||||
*/
|
||||
public class PricingTier extends DomainWrapper<PricingTierDto> {
|
||||
private Tier tier;
|
||||
|
||||
private PricingTemplate pricingTemplate;
|
||||
|
||||
protected PricingTier(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final PricingTierDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final PricingTemplate pricingtemplate, final Tier tier) {
|
||||
return new Builder(context, pricingtemplate, tier);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private Integer id;
|
||||
|
||||
private PricingTemplate pricingTemplate;
|
||||
|
||||
private Tier tier;
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final PricingTemplate pricingTemplate,
|
||||
final Tier tier) {
|
||||
super();
|
||||
this.pricingTemplate = checkNotNull(pricingTemplate, ValidationErrors.NULL_RESOURCE + PricingTemplate.class);
|
||||
this.tier = checkNotNull(tier, ValidationErrors.NULL_RESOURCE + Tier.class);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder price(final BigDecimal price) {
|
||||
this.price = price;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PricingTier build() {
|
||||
PricingTierDto dto = new PricingTierDto();
|
||||
dto.setId(id);
|
||||
dto.setPrice(price);
|
||||
|
||||
RESTLink link = tier.unwrap().searchLink("edit");
|
||||
checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK);
|
||||
dto.addLink(new RESTLink("tier", link.getHref()));
|
||||
|
||||
PricingTier pricingTier = new PricingTier(context, dto);
|
||||
pricingTier.pricingTemplate = pricingTemplate;
|
||||
pricingTier.tier = tier;
|
||||
|
||||
return pricingTier;
|
||||
}
|
||||
|
||||
public static Builder fromPricingTier(final PricingTier in) {
|
||||
return PricingTier.builder(in.context, in.pricingTemplate, in.tier).price(in.getPrice());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return target.getPrice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PricingTier [id=" + getId() + ", price=" + getPrice() + "]";
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.enterprise.PrivilegeDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link PrivilegeDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class Privilege extends DomainWrapper<PrivilegeDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder. This resource cannot be
|
||||
* created.
|
||||
*/
|
||||
private Privilege(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final PrivilegeDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Privilege [id=" + getId() + ", name=" + getName() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.config;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.config.SystemPropertyDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link SystemPropertyDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/System+Property+resource"
|
||||
* > http://community.abiquo.com/display/ABI20/System+Property+resource</a>
|
||||
*/
|
||||
|
||||
public class SystemProperty extends DomainWrapper<SystemPropertyDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder. This resource cannot be
|
||||
* created.
|
||||
*/
|
||||
private SystemProperty(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final SystemPropertyDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/System+Property+resource#SystemPropertyresource-ModifyanexistingSystemProperty"
|
||||
* > http://community.abiquo.com/display/ABI20/System+Property+resource#
|
||||
* SystemPropertyresource-ModifyanexistingSystemProperty</a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getConfigApi().updateSystemProperty(target);
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return target.getValue();
|
||||
}
|
||||
|
||||
public void setValue(final String value) {
|
||||
target.setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SystemProperty [getName()=" + getName() + ", getValue()=" + getValue() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.config.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query icons.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class IconOptions extends BaseHttpRequestOptions {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
IconOptions options = new IconOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String path;
|
||||
|
||||
public Builder path(final String path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IconOptions build() {
|
||||
IconOptions options = new IconOptions();
|
||||
if (path != null) {
|
||||
options.queryParameters.put("path", path);
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.config.options;
|
||||
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query licenses.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class LicenseOptions extends BaseHttpRequestOptions {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
LicenseOptions options = new LicenseOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Boolean active;
|
||||
|
||||
/**
|
||||
* Search active licenses
|
||||
*/
|
||||
public Builder active(final boolean active) {
|
||||
this.active = active;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search inactive licenses
|
||||
*/
|
||||
public Builder inactive(final boolean inactive) {
|
||||
this.active = !inactive;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LicenseOptions build() {
|
||||
LicenseOptions options = new LicenseOptions();
|
||||
if (active != null) {
|
||||
options.queryParameters.put("active", active.toString());
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.config.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query system properties.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class PropertyOptions extends BaseHttpRequestOptions {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
PropertyOptions options = new PropertyOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String component;
|
||||
|
||||
private String name;
|
||||
|
||||
public Builder component(final String component) {
|
||||
this.component = component;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyOptions build() {
|
||||
PropertyOptions options = new PropertyOptions();
|
||||
if (component != null) {
|
||||
options.queryParameters.put("component", component.toString());
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
options.queryParameters.put("name", name.toString());
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,933 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.enterprise;
|
||||
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWithLimitsWrapper;
|
||||
import org.jclouds.abiquo.domain.builder.LimitsBuilder;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
import org.jclouds.abiquo.domain.exception.AbiquoException;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Machine;
|
||||
import org.jclouds.abiquo.domain.network.ExternalIp;
|
||||
import org.jclouds.abiquo.domain.network.ExternalNetwork;
|
||||
import org.jclouds.abiquo.domain.network.Network;
|
||||
import org.jclouds.abiquo.domain.network.UnmanagedIp;
|
||||
import org.jclouds.abiquo.domain.network.UnmanagedNetwork;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
|
||||
import org.jclouds.abiquo.strategy.enterprise.ListVirtualMachineTemplates;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.appslibrary.TemplateDefinitionListDto;
|
||||
import com.abiquo.server.core.appslibrary.TemplateDefinitionListsDto;
|
||||
import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto;
|
||||
import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto;
|
||||
import com.abiquo.server.core.cloud.VirtualAppliancesDto;
|
||||
import com.abiquo.server.core.cloud.VirtualDatacentersDto;
|
||||
import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto;
|
||||
import com.abiquo.server.core.enterprise.DatacenterLimitsDto;
|
||||
import com.abiquo.server.core.enterprise.DatacentersLimitsDto;
|
||||
import com.abiquo.server.core.enterprise.EnterpriseDto;
|
||||
import com.abiquo.server.core.enterprise.EnterprisePropertiesDto;
|
||||
import com.abiquo.server.core.enterprise.RolesDto;
|
||||
import com.abiquo.server.core.enterprise.UserDto;
|
||||
import com.abiquo.server.core.enterprise.UsersDto;
|
||||
import com.abiquo.server.core.infrastructure.DatacentersDto;
|
||||
import com.abiquo.server.core.infrastructure.MachinesDto;
|
||||
import com.abiquo.server.core.infrastructure.network.VLANNetworksDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Represents a tenant.
|
||||
* <p>
|
||||
* Each tenant has a set of available locations, and a set of compute,
|
||||
* networking and storage resources that can be consumed in the assigned
|
||||
* locations.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class Enterprise extends DomainWithLimitsWrapper<EnterpriseDto> {
|
||||
/** The default value for the reservation restricted flag. */
|
||||
private static final boolean DEFAULT_RESERVATION_RESTRICTED = false;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Enterprise(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final EnterpriseDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* Delete the enterprise.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-DeleteanexistingEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource- DeleteanexistingEnterprise</a>
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getEnterpriseApi().deleteEnterprise(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new enterprise in Abiquo.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-CreatesanewEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource- CreatesanewEnterprise</a>
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getEnterpriseApi().createEnterprise(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update enterprise information in the server with the data from this
|
||||
* enterprise.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-Updateanexistingenterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource- Updateanexistingenterprise</a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getEnterpriseApi().updateEnterprise(target);
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
/**
|
||||
* Retrieve the list of virtual datacenters by this enterprise.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-RetrievealistofvitualdatacentersbyanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource-
|
||||
* RetrievealistofvitualdatacentersbyanEnterprise</a>
|
||||
* @return List of virtual datacenters in this enterprise.
|
||||
*/
|
||||
public List<VirtualDatacenter> listVirtualDatacenters() {
|
||||
VirtualDatacentersDto dto = context.getApi().getEnterpriseApi().listVirtualDatacenters(target);
|
||||
return wrap(context, VirtualDatacenter.class, dto.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of virtual datacenters by this enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-RetrievealistofvitualdatacentersbyanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource-
|
||||
* RetrievealistofvitualdatacentersbyanEnterprise</a>
|
||||
* @return Filtered list of virtual datacenters in this enterprise.
|
||||
*/
|
||||
public List<VirtualDatacenter> listVirtualDatacenters(final Predicate<VirtualDatacenter> filter) {
|
||||
return ImmutableList.copyOf(filter(listVirtualDatacenters(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a the first virtual datacenter matching the filter within the
|
||||
* list of virtual datacenters by this enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-RetrievealistofvitualdatacentersbyanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource-
|
||||
* RetrievealistofvitualdatacentersbyanEnterprise</a>
|
||||
* @return First virtual datacenter matching the filter or <code>null</code>
|
||||
* if the is none.
|
||||
*/
|
||||
public VirtualDatacenter findVirtualDatacenter(final Predicate<VirtualDatacenter> filter) {
|
||||
return Iterables.getFirst(filter(listVirtualDatacenters(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of template definition lists of the enterprise.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource#TemplateDefinitionListResource-Retrievealltemplatedefinitionlists"
|
||||
* > http://community.abiquo.com/display/ABI20/
|
||||
* TemplateDefinitionListResource#
|
||||
* TemplateDefinitionListResource-Retrievealltemplatedefinitionlists</a>
|
||||
* @return List of template definition lists of the enterprise.
|
||||
*/
|
||||
public List<TemplateDefinitionList> listTemplateDefinitionLists() {
|
||||
TemplateDefinitionListsDto dto = context.getApi().getEnterpriseApi().listTemplateDefinitionLists(target);
|
||||
return wrap(context, TemplateDefinitionList.class, dto.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of template definition lists from this
|
||||
* enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource#TemplateDefinitionListResource-Retrievealltemplatedefinitionlists"
|
||||
* > http://community.abiquo.com/display/ABI20/
|
||||
* TemplateDefinitionListResource#
|
||||
* TemplateDefinitionListResource-Retrievealltemplatedefinitionlists</a>
|
||||
* @return Filtered list of template definition lists of the enterprise.
|
||||
*/
|
||||
public List<TemplateDefinitionList> listTemplateDefinitionLists(final Predicate<TemplateDefinitionList> filter) {
|
||||
return ImmutableList.copyOf(filter(listTemplateDefinitionLists(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first template definition list matching the filter within the
|
||||
* list.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource#TemplateDefinitionListResource-Retrievealltemplatedefinitionlists"
|
||||
* > http://community.abiquo.com/display/ABI20/
|
||||
* TemplateDefinitionListResource#
|
||||
* TemplateDefinitionListResource-Retrievealltemplatedefinitionlists</a>
|
||||
* @return First template definition list matching the filter or
|
||||
* <code>null</code> if the is none.
|
||||
*/
|
||||
public TemplateDefinitionList findTemplateDefinitionList(final Predicate<TemplateDefinitionList> filter) {
|
||||
return Iterables.getFirst(filter(listTemplateDefinitionLists(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single template definition list.
|
||||
*
|
||||
* @param id
|
||||
* Unique ID of the template definition list for this enterprise.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource#TemplateDefinitionListResource-Retrieveatemplatedefinitionlist"
|
||||
* > http://community.abiquo.com/display/ABI20/
|
||||
* TemplateDefinitionListResource#
|
||||
* TemplateDefinitionListResource-Retrieveatemplatedefinitionlist</a>
|
||||
* @return Template definition with the given id or <code>null</code> if it
|
||||
* does not exist.
|
||||
*/
|
||||
public TemplateDefinitionList getTemplateDefinitionList(final Integer id) {
|
||||
TemplateDefinitionListDto templateList = context.getApi().getEnterpriseApi()
|
||||
.getTemplateDefinitionList(target, id);
|
||||
return wrap(context, TemplateDefinitionList.class, templateList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of datacenter limits by enterprise.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/DatacenterLimitsResource#DatacenterLimitsResource-Retrievelimitsbyenterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/DatacenterLimitsResource#
|
||||
* DatacenterLimitsResource-Retrievelimitsbyenterprise</a>
|
||||
* @return List of datacenter limits by enterprise.
|
||||
*/
|
||||
public List<Limits> listLimits() {
|
||||
DatacentersLimitsDto dto = context.getApi().getEnterpriseApi().listLimits(this.unwrap());
|
||||
return wrap(context, Limits.class, dto.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of datacenter limits by enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/DatacenterLimitsResource#DatacenterLimitsResource-Retrievelimitsbyenterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/DatacenterLimitsResource#
|
||||
* DatacenterLimitsResource-Retrievelimitsbyenterprise</a>
|
||||
* @return Filtered list of datacenter limits by enterprise.
|
||||
*/
|
||||
public List<Limits> listLimits(final Predicate<Limits> filter) {
|
||||
return ImmutableList.copyOf(filter(listLimits(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first datacenter limits matching the filter within the list
|
||||
* of datacenter limits by enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/DatacenterLimitsResource#DatacenterLimitsResource-Retrievelimitsbyenterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/DatacenterLimitsResource#
|
||||
* DatacenterLimitsResource-Retrievelimitsbyenterprise</a>
|
||||
* @return First datacenter limits matching the filter or <code>null</code>
|
||||
* if there is none.
|
||||
*/
|
||||
public Limits findLimits(final Predicate<Limits> filter) {
|
||||
return Iterables.getFirst(filter(listLimits(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the defined properties of the given enterprise.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterprisePropertiesResource#EnterprisePropertiesResource-Retrievethepropertiesforanenterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/
|
||||
* EnterprisePropertiesResource#
|
||||
* EnterprisePropertiesResource-Retrievethepropertiesforanenterprise</a>
|
||||
* @return The defined properties of the given enterprise.
|
||||
*/
|
||||
public EnterpriseProperties getEnterpriseProperties() {
|
||||
EnterprisePropertiesDto dto = context.getApi().getEnterpriseApi().getEnterpriseProperties(this.unwrap());
|
||||
return wrap(context, EnterpriseProperties.class, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of users of this enterprise.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/UserResource#UserResource-Retrievealistofusers"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/UserResource#UserResource-
|
||||
* Retrievealistofusers </a>
|
||||
* @return List of users of this enterprise.
|
||||
*/
|
||||
public List<User> listUsers() {
|
||||
UsersDto dto = context.getApi().getEnterpriseApi().listUsers(this.unwrap());
|
||||
return wrap(context, User.class, dto.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of users of this enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/UserResource#UserResource-Retrievealistofusers"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/UserResource#UserResource-
|
||||
* Retrievealistofusers </a>
|
||||
* @return Filtered list of users of this enterprise.
|
||||
*/
|
||||
public List<User> listUsers(final Predicate<User> filter) {
|
||||
return ImmutableList.copyOf(filter(listUsers(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first user matching the filter within the list of users of
|
||||
* this enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/UserResource#UserResource-Retrievealistofusers"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/UserResource#UserResource-
|
||||
* Retrievealistofusers </a>
|
||||
* @return First user matching the filter or <code>null</code> if there is
|
||||
* none.
|
||||
*/
|
||||
public User findUser(final Predicate<User> filter) {
|
||||
return Iterables.getFirst(filter(listUsers(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single user.
|
||||
*
|
||||
* @param id
|
||||
* Unique ID of the user in this enterprise.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/UserResource#UserResource-Retrieveauser"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/UserResource#UserResource-
|
||||
* Retrieveauser</a>
|
||||
* @return User with the given id or <code>null</code> if it does not exist.
|
||||
*/
|
||||
public User getUser(final Integer id) {
|
||||
UserDto user = context.getApi().getEnterpriseApi().getUser(target, id);
|
||||
return wrap(context, User.class, user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of roles defined by this enterprise.
|
||||
*
|
||||
* @return List of roles by this enterprise.
|
||||
*/
|
||||
public List<Role> listRoles() {
|
||||
RolesDto dto = context.getApi().getAdminApi().listRoles(target);
|
||||
return wrap(context, Role.class, dto.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of roles defined by this enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @return Filtered list of roles by this enterprise.
|
||||
*/
|
||||
public List<Role> listRoles(final Predicate<Role> filter) {
|
||||
return ImmutableList.copyOf(filter(listRoles(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first role matching the filter within the list of roles
|
||||
* defined by this enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @return First role matching the filter or <code>null</code> if there is
|
||||
* none.
|
||||
*/
|
||||
public Role findRole(final Predicate<Role> filter) {
|
||||
return Iterables.getFirst(filter(listRoles(), filter), null);
|
||||
}
|
||||
|
||||
public List<VirtualMachineTemplate> listTemplatesInRepository(final Datacenter datacenter) {
|
||||
VirtualMachineTemplatesDto dto = context.getApi().getVirtualMachineTemplateApi()
|
||||
.listVirtualMachineTemplates(target.getId(), datacenter.getId());
|
||||
return wrap(context, VirtualMachineTemplate.class, dto.getCollection());
|
||||
}
|
||||
|
||||
public List<VirtualMachineTemplate> listTemplatesInRepository(final Datacenter datacenter,
|
||||
final Predicate<VirtualMachineTemplate> filter) {
|
||||
return ImmutableList.copyOf(filter(listTemplatesInRepository(datacenter), filter));
|
||||
}
|
||||
|
||||
public VirtualMachineTemplate findTemplateInRepository(final Datacenter datacenter,
|
||||
final Predicate<VirtualMachineTemplate> filter) {
|
||||
return Iterables.getFirst(filter(listTemplatesInRepository(datacenter), filter), null);
|
||||
}
|
||||
|
||||
public VirtualMachineTemplate getTemplateInRepository(final Datacenter datacenter, final Integer id) {
|
||||
VirtualMachineTemplateDto template = context.getApi().getVirtualMachineTemplateApi()
|
||||
.getVirtualMachineTemplate(target.getId(), datacenter.getId(), id);
|
||||
return wrap(context, VirtualMachineTemplate.class, template);
|
||||
}
|
||||
|
||||
public List<VirtualMachineTemplate> listTemplates() {
|
||||
ListVirtualMachineTemplates strategy = context.getUtils().getInjector()
|
||||
.getInstance(ListVirtualMachineTemplates.class);
|
||||
return ImmutableList.copyOf(strategy.execute(this));
|
||||
}
|
||||
|
||||
public List<VirtualMachineTemplate> listTemplates(final Predicate<VirtualMachineTemplate> filter) {
|
||||
ListVirtualMachineTemplates strategy = context.getUtils().getInjector()
|
||||
.getInstance(ListVirtualMachineTemplates.class);
|
||||
return ImmutableList.copyOf(strategy.execute(this, filter));
|
||||
}
|
||||
|
||||
public VirtualMachineTemplate findTemplate(final Predicate<VirtualMachineTemplate> filter) {
|
||||
ListVirtualMachineTemplates strategy = context.getUtils().getInjector()
|
||||
.getInstance(ListVirtualMachineTemplates.class);
|
||||
return Iterables.getFirst(strategy.execute(this, filter), null);
|
||||
}
|
||||
|
||||
public List<Datacenter> listAllowedDatacenters() {
|
||||
DatacentersDto datacenters = context.getApi().getEnterpriseApi().listAllowedDatacenters(target.getId());
|
||||
return wrap(context, Datacenter.class, datacenters.getCollection());
|
||||
}
|
||||
|
||||
public List<Datacenter> listAllowedDatacenters(final Predicate<Datacenter> filter) {
|
||||
return ImmutableList.copyOf(filter(listAllowedDatacenters(), filter));
|
||||
}
|
||||
|
||||
public Datacenter findAllowedDatacenter(final Predicate<Datacenter> filter) {
|
||||
return Iterables.getFirst(filter(listAllowedDatacenters(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource-Getthelistofexternalnetworks"
|
||||
* > http://community.abiquo.com/display/ABI20/Enterprise+Resource#
|
||||
* EnterpriseResource- Getthelistofexternalnetworks</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public List<ExternalNetwork> listExternalNetworks(final Datacenter datacenter) {
|
||||
DatacenterLimitsDto limitForDatacenter = getLimits(datacenter);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(limitForDatacenter.searchLink("externalnetworks"));
|
||||
|
||||
ParseXMLWithJAXB<VLANNetworksDto> parser = new ParseXMLWithJAXB<VLANNetworksDto>(utils.getXml(),
|
||||
TypeLiteral.get(VLANNetworksDto.class));
|
||||
|
||||
return wrap(context, ExternalNetwork.class, parser.apply(response).getCollection());
|
||||
}
|
||||
|
||||
@EnterpriseEdition
|
||||
public List<ExternalNetwork> listExternalNetworks(final Datacenter datacenter,
|
||||
final Predicate<Network<ExternalIp>> filter) {
|
||||
return ImmutableList.copyOf(filter(listExternalNetworks(datacenter), filter));
|
||||
}
|
||||
|
||||
@EnterpriseEdition
|
||||
public ExternalNetwork findExternalNetwork(final Datacenter datacenter, final Predicate<Network<ExternalIp>> filter) {
|
||||
return Iterables.getFirst(filter(listExternalNetworks(datacenter), filter), null);
|
||||
}
|
||||
|
||||
@EnterpriseEdition
|
||||
public List<UnmanagedNetwork> listUnmanagedNetworks(final Datacenter datacenter) {
|
||||
DatacenterLimitsDto limitForDatacenter = getLimits(datacenter);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
// The "rel" for the unmanaged networks is the same than the one used for
|
||||
// external networks
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(limitForDatacenter.searchLink("externalnetworks"));
|
||||
|
||||
ParseXMLWithJAXB<VLANNetworksDto> parser = new ParseXMLWithJAXB<VLANNetworksDto>(utils.getXml(),
|
||||
TypeLiteral.get(VLANNetworksDto.class));
|
||||
|
||||
return wrap(context, UnmanagedNetwork.class, parser.apply(response).getCollection());
|
||||
}
|
||||
|
||||
@EnterpriseEdition
|
||||
public List<UnmanagedNetwork> listUnmanagedNetworks(final Datacenter datacenter,
|
||||
final Predicate<Network<UnmanagedIp>> filter) {
|
||||
return ImmutableList.copyOf(filter(listUnmanagedNetworks(datacenter), filter));
|
||||
}
|
||||
|
||||
@EnterpriseEdition
|
||||
public UnmanagedNetwork findUnmanagedNetwork(final Datacenter datacenter,
|
||||
final Predicate<Network<UnmanagedIp>> filter) {
|
||||
return Iterables.getFirst(filter(listUnmanagedNetworks(datacenter), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of virtual appliances by this enterprise.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-RetrievethelistofvirtualappliancesbyanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource-
|
||||
* RetrievethelistofvirtualappliancesbyanEnterprise</a>
|
||||
* @return List of virtual appliances by this enterprise.
|
||||
*/
|
||||
public List<VirtualAppliance> listVirtualAppliances() {
|
||||
VirtualAppliancesDto virtualAppliances = context.getApi().getEnterpriseApi().listVirtualAppliances(target);
|
||||
return wrap(context, VirtualAppliance.class, virtualAppliances.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of virtual appliances by this enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-RetrievethelistofvirtualappliancesbyanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource-
|
||||
* RetrievethelistofvirtualappliancesbyanEnterprise</a>
|
||||
* @return Filtered list of virtual appliances by this enterprise.
|
||||
*/
|
||||
public List<VirtualAppliance> listVirtualAppliances(final Predicate<VirtualAppliance> filter) {
|
||||
return ImmutableList.copyOf(filter(listVirtualAppliances(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first virtual appliance matching the filter within the list
|
||||
* of virtual appliances in this enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-RetrievethelistofvirtualappliancesbyanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource-
|
||||
* RetrievethelistofvirtualappliancesbyanEnterprise</a>
|
||||
* @return First virtual machine matching the filter or <code>null</code> if
|
||||
* the is none.
|
||||
*/
|
||||
public VirtualAppliance findVirtualAppliance(final Predicate<VirtualAppliance> filter) {
|
||||
return Iterables.getFirst(filter(listVirtualAppliances(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of virtual machines by this enterprise.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-RetrievealistofvirtualmachinesbyanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource- RetrievealistofvirtualmachinesbyanEnterprise</a>
|
||||
* @return List of virtual machines by this enterprise.
|
||||
*/
|
||||
public List<VirtualMachine> listVirtualMachines() {
|
||||
VirtualMachinesWithNodeExtendedDto machines = context.getApi().getEnterpriseApi().listVirtualMachines(target);
|
||||
return wrap(context, VirtualMachine.class, machines.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of virtual machines by this enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-RetrievealistofvirtualmachinesbyanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource- RetrievealistofvirtualmachinesbyanEnterprise</a>
|
||||
* @return Filtered list of virtual machines by this enterprise.
|
||||
*/
|
||||
public List<VirtualMachine> listVirtualMachines(final Predicate<VirtualMachine> filter) {
|
||||
return ImmutableList.copyOf(filter(listVirtualMachines(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first virtual machine matching the filter within the list of
|
||||
* virtual machines in this enterprise.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/EnterpriseResource#EnterpriseResource-RetrievealistofvirtualmachinesbyanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/EnterpriseResource#
|
||||
* EnterpriseResource- RetrievealistofvirtualmachinesbyanEnterprise</a>
|
||||
* @return First virtual machine matching the filter or <code>null</code> if
|
||||
* the is none.
|
||||
*/
|
||||
public VirtualMachine findVirtualMachine(final Predicate<VirtualMachine> filter) {
|
||||
return Iterables.getFirst(filter(listVirtualMachines(), filter), null);
|
||||
}
|
||||
|
||||
public List<Machine> listReservedMachines() {
|
||||
MachinesDto machines = context.getApi().getEnterpriseApi().listReservedMachines(target);
|
||||
return wrap(context, Machine.class, machines.getCollection());
|
||||
}
|
||||
|
||||
public List<VirtualMachine> listReservedMachines(final Predicate<VirtualMachine> filter) {
|
||||
return ImmutableList.copyOf(filter(listVirtualMachines(), filter));
|
||||
}
|
||||
|
||||
public VirtualMachine findReservedMachine(final Predicate<VirtualMachine> filter) {
|
||||
return Iterables.getFirst(filter(listVirtualMachines(), filter), null);
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Datacenter+Repository+Resource#DatacenterRepositoryResource-SynchronizetheDatacenterRepositorywiththerepository"
|
||||
* > http://community.abiquo.com/display/ABI20/Datacenter+Repository+
|
||||
* Resource# DatacenterRepositoryResource-
|
||||
* SynchronizetheDatacenterRepositorywiththerepository</a>
|
||||
*/
|
||||
public void refreshTemplateRepository(final Datacenter datacenter) {
|
||||
context.getApi().getEnterpriseApi().refreshTemplateRepository(target.getId(), datacenter.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the given datacenter to be used by this enterprise. Creates a
|
||||
* {@link Limits} object if not exists.
|
||||
*
|
||||
* @param datacenter
|
||||
* The datacenter.
|
||||
* @return Default datacenter limits of the enterprise for the given
|
||||
* datacenter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Datacenter+Limits+Resource#DatacenterLimitsResource-CreateanewLimitforanenterpriseinadatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Datacenter+Limits+
|
||||
* Resource#
|
||||
* DatacenterLimitsResource-CreateanewLimitforanenterpriseinadatacenter
|
||||
* </a>
|
||||
*/
|
||||
public Limits allowDatacenter(final Datacenter datacenter) {
|
||||
DatacenterLimitsDto dto;
|
||||
|
||||
try {
|
||||
// Create new limits
|
||||
Limits limits = Limits.builder(context).build();
|
||||
|
||||
// Save new limits
|
||||
dto = context.getApi().getEnterpriseApi().createLimits(target, datacenter.unwrap(), limits.unwrap());
|
||||
} catch (AbiquoException ex) {
|
||||
// Controlled error to allow duplicated authorizations
|
||||
if (ex.hasError("LIMIT-7")) {
|
||||
DatacentersLimitsDto limits = context.getApi().getEnterpriseApi().getLimits(target, datacenter.unwrap());
|
||||
// Should be only one limit
|
||||
dto = limits.getCollection().get(0);
|
||||
} else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
return wrap(context, Limits.class, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prohibit the given datacenter to be used by this enterprise. Deletes a
|
||||
* {@link Limits} object.
|
||||
*
|
||||
* @param datacenter
|
||||
* The datacenter.
|
||||
* @return Default datacenter limits of the enterprise for the given
|
||||
* datacenter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Datacenter+Limits+Resource#DatacenterLimitsResource-Deleteanexistinglimitforanenterpriseinadatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/Datacenter+Limits+
|
||||
* Resource# DatacenterLimitsResource-
|
||||
* Deleteanexistinglimitforanenterpriseinadatacenter</a>
|
||||
*/
|
||||
public void prohibitDatacenter(final Datacenter datacenter) {
|
||||
// Get limits
|
||||
DatacentersLimitsDto dto = context.getApi().getEnterpriseApi().getLimits(target, datacenter.unwrap());
|
||||
|
||||
// Delete limits (if any)
|
||||
if (dto != null && !dto.isEmpty()) {
|
||||
// Should be only one limit
|
||||
context.getApi().getEnterpriseApi().deleteLimits(dto.getCollection().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables chef in the enterprise.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource-DisableChefinanexistingEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/Enterprise+Resource#
|
||||
* EnterpriseResource- DisableChefinanexistingEnterprise</a>
|
||||
*/
|
||||
public void disableChef() {
|
||||
target.setChefClient(null);
|
||||
target.setChefClientCertificate(null);
|
||||
target.setChefURL(null);
|
||||
target.setChefValidator(null);
|
||||
target.setChefValidatorCertificate(null);
|
||||
update();
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
return new Builder(context);
|
||||
}
|
||||
|
||||
public static class Builder extends LimitsBuilder<Builder> {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private String name;
|
||||
|
||||
protected Long repositorySoft = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
protected Long repositoryHard = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
private Boolean isReservationRestricted = DEFAULT_RESERVATION_RESTRICTED;
|
||||
|
||||
private String chefURL;
|
||||
|
||||
private String chefClient;
|
||||
|
||||
private String chefValidator;
|
||||
|
||||
private String chefApiCertificate;
|
||||
|
||||
private String chefValidatorCertificate;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder isReservationRestricted(final boolean isReservationRestricted) {
|
||||
this.isReservationRestricted = isReservationRestricted;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder chefURL(final String chefURL) {
|
||||
this.chefURL = chefURL;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder chefClient(final String chefClient) {
|
||||
this.chefClient = chefClient;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder chefApiCertificate(final String chefApiCertificate) {
|
||||
this.chefApiCertificate = chefApiCertificate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder chefValidator(final String chefValidator) {
|
||||
this.chefValidator = chefValidator;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder chefValidatorCertificate(final String chefValidatorCertificate) {
|
||||
this.chefValidatorCertificate = chefValidatorCertificate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder repositoryLimits(final long soft, final long hard) {
|
||||
this.repositorySoft = soft;
|
||||
this.repositoryHard = hard;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Enterprise build() {
|
||||
EnterpriseDto dto = new EnterpriseDto();
|
||||
dto.setName(name);
|
||||
dto.setRamLimitsInMb(ramSoftLimitInMb, ramHardLimitInMb);
|
||||
dto.setCpuCountLimits(cpuCountSoftLimit, cpuCountHardLimit);
|
||||
dto.setHdLimitsInMb(hdSoftLimitInMb, hdHardLimitInMb);
|
||||
dto.setStorageLimits(storageSoft, storageHard);
|
||||
dto.setVlansLimits(vlansSoft, vlansHard);
|
||||
dto.setPublicIPLimits(publicIpsSoft, publicIpsHard);
|
||||
dto.setRepositoryLimits(repositorySoft, repositoryHard);
|
||||
dto.setIsReservationRestricted(isReservationRestricted);
|
||||
dto.setChefClient(chefClient);
|
||||
dto.setChefClientCertificate(chefApiCertificate);
|
||||
dto.setChefURL(chefURL);
|
||||
dto.setChefValidator(chefValidator);
|
||||
dto.setChefValidatorCertificate(chefValidatorCertificate);
|
||||
|
||||
return new Enterprise(context, dto);
|
||||
}
|
||||
|
||||
public static Builder fromEnterprise(final Enterprise in) {
|
||||
return Enterprise.builder(in.context).name(in.getName())
|
||||
.ramLimits(in.getRamSoftLimitInMb(), in.getRamHardLimitInMb())
|
||||
.cpuCountLimits(in.getCpuCountSoftLimit(), in.getCpuCountHardLimit())
|
||||
.hdLimitsInMb(in.getHdSoftLimitInMb(), in.getHdHardLimitInMb())
|
||||
.storageLimits(in.getStorageSoft(), in.getStorageHard())
|
||||
.vlansLimits(in.getVlansSoft(), in.getVlansHard())
|
||||
.publicIpsLimits(in.getPublicIpsSoft(), in.getPublicIpsHard())
|
||||
.repositoryLimits(in.getRepositorySoft(), in.getRepositoryHard())
|
||||
.isReservationRestricted(in.getIsReservationRestricted()).chefClient(in.getChefClient())
|
||||
.chefApiCertificate(in.getChefApiCertificate()).chefURL(in.getChefURL())
|
||||
.chefValidator(in.getChefValidator()).chefValidatorCertificate(in.getChefValidatorCertificate());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public boolean getIsReservationRestricted() {
|
||||
return target.getIsReservationRestricted();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public long getRepositoryHard() {
|
||||
return target.getRepositoryHard();
|
||||
}
|
||||
|
||||
public long getRepositorySoft() {
|
||||
return target.getRepositorySoft();
|
||||
}
|
||||
|
||||
public void setIsReservationRestricted(final boolean isReservationRestricted) {
|
||||
target.setIsReservationRestricted(isReservationRestricted);
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public void setRepositoryHard(final long repositoryHard) {
|
||||
target.setRepositoryHard(repositoryHard);
|
||||
}
|
||||
|
||||
public void setRepositoryLimits(final long soft, final long hard) {
|
||||
target.setRepositoryLimits(soft, hard);
|
||||
}
|
||||
|
||||
public void setRepositorySoft(final long repositorySoft) {
|
||||
target.setRepositorySoft(repositorySoft);
|
||||
}
|
||||
|
||||
public String getChefClient() {
|
||||
return target.getChefClient();
|
||||
}
|
||||
|
||||
public String getChefApiCertificate() {
|
||||
return target.getChefClientCertificate();
|
||||
}
|
||||
|
||||
public String getChefURL() {
|
||||
return target.getChefURL();
|
||||
}
|
||||
|
||||
public String getChefValidator() {
|
||||
return target.getChefValidator();
|
||||
}
|
||||
|
||||
public String getChefValidatorCertificate() {
|
||||
return target.getChefValidatorCertificate();
|
||||
}
|
||||
|
||||
public void setChefClient(final String chefClient) {
|
||||
target.setChefClient(chefClient);
|
||||
}
|
||||
|
||||
public void setChefClientCertificate(final String chefClientCertificate) {
|
||||
target.setChefClientCertificate(chefClientCertificate);
|
||||
}
|
||||
|
||||
public void setChefURL(final String chefURL) {
|
||||
target.setChefURL(chefURL);
|
||||
}
|
||||
|
||||
public void setChefValidator(final String chefValidator) {
|
||||
target.setChefValidator(chefValidator);
|
||||
}
|
||||
|
||||
public void setChefValidatorCertificate(final String chefValidatorCertificate) {
|
||||
target.setChefValidatorCertificate(chefValidatorCertificate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Enterprise [id=" + getId() + ", isReservationRestricted=" + getIsReservationRestricted() + ", name="
|
||||
+ getName() + "]";
|
||||
}
|
||||
|
||||
private DatacenterLimitsDto getLimits(final Datacenter datacenter) {
|
||||
DatacentersLimitsDto limits = context.getApi().getEnterpriseApi().listLimits(target);
|
||||
|
||||
return Iterables.find(limits.getCollection(), new Predicate<DatacenterLimitsDto>() {
|
||||
@Override
|
||||
public boolean apply(final DatacenterLimitsDto input) {
|
||||
RESTLink datacenterLink = input.searchLink("datacenter");
|
||||
return datacenterLink != null
|
||||
&& datacenterLink.getHref().equals(datacenter.unwrap().getEditLink().getHref());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.enterprise;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.enterprise.EnterprisePropertiesDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link EnterprisePropertiesDto}.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Enterprise+Properties+Resource"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Enterprise+Properties+Resource
|
||||
* </a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class EnterpriseProperties extends DomainWrapper<EnterprisePropertiesDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected EnterpriseProperties(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final EnterprisePropertiesDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Enterprise+Properties+Resource#EnterprisePropertiesResource-UpdatesthepropertiesforanEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/Enterprise+Properties+
|
||||
* Resource#
|
||||
* EnterprisePropertiesResource-UpdatesthepropertiesforanEnterprise</a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getEnterpriseApi().updateEnterpriseProperties(target);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource-RetrieveaEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/Enterprise+Resource#
|
||||
* EnterpriseResource- RetrieveaEnterprise</a>
|
||||
*/
|
||||
public Enterprise getEnterprise() {
|
||||
Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE);
|
||||
return wrap(context, Enterprise.class, context.getApi().getEnterpriseApi().getEnterprise(enterpriseId));
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
public Map<String, String> getProperties() {
|
||||
return target.getProperties();
|
||||
}
|
||||
|
||||
public void setProperties(final Map<String, String> properties) {
|
||||
target.setProperties(properties);
|
||||
}
|
||||
}
|
|
@ -1,151 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.enterprise;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWithLimitsWrapper;
|
||||
import org.jclouds.abiquo.domain.builder.LimitsBuilder;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.enterprise.DatacenterLimitsDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link DatacenterLimitsDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/Datacenter+Limits+Resource"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Datacenter+Limits+Resource</a>
|
||||
*/
|
||||
public class Limits extends DomainWithLimitsWrapper<DatacenterLimitsDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Limits(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final DatacenterLimitsDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Datacenter+Limits+Resource#DatacenterLimitsResource-UpdatesanexistingLimitforanenterpriseinadatacenter"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Datacenter+Limits+Resource
|
||||
* #DatacenterLimitsResource
|
||||
* -UpdatesanexistingLimitforanenterpriseinadatacenter</a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getEnterpriseApi().updateLimits(target);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
return new Builder(context);
|
||||
}
|
||||
|
||||
public static class Builder extends LimitsBuilder<Builder> {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
protected Long repositorySoft = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
protected Long repositoryHard = Long.valueOf(DEFAULT_LIMITS);
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder repositoryLimits(final long soft, final long hard) {
|
||||
this.repositorySoft = soft;
|
||||
this.repositoryHard = hard;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Limits build() {
|
||||
DatacenterLimitsDto dto = new DatacenterLimitsDto();
|
||||
dto.setRamLimitsInMb(ramSoftLimitInMb, ramHardLimitInMb);
|
||||
dto.setCpuCountLimits(cpuCountSoftLimit, cpuCountHardLimit);
|
||||
dto.setHdLimitsInMb(hdSoftLimitInMb, hdHardLimitInMb);
|
||||
dto.setStorageLimits(storageSoft, storageHard);
|
||||
dto.setVlansLimits(vlansSoft, vlansHard);
|
||||
dto.setPublicIPLimits(publicIpsSoft, publicIpsHard);
|
||||
dto.setRepositoryHardLimitsInMb(repositoryHard);
|
||||
dto.setRepositorySoftLimitsInMb(repositorySoft);
|
||||
|
||||
Limits limits = new Limits(context, dto);
|
||||
|
||||
return limits;
|
||||
}
|
||||
|
||||
public static Builder fromEnterprise(final Limits in) {
|
||||
return Limits.builder(in.context).ramLimits(in.getRamSoftLimitInMb(), in.getRamHardLimitInMb())
|
||||
.cpuCountLimits(in.getCpuCountSoftLimit(), in.getCpuCountHardLimit())
|
||||
.hdLimitsInMb(in.getHdSoftLimitInMb(), in.getHdHardLimitInMb())
|
||||
.storageLimits(in.getStorageSoft(), in.getStorageHard())
|
||||
.vlansLimits(in.getVlansSoft(), in.getVlansHard())
|
||||
.publicIpsLimits(in.getPublicIpsSoft(), in.getPublicIpsHard())
|
||||
.repositoryLimits(in.getRepositorySoft(), in.getRepositoryHard());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public long getRepositoryHard() {
|
||||
return target.getRepositoryHardLimitsInMb();
|
||||
}
|
||||
|
||||
public long getRepositorySoft() {
|
||||
return target.getRepositorySoftLimitsInMb();
|
||||
}
|
||||
|
||||
public void setRepositoryHard(final long repositoryHard) {
|
||||
target.setRepositoryHardLimitsInMb(repositoryHard);
|
||||
}
|
||||
|
||||
public void setRepositoryLimits(final long soft, final long hard) {
|
||||
target.setRepositoryHardLimitsInMb(hard);
|
||||
target.setRepositorySoftLimitsInMb(soft);
|
||||
}
|
||||
|
||||
public void setRepositorySoft(final long repositorySoft) {
|
||||
target.setRepositorySoftLimitsInMb(repositorySoft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Limits [id=" + getId() + ", repositoryHard=" + getRepositoryHard() + ", repositorySoft="
|
||||
+ getRepositorySoft() + ", cpuCountHard=" + getCpuCountHardLimit() + ", cpuCountSoft="
|
||||
+ getCpuCountSoftLimit() + ", hdHardInMB=" + getHdHardLimitInMb() + ", hdSoftInMB=" + getHdSoftLimitInMb()
|
||||
+ ", publicIPsHard=" + getPublicIpsHard() + ", publicIpsSoft=" + getPublicIpsSoft() + ", ramHardInMB="
|
||||
+ getRamHardLimitInMb() + ", ramSoftInMB=" + getRamSoftLimitInMb() + ", storageHard=" + getStorageHard()
|
||||
+ ", storageSoft=" + getStorageSoft() + ", vlansHard=" + getVlansHard() + ", vlansSoft=" + getVlansSoft()
|
||||
+ "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.enterprise;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.domain.config.Privilege;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.enterprise.PrivilegesDto;
|
||||
import com.abiquo.server.core.enterprise.RoleDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link RoleDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/Roles+Resource">
|
||||
* http://community.abiquo.com/display/ABI20/Roles+Resource</a>
|
||||
*/
|
||||
public class Role extends DomainWrapper<RoleDto> {
|
||||
/** Default active value of the user */
|
||||
private static final boolean DEFAULT_BLOCKED = false;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Role(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final RoleDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource-DeleteanexistingRole"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource
|
||||
* -DeleteanexistingRole </a>
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getAdminApi().deleteRole(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource-CreateanewRole"
|
||||
* > http
|
||||
* ://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource
|
||||
* -CreateanewRole</a>
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getAdminApi().createRole(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource-UpdateanexistingRole"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource
|
||||
* -UpdateanexistingRole </a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getAdminApi().updateRole(target);
|
||||
}
|
||||
|
||||
public void setEnterprise(final Enterprise enterprise) {
|
||||
checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class);
|
||||
checkNotNull(enterprise.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + Enterprise.class);
|
||||
|
||||
RESTLink link = enterprise.unwrap().searchLink("edit");
|
||||
|
||||
checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK);
|
||||
|
||||
target.addLink(new RESTLink("enterprise", link.getHref()));
|
||||
}
|
||||
|
||||
@EnterpriseEdition
|
||||
public void setPrivileges(final List<Privilege> privileges) {
|
||||
for (Privilege privilege : privileges) {
|
||||
addPrivilege(privilege);
|
||||
}
|
||||
}
|
||||
|
||||
@EnterpriseEdition
|
||||
private void addPrivilege(final Privilege privilege) {
|
||||
checkNotNull(privilege, ValidationErrors.NULL_RESOURCE + Privilege.class);
|
||||
checkNotNull(privilege.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + Privilege.class);
|
||||
|
||||
RESTLink link = privilege.unwrap().searchLink("self");
|
||||
|
||||
// rel would be "privilege" if the object is coming from a privilege list.
|
||||
if (link == null) {
|
||||
link = privilege.unwrap().searchLink("privilege");
|
||||
}
|
||||
|
||||
checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK);
|
||||
|
||||
target.addLink(new RESTLink("privilege" + privilege.getId(), link.getHref()));
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Roles+Resource#RolesResource-RetrievealistofprivilegesfromaRole"
|
||||
* > http://community.abiquo.com/display/ABI20/Roles+Resource#
|
||||
* RolesResource- RetrievealistofprivilegesfromaRole</a>
|
||||
*/
|
||||
public List<Privilege> listPrivileges() {
|
||||
PrivilegesDto dto = context.getApi().getAdminApi().listPrivileges(target);
|
||||
|
||||
return wrap(context, Privilege.class, dto.getCollection());
|
||||
}
|
||||
|
||||
public List<Privilege> listPrivileges(final Predicate<Privilege> filter) {
|
||||
return ImmutableList.copyOf(filter(listPrivileges(), filter));
|
||||
}
|
||||
|
||||
public Privilege findPrivileges(final Predicate<Privilege> filter) {
|
||||
return Iterables.getFirst(filter(listPrivileges(), filter), null);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
return new Builder(context);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private String name;
|
||||
|
||||
private boolean blocked = DEFAULT_BLOCKED;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder blocked(final boolean blocked) {
|
||||
this.blocked = blocked;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Role build() {
|
||||
RoleDto dto = new RoleDto();
|
||||
dto.setName(name);
|
||||
dto.setBlocked(blocked);
|
||||
Role role = new Role(context, dto);
|
||||
|
||||
return role;
|
||||
}
|
||||
|
||||
public static Builder fromRole(final Role in) {
|
||||
return Role.builder(in.context).blocked(in.isBlocked()).name(in.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public boolean isBlocked() {
|
||||
return target.isBlocked();
|
||||
}
|
||||
|
||||
public void setBlocked(final boolean blocked) {
|
||||
target.setBlocked(blocked);
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Role [id=" + getId() + ", name=" + getName() + ", blocked=" + isBlocked() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,219 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.enterprise;
|
||||
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.am.model.TemplatesStateDto;
|
||||
import com.abiquo.server.core.appslibrary.TemplateDefinitionListDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link TemplateDefinitionListDto}. A
|
||||
* Template Definition List provides a way to organize multiple Template
|
||||
* Definitions. A single Template Definition can be shared by many lists. Its
|
||||
* compatible with ovfindex.xml format.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class TemplateDefinitionList extends DomainWrapper<TemplateDefinitionListDto> {
|
||||
/** The enterprise where the list belongs. */
|
||||
private Enterprise enterprise;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected TemplateDefinitionList(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final TemplateDefinitionListDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* Delete the template definition list. Deleting the list doesn't delete the
|
||||
* containing Template Definitions.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource#TemplateDefinitionListResource-Deleteatemplatedefinitionlist"
|
||||
* > http://community.abiquo.com/display/ABI20/
|
||||
* TemplateDefinitionListResource#
|
||||
* TemplateDefinitionListResource-Deleteatemplatedefinitionlist</a>
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getEnterpriseApi().deleteTemplateDefinitionList(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a template definition list. All the contained Template Definitions
|
||||
* will also be created.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource#TemplateDefinitionListResource-Createatemplatedefinitionlist"
|
||||
* > http://community.abiquo.com/display/ABI20/
|
||||
* TemplateDefinitionListResource#
|
||||
* TemplateDefinitionListResource-Createatemplatedefinitionlistr</a>
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getEnterpriseApi().createTemplateDefinitionList(enterprise.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a template definition list with the data from this template
|
||||
* definition list.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource#TemplateDefinitionListResource-Modifyatemplatedefinitionlist"
|
||||
* > http://community.abiquo.com/display/ABI20/
|
||||
* TemplateDefinitionListResource#
|
||||
* TemplateDefinitionListResource-Modifyatemplatedefinitionlist</a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getEnterpriseApi().updateTemplateDefinitionList(target);
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
/**
|
||||
* Retrieve the list of states of the templates in the template definition
|
||||
* list in the repository of the given datacenter. Template Definition are
|
||||
* available sources, but in order to create a Virtual Machine the Definition
|
||||
* should be downloaded into the Datacenter Repository (NFS filesystem).
|
||||
*
|
||||
* @param The
|
||||
* datacenter in which repository search.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource#TemplateDefinitionListResource-Retrievealistofthestatusofalltemplatestatuslist"
|
||||
* > http://community.abiquo.com/display/ABI20/
|
||||
* TemplateDefinitionListResource# TemplateDefinitionListResource-
|
||||
* Retrievealistofthestatusofalltemplatestatuslist</a>
|
||||
*/
|
||||
public List<TemplateState> listStatus(final Datacenter datacenter) {
|
||||
TemplatesStateDto states = context.getApi().getEnterpriseApi()
|
||||
.listTemplateListStatus(target, datacenter.unwrap());
|
||||
return wrap(context, TemplateState.class, states.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of states of the templates in the template
|
||||
* definition list in the repository of the given datacenter. Template
|
||||
* Definition are available sources, but in order to create a Virtual Machine
|
||||
* the Definition should be downloaded into the Datacenter Repository (NFS
|
||||
* filesystem).
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @param The
|
||||
* datacenter in which repository search.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TemplateDefinitionListResource#TemplateDefinitionListResource-Retrievealistofthestatusofalltemplatestatuslist"
|
||||
* > http://community.abiquo.com/display/ABI20/
|
||||
* TemplateDefinitionListResource# TemplateDefinitionListResource-
|
||||
* Retrievealistofthestatusofalltemplatestatuslist</a>
|
||||
*/
|
||||
public List<TemplateState> listStatus(final Predicate<TemplateState> filter, final Datacenter datacenter) {
|
||||
return ImmutableList.copyOf(filter(listStatus(datacenter), filter));
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Enterprise enterprise) {
|
||||
return new Builder(context, enterprise);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private Enterprise enterprise;
|
||||
|
||||
private String name;
|
||||
|
||||
private String url;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Enterprise enterprise) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.enterprise = enterprise;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder url(final String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemplateDefinitionList build() {
|
||||
TemplateDefinitionListDto dto = new TemplateDefinitionListDto();
|
||||
dto.setName(name);
|
||||
dto.setUrl(url);
|
||||
|
||||
TemplateDefinitionList templateList = new TemplateDefinitionList(context, dto);
|
||||
templateList.enterprise = enterprise;
|
||||
return templateList;
|
||||
|
||||
}
|
||||
|
||||
public static Builder fromTemplateDefinitionList(final TemplateDefinitionList in) {
|
||||
return TemplateDefinitionList.builder(in.context, in.enterprise).name(in.getName()).url(in.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return target.getUrl();
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public void setUrl(final String url) {
|
||||
target.setUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TemplateDefinitionList [getId()=" + getId() + ", getName()=" + getName() + ", getUrl()=" + getUrl() + "]";
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.enterprise;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.am.model.TemplateStateDto;
|
||||
import com.abiquo.am.model.TemplateStatusEnumType;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link TemplateStateDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class TemplateState extends DomainWrapper<TemplateStateDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected TemplateState(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final TemplateStateDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
public Double getDownloadingProgress() {
|
||||
return target.getDownloadingProgress();
|
||||
}
|
||||
|
||||
public String getErrorCause() {
|
||||
return target.getErrorCause();
|
||||
}
|
||||
|
||||
public String getMasterOvf() {
|
||||
return target.getMasterOvf();
|
||||
}
|
||||
|
||||
public String getOvfId() {
|
||||
return target.getOvfId();
|
||||
}
|
||||
|
||||
public TemplateStatusEnumType getStatus() {
|
||||
return target.getStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TemplateState [getDownloadingProgress()=" + getDownloadingProgress() + ", getErrorCause()="
|
||||
+ getErrorCause() + ", getMasterOvf()=" + getMasterOvf() + ", getOvfId()=" + getOvfId() + ", getStatus()="
|
||||
+ getStatus() + "]";
|
||||
}
|
||||
}
|
|
@ -1,444 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.enterprise;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.abiquo.strategy.cloud.ListVirtualDatacenters;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto;
|
||||
import com.abiquo.server.core.enterprise.RoleDto;
|
||||
import com.abiquo.server.core.enterprise.UserDto;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link UserDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/Users+Resource">
|
||||
* http://community.abiquo.com/display/ABI20/Users+Resource</a>
|
||||
*/
|
||||
public class User extends DomainWrapper<UserDto> {
|
||||
/** Default active value of the user */
|
||||
private static final boolean DEFAULT_ACTIVE = true;
|
||||
|
||||
/** The default authentication type. */
|
||||
private static final String DEFAULT_AUTH_TYPE = "ABIQUO";
|
||||
|
||||
/** The default locale for the user. */
|
||||
private static final String DEFAULT_LOCALE = "en_US";
|
||||
|
||||
/** The enterprise where the user belongs. */
|
||||
private Enterprise enterprise;
|
||||
|
||||
/** Role of the user. */
|
||||
private Role role;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected User(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final UserDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/User+resource#Userresource-Deleteanexistinguser"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/User+resource#Userresource
|
||||
* -Deleteanexistinguser </a>
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getEnterpriseApi().deleteUser(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/User+resource#Userresource-Createanewuser"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/User+resource#Userresource
|
||||
* -Createanewuser</a>
|
||||
*/
|
||||
public void save() {
|
||||
// set role link
|
||||
target.addLink(new RESTLink("role", role.unwrap().getEditLink().getHref()));
|
||||
target = context.getApi().getEnterpriseApi().createUser(enterprise.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/User+resource#Userresource-Updatesanexistinguser"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/User+resource#Userresource
|
||||
* -Updatesanexistinguser </a>
|
||||
*/
|
||||
public void update() {
|
||||
// update role link (if exists)
|
||||
if (role != null) {
|
||||
target.searchLink("role").setHref(role.unwrap().getEditLink().getHref());
|
||||
}
|
||||
|
||||
target = context.getApi().getEnterpriseApi().updateUser(target);
|
||||
}
|
||||
|
||||
public List<VirtualDatacenter> listPermittedVirtualDatacenters() {
|
||||
List<Integer> ids = extractAvailableDatacenters();
|
||||
|
||||
// null value means all virtual datacenters all allowed
|
||||
if (ids.size() == 0) {
|
||||
return this.getEnterprise().listVirtualDatacenters();
|
||||
}
|
||||
|
||||
ListVirtualDatacenters listVirtualDatacenters = context.getUtils().getInjector()
|
||||
.getInstance(ListVirtualDatacenters.class);
|
||||
return ImmutableList.copyOf(listVirtualDatacenters.execute(ids));
|
||||
}
|
||||
|
||||
public List<VirtualDatacenter> listPermittedVirtualDatacenters(final Predicate<VirtualDatacenter> filter) {
|
||||
return ImmutableList.copyOf(filter(listPermittedVirtualDatacenters(), filter));
|
||||
}
|
||||
|
||||
public VirtualDatacenter findPermittedVirtualDatacenter(final Predicate<VirtualDatacenter> filter) {
|
||||
return Iterables.getFirst(filter(listPermittedVirtualDatacenters(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give access to all virtualdatacenters in the enterprise (requires update).
|
||||
*/
|
||||
public void permitAllVirtualDatacenters() {
|
||||
setAvailableVirtualDatacenters(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits user access ONLY to the virtual datacenters in the list. If the
|
||||
* list is empty, user will get access to all virtual datacenters.
|
||||
*
|
||||
* @param vdc
|
||||
* List of virtual datacenters from the user's enterprise.
|
||||
*/
|
||||
public void setPermittedVirtualDatacenters(final List<VirtualDatacenter> vdcs) {
|
||||
List<Integer> ids = Lists.newArrayList();
|
||||
|
||||
for (VirtualDatacenter vdc : vdcs) {
|
||||
checkNotNull(vdc.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + VirtualDatacenter.class);
|
||||
ids.add(vdc.getId());
|
||||
}
|
||||
|
||||
setAvailableVirtualDatacenters(ids);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Enterprise+Resource#EnterpriseResource-RetrieveaEnterprise"
|
||||
* > http://community.abiquo.com/display/ABI20/Enterprise+Resource#
|
||||
* EnterpriseResource- RetrieveaEnterprise</a>
|
||||
*/
|
||||
public Enterprise getEnterprise() {
|
||||
Integer enterpriseId = target.getIdFromLink(ParentLinkName.ENTERPRISE);
|
||||
return wrap(context, Enterprise.class, context.getApi().getEnterpriseApi().getEnterprise(enterpriseId));
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
public Role getRole() {
|
||||
RoleDto role = context.getApi().getAdminApi().getRole(target);
|
||||
return wrap(context, Role.class, role);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/User+resource#Userresource-Retrievethelistofvirtualmachinesbyuser"
|
||||
* > http://community.abiquo.com/display/ABI20/User+resource#
|
||||
* Userresource- Retrievethelistofvirtualmachinesbyuser</a>
|
||||
*/
|
||||
public List<VirtualMachine> listMachines() {
|
||||
VirtualMachinesWithNodeExtendedDto machines = context.getApi().getEnterpriseApi().listVirtualMachines(target);
|
||||
return wrap(context, VirtualMachine.class, machines.getCollection());
|
||||
}
|
||||
|
||||
public List<VirtualMachine> listMachines(final Predicate<VirtualMachine> filter) {
|
||||
return ImmutableList.copyOf(filter(listMachines(), filter));
|
||||
}
|
||||
|
||||
public VirtualMachine findMachine(final Predicate<VirtualMachine> filter) {
|
||||
return Iterables.getFirst(filter(listMachines(), filter), null);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Enterprise enterprise,
|
||||
final Role role) {
|
||||
return new Builder(context, enterprise, role);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private Enterprise enterprise;
|
||||
|
||||
private Role role;
|
||||
|
||||
private String name;
|
||||
|
||||
private String nick;
|
||||
|
||||
private String locale = DEFAULT_LOCALE;
|
||||
|
||||
private String password;
|
||||
|
||||
private String surname;
|
||||
|
||||
private boolean active = DEFAULT_ACTIVE;
|
||||
|
||||
private String email;
|
||||
|
||||
private String description;
|
||||
|
||||
private String authType = DEFAULT_AUTH_TYPE;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Enterprise enterprise, final Role role) {
|
||||
super();
|
||||
checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class);
|
||||
checkNotNull(role, ValidationErrors.NULL_RESOURCE + Role.class);
|
||||
this.context = context;
|
||||
this.enterprise = enterprise;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public Builder enterprise(final Enterprise enterprise) {
|
||||
checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class);
|
||||
this.enterprise = enterprise;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder role(final Role role) {
|
||||
this.role = role;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(final String name, final String surname) {
|
||||
this.name = name;
|
||||
this.surname = surname;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder nick(final String nick) {
|
||||
this.nick = nick;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder locale(final String locale) {
|
||||
this.locale = locale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder password(final String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder active(final boolean active) {
|
||||
this.active = active;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder email(final String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(final String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder authType(final String authType) {
|
||||
this.authType = authType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public User build() {
|
||||
UserDto dto = new UserDto();
|
||||
dto.setActive(active);
|
||||
dto.setAuthType(authType);
|
||||
dto.setDescription(description);
|
||||
dto.setEmail(email);
|
||||
dto.setLocale(locale);
|
||||
dto.setName(name);
|
||||
dto.setNick(nick);
|
||||
dto.setPassword(password);
|
||||
dto.setSurname(surname);
|
||||
User user = new User(context, dto);
|
||||
user.enterprise = enterprise;
|
||||
user.role = role;
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public static Builder fromUser(final User in) {
|
||||
return User.builder(in.context, in.enterprise, in.role).active(in.isActive()).authType(in.getAuthType())
|
||||
.description(in.getDescription()).email(in.getEmail()).locale(in.getLocale())
|
||||
.name(in.getName(), in.getSurname()).nick(in.getNick()).password(in.getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public String getAuthType() {
|
||||
return target.getAuthType();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return target.getEmail();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getLocale() {
|
||||
return target.getLocale();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getNick() {
|
||||
return target.getNick();
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return target.getPassword();
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return target.getSurname();
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return target.isActive();
|
||||
}
|
||||
|
||||
public void setActive(final boolean active) {
|
||||
target.setActive(active);
|
||||
}
|
||||
|
||||
public void setAuthType(final String authType) {
|
||||
target.setAuthType(authType);
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
target.setDescription(description);
|
||||
}
|
||||
|
||||
public void setEmail(final String email) {
|
||||
target.setEmail(email);
|
||||
}
|
||||
|
||||
public void setLocale(final String locale) {
|
||||
target.setLocale(locale);
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public void setNick(final String nick) {
|
||||
target.setNick(nick);
|
||||
}
|
||||
|
||||
public void setPassword(final String password) {
|
||||
target.setPassword(password);
|
||||
}
|
||||
|
||||
public void setSurname(final String surname) {
|
||||
target.setSurname(surname);
|
||||
}
|
||||
|
||||
public void setRole(final Role role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
// Aux operations
|
||||
|
||||
/**
|
||||
* Converts the tokenized String of available virtual datacenters provided in
|
||||
* the userDto to a list of ids.
|
||||
*/
|
||||
private List<Integer> extractAvailableDatacenters() {
|
||||
List<Integer> ids = Lists.newArrayList();
|
||||
|
||||
if (target.getAvailableVirtualDatacenters() != null) {
|
||||
|
||||
StringTokenizer st = new StringTokenizer(target.getAvailableVirtualDatacenters(), ",");
|
||||
|
||||
while (st.hasMoreTokens()) {
|
||||
ids.add(Integer.parseInt(st.nextToken()));
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
private void setAvailableVirtualDatacenters(final List<Integer> ids) {
|
||||
if (ids == null || ids.size() == 0) {
|
||||
target.setAvailableVirtualDatacenters("");
|
||||
} else {
|
||||
Joiner joiner = Joiner.on(",").skipNulls();
|
||||
target.setAvailableVirtualDatacenters(joiner.join(ids));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User [id=" + getId() + ", role=" + getRole() + ", authType=" + getAuthType() + ", description="
|
||||
+ getDescription() + ", email=" + getEmail() + ", locale=" + getLocale() + ", name=" + getName()
|
||||
+ ", nick=" + getNick() + ", password=" + getPassword() + ", surname=" + getSurname() + ", active="
|
||||
+ isActive() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.enterprise.options;
|
||||
|
||||
import org.jclouds.abiquo.domain.options.search.FilterOptions.BaseFilterOptionsBuilder;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query enterprises.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class EnterpriseOptions extends BaseHttpRequestOptions {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
EnterpriseOptions options = new EnterpriseOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder extends BaseFilterOptionsBuilder<Builder> {
|
||||
private String idPricingTemplate;
|
||||
|
||||
private Boolean included;
|
||||
|
||||
private String filter;
|
||||
|
||||
private Integer page;
|
||||
|
||||
private Integer results;
|
||||
|
||||
private Boolean network;
|
||||
|
||||
public Builder pricingTemplate(final String idPricingTemplate) {
|
||||
this.idPricingTemplate = idPricingTemplate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder included(final boolean included) {
|
||||
this.included = included;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder filter(final String filter) {
|
||||
this.filter = filter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder network(final boolean network) {
|
||||
this.network = network;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder page(final int page) {
|
||||
this.page = page;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder results(final int results) {
|
||||
this.results = results;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EnterpriseOptions build() {
|
||||
EnterpriseOptions options = new EnterpriseOptions();
|
||||
|
||||
if (idPricingTemplate != null) {
|
||||
options.queryParameters.put("idPricingTemplate", String.valueOf(idPricingTemplate));
|
||||
}
|
||||
|
||||
if (included != null) {
|
||||
options.queryParameters.put("included", String.valueOf(included));
|
||||
}
|
||||
|
||||
if (filter != null) {
|
||||
options.queryParameters.put("filter", String.valueOf(filter));
|
||||
}
|
||||
|
||||
if (page != null) {
|
||||
options.queryParameters.put("page", String.valueOf(page));
|
||||
}
|
||||
|
||||
if (results != null) {
|
||||
options.queryParameters.put("numResults", String.valueOf(results));
|
||||
}
|
||||
|
||||
if (network != null) {
|
||||
options.queryParameters.put("network", String.valueOf(network));
|
||||
}
|
||||
|
||||
return addFilterOptions(options);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,321 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.event;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.SeverityType;
|
||||
import com.abiquo.server.core.event.EventDto;
|
||||
|
||||
/**
|
||||
* @author Vivien Mahé
|
||||
*/
|
||||
public class Event extends DomainWrapper<EventDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Event(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final EventDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return target.getUser();
|
||||
}
|
||||
|
||||
public void setUser(final String user) {
|
||||
target.setUser(user);
|
||||
}
|
||||
|
||||
public String getStacktrace() {
|
||||
return target.getStacktrace();
|
||||
}
|
||||
|
||||
public void setStacktrace(final String stacktrace) {
|
||||
target.setStacktrace(stacktrace);
|
||||
}
|
||||
|
||||
public String getComponent() {
|
||||
return target.getComponent();
|
||||
}
|
||||
|
||||
public void setComponent(final String component) {
|
||||
target.setComponent(component);
|
||||
}
|
||||
|
||||
public String getPerformedBy() {
|
||||
return target.getPerformedBy();
|
||||
}
|
||||
|
||||
public void setPerformedBy(final String performedBy) {
|
||||
target.setPerformedBy(performedBy);
|
||||
}
|
||||
|
||||
public Integer getIdNetwork() {
|
||||
return target.getIdNetwork();
|
||||
}
|
||||
|
||||
public void setIdNetwork(final Integer idNetwork) {
|
||||
target.setIdNetwork(idNetwork);
|
||||
}
|
||||
|
||||
public String getIdVolume() {
|
||||
return target.getIdVolume();
|
||||
}
|
||||
|
||||
public void setIdVolume(final String idVolume) {
|
||||
target.setIdVolume(idVolume);
|
||||
}
|
||||
|
||||
public String getStoragePool() {
|
||||
return target.getStoragePool();
|
||||
}
|
||||
|
||||
public void setStoragePool(final String storagePool) {
|
||||
target.setStoragePool(storagePool);
|
||||
}
|
||||
|
||||
public Date getTimestamp() {
|
||||
return target.getTimestamp();
|
||||
}
|
||||
|
||||
public void setTimestamp(final Date timestamp) {
|
||||
target.setTimestamp(timestamp);
|
||||
}
|
||||
|
||||
public String getVirtualApp() {
|
||||
return target.getVirtualApp();
|
||||
}
|
||||
|
||||
public void setVirtualApp(final String virtualApp) {
|
||||
target.setVirtualApp(virtualApp);
|
||||
}
|
||||
|
||||
public String getDatacenter() {
|
||||
return target.getDatacenter();
|
||||
}
|
||||
|
||||
public void setDatacenter(final String datacenter) {
|
||||
target.setDatacenter(datacenter);
|
||||
}
|
||||
|
||||
public String getActionPerformed() {
|
||||
return target.getActionPerformed();
|
||||
}
|
||||
|
||||
public void setActionPerformed(final String actionPerformed) {
|
||||
target.setActionPerformed(actionPerformed);
|
||||
}
|
||||
|
||||
public Integer getIdVirtualMachine() {
|
||||
return target.getIdVirtualMachine();
|
||||
}
|
||||
|
||||
public void setIdVirtualMachine(final Integer idVirtualMachine) {
|
||||
target.setIdVirtualMachine(idVirtualMachine);
|
||||
}
|
||||
|
||||
public String getVirtualDatacenter() {
|
||||
return target.getVirtualDatacenter();
|
||||
}
|
||||
|
||||
public void setVirtualDatacenter(final String virtualDatacenter) {
|
||||
target.setVirtualDatacenter(virtualDatacenter);
|
||||
}
|
||||
|
||||
public String getEnterprise() {
|
||||
return target.getEnterprise();
|
||||
}
|
||||
|
||||
public void setEnterprise(final String enterprise) {
|
||||
target.setEnterprise(enterprise);
|
||||
}
|
||||
|
||||
public String getStorageSystem() {
|
||||
return target.getStorageSystem();
|
||||
}
|
||||
|
||||
public void setStorageSystem(final String storageSystem) {
|
||||
target.setStorageSystem(storageSystem);
|
||||
}
|
||||
|
||||
public Integer getIdPhysicalMachine() {
|
||||
return target.getIdPhysicalMachine();
|
||||
}
|
||||
|
||||
public void setIdPhysicalMachine(final Integer idPhysicalMachine) {
|
||||
target.setIdPhysicalMachine(idPhysicalMachine);
|
||||
}
|
||||
|
||||
public SeverityType getSeverity() {
|
||||
return target.getSeverity();
|
||||
}
|
||||
|
||||
public void setSeverity(final SeverityType severity) {
|
||||
target.setSeverity(severity);
|
||||
}
|
||||
|
||||
public Integer getIdStorageSystem() {
|
||||
return target.getIdStorageSystem();
|
||||
}
|
||||
|
||||
public void setIdStorageSystem(final Integer idStorageSystem) {
|
||||
target.setIdStorageSystem(idStorageSystem);
|
||||
}
|
||||
|
||||
public Integer getIdDatacenter() {
|
||||
return target.getIdDatacenter();
|
||||
}
|
||||
|
||||
public void setIdDatacenter(final Integer idDatacenter) {
|
||||
target.setIdDatacenter(idDatacenter);
|
||||
}
|
||||
|
||||
public String getNetwork() {
|
||||
return target.getNetwork();
|
||||
}
|
||||
|
||||
public void setNetwork(final String network) {
|
||||
target.setNetwork(network);
|
||||
}
|
||||
|
||||
public String getPhysicalMachine() {
|
||||
return target.getPhysicalMachine();
|
||||
}
|
||||
|
||||
public void setPhysicalMachine(final String physicalMachine) {
|
||||
target.setPhysicalMachine(physicalMachine);
|
||||
}
|
||||
|
||||
public String getRack() {
|
||||
return target.getRack();
|
||||
}
|
||||
|
||||
public void setRack(final String rack) {
|
||||
target.setRack(rack);
|
||||
}
|
||||
|
||||
public Integer getIdVirtualDatacenter() {
|
||||
return target.getIdVirtualDatacenter();
|
||||
}
|
||||
|
||||
public void setIdVirtualDatacenter(final Integer idVirtualDatacenter) {
|
||||
target.setIdVirtualDatacenter(idVirtualDatacenter);
|
||||
}
|
||||
|
||||
public Integer getIdSubnet() {
|
||||
return target.getIdSubnet();
|
||||
}
|
||||
|
||||
public void setIdSubnet(final Integer idSubnet) {
|
||||
target.setIdSubnet(idSubnet);
|
||||
}
|
||||
|
||||
public String getVolume() {
|
||||
return target.getVolume();
|
||||
}
|
||||
|
||||
public void setVolume(final String volume) {
|
||||
target.setVolume(volume);
|
||||
}
|
||||
|
||||
public String getSubnet() {
|
||||
return target.getSubnet();
|
||||
}
|
||||
|
||||
public void setSubnet(final String subnet) {
|
||||
target.setSubnet(subnet);
|
||||
}
|
||||
|
||||
public Integer getIdUser() {
|
||||
return target.getIdUser();
|
||||
}
|
||||
|
||||
public void setIdUser(final Integer idUser) {
|
||||
target.setIdUser(idUser);
|
||||
}
|
||||
|
||||
public String getIdStoragePool() {
|
||||
return target.getIdStoragePool();
|
||||
}
|
||||
|
||||
public void setIdStoragePool(final String idStoragePool) {
|
||||
target.setIdStoragePool(idStoragePool);
|
||||
}
|
||||
|
||||
public Integer getIdRack() {
|
||||
return target.getIdRack();
|
||||
}
|
||||
|
||||
public void setIdRack(final Integer idRack) {
|
||||
target.setIdRack(idRack);
|
||||
}
|
||||
|
||||
public String getVirtualMachine() {
|
||||
return target.getVirtualMachine();
|
||||
}
|
||||
|
||||
public void setVirtualMachine(final String virtualMachine) {
|
||||
target.setVirtualMachine(virtualMachine);
|
||||
}
|
||||
|
||||
public Integer getIdVirtualApp() {
|
||||
return target.getIdVirtualApp();
|
||||
}
|
||||
|
||||
public void setIdVirtualApp(final Integer idVirtualApp) {
|
||||
target.setIdVirtualApp(idVirtualApp);
|
||||
}
|
||||
|
||||
public Integer getIdEnterprise() {
|
||||
return target.getIdEnterprise();
|
||||
}
|
||||
|
||||
public void setIdEnterprise(final Integer idEnterprise) {
|
||||
target.setIdEnterprise(idEnterprise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Event [id=" + getId() + ", idUser=" + getIdUser() + ", user=" + getUser() + ", idEnterprise="
|
||||
+ getIdEnterprise() + ", enterprise=" + getEnterprise() + ", actionPerformed=" + getActionPerformed()
|
||||
+ ", component=" + getComponent() + ", idDatacenter=" + getIdDatacenter() + ", datacenter="
|
||||
+ getDatacenter() + ", idStoragePool=" + getIdStoragePool() + ", storagePool=" + getStoragePool()
|
||||
+ ", idVolume=" + getIdVolume() + ", volume=" + getVolume() + ", idNetwork=" + getIdNetwork()
|
||||
+ ", network=" + getNetwork() + ", idPhysicalMachine=" + getIdPhysicalMachine() + ", physicalMachine="
|
||||
+ getPhysicalMachine() + ", idRack=" + getIdRack() + ", rack=" + getRack() + ", idStorageSystem="
|
||||
+ getIdStorageSystem() + ", storageSystem=" + getStorageSystem() + ", idSubnet=" + getIdSubnet()
|
||||
+ ", subnet=" + getSubnet() + ", idVirtualApp=" + getIdVirtualApp() + ", virtualApp=" + getVirtualApp()
|
||||
+ ", idVirtualDatacenter=" + getIdVirtualDatacenter() + ", virtualDatacenter=" + getVirtualDatacenter()
|
||||
+ ", idVirtualMachine=" + getIdVirtualMachine() + ", virtualMachine=" + getVirtualMachine()
|
||||
+ ", stacktrace=" + getStacktrace() + ", performedBy=" + getPerformedBy() + ", severity=" + getSeverity()
|
||||
+ "]";
|
||||
}
|
||||
}
|
|
@ -1,169 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.event.options;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.jclouds.abiquo.domain.options.search.FilterOptions.BaseFilterOptionsBuilder;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.abiquo.model.enumerator.ComponentType;
|
||||
import com.abiquo.model.enumerator.EventType;
|
||||
import com.abiquo.model.enumerator.SeverityType;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* Available options to query events.
|
||||
*
|
||||
* @author Vivien Mahé
|
||||
*/
|
||||
public class EventOptions extends BaseHttpRequestOptions {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
EventOptions options = new EventOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder extends BaseFilterOptionsBuilder<Builder> {
|
||||
private Map<String, String> filters = Maps.newHashMap();
|
||||
|
||||
public Builder filters(final Map<String, String> filters) {
|
||||
this.filters = filters;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder severity(final SeverityType severity) {
|
||||
this.filters.put("severity", severity.name());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder component(final ComponentType component) {
|
||||
this.filters.put("component", component.name());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder actionPerformed(final EventType action) {
|
||||
this.filters.put("actionperformed", action.name());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder datacenterName(final String dc) {
|
||||
this.filters.put("datacenter", dc);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder rackName(final String rack) {
|
||||
this.filters.put("rack", rack);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder physicalMachineName(final String pm) {
|
||||
this.filters.put("physicalmachine", pm);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder storageSystemName(final String ss) {
|
||||
this.filters.put("storagesystem", ss);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder storagePoolName(final String sp) {
|
||||
this.filters.put("storagepool", sp);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder volumeName(final String volume) {
|
||||
this.filters.put("volume", volume);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder networkName(final String network) {
|
||||
this.filters.put("network", network);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder subnetName(final String subnet) {
|
||||
this.filters.put("subnet", subnet);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder enterpriseName(final String ent) {
|
||||
this.filters.put("enterprise", ent);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder userName(final String user) {
|
||||
this.filters.put("user", user);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualDatacenterName(final String vdc) {
|
||||
this.filters.put("virtualdatacenter", vdc);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualAppName(final String vapp) {
|
||||
this.filters.put("virtualapp", vapp);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualMachineName(final String vm) {
|
||||
this.filters.put("virtualMachine", vm);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder performedBy(final String pb) {
|
||||
this.filters.put("performedBy", pb);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(final String description) {
|
||||
this.filters.put("stacktrace", description);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder dateFrom(final Date date) {
|
||||
this.filters.put("datefrom", String.valueOf(date.getTime()));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder dateTo(final Date date) {
|
||||
this.filters.put("dateTo", String.valueOf(date.getTime()));
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventOptions build() {
|
||||
EventOptions options = new EventOptions();
|
||||
|
||||
for (Entry<String, String> filter : filters.entrySet()) {
|
||||
options.queryParameters.put(filter.getKey(), filter.getValue());
|
||||
}
|
||||
|
||||
return addFilterOptions(options);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.exception;
|
||||
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static org.jclouds.abiquo.predicates.ErrorPredicates.code;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import com.abiquo.model.transport.error.ErrorDto;
|
||||
import com.abiquo.model.transport.error.ErrorsDto;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Abiquo API exception.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class AbiquoException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 3627304442037389536L;
|
||||
|
||||
/** The HTTP status. */
|
||||
private Status httpStatus;
|
||||
|
||||
/** The errors. */
|
||||
private ErrorsDto errors;
|
||||
|
||||
public AbiquoException(final Status httpStatus, final ErrorsDto errors) {
|
||||
super();
|
||||
this.httpStatus = httpStatus;
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is an error with the given code.
|
||||
*/
|
||||
public boolean hasError(final String code) {
|
||||
return any(errors.getCollection(), code(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the first error with the given code.
|
||||
*/
|
||||
public ErrorDto findError(final String code) {
|
||||
return find(errors.getCollection(), code(code), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all errors with the given code.
|
||||
*/
|
||||
public List<ErrorDto> findErrors(final String code) {
|
||||
return ImmutableList.copyOf(filter(errors.getCollection(), code(code)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of errors.
|
||||
*/
|
||||
public int numErrors() {
|
||||
return errors.getCollection().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of all errors.
|
||||
*/
|
||||
public List<ErrorDto> getErrors() {
|
||||
return errors.getCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP status code.
|
||||
*/
|
||||
public int getHttpStatusCode() {
|
||||
return httpStatus.getStatusCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP status name.
|
||||
*/
|
||||
public String getHttpStatusName() {
|
||||
return httpStatus.getReasonPhrase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP status.
|
||||
*/
|
||||
public Status getHttpStatus() {
|
||||
return httpStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return errors.toString();
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown during domain object building.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class BuilderException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 540948631643049450L;
|
||||
|
||||
/**
|
||||
* Creates a {@link BuilderException} with the given message.
|
||||
*
|
||||
* @param message
|
||||
* The message.
|
||||
*/
|
||||
public BuilderException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link BuilderException} with the given cause.
|
||||
*
|
||||
* @param cause
|
||||
* The cause.
|
||||
*/
|
||||
public BuilderException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link BuilderException} with the given message and cause.
|
||||
*
|
||||
* @param message
|
||||
* The message.
|
||||
* @param cause
|
||||
* The cause.
|
||||
*/
|
||||
public BuilderException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.exception;
|
||||
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
|
||||
import com.abiquo.model.transport.SingleResourceTransportDto;
|
||||
|
||||
/**
|
||||
* Exception thrown during the wrapping process.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class WrapperException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 3756802225851609583L;
|
||||
|
||||
private Class<? extends DomainWrapper<?>> wrapperClass;
|
||||
|
||||
private SingleResourceTransportDto target;
|
||||
|
||||
public WrapperException(final Class<? extends DomainWrapper<?>> wrapperClass,
|
||||
final SingleResourceTransportDto target, Throwable cause) {
|
||||
super(cause);
|
||||
this.wrapperClass = wrapperClass;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
String msg = "Could not wrap object [" + target + "] in class " + wrapperClass.getName() + ": ";
|
||||
return msg + super.getMessage();
|
||||
}
|
||||
|
||||
public Class<? extends DomainWrapper<?>> getWrapperClass() {
|
||||
return wrapperClass;
|
||||
}
|
||||
|
||||
public void setWrapperClass(Class<? extends DomainWrapper<?>> wrapperClass) {
|
||||
this.wrapperClass = wrapperClass;
|
||||
}
|
||||
|
||||
public SingleResourceTransportDto getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(SingleResourceTransportDto target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,270 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.predicates.infrastructure.DatastorePredicates;
|
||||
import org.jclouds.abiquo.predicates.infrastructure.NetworkInterfacePredicates;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.HypervisorType;
|
||||
import com.abiquo.model.enumerator.MachineIpmiState;
|
||||
import com.abiquo.model.enumerator.MachineState;
|
||||
import com.abiquo.server.core.infrastructure.DatastoresDto;
|
||||
import com.abiquo.server.core.infrastructure.MachineDto;
|
||||
import com.abiquo.server.core.infrastructure.MachineIpmiStateDto;
|
||||
import com.abiquo.server.core.infrastructure.MachineStateDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link MachineDto}. This class defines
|
||||
* common methods for unmanaged {@link Machine} and managed {@link Blade}
|
||||
* physical machines.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/MachineResource">
|
||||
* http://community.abiquo.com/display/ABI20/MachineResource</a>
|
||||
*/
|
||||
public abstract class AbstractPhysicalMachine extends DomainWrapper<MachineDto> {
|
||||
/** The default virtual ram used in MB. */
|
||||
protected static final int DEFAULT_VRAM_USED = 1;
|
||||
|
||||
/** The default virtual cpu used in MB. */
|
||||
protected static final int DEFAULT_VCPU_USED = 1;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected AbstractPhysicalMachine(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final MachineDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
context.getApi().getInfrastructureApi().deleteMachine(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
target = context.getApi().getInfrastructureApi().updateMachine(target);
|
||||
}
|
||||
|
||||
public MachineState check() {
|
||||
MachineStateDto dto = context.getApi().getInfrastructureApi().checkMachineState(target, true);
|
||||
MachineState state = dto.getState();
|
||||
target.setState(state);
|
||||
return state;
|
||||
}
|
||||
|
||||
public MachineIpmiState checkIpmi() {
|
||||
MachineIpmiStateDto dto = context.getApi().getInfrastructureApi().checkMachineIpmiState(target);
|
||||
return dto.getState();
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
public List<Datastore> getDatastores() {
|
||||
return wrap(context, Datastore.class, target.getDatastores().getCollection());
|
||||
}
|
||||
|
||||
public Datastore findDatastore(final String name) {
|
||||
return find(getDatastores(), DatastorePredicates.name(name), null);
|
||||
}
|
||||
|
||||
public List<NetworkInterface> getNetworkInterfaces() {
|
||||
return wrap(context, NetworkInterface.class, target.getNetworkInterfaces().getCollection());
|
||||
}
|
||||
|
||||
public NetworkInterface findNetworkInterface(final String name) {
|
||||
return find(getNetworkInterfaces(), NetworkInterfacePredicates.name(name), null);
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return target.getIp();
|
||||
}
|
||||
|
||||
public String getIpmiIp() {
|
||||
return target.getIpmiIP();
|
||||
}
|
||||
|
||||
public String getIpmiPassword() {
|
||||
return target.getIpmiPassword();
|
||||
}
|
||||
|
||||
public Integer getIpmiPort() {
|
||||
return target.getIpmiPort();
|
||||
}
|
||||
|
||||
public String getIpmiUser() {
|
||||
return target.getIpmiUser();
|
||||
}
|
||||
|
||||
public String getIpService() {
|
||||
return target.getIpService();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return target.getPassword();
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return target.getPort();
|
||||
}
|
||||
|
||||
public MachineState getState() {
|
||||
return target.getState();
|
||||
}
|
||||
|
||||
public HypervisorType getType() {
|
||||
return target.getType();
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return target.getUser();
|
||||
}
|
||||
|
||||
public Integer getVirtualCpuCores() {
|
||||
return target.getVirtualCpuCores();
|
||||
}
|
||||
|
||||
public Integer getVirtualCpusUsed() {
|
||||
return target.getVirtualCpusUsed();
|
||||
}
|
||||
|
||||
public Integer getVirtualRamInMb() {
|
||||
return target.getVirtualRamInMb();
|
||||
}
|
||||
|
||||
public Integer getVirtualRamUsedInMb() {
|
||||
return target.getVirtualRamUsedInMb();
|
||||
}
|
||||
|
||||
public void setDatastores(final List<Datastore> datastores) {
|
||||
DatastoresDto datastoresDto = new DatastoresDto();
|
||||
datastoresDto.getCollection().addAll(DomainWrapper.unwrap(datastores));
|
||||
target.setDatastores(datastoresDto);
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
target.setDescription(description);
|
||||
}
|
||||
|
||||
public void setIp(final String ip) {
|
||||
target.setIp(ip);
|
||||
}
|
||||
|
||||
public void setIpmiIp(final String ipmiIp) {
|
||||
target.setIpmiIP(ipmiIp);
|
||||
}
|
||||
|
||||
public void setIpmiPassword(final String ipmiPassword) {
|
||||
target.setIpmiPassword(ipmiPassword);
|
||||
}
|
||||
|
||||
public void setIpmiPort(final Integer ipmiPort) {
|
||||
target.setIpmiPort(ipmiPort);
|
||||
}
|
||||
|
||||
public void setIpmiUser(final String ipmiUser) {
|
||||
target.setIpmiUser(ipmiUser);
|
||||
}
|
||||
|
||||
public void setIpService(final String ipService) {
|
||||
target.setIpService(ipService);
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public void setPassword(final String password) {
|
||||
target.setPassword(password);
|
||||
}
|
||||
|
||||
public void setPort(final Integer port) {
|
||||
target.setPort(port);
|
||||
}
|
||||
|
||||
public void setState(final MachineState state) {
|
||||
target.setState(state);
|
||||
}
|
||||
|
||||
public void setType(final HypervisorType type) {
|
||||
target.setType(type);
|
||||
}
|
||||
|
||||
public void setUser(final String user) {
|
||||
target.setUser(user);
|
||||
}
|
||||
|
||||
public void setVirtualCpuCores(final Integer virtualCpuCores) {
|
||||
target.setVirtualCpuCores(virtualCpuCores);
|
||||
}
|
||||
|
||||
public void setVirtualCpusUsed(final Integer virtualCpusUsed) {
|
||||
target.setVirtualCpusUsed(virtualCpusUsed);
|
||||
}
|
||||
|
||||
public void setVirtualRamInMb(final Integer virtualRamInMb) {
|
||||
target.setVirtualRamInMb(virtualRamInMb);
|
||||
}
|
||||
|
||||
public void setVirtualRamUsedInMb(final Integer virtualRamUsedInMb) {
|
||||
target.setVirtualRamUsedInMb(virtualRamUsedInMb);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
// Aux operations
|
||||
|
||||
public NetworkInterface findAvailableVirtualSwitch(final String virtualswitch) {
|
||||
return find(getNetworkInterfaces(), NetworkInterfacePredicates.name(virtualswitch));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Machine [id=" + getId() + ", ip=" + getIp() + ", ipmiIp=" + getIpmiIp() + ", ipmiPassword="
|
||||
+ getIpmiPassword() + ", ipmiPort=" + getIpmiPort() + ", ipmiUser=" + getIpmiUser() + ", ipService="
|
||||
+ getIpService() + ", name=" + getName() + ", password=" + getPassword() + ", port=" + getPort()
|
||||
+ ", state=" + getState() + ", type=" + getType() + ", user=" + getUser() + ", virtualCpuCores="
|
||||
+ getVirtualCpuCores() + ", virtualCpusUsed=" + getVirtualCpusUsed() + ", getVirtualRamInMb()="
|
||||
+ getVirtualRamInMb() + ", virtualRamUsedInMb=" + getVirtualRamUsedInMb() + ", description="
|
||||
+ getDescription() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.infrastructure.BladeLocatorLedDto;
|
||||
import com.abiquo.server.core.infrastructure.LogicServerDto;
|
||||
import com.abiquo.server.core.infrastructure.MachineDto;
|
||||
import com.abiquo.server.core.infrastructure.UcsRackDto;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to a {@link MachineDto} managed in a UCS rack.
|
||||
* This resource allows you to access blades in managed racks in the cloud
|
||||
* infrastructure.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/MachineResource">
|
||||
* http://community.abiquo.com/display/ABI20/MachineResource</a>
|
||||
*/
|
||||
public class Blade extends AbstractPhysicalMachine {
|
||||
/** The rack where the machine belongs. */
|
||||
protected UcsRackDto rack;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Blade(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final MachineDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* Retrieve the UCS rack where the blade is.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrieveaUCSRack"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/RackResource#RackResource-
|
||||
* RetrieveaUCSRack</a>
|
||||
*/
|
||||
public ManagedRack getRack() {
|
||||
RESTLink link = checkNotNull(target.searchLink(ParentLinkName.RACK), ValidationErrors.MISSING_REQUIRED_LINK + " "
|
||||
+ ParentLinkName.RACK);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<UcsRackDto> parser = new ParseXMLWithJAXB<UcsRackDto>(utils.getXml(),
|
||||
TypeLiteral.get(UcsRackDto.class));
|
||||
|
||||
return wrap(context, ManagedRack.class, parser.apply(response));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the logic server associated with this machine in the Cisco UCS
|
||||
* rack.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-RetrieveslogicserverassociatedwithamachineinaCiscoUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource-
|
||||
* RetrieveslogicserverassociatedwithamachineinaCiscoUCS</a>
|
||||
*/
|
||||
public LogicServer getLogicServer() {
|
||||
LogicServerDto server = context.getApi().getInfrastructureApi().getLogicServer(target);
|
||||
|
||||
return wrap(context, LogicServer.class, server);
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/**
|
||||
* Turn the blade associated to the provided logic server off. The blade must
|
||||
* belong to a Logic Server. This action sets the state of a given machine to
|
||||
* STOPPED. Also sends a stop request to Cisco UCS to shut down the machine.
|
||||
* The given machine must be a Physical Machine inside a Cisco UCS.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-PoweroffanexistingmachineinCiscoUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- PoweroffanexistingmachineinCiscoUCS</a>
|
||||
*/
|
||||
public void powerOff() {
|
||||
context.getApi().getInfrastructureApi().powerOff(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn the blade associated to the provided logic server on. The machine
|
||||
* must belong to an UCS Rack. The blade must belong to a Logic Server.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-PoweronanexistingmachineinCiscoUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- PoweronanexistingmachineinCiscoUCS</a>
|
||||
*/
|
||||
public void powerOn() {
|
||||
context.getApi().getInfrastructureApi().powerOn(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn blade led on. The machine must belong to an UCS Rack. The blade must
|
||||
* belong to a Logic Server.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-LightoffthelocatorledofanexistingmachineinaCiscoUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource-
|
||||
* LightoffthelocatorledofanexistingmachineinaCiscoUCS</a>
|
||||
*/
|
||||
public void ledOn() {
|
||||
context.getApi().getInfrastructureApi().ledOn(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn blade led off. The machine must belong to an UCS Rack. The blade must
|
||||
* belong to a Logic Server.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource-LightoffthelocatorledofanexistingmachineinaCiscoUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource-
|
||||
* LightoffthelocatorledofanexistingmachineinaCiscoUCS</a>
|
||||
*/
|
||||
public void ledOff() {
|
||||
context.getApi().getInfrastructureApi().ledOff(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the led locator information as a {@link BladeLocatorLed}.
|
||||
*
|
||||
* @return Blade locator led representation.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-Retrievethelocatorledoftheblade"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- Retrievethelocatorledoftheblade</a>
|
||||
*/
|
||||
public BladeLocatorLed getLocatorLed() {
|
||||
BladeLocatorLedDto led = context.getApi().getInfrastructureApi().getLocatorLed(target);
|
||||
|
||||
return wrap(context, BladeLocatorLed.class, led);
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.BladeLocatorLedDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link BladeLocatorLedDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-Retrievethelocatorledoftheblade"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- Retrievethelocatorledoftheblade</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class BladeLocatorLed extends DomainWrapper<BladeLocatorLedDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected BladeLocatorLed(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final BladeLocatorLedDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate Methods
|
||||
|
||||
public String getAdminStatus() {
|
||||
return target.getAdminStatus();
|
||||
}
|
||||
|
||||
public String getBladeDn() {
|
||||
return target.getBladeDn();
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return target.getColor();
|
||||
}
|
||||
|
||||
public String getDn() {
|
||||
return target.getDn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BladeLocatorLed [Dn=" + getDn() + ", BladeDn=" + getBladeDn() + ", Color=" + getColor()
|
||||
+ ", AdminStatus=" + getAdminStatus() + "]";
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,89 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.DatastoreDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link DatastoreDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class Datastore extends DomainWrapper<DatastoreDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder. This resource cannot be
|
||||
* created.
|
||||
*/
|
||||
private Datastore(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final DatastoreDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public String getDatastoreUUID() {
|
||||
return target.getDatastoreUUID();
|
||||
}
|
||||
|
||||
public String getDirectory() {
|
||||
return target.getDirectory();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getRootPath() {
|
||||
return target.getRootPath();
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return target.getSize();
|
||||
}
|
||||
|
||||
public long getUsedSize() {
|
||||
return target.getUsedSize();
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return target.isEnabled();
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean enabled) {
|
||||
target.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Datastore [id=" + getId() + ", uuid=" + getDatastoreUUID() + ", directory=" + getDirectory() + ", name="
|
||||
+ getName() + ", rootPath=" + getRootPath() + ", size=" + getSize() + ", usedSize=" + getUsedSize()
|
||||
+ ", enabled=" + isEnabled() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.FsmDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link FsmDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/Rack+Resource">
|
||||
* http://community.abiquo.com/display/ABI20/Rack+Resource</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class Fsm extends DomainWrapper<FsmDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Fsm(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final FsmDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate Methods
|
||||
|
||||
public String getDescription() {
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
public String getDn() {
|
||||
return target.getDn();
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return target.getError();
|
||||
}
|
||||
|
||||
public String getProgress() {
|
||||
return target.getProgress();
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return target.getStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Fsm [Dn=" + getDn() + ", Description=" + getDescription() + ", Error=" + getError() + ", Progress="
|
||||
+ getProgress() + ", Status=" + getStatus() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.LogicServerDto;
|
||||
import com.abiquo.server.core.infrastructure.LogicServerPolicyDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link LogicServerDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/Rack+Resource">
|
||||
* http://community.abiquo.com/display/ABI20/Rack+Resource</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class LogicServer extends DomainWrapper<LogicServerDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected LogicServer(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final LogicServerDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate Methods
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public void setType(final String value) {
|
||||
target.setType(value);
|
||||
}
|
||||
|
||||
public String getAssociated() {
|
||||
return target.getAssociated();
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return target.getType();
|
||||
}
|
||||
|
||||
public String getAssociatedTo() {
|
||||
return target.getAssociatedTo();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
public void setDescription(final String value) {
|
||||
target.setDescription(value);
|
||||
}
|
||||
|
||||
public List<LogicServerPolicyDto> getCollection() {
|
||||
return target.getCollection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LogicServer [name=" + getName() + ", associated=" + getAssociated() + ", type=" + getType()
|
||||
+ ", associatedTo=" + getAssociatedTo() + ", description=" + getDescription() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,526 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachine;
|
||||
import org.jclouds.abiquo.domain.enterprise.Enterprise;
|
||||
import org.jclouds.abiquo.domain.infrastructure.options.MachineOptions;
|
||||
import org.jclouds.abiquo.predicates.infrastructure.DatastorePredicates;
|
||||
import org.jclouds.abiquo.predicates.infrastructure.NetworkInterfacePredicates;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.HypervisorType;
|
||||
import com.abiquo.model.enumerator.MachineState;
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto;
|
||||
import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto;
|
||||
import com.abiquo.server.core.enterprise.EnterpriseDto;
|
||||
import com.abiquo.server.core.infrastructure.DatastoresDto;
|
||||
import com.abiquo.server.core.infrastructure.MachineDto;
|
||||
import com.abiquo.server.core.infrastructure.MachineStateDto;
|
||||
import com.abiquo.server.core.infrastructure.RackDto;
|
||||
import com.abiquo.server.core.infrastructure.network.NetworkInterfacesDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link MachineDto}. This resource allows you
|
||||
* to manage physical machines in the cloud infrastructure.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/MachineResource">
|
||||
* http://community.abiquo.com/display/ABI20/MachineResource</a>
|
||||
*/
|
||||
public class Machine extends AbstractPhysicalMachine {
|
||||
/** The rack where the machine belongs. */
|
||||
protected Rack rack;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Machine(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final MachineDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new physical machine in Abiquo. The best way to create a machine
|
||||
* if first calling {@link Datacenter#discoverSingleMachine} or
|
||||
* {@link Datacenter#discoverMultipleMachines}. This will return a new
|
||||
* {@link Machine}. The following steps are: enabling a datastore, selecting
|
||||
* a virtual switch and choosing a rack. Refer link for more information.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrieveremotemachineinformation"
|
||||
* > http://community.abiquo.com/display/ABI20/DatacenterResource#
|
||||
* DatacenterResource- Retrieveremotemachineinformation</a>
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-Createamachine"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- Createamachine</a>
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getInfrastructureApi().createMachine(rack.unwrap(), target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MachineState check() {
|
||||
MachineStateDto dto = context.getApi().getInfrastructureApi().checkMachineState(target, true);
|
||||
MachineState state = dto.getState();
|
||||
target.setState(state);
|
||||
return state;
|
||||
}
|
||||
|
||||
// Parent access
|
||||
/**
|
||||
* Retrieve the unmanaged rack where the machine is.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrieveaRack"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/RackResource#RackResource-
|
||||
* RetrieveaRack</a>
|
||||
*/
|
||||
public Rack getRack() {
|
||||
RESTLink link = checkNotNull(target.searchLink(ParentLinkName.RACK), ValidationErrors.MISSING_REQUIRED_LINK + " "
|
||||
+ ParentLinkName.RACK);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<RackDto> parser = new ParseXMLWithJAXB<RackDto>(utils.getXml(), TypeLiteral.get(RackDto.class));
|
||||
|
||||
return wrap(context, Rack.class, parser.apply(response));
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
@Override
|
||||
public List<Datastore> getDatastores() {
|
||||
return wrap(context, Datastore.class, target.getDatastores().getCollection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Datastore findDatastore(final String name) {
|
||||
return find(getDatastores(), DatastorePredicates.name(name), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NetworkInterface> getNetworkInterfaces() {
|
||||
return wrap(context, NetworkInterface.class, target.getNetworkInterfaces().getCollection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkInterface findNetworkInterface(final String name) {
|
||||
return find(getNetworkInterfaces(), NetworkInterfacePredicates.name(name), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of virtual machines in the physical machine.
|
||||
*
|
||||
* @return The list of virtual machines in the physical machine.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Machine+Resource#MachineResource-Retrievethelistofvirtualmachinesbymachine'shypervisor"
|
||||
* > http://community.abiquo.com/display/ABI20/Machine+Resource#
|
||||
* MachineResource-
|
||||
* Retrievethelistofvirtualmachinesbymachine'shypervisor</a>
|
||||
*/
|
||||
public List<VirtualMachine> listVirtualMachines() {
|
||||
MachineOptions options = MachineOptions.builder().sync(false).build();
|
||||
VirtualMachinesWithNodeExtendedDto vms = context.getApi().getInfrastructureApi()
|
||||
.listVirtualMachinesByMachine(target, options);
|
||||
return wrap(context, VirtualMachine.class, vms.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of virtual machines in the physical machine matching the
|
||||
* given filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The list of virtual machines in the physical machine matching the
|
||||
* given filter.
|
||||
*/
|
||||
public List<VirtualMachine> listVirtualMachines(final Predicate<VirtualMachine> filter) {
|
||||
return ImmutableList.copyOf(filter(listVirtualMachines(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single virtual machine in the physical machine matching the given
|
||||
* filter.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The virtual machine or <code>null</code> if none matched the given
|
||||
* filter.
|
||||
*/
|
||||
public VirtualMachine findVirtualMachine(final Predicate<VirtualMachine> filter) {
|
||||
return Iterables.getFirst(filter(listVirtualMachines(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of virtual machines in the physical machine synchronizing
|
||||
* virtual machines from remote hypervisor with abiquo's database.
|
||||
*
|
||||
* @return The list of virtual machines in the physical machine.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Machine+Resource#MachineResource-Retrievethelistofvirtualmachinesbymachine'shypervisor"
|
||||
* > http://community.abiquo.com/display/ABI20/Machine+Resource#
|
||||
* MachineResource-
|
||||
* Retrievethelistofvirtualmachinesbymachine'shypervisor</a>
|
||||
*/
|
||||
public List<VirtualMachine> listRemoteVirtualMachines() {
|
||||
MachineOptions options = MachineOptions.builder().sync(true).build();
|
||||
VirtualMachinesWithNodeExtendedDto vms = context.getApi().getInfrastructureApi()
|
||||
.listVirtualMachinesByMachine(target, options);
|
||||
return wrap(context, VirtualMachine.class, vms.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of virtual machines in the physical machine matching the
|
||||
* given filter synchronizing virtual machines from remote hypervisor with
|
||||
* abiquo's database.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The list of remote virtual machines in the physical machine
|
||||
* matching the given filter.
|
||||
*/
|
||||
public List<VirtualMachine> listRemoteVirtualMachines(final Predicate<VirtualMachine> filter) {
|
||||
return ImmutableList.copyOf(filter(listVirtualMachines(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single virtual machine in the physical machine matching the given
|
||||
* filter synchronizing virtual machines from remote hypervisor with abiquo's
|
||||
* database.
|
||||
*
|
||||
* @param filter
|
||||
* The filter to apply.
|
||||
* @return The virtual machine or <code>null</code> if none matched the given
|
||||
* filter.
|
||||
*/
|
||||
public VirtualMachine findRemoteVirtualMachine(final Predicate<VirtualMachine> filter) {
|
||||
return Iterables.getFirst(filter(listVirtualMachines(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve the machine for the given enterprise.
|
||||
* <p>
|
||||
* When a {@link Machine} is reserved for an {@link Enterprise}, only the
|
||||
* users of that enterprise will be able to deploy {@link VirtualMachine}s in
|
||||
* it.
|
||||
*
|
||||
* @param enterprise
|
||||
* The enterprise reserving the machine.
|
||||
*/
|
||||
public void reserveFor(final Enterprise enterprise) {
|
||||
target = context.getApi().getInfrastructureApi().reserveMachine(enterprise.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the machine reservation for the given enterprise.
|
||||
*
|
||||
* @param enterprise
|
||||
* The enterprise to cancel reservation for.
|
||||
*/
|
||||
public void cancelReservationFor(final Enterprise enterprise) {
|
||||
context.getApi().getInfrastructureApi().cancelReservation(enterprise.unwrap(), target);
|
||||
target.getLinks().remove(target.searchLink(ParentLinkName.ENTERPRISE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the machine is reserved.
|
||||
*
|
||||
* @return Boolean indicating if the machine is reserved for an enterprise.
|
||||
*/
|
||||
public boolean isReserved() {
|
||||
return target.searchLink(ParentLinkName.ENTERPRISE) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enterprise that has reserved the machine or <code>null</code> if
|
||||
* the machine is not reserved.
|
||||
*
|
||||
* @return The enterprise that has reserved the machine or <code>null</code>
|
||||
* if the machine is not reserved.
|
||||
*/
|
||||
public Enterprise getOwnerEnterprise() {
|
||||
if (!isReserved()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
EnterpriseDto enterprise = context.getApi().getEnterpriseApi()
|
||||
.getEnterprise(target.getIdFromLink(ParentLinkName.ENTERPRISE));
|
||||
|
||||
return wrap(context, Enterprise.class, enterprise);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Rack rack) {
|
||||
return new Builder(context, rack);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private Integer virtualRamInMb;
|
||||
|
||||
private Integer virtualRamUsedInMb = DEFAULT_VRAM_USED;
|
||||
|
||||
private Integer virtualCpuCores;
|
||||
|
||||
private Integer virtualCpusUsed = DEFAULT_VCPU_USED;
|
||||
|
||||
private Integer port;
|
||||
|
||||
private String ip;
|
||||
|
||||
private MachineState state = MachineState.STOPPED;
|
||||
|
||||
private String ipService;
|
||||
|
||||
private HypervisorType type;
|
||||
|
||||
private String user;
|
||||
|
||||
private String password;
|
||||
|
||||
private Iterable<Datastore> datastores;
|
||||
|
||||
private Iterable<NetworkInterface> networkInterfaces;
|
||||
|
||||
private String ipmiIp;
|
||||
|
||||
private Integer ipmiPort;
|
||||
|
||||
private String ipmiUser;
|
||||
|
||||
private String ipmiPassword;
|
||||
|
||||
private Rack rack;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Rack rack) {
|
||||
super();
|
||||
checkNotNull(rack, ValidationErrors.NULL_RESOURCE + Rack.class);
|
||||
this.rack = rack;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder state(final MachineState state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ipmiPassword(final String ipmiPassword) {
|
||||
this.ipmiPassword = ipmiPassword;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ipmiUser(final String ipmiUser) {
|
||||
this.ipmiUser = ipmiUser;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ipmiPort(final int ipmiPort) {
|
||||
this.ipmiPort = ipmiPort;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ipmiIp(final String ipmiIp) {
|
||||
this.ipmiIp = ipmiIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder user(final String user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ip(final String ip) {
|
||||
this.ip = ip;
|
||||
if (ipService == null) {
|
||||
ipService = ip;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ipService(final String ipService) {
|
||||
this.ipService = ipService;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder password(final String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(final String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder port(final int port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder datastores(final Iterable<Datastore> datastores) {
|
||||
this.datastores = datastores;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder networkInterfaces(final Iterable<NetworkInterface> networkInterfaces) {
|
||||
this.networkInterfaces = networkInterfaces;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualRamInMb(final int virtualRamInMb) {
|
||||
this.virtualRamInMb = virtualRamInMb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualRamUsedInMb(final int virtualRamUsedInMb) {
|
||||
this.virtualRamUsedInMb = virtualRamUsedInMb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualCpuCores(final int virtualCpuCores) {
|
||||
this.virtualCpuCores = virtualCpuCores;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualCpusUsed(final int virtualCpusUsed) {
|
||||
this.virtualCpusUsed = virtualCpusUsed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hypervisorType(final HypervisorType hypervisorType) {
|
||||
this.type = hypervisorType;
|
||||
|
||||
// Sets default hypervisor port
|
||||
if (this.port == null) {
|
||||
this.port = hypervisorType.defaultPort;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder rack(final Rack rack) {
|
||||
checkNotNull(rack, ValidationErrors.NULL_RESOURCE + Datacenter.class);
|
||||
this.rack = rack;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Machine build() {
|
||||
MachineDto dto = new MachineDto();
|
||||
dto.setName(name);
|
||||
dto.setDescription(description);
|
||||
dto.setVirtualRamInMb(virtualRamInMb);
|
||||
dto.setVirtualRamUsedInMb(virtualRamUsedInMb);
|
||||
dto.setVirtualCpuCores(virtualCpuCores);
|
||||
dto.setVirtualCpusUsed(virtualCpusUsed);
|
||||
if (port != null) {
|
||||
dto.setPort(port);
|
||||
}
|
||||
dto.setIp(ip);
|
||||
dto.setIpService(ipService);
|
||||
dto.setType(type);
|
||||
dto.setUser(user);
|
||||
dto.setPassword(password);
|
||||
dto.setIpmiIP(ipmiIp);
|
||||
dto.setIpmiPassword(ipmiPassword);
|
||||
if (ipmiPort != null) {
|
||||
dto.setIpmiPort(ipmiPort);
|
||||
}
|
||||
dto.setIpmiUser(ipmiUser);
|
||||
dto.setState(state);
|
||||
|
||||
DatastoresDto datastoresDto = new DatastoresDto();
|
||||
datastoresDto.getCollection().addAll(unwrap(datastores));
|
||||
dto.setDatastores(datastoresDto);
|
||||
|
||||
NetworkInterfacesDto networkInterfacesDto = new NetworkInterfacesDto();
|
||||
networkInterfacesDto.getCollection().addAll(unwrap(networkInterfaces));
|
||||
dto.setNetworkInterfaces(networkInterfacesDto);
|
||||
|
||||
Machine machine = new Machine(context, dto);
|
||||
machine.rack = rack;
|
||||
|
||||
return machine;
|
||||
}
|
||||
|
||||
public static Builder fromMachine(final Machine in) {
|
||||
Builder builder = Machine.builder(in.context, in.rack).name(in.getName()).description(in.getDescription())
|
||||
.virtualCpuCores(in.getVirtualCpuCores()).virtualCpusUsed(in.getVirtualCpusUsed())
|
||||
.virtualRamInMb(in.getVirtualRamInMb()).virtualRamUsedInMb(in.getVirtualRamUsedInMb())
|
||||
.port(in.getPort()).ip(in.getIp()).ipService(in.getIpService()).hypervisorType(in.getType())
|
||||
.user(in.getUser()).password(in.getPassword()).ipmiIp(in.getIpmiIp()).ipmiPassword(in.getIpmiPassword())
|
||||
.ipmiUser(in.getIpmiUser()).state(in.getState()).datastores(in.getDatastores())
|
||||
.networkInterfaces(in.getNetworkInterfaces());
|
||||
|
||||
// Parameters that can be null
|
||||
if (in.getIpmiPort() != null) {
|
||||
builder.ipmiPort(in.getIpmiPort());
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public void setRack(final Rack rack) {
|
||||
this.rack = rack;
|
||||
}
|
||||
|
||||
public VirtualMachine getVirtualMachine(final Integer virtualMachineId) {
|
||||
VirtualMachineWithNodeExtendedDto vm = context.getApi().getInfrastructureApi()
|
||||
.getVirtualMachine(target, virtualMachineId);
|
||||
return wrap(context, VirtualMachine.class, vm);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,713 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.FsmsDto;
|
||||
import com.abiquo.server.core.infrastructure.LogicServersDto;
|
||||
import com.abiquo.server.core.infrastructure.MachinesDto;
|
||||
import com.abiquo.server.core.infrastructure.OrganizationsDto;
|
||||
import com.abiquo.server.core.infrastructure.RackDto;
|
||||
import com.abiquo.server.core.infrastructure.UcsRackDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link RackDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/RackResource">
|
||||
* http://community.abiquo.com/display/ABI20/RackResource</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class ManagedRack extends DomainWrapper<UcsRackDto> {
|
||||
/** The default minimum VLAN id. */
|
||||
private static final int DEFAULT_VLAN_ID_MIN = 2;
|
||||
|
||||
/** The default maximum VLAN id. */
|
||||
private static final int DEFAULT_VLAN_ID_MAX = 4094;
|
||||
|
||||
/** The default maximum VLAN per virtual datacenter. */
|
||||
private static final int DEFAULT_VLAN_PER_VDC = 1;
|
||||
|
||||
/** The default nrsq factor. */
|
||||
private static final int DEFAULT_NRSQ = 10;
|
||||
|
||||
/** The datacenter where the rack belongs. */
|
||||
private Datacenter datacenter;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected ManagedRack(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final UcsRackDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* Delete the managed rack.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-DeleteaRack"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Rack+Resource#RackResource
|
||||
* #RackResource- DeleteaRack</a>
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getInfrastructureApi().deleteRack(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new managed rack in Abiquo. This method wil discover the blades
|
||||
* configured in the UCS. If the data provided for the connection is invalid
|
||||
* a UcsRack will be created in Abiquo but with no Physical Machines attached
|
||||
* to it.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-CreateanewUCSRack"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* -CreateanewUCSRack< /a>
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getInfrastructureApi().createManagedRack(datacenter.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update rack information in the server with the data from this rack. The IP
|
||||
* data member cannot be updated. If changed will be ignored and the old IP
|
||||
* will remain.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource#RackResource-UpdateanexistingUCSrack"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* #RackResource- UpdateanexistingUCSrack</a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getInfrastructureApi().updateManagedRack(target);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
/**
|
||||
* Retrieve the datacenter where this rack is.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrieveadatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/DatacenterResource#
|
||||
* DatacenterResource- Retrieveadatacenter</a>
|
||||
*/
|
||||
public Datacenter getDatacenter() {
|
||||
Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER);
|
||||
return wrap(context, Datacenter.class, context.getApi().getInfrastructureApi().getDatacenter(datacenterId));
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
/**
|
||||
* Retrieve the list of blades in this rack.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-RetrievealistofMachines"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- RetrievealistofMachines</a>
|
||||
*/
|
||||
public List<Blade> listMachines() {
|
||||
MachinesDto machines = context.getApi().getInfrastructureApi().listMachines(target);
|
||||
return wrap(context, Blade.class, machines.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of blades in this rack.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-RetrievealistofMachines"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- RetrievealistofMachines</a>
|
||||
*/
|
||||
public List<Blade> listMachines(final Predicate<Blade> filter) {
|
||||
return ImmutableList.copyOf(filter(listMachines(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first blade matching the filter within the list of machines
|
||||
* in this rack.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-RetrievealistofMachines"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- RetrievealistofMachines</a>
|
||||
*/
|
||||
public Blade findMachine(final Predicate<Blade> filter) {
|
||||
return Iterables.getFirst(filter(listMachines(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of service profiles in this UCS rack.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrievealistofallservicesprofilesinaUCSrack"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* - RetrievealistofallservicesprofilesinaUCSrack</a>
|
||||
*/
|
||||
public List<LogicServer> listServiceProfiles() {
|
||||
LogicServersDto profiles = context.getApi().getInfrastructureApi().listServiceProfiles(target);
|
||||
return wrap(context, LogicServer.class, profiles.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of service profiles in this UCS rack.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrievealistofallservicesprofilesinaUCSrack"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* - RetrievealistofallservicesprofilesinaUCSrack</a>
|
||||
*/
|
||||
public List<LogicServer> listServiceProfiles(final Predicate<LogicServer> filter) {
|
||||
return ImmutableList.copyOf(filter(listServiceProfiles(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first service profile matching the filter within the list of
|
||||
* profiles in this rack.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrievealistofallservicesprofilesinaUCSrack"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* - RetrievealistofallservicesprofilesinaUCSrack</a>
|
||||
*/
|
||||
public LogicServer findServiceProfile(final Predicate<LogicServer> filter) {
|
||||
return Iterables.getFirst(filter(listServiceProfiles(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of service profile templates in this UCS rack.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource-RetrievealistofallServicesProfilesTemplatesinaUCSRack"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource-
|
||||
* RetrievealistofallServicesProfilesTemplatesinaUCSRack</a>
|
||||
*/
|
||||
public List<LogicServer> listServiceProfileTemplates() {
|
||||
LogicServersDto templates = context.getApi().getInfrastructureApi().listServiceProfileTemplates(target);
|
||||
return wrap(context, LogicServer.class, templates.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of service profile templates in this UCS rack.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource-RetrievealistofallServicesProfilesTemplatesinaUCSRack"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource-
|
||||
* RetrievealistofallServicesProfilesTemplatesinaUCSRack</a>
|
||||
*/
|
||||
public List<LogicServer> listServiceProfileTemplates(final Predicate<LogicServer> filter) {
|
||||
return ImmutableList.copyOf(filter(listServiceProfileTemplates(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first service profile template matching the filter within the
|
||||
* list of templates in this rack.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource-RetrievealistofallServicesProfilesTemplatesinaUCSRack"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource-
|
||||
* RetrievealistofallServicesProfilesTemplatesinaUCSRack</a>
|
||||
*/
|
||||
public LogicServer findServiceProfileTemplate(final Predicate<LogicServer> filter) {
|
||||
return Iterables.getFirst(filter(listServiceProfileTemplates(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of organization in this UCS rack. The credentials in the
|
||||
* UcsRack configuration might not have enough rights in the UCS to retrieve
|
||||
* all organizations. Then only the allowed ones are returned. This data is
|
||||
* not persisted in Abiquo.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-
|
||||
* RetrieveallorganizationsfromaUCS">
|
||||
* http://community.abiquo.com/display/ABI20/</a>
|
||||
*/
|
||||
public List<Organization> listOrganizations() {
|
||||
OrganizationsDto organizations = context.getApi().getInfrastructureApi().listOrganizations(target);
|
||||
return wrap(context, Organization.class, organizations.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of organization in this UCS rack. The credentials
|
||||
* in the UcsRack configuration might not have enough rights in the UCS to
|
||||
* retrieve all organizations. Then only the allowed ones are returned. This
|
||||
* data is not persisted in Abiquo.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-
|
||||
* RetrieveallorganizationsfromaUCS" >
|
||||
* http://community.abiquo.com/display/ABI20/RackResource#RackResource-
|
||||
* RetrieveallorganizationsfromaUCS</a>
|
||||
*/
|
||||
public List<Organization> listOrganizations(final Predicate<Organization> filter) {
|
||||
return ImmutableList.copyOf(filter(listOrganizations(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first organization matching the filter within the list of
|
||||
* organization in this rack. The credentials in the UcsRack configuration
|
||||
* might not have enough rights in the UCS to retrieve all organizations.
|
||||
* Then only the allowed ones are returned. This data is not persisted in
|
||||
* Abiquo.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-
|
||||
* RetrieveallorganizationsfromaUCS">
|
||||
* http://community.abiquo.com/display/ABI20/RackResource#RackResource-
|
||||
* RetrieveallorganizationsfromaUCS</a>
|
||||
*/
|
||||
public Organization findOrganization(final Predicate<Organization> filter) {
|
||||
return Iterables.getFirst(filter(listOrganizations(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrieveFSMofanentityinUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* - RetrieveFSMofanentityinUCS</a>
|
||||
*/
|
||||
public List<Fsm> listFsm(final String entityName) {
|
||||
FsmsDto fsms = context.getApi().getInfrastructureApi().listFsms(target, entityName);
|
||||
return wrap(context, Fsm.class, fsms.getCollection());
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/**
|
||||
* Clone a Service Profile this rack. This data is not persisted in Abiquo.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-ClonelogicserverinUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* - ClonelogicserverinUCS</a>
|
||||
*/
|
||||
public void cloneLogicServer(final LogicServer logicServer, final Organization organization, final String newName) {
|
||||
context.getApi().getInfrastructureApi()
|
||||
.cloneLogicServer(this.unwrap(), logicServer.unwrap(), organization.unwrap(), newName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Associate a Service Profile and a Blade in UCS. If the Service Profile is
|
||||
* already associated then the request cannot be completed. This data is not
|
||||
* persisted in Abiquo.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-AssociatelogicserverwithabladeinUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* - AssociatelogicserverwithabladeinUCS</a>
|
||||
*/
|
||||
public void associateLogicServer(final String bladeName, final LogicServer logicServer,
|
||||
final Organization organization) {
|
||||
context.getApi().getInfrastructureApi()
|
||||
.associateLogicServer(this.unwrap(), logicServer.unwrap(), organization.unwrap(), bladeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone and associate a Service Profile and a Blade in UCS. If the Blade is
|
||||
* already associated then Abiquo will dissociate it first. If the request
|
||||
* cannot be completed successfully the Blade might be left with no Service
|
||||
* Profile associated. This data is not persisted in Abiquo.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-CloneandassociateLogicServerwithabladeinUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* - CloneandassociateLogicServerwithabladeinUCS</a>
|
||||
*/
|
||||
public void cloneAndAssociateLogicServer(final String bladeName, final LogicServer logicServer,
|
||||
final Organization organization, final String logicServerName) {
|
||||
context
|
||||
.getApi()
|
||||
.getInfrastructureApi()
|
||||
.cloneAndAssociateLogicServer(this.unwrap(), logicServer.unwrap(), organization.unwrap(), bladeName,
|
||||
logicServerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate and associate a Service Profile Template and a Blade in UCS.
|
||||
* If the Service Profile is already associated the request cannot be
|
||||
* successful. If the Blade is already associated then Abiquo will dissociate
|
||||
* it first. If the request cannot be completed successfully the Blade might
|
||||
* be left with no Service Profile associated. This data is not persisted in
|
||||
* Abiquo.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-AssociateabladewithaLogicServerTemplate"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* - AssociateabladewithaLogicServerTemplate</a>
|
||||
*/
|
||||
public void associateLogicServerTemplate(final String bladeName, final LogicServer logicServer,
|
||||
final Organization organization, final String logicServerName) {
|
||||
context.getApi().getInfrastructureApi()
|
||||
.associateTemplate(this.unwrap(), logicServer.unwrap(), organization.unwrap(), bladeName, logicServerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dissociates a Service Profile and a Blade in UCS. This data is not
|
||||
* persisted in Abiquo.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-DisassociatelogicserverfromabladeinUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* - DisassociatelogicserverfromabladeinUCS</a>
|
||||
*/
|
||||
public void disassociateLogicServer(final LogicServer logicServer) {
|
||||
context.getApi().getInfrastructureApi().dissociateLogicServer(this.unwrap(), logicServer.unwrap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a Service Profile in UCS. This data is not persisted in Abiquo.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-DeletelogicserverwithabladeinUCS"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* - DeletelogicserverwithabladeinUCS</a>
|
||||
*/
|
||||
public void deleteLogicServer(final LogicServer logicServer) {
|
||||
context.getApi().getInfrastructureApi().deleteLogicServer(this.unwrap(), logicServer.unwrap());
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Datacenter datacenter) {
|
||||
return new Builder(context, datacenter);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String shortDescription;
|
||||
|
||||
private boolean haEnabled = false;
|
||||
|
||||
private Integer nrsq = DEFAULT_NRSQ;
|
||||
|
||||
private Integer vlanIdMax = DEFAULT_VLAN_ID_MAX;
|
||||
|
||||
private Integer vlanIdMin = DEFAULT_VLAN_ID_MIN;
|
||||
|
||||
private Integer vlanPerVdcReserved = DEFAULT_VLAN_PER_VDC;
|
||||
|
||||
private String vlansIdAvoided;
|
||||
|
||||
private Integer port;
|
||||
|
||||
private String ip;
|
||||
|
||||
private String password;
|
||||
|
||||
private String user;
|
||||
|
||||
private String defaultTemplate;
|
||||
|
||||
private Integer maxMachinesOn;
|
||||
|
||||
private Datacenter datacenter;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Datacenter datacenter) {
|
||||
super();
|
||||
checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class);
|
||||
this.datacenter = datacenter;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder port(final Integer port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ipAddress(final String ip) {
|
||||
this.ip = ip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder password(final String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder user(final String user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder defaultTemplate(final String defaultTemplate) {
|
||||
this.defaultTemplate = defaultTemplate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder maxMachinesOn(final Integer maxMachinesOn) {
|
||||
this.maxMachinesOn = maxMachinesOn;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder id(final Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder shortDescription(final String shortDescription) {
|
||||
this.shortDescription = shortDescription;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder haEnabled(final boolean haEnabled) {
|
||||
this.haEnabled = haEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder nrsq(final int nrsq) {
|
||||
this.nrsq = nrsq;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vlanIdMax(final int vlanIdMax) {
|
||||
this.vlanIdMax = vlanIdMax;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vlanIdMin(final int vlanIdMin) {
|
||||
this.vlanIdMin = vlanIdMin;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vlanPerVdcReserved(final int vlanPerVdcExpected) {
|
||||
this.vlanPerVdcReserved = vlanPerVdcExpected;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vlansIdAvoided(final String vlansIdAvoided) {
|
||||
this.vlansIdAvoided = vlansIdAvoided;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder datacenter(final Datacenter datacenter) {
|
||||
checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class);
|
||||
this.datacenter = datacenter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ManagedRack build() {
|
||||
UcsRackDto dto = new UcsRackDto();
|
||||
dto.setId(id);
|
||||
dto.setName(name);
|
||||
dto.setShortDescription(shortDescription);
|
||||
dto.setHaEnabled(haEnabled);
|
||||
dto.setNrsq(nrsq);
|
||||
dto.setVlanIdMax(vlanIdMax);
|
||||
dto.setVlanIdMin(vlanIdMin);
|
||||
dto.setVlanPerVdcReserved(vlanPerVdcReserved);
|
||||
dto.setVlansIdAvoided(vlansIdAvoided);
|
||||
dto.setPort(port);
|
||||
dto.setIp(ip);
|
||||
dto.setPassword(password);
|
||||
dto.setUser(user);
|
||||
dto.setDefaultTemplate(defaultTemplate);
|
||||
dto.setMaxMachinesOn(maxMachinesOn);
|
||||
|
||||
ManagedRack rack = new ManagedRack(context, dto);
|
||||
rack.datacenter = datacenter;
|
||||
return rack;
|
||||
}
|
||||
|
||||
public static Builder fromRack(final ManagedRack in) {
|
||||
return ManagedRack.builder(in.context, in.datacenter).id(in.getId()).name(in.getName())
|
||||
.shortDescription(in.getShortDescription()).haEnabled(in.isHaEnabled()).nrsq(in.getNrsq())
|
||||
.vlanIdMax(in.getVlanIdMax()).vlanIdMin(in.getVlanIdMin())
|
||||
.vlanPerVdcReserved(in.getVlanPerVdcReserved()).vlansIdAvoided(in.getVlansIdAvoided())
|
||||
.port(in.getPort()).ipAddress(in.getIp()).password(in.getPassword()).user(in.getUser())
|
||||
.defaultTemplate(in.getDefaultTemplate()).maxMachinesOn(in.getMaxMachinesOn());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getShortDescription() {
|
||||
return target.getShortDescription();
|
||||
}
|
||||
|
||||
public void setShortDescription(final String description) {
|
||||
target.setShortDescription(description);
|
||||
}
|
||||
|
||||
public void setHaEnabled(final boolean haEnabled) {
|
||||
target.setHaEnabled(haEnabled);
|
||||
}
|
||||
|
||||
public boolean isHaEnabled() {
|
||||
return target.isHaEnabled();
|
||||
}
|
||||
|
||||
public Integer getNrsq() {
|
||||
return target.getNrsq();
|
||||
}
|
||||
|
||||
public Integer getVlanIdMax() {
|
||||
return target.getVlanIdMax();
|
||||
}
|
||||
|
||||
public Integer getVlanIdMin() {
|
||||
return target.getVlanIdMin();
|
||||
}
|
||||
|
||||
public Integer getVlanPerVdcReserved() {
|
||||
return target.getVlanPerVdcReserved();
|
||||
}
|
||||
|
||||
public String getVlansIdAvoided() {
|
||||
return target.getVlansIdAvoided();
|
||||
}
|
||||
|
||||
public void setNrsq(final Integer nrsq) {
|
||||
target.setNrsq(nrsq);
|
||||
}
|
||||
|
||||
public void setVlanIdMax(final Integer vlanIdMax) {
|
||||
target.setVlanIdMax(vlanIdMax);
|
||||
}
|
||||
|
||||
public void setVlanIdMin(final Integer vlanIdMin) {
|
||||
target.setVlanIdMin(vlanIdMin);
|
||||
}
|
||||
|
||||
public void setVlanPerVdcReserved(final Integer vlanPerVdcReserved) {
|
||||
target.setVlanPerVdcReserved(vlanPerVdcReserved);
|
||||
}
|
||||
|
||||
public void setVlansIdAvoided(final String vlansIdAvoided) {
|
||||
target.setVlansIdAvoided(vlansIdAvoided);
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return target.getIp();
|
||||
}
|
||||
|
||||
public String getLongDescription() {
|
||||
return target.getLongDescription();
|
||||
}
|
||||
|
||||
public Integer getMaxMachinesOn() {
|
||||
return target.getMaxMachinesOn();
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return target.getPassword();
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return target.getPort();
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return target.getUser();
|
||||
}
|
||||
|
||||
public void setDefaultTemplate(final String defaultTemplate) {
|
||||
target.setDefaultTemplate(defaultTemplate);
|
||||
}
|
||||
|
||||
public String getDefaultTemplate() {
|
||||
return target.getDefaultTemplate();
|
||||
}
|
||||
|
||||
public void setIp(final String ip) {
|
||||
target.setIp(ip);
|
||||
}
|
||||
|
||||
public void setMaxMachinesOn(final Integer maxMachinesOn) {
|
||||
target.setMaxMachinesOn(maxMachinesOn);
|
||||
}
|
||||
|
||||
public void setPassword(final String password) {
|
||||
target.setPassword(password);
|
||||
}
|
||||
|
||||
public void setPort(final Integer port) {
|
||||
target.setPort(port);
|
||||
}
|
||||
|
||||
public void setUser(final String user) {
|
||||
target.setUser(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ManagedRack [id=" + getId() + ", name=" + getName() + ", shortDescription=" + getShortDescription()
|
||||
+ ", haEnabled=" + isHaEnabled() + ", nrsq=" + getNrsq() + ", vlanIdMax=" + getVlanIdMax() + ", vlanIdMin="
|
||||
+ getVlanIdMin() + ", vlanPerVdcReserved=" + getVlanPerVdcReserved() + ", vlansIdAvoided="
|
||||
+ getVlansIdAvoided() + ", ip=" + getIp() + ", longDescription=" + getLongDescription()
|
||||
+ ", maxMachinesOn=" + getMaxMachinesOn() + ", password=**PROTECTED**, port=" + getPort() + ", user="
|
||||
+ getUser() + ", defaultTemplate=" + getDefaultTemplate() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.domain.network.NetworkServiceType;
|
||||
import org.jclouds.abiquo.rest.internal.ExtendedUtils;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.infrastructure.network.NetworkInterfaceDto;
|
||||
import com.abiquo.server.core.infrastructure.network.NetworkServiceTypeDto;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Represents a physical attached NIC.
|
||||
*
|
||||
* Allows to specify the {@link NetworkServiceType} for the network interface.
|
||||
* This way all network interfaces have the information of the kind of network
|
||||
* they are attached to.
|
||||
*
|
||||
* @author Jaume Devesa
|
||||
*/
|
||||
public class NetworkInterface extends DomainWrapper<NetworkInterfaceDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder. This resource cannot be
|
||||
* created.
|
||||
*/
|
||||
protected NetworkInterface(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final NetworkInterfaceDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getMac() {
|
||||
return target.getMac();
|
||||
}
|
||||
|
||||
public void setNetworkServiceType(final NetworkServiceType type) {
|
||||
checkNotNull(type, "network service type cannot be null");
|
||||
target.setNetworkServiceTypeLink(type.unwrap().getEditLink().getHref());
|
||||
}
|
||||
|
||||
public NetworkServiceType getNetworkServiceType() {
|
||||
RESTLink link = target.getNetworkServiceTypeLink();
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<NetworkServiceTypeDto> parser = new ParseXMLWithJAXB<NetworkServiceTypeDto>(utils.getXml(),
|
||||
TypeLiteral.get(NetworkServiceTypeDto.class));
|
||||
|
||||
return wrap(context, NetworkServiceType.class, parser.apply(response));
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.OrganizationDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link OrganizationDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/RackResource">
|
||||
* http://community.abiquo.com/display/ABI20/RackResource</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class Organization extends DomainWrapper<OrganizationDto> {
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Organization(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final OrganizationDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate Methods
|
||||
|
||||
public String getDescription() {
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
public String getDn() {
|
||||
return target.getDn();
|
||||
}
|
||||
|
||||
public String getLevel() {
|
||||
return target.getLevel();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return target.getStatus();
|
||||
}
|
||||
|
||||
public void setDescription(final String value) {
|
||||
target.setDescription(value);
|
||||
}
|
||||
|
||||
public void setDn(final String dn) {
|
||||
target.setDn(dn);
|
||||
}
|
||||
|
||||
public void setLevel(final String value) {
|
||||
target.setLevel(value);
|
||||
}
|
||||
|
||||
public void setName(final String value) {
|
||||
target.setName(value);
|
||||
}
|
||||
|
||||
public void setStatus(final String value) {
|
||||
target.setStatus(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Organization [name=" + getName() + ", description=" + getDescription() + ", dn=" + getDn() + ", level="
|
||||
+ getLevel() + ", status=" + getStatus() + "]";
|
||||
}
|
||||
}
|
|
@ -1,377 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.MachineDto;
|
||||
import com.abiquo.server.core.infrastructure.MachinesDto;
|
||||
import com.abiquo.server.core.infrastructure.RackDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link RackDto}. Represents unmanaged racks
|
||||
* in the Abiquo platform.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/RackResource">
|
||||
* http://community.abiquo.com/display/ABI20/RackResource</a>
|
||||
*/
|
||||
public class Rack extends DomainWrapper<RackDto> {
|
||||
/** The default minimum VLAN id. */
|
||||
private static final int DEFAULT_VLAN_ID_MIN = 2;
|
||||
|
||||
/** The default maximum VLAN id. */
|
||||
private static final int DEFAULT_VLAN_ID_MAX = 4094;
|
||||
|
||||
/** The default maximum VLAN per virtual datacenter. */
|
||||
private static final int DEFAULT_VLAN_PER_VDC = 1;
|
||||
|
||||
/** The default nrsq factor. */
|
||||
private static final int DEFAULT_NRSQ = 10;
|
||||
|
||||
/** The datacenter where the rack belongs. */
|
||||
private Datacenter datacenter;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Rack(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final RackDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* Delete the unmanaged rack.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-DeleteaRack"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Rack+Resource#RackResource
|
||||
* #RackResource- DeleteaRack</a>
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getInfrastructureApi().deleteRack(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new unmanaged rack in Abiquo.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-CreateanewRack"
|
||||
* > http://community.abiquo.com/display/ABI20/RackResource#RackResource
|
||||
* -CreateanewRack</a>
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getInfrastructureApi().createRack(datacenter.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update rack information in the server with the data from this rack.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RackResource#RackResource-UpdateanexistingRack"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/RackResource#RackResource-
|
||||
* UpdateanexistingRack </a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getInfrastructureApi().updateRack(target);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
/**
|
||||
* Retrieve the datacenter where this rack is.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrieveadatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/DatacenterResource#
|
||||
* DatacenterResource- Retrieveadatacenter</a>
|
||||
*/
|
||||
public Datacenter getDatacenter() {
|
||||
Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER);
|
||||
return wrap(context, Datacenter.class, context.getApi().getInfrastructureApi().getDatacenter(datacenterId));
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
/**
|
||||
* Retrieve the list of physical machines in this rack.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-RetrievealistofMachines"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- RetrievealistofMachines</a>
|
||||
*/
|
||||
public List<Machine> listMachines() {
|
||||
MachinesDto machines = context.getApi().getInfrastructureApi().listMachines(target);
|
||||
return wrap(context, Machine.class, machines.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of physical machines in this rack.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-RetrievealistofMachines"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- RetrievealistofMachines</a>
|
||||
*/
|
||||
public List<Machine> listMachines(final Predicate<Machine> filter) {
|
||||
return ImmutableList.copyOf(filter(listMachines(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first physical machine matching the filter within the list of
|
||||
* machines in this rack.
|
||||
*
|
||||
* @param filter
|
||||
* Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-RetrievealistofMachines"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource- RetrievealistofMachines</a>
|
||||
*/
|
||||
public Machine findMachine(final Predicate<Machine> filter) {
|
||||
return Iterables.getFirst(filter(listMachines(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single physical machine.
|
||||
*
|
||||
* @param id
|
||||
* Unique ID of the physical machine in this rack.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-RetrieveaMachine"
|
||||
* > http://community.abiquo.com/display/ABI20/MachineResource#
|
||||
* MachineResource-RetrieveaMachine </a>
|
||||
* @return Unmanaged rack with the given id or <code>null</code> if it does
|
||||
* not exist.
|
||||
*/
|
||||
public Machine getMachine(final Integer id) {
|
||||
MachineDto machine = context.getApi().getInfrastructureApi().getMachine(target, id);
|
||||
return wrap(context, Machine.class, machine);
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Datacenter datacenter) {
|
||||
return new Builder(context, datacenter);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String shortDescription;
|
||||
|
||||
private boolean haEnabled = false;
|
||||
|
||||
private Integer nrsq = DEFAULT_NRSQ;
|
||||
|
||||
private Integer vlanIdMax = DEFAULT_VLAN_ID_MAX;
|
||||
|
||||
private Integer vlanIdMin = DEFAULT_VLAN_ID_MIN;
|
||||
|
||||
private Integer vlanPerVdcReserved = DEFAULT_VLAN_PER_VDC;
|
||||
|
||||
private String vlansIdAvoided;
|
||||
|
||||
private Datacenter datacenter;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Datacenter datacenter) {
|
||||
super();
|
||||
checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class);
|
||||
this.datacenter = datacenter;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder id(final Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder shortDescription(final String shortDescription) {
|
||||
this.shortDescription = shortDescription;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder haEnabled(final boolean haEnabled) {
|
||||
this.haEnabled = haEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder nrsq(final int nrsq) {
|
||||
this.nrsq = nrsq;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vlanIdMax(final int vlanIdMax) {
|
||||
this.vlanIdMax = vlanIdMax;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vlanIdMin(final int vlanIdMin) {
|
||||
this.vlanIdMin = vlanIdMin;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vlanPerVdcReserved(final int vlanPerVdcExpected) {
|
||||
this.vlanPerVdcReserved = vlanPerVdcExpected;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vlansIdAvoided(final String vlansIdAvoided) {
|
||||
this.vlansIdAvoided = vlansIdAvoided;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder datacenter(final Datacenter datacenter) {
|
||||
checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class);
|
||||
this.datacenter = datacenter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Rack build() {
|
||||
RackDto dto = new RackDto();
|
||||
dto.setId(id);
|
||||
dto.setName(name);
|
||||
dto.setShortDescription(shortDescription);
|
||||
dto.setHaEnabled(haEnabled);
|
||||
dto.setNrsq(nrsq);
|
||||
dto.setVlanIdMax(vlanIdMax);
|
||||
dto.setVlanIdMin(vlanIdMin);
|
||||
dto.setVlanPerVdcReserved(vlanPerVdcReserved);
|
||||
dto.setVlansIdAvoided(vlansIdAvoided);
|
||||
Rack rack = new Rack(context, dto);
|
||||
rack.datacenter = datacenter;
|
||||
return rack;
|
||||
}
|
||||
|
||||
public static Builder fromRack(final Rack in) {
|
||||
return Rack.builder(in.context, in.datacenter).id(in.getId()).name(in.getName())
|
||||
.shortDescription(in.getShortDescription()).haEnabled(in.isHaEnabled()).nrsq(in.getNrsq())
|
||||
.vlanIdMax(in.getVlanIdMax()).vlanIdMin(in.getVlanIdMin())
|
||||
.vlanPerVdcReserved(in.getVlanPerVdcReserved()).vlansIdAvoided(in.getVlansIdAvoided());
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getShortDescription() {
|
||||
return target.getShortDescription();
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public void setShortDescription(final String description) {
|
||||
target.setShortDescription(description);
|
||||
}
|
||||
|
||||
public void setHaEnabled(final boolean haEnabled) {
|
||||
target.setHaEnabled(haEnabled);
|
||||
}
|
||||
|
||||
public boolean isHaEnabled() {
|
||||
return target.isHaEnabled();
|
||||
}
|
||||
|
||||
public Integer getNrsq() {
|
||||
return target.getNrsq();
|
||||
}
|
||||
|
||||
public Integer getVlanIdMax() {
|
||||
return target.getVlanIdMax();
|
||||
}
|
||||
|
||||
public Integer getVlanIdMin() {
|
||||
return target.getVlanIdMin();
|
||||
}
|
||||
|
||||
public Integer getVlanPerVdcReserved() {
|
||||
return target.getVlanPerVdcReserved();
|
||||
}
|
||||
|
||||
public String getVlansIdAvoided() {
|
||||
return target.getVlansIdAvoided();
|
||||
}
|
||||
|
||||
public void setNrsq(final Integer nrsq) {
|
||||
target.setNrsq(nrsq);
|
||||
}
|
||||
|
||||
public void setVlanIdMax(final Integer vlanIdMax) {
|
||||
target.setVlanIdMax(vlanIdMax);
|
||||
}
|
||||
|
||||
public void setVlanIdMin(final Integer vlanIdMin) {
|
||||
target.setVlanIdMin(vlanIdMin);
|
||||
}
|
||||
|
||||
public void setVlanPerVdcReserved(final Integer vlanPerVdcReserved) {
|
||||
target.setVlanPerVdcReserved(vlanPerVdcReserved);
|
||||
}
|
||||
|
||||
public void setVlansIdAvoided(final String vlansIdAvoided) {
|
||||
target.setVlansIdAvoided(vlansIdAvoided);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Rack [id=" + getId() + ", name=" + getName() + ", description=" + getShortDescription() + ", haEnabled="
|
||||
+ isHaEnabled() + ", nrsq=" + getNrsq() + ", vlanIdMax=" + getVlanIdMax() + ", vlanIdMin=" + getVlanIdMin()
|
||||
+ ", vlanPerVdcReserved=" + getVlanPerVdcReserved() + ", vlansIdAvoided=" + getVlansIdAvoided() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,249 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.abiquo.domain.infrastructure;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.RemoteServiceType;
|
||||
import com.abiquo.server.core.infrastructure.DatacenterDto;
|
||||
import com.abiquo.server.core.infrastructure.RemoteServiceDto;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link RemoteServiceDto}. The Remote Service
|
||||
* resource offers the functionality of managing the remote services of a
|
||||
* datacenter in a logical way.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/RemoteServiceResource">
|
||||
* http://community.abiquo.com/display/ABI20/RemoteServiceResource</a>
|
||||
*/
|
||||
public class RemoteService extends DomainWrapper<RemoteServiceDto> {
|
||||
/** The default status. */
|
||||
private static final int DEFAULT_STATUS = 0;
|
||||
|
||||
/** The datacenter using the remote service. */
|
||||
private Datacenter datacenter;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected RemoteService(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final RemoteServiceDto target) {
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the remote service.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource-DeleteaRemoteService"
|
||||
* > http://community.abiquo.com/display/ABI20/RemoteServiceResource#
|
||||
* RemoteServiceResource- DeleteaRemoteService</a>
|
||||
*/
|
||||
public void delete() {
|
||||
context.getApi().getInfrastructureApi().deleteRemoteService(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the remote service.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource-CreateaRemoteService"
|
||||
* > http://community.abiquo.com/display/ABI20/RemoteServiceResource#
|
||||
* RemoteServiceResource- CreateaRemoteService</a>
|
||||
*/
|
||||
public void save() {
|
||||
target = context.getApi().getInfrastructureApi().createRemoteService(datacenter.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update remote service information in the server with the data from this
|
||||
* remote service.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource-UpdateanexistingRemoteService"
|
||||
* > http://community.abiquo.com/display/ABI20/RemoteServiceResource#
|
||||
* RemoteServiceResource- UpdateanexistingRemoteService</a>
|
||||
*/
|
||||
public void update() {
|
||||
target = context.getApi().getInfrastructureApi().updateRemoteService(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check remote service availability.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource-CheckthestatusofaRemoteService"
|
||||
* > http://community.abiquo.com/display/ABI20/RemoteServiceResource#
|
||||
* RemoteServiceResource- CheckthestatusofaRemoteService</a>
|
||||
*/
|
||||
public boolean isAvailable() {
|
||||
// If the remote service can not be checked, assume it is available
|
||||
return !getType().canBeChecked() ? true : context.getApi().getInfrastructureApi().isAvailable(target);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* Retrieve the datacenter using this remotes service.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrieveadatacenter"
|
||||
* > http://community.abiquo.com/display/ABI20/DatacenterResource#
|
||||
* DatacenterResource- Retrieveadatacenter</a>
|
||||
*/
|
||||
public Datacenter getDatacenter() {
|
||||
Integer datacenterId = target.getIdFromLink(ParentLinkName.DATACENTER);
|
||||
DatacenterDto dto = context.getApi().getInfrastructureApi().getDatacenter(datacenterId);
|
||||
datacenter = wrap(context, Datacenter.class, dto);
|
||||
return datacenter;
|
||||
}
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Datacenter datacenter) {
|
||||
return new Builder(context, datacenter);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Datacenter datacenter;
|
||||
|
||||
private String ip;
|
||||
|
||||
private Integer port;
|
||||
|
||||
private RemoteServiceType type;
|
||||
|
||||
private Integer status = DEFAULT_STATUS;
|
||||
|
||||
// To be used only internally by the builder
|
||||
private String uri;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final Datacenter datacenter) {
|
||||
super();
|
||||
checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class);
|
||||
this.datacenter = datacenter;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder datacenter(final Datacenter datacenter) {
|
||||
checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class);
|
||||
this.datacenter = datacenter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder status(final int status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(final RemoteServiceType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ip(final String ip) {
|
||||
this.ip = ip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder port(final int port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
private String generateUri(final String ip, final Integer port, final RemoteServiceType type) {
|
||||
return type.getDefaultProtocol() + ip + ":" + port + "/" + type.getServiceMapping();
|
||||
}
|
||||
|
||||
public RemoteService build() {
|
||||
if (uri == null) {
|
||||
checkNotNull(ip, ValidationErrors.MISSING_REQUIRED_FIELD + "ip");
|
||||
checkNotNull(type, ValidationErrors.MISSING_REQUIRED_FIELD + "type");
|
||||
|
||||
uri = generateUri(ip, port == null ? type.getDefaultPort() : port, type);
|
||||
}
|
||||
|
||||
RemoteServiceDto dto = new RemoteServiceDto();
|
||||
dto.setId(id);
|
||||
dto.setType(type);
|
||||
dto.setUri(uri);
|
||||
dto.setStatus(status);
|
||||
RemoteService remoteservice = new RemoteService(context, dto);
|
||||
remoteservice.datacenter = datacenter;
|
||||
return remoteservice;
|
||||
}
|
||||
|
||||
public static Builder fromRemoteService(final RemoteService in) {
|
||||
Builder builder = RemoteService.builder(in.context, in.getDatacenter()).status(in.getStatus())
|
||||
.type(in.getType());
|
||||
builder.uri = in.getUri();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId() {
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public RemoteServiceType getType() {
|
||||
return target.getType();
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return target.getStatus();
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return target.getUri();
|
||||
}
|
||||
|
||||
public void setStatus(final int status) {
|
||||
target.setStatus(status);
|
||||
}
|
||||
|
||||
public void setType(final RemoteServiceType type) {
|
||||
target.setType(type);
|
||||
}
|
||||
|
||||
public void setUri(final String uri) {
|
||||
target.setUri(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RemoteService [id=" + getId() + ", available=" + isAvailable() + ", type=" + getType() + ", status="
|
||||
+ getStatus() + ", uri" + getUri() + "]";
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue