mirror of https://github.com/apache/jclouds.git
Added Abiquo support in labs
This commit is contained in:
parent
b3907ebf77
commit
063e7e7168
|
@ -0,0 +1,25 @@
|
|||
====
|
||||
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.
|
||||
====
|
||||
|
||||
jclouds
|
||||
Copyright 2009-2011 jclouds, Inc.
|
||||
|
||||
This product includes software developed at
|
||||
Abiquo Holdings S.L. (http://www.abiquo.com/).
|
||||
distributed under the GNU Lesser General Public License version 3
|
|
@ -0,0 +1,21 @@
|
|||
Jclouds Abiquo Provider
|
||||
=======================
|
||||
|
||||
This is the jclouds Abiquo provider. It enables compute features for the Abiquo cloud platform.
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Detailed information about the Abiquo REST API can be found in the
|
||||
[Abiquo documentation page](http://community.abiquo.com).
|
||||
|
||||
All information about building and using the **jclouds-abiquo** provider in your own project
|
||||
can be found in the [Project Wiki](https://github.com/abiquo/jclouds-abiquo/wiki).
|
||||
|
||||
|
||||
Issue Tracking
|
||||
--------------
|
||||
|
||||
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.
|
||||
|
|
@ -0,0 +1,331 @@
|
|||
<?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</groupId>
|
||||
<artifactId>jclouds-project</artifactId>
|
||||
<version>1.5.0-SNAPSHOT</version>
|
||||
<relativePath>../../project/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>org.jclouds.labs</groupId>
|
||||
<artifactId>abiquo</artifactId>
|
||||
<name>jclouds Abiquo api</name>
|
||||
<description>jclouds components to access an implementation of Abiquo</description>
|
||||
<packaging>bundle</packaging>
|
||||
|
||||
<properties>
|
||||
<abiquo.version>2.1-SNAPSHOT</abiquo.version>
|
||||
<test.abiquo.identity></test.abiquo.identity>
|
||||
<test.abiquo.credential></test.abiquo.credential>
|
||||
<test.abiquo.api-version></test.abiquo.api-version>
|
||||
<test.abiquo.build-version></test.abiquo.build-version>
|
||||
<jclouds.osgi.export>org.jclouds.abiquo*;version="${project.version}"</jclouds.osgi.export>
|
||||
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
|
||||
</properties>
|
||||
|
||||
<!-- To be removed when the Abiquo deps are in Maven Central -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>abiquo-repo</id>
|
||||
<name>Abiquo Maven Repository</name>
|
||||
<url>http://repo.community.abiquo.com/repo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- Abiquo -->
|
||||
<dependency>
|
||||
<groupId>com.abiquo</groupId>
|
||||
<artifactId>api-model-transport</artifactId>
|
||||
<version>${abiquo.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>${abiquo.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>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.driver</groupId>
|
||||
<artifactId>jclouds-jsch</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.driver</groupId>
|
||||
<artifactId>jclouds-slf4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.6.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</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>
|
||||
<profile>
|
||||
<id>jenkins</id>
|
||||
<build>
|
||||
<filters>
|
||||
<filter>src/test/resources/filters/filters_jenkins.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>
|
||||
<threadCount>1</threadCount>
|
||||
<excludes>
|
||||
<exclude>none</exclude>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/*Live*.java</include>
|
||||
</includes>
|
||||
<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>ucs</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>
|
||||
<threadCount>1</threadCount>
|
||||
<excludes>
|
||||
<exclude>none</exclude>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/*LiveApiTest.java</include>
|
||||
<include>**/*LiveUcsTest.java</include>
|
||||
</includes>
|
||||
<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>
|
||||
-->
|
||||
</profiles>
|
||||
</project>
|
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
* 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 java.util.concurrent.TimeUnit;
|
||||
|
||||
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.concurrent.Timeout;
|
||||
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
|
||||
*/
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
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();
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
/**
|
||||
* 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.reference.AbiquoConstants.ASYNC_TASK_MONITOR_DELAY;
|
||||
import static org.jclouds.abiquo.reference.AbiquoConstants.CREDENTIAL_IS_TOKEN;
|
||||
|
||||
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
|
||||
{
|
||||
/** Serial UID. */
|
||||
private static final long serialVersionUID = -8355533493674898171L;
|
||||
|
||||
/** The token describing the rest api context. */
|
||||
public static final TypeToken<RestContext<AbiquoApi, AbiquoAsyncApi>> CONTEXT_TOKEN =
|
||||
new TypeToken<RestContext<AbiquoApi, AbiquoAsyncApi>>()
|
||||
{
|
||||
private static final long serialVersionUID = -5070937833892503232L;
|
||||
};
|
||||
|
||||
public AbiquoApiMetadata()
|
||||
{
|
||||
this(new Builder());
|
||||
}
|
||||
|
||||
protected AbiquoApiMetadata(final 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder toBuilder()
|
||||
{
|
||||
return new Builder().fromApiMetadata(this);
|
||||
}
|
||||
|
||||
public static class Builder extends BaseRestApiMetadata.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.of(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
|
||||
public Builder fromApiMetadata(final ApiMetadata in)
|
||||
{
|
||||
super.fromApiMetadata(in);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
* 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();
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* 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();
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,159 @@
|
|||
/**
|
||||
* 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.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.getArgs().indexOf(payload);
|
||||
Annotation[] annotations = request.getJavaMethod().getParameterAnnotations()[argIndex];
|
||||
|
||||
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 and matrix 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('?');
|
||||
int matrix = endpoint.indexOf(';');
|
||||
|
||||
if (query == -1 && matrix == -1)
|
||||
{
|
||||
// No parameters
|
||||
return "";
|
||||
}
|
||||
else if (query != -1 && matrix != -1)
|
||||
{
|
||||
// Both parameter types
|
||||
return endpoint.substring(query < matrix ? query : matrix);
|
||||
}
|
||||
else if (query != -1)
|
||||
{
|
||||
// Only request parameters
|
||||
return endpoint.substring(query);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only matrix parameters
|
||||
return endpoint.substring(matrix);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* 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 javax.ws.rs.PUT;
|
||||
|
||||
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 teh 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.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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.storage.DiskManagementDto;
|
||||
|
||||
/**
|
||||
* 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";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* 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";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* 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.getArgs() != null, "args should be initialized at this point");
|
||||
|
||||
VLANNetworkDto network = (VLANNetworkDto) input;
|
||||
VirtualMachineDto vm =
|
||||
(VirtualMachineDto) Iterables.find(gRequest.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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* 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.AbstractIpDto;
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* 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;
|
||||
import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto;
|
||||
|
||||
/**
|
||||
* 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";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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.domain.infrastructure.Machine;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* 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";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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", server.getName()).build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* 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", org.getDn()).build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* 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.VirtualMachineTemplateToHardware;
|
||||
import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateToImage;
|
||||
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.VirtualMachine;
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
|
||||
import org.jclouds.compute.config.ComputeServiceAdapterContextModule.LocationsFromComputeServiceAdapterModule;
|
||||
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, VirtualMachineTemplate, VirtualMachineTemplate, Datacenter>
|
||||
{
|
||||
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
super.configure();
|
||||
bind(
|
||||
new TypeLiteral<ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplate, VirtualMachineTemplate, Datacenter>>()
|
||||
{
|
||||
}).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<VirtualMachineTemplate, Hardware>>()
|
||||
{
|
||||
}).to(VirtualMachineTemplateToHardware.class);
|
||||
bind(new TypeLiteral<Function<Datacenter, Location>>()
|
||||
{
|
||||
}).to(DatacenterToLocation.class);
|
||||
bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON);
|
||||
bind(TemplateOptions.class).to(AbiquoTemplateOptions.class);
|
||||
install(new LocationsFromComputeServiceAdapterModule<VirtualMachine, VirtualMachineTemplate, VirtualMachineTemplate, Datacenter>()
|
||||
{
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown when there are not enough resources in the infrastructure to deploy the desired
|
||||
* template.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class NotEnoughResourcesException extends RuntimeException
|
||||
{
|
||||
/** Serial UID. */
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NotEnoughResourcesException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public NotEnoughResourcesException(final String arg0, final Throwable arg1)
|
||||
{
|
||||
super(arg0, arg1);
|
||||
}
|
||||
|
||||
public NotEnoughResourcesException(final String arg0)
|
||||
{
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public NotEnoughResourcesException(final Throwable arg0)
|
||||
{
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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.ZONE);
|
||||
// TODO: Convert to ISO3166 code?
|
||||
builder.iso3166Codes(ImmutableSet.<String> of());
|
||||
|
||||
builder.parent(new LocationBuilder().scope(LocationScope.PROVIDER).id("abiquo")
|
||||
.description("abiquo").build());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* 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:
|
||||
return Status.PENDING;
|
||||
case ON:
|
||||
return Status.RUNNING;
|
||||
case OFF:
|
||||
case PAUSED:
|
||||
return Status.SUSPENDED;
|
||||
case NOT_ALLOCATED:
|
||||
// TODO: What about nodes created but still not deployed?
|
||||
return Status.TERMINATED;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
return Status.UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* 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.cloud.VirtualMachineTemplate;
|
||||
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 com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Transforms a {@link VirtualMachineTemplate} into an {@link Hardware}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class VirtualMachineTemplateToHardware implements Function<VirtualMachineTemplate, Hardware>
|
||||
{
|
||||
/** The default core speed, 2.0Ghz. */
|
||||
public static final double DEFAULT_CORE_SPEED = 2.0;
|
||||
|
||||
@Override
|
||||
public Hardware apply(final VirtualMachineTemplate template)
|
||||
{
|
||||
HardwareBuilder builder = new HardwareBuilder();
|
||||
builder.ids(template.getId().toString());
|
||||
builder.uri(template.getURI());
|
||||
|
||||
builder.name(template.getName());
|
||||
builder.processor(new Processor(template.getCpuRequired(), DEFAULT_CORE_SPEED));
|
||||
builder.ram(template.getRamRequired());
|
||||
|
||||
// Currently we consider each template as a hardware profile
|
||||
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 / 1024 / 1024 / (float) 1024;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* 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 java.net.URI;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
|
||||
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 com.abiquo.model.rest.RESTLink;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Transforms a {@link VirtualMachineTemplate} into an {@link Image}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class VirtualMachineTemplateToImage implements Function<VirtualMachineTemplate, Image>
|
||||
{
|
||||
|
||||
@Override
|
||||
public Image apply(final VirtualMachineTemplate template)
|
||||
{
|
||||
ImageBuilder builder = new ImageBuilder();
|
||||
builder.ids(template.getId().toString());
|
||||
builder.name(template.getName());
|
||||
builder.description(template.getDescription());
|
||||
|
||||
// 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
|
||||
builder.operatingSystem(OperatingSystem.builder().description(template.getName()).build());
|
||||
// TODO: image credentials
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
* 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.infrastructure.Datacenter;
|
||||
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.logging.Logger;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
|
||||
import com.abiquo.server.core.cloud.VirtualMachineState;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
|
||||
/**
|
||||
* 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 VirtualMachineTemplateToHardware virtualMachineTemplateToHardware;
|
||||
|
||||
private final VirtualMachineStateToNodeState virtualMachineStateToNodeState;
|
||||
|
||||
private final DatacenterToLocation datacenterToLocation;
|
||||
|
||||
@Inject
|
||||
public VirtualMachineToNodeMetadata(
|
||||
final VirtualMachineTemplateToImage virtualMachineTemplateToImage,
|
||||
final VirtualMachineTemplateToHardware virtualMachineTemplateToHardware,
|
||||
final VirtualMachineStateToNodeState virtualMachineStateToNodeState,
|
||||
final DatacenterToLocation datacenterToLocation)
|
||||
{
|
||||
this.virtualMachineTemplateToImage =
|
||||
checkNotNull(virtualMachineTemplateToImage, "virtualMachineTemplateToImage");
|
||||
this.virtualMachineTemplateToHardware =
|
||||
checkNotNull(virtualMachineTemplateToHardware, "virtualMachineTemplateToHardware");
|
||||
this.virtualMachineStateToNodeState =
|
||||
checkNotNull(virtualMachineStateToNodeState, "virtualMachineStateToNodeState");
|
||||
this.datacenterToLocation = checkNotNull(datacenterToLocation, "datacenterToLocation");
|
||||
}
|
||||
|
||||
@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: builder.credentials() (http://jira.abiquo.com/browse/ABICLOUDPREMIUM-3647)
|
||||
VirtualDatacenter vdc = vm.getVirtualDatacenter();
|
||||
|
||||
// Location details
|
||||
try
|
||||
{
|
||||
Datacenter datacenter = vdc.getDatacenter();
|
||||
builder.location(datacenterToLocation.apply(datacenter));
|
||||
}
|
||||
catch (AuthorizationException ex)
|
||||
{
|
||||
logger.debug("User does not have permissions to see the location of the node");
|
||||
}
|
||||
|
||||
// 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(template);
|
||||
Hardware hardware =
|
||||
new HardwareBuilder() //
|
||||
.ids(defaultHardware.getId()) //
|
||||
.uri(defaultHardware.getUri()) //
|
||||
.name(defaultHardware.getName()) //
|
||||
.supportsImage(defaultHardware.supportsImage()) //
|
||||
.ram(vm.getRam()) //
|
||||
.hypervisor(vdc.getHypervisorType().name()) //
|
||||
.processor(
|
||||
new Processor(vm.getCpu(), VirtualMachineTemplateToHardware.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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,257 @@
|
|||
/**
|
||||
* 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.abiquo.domain.network.Ip;
|
||||
import org.jclouds.abiquo.domain.network.Network;
|
||||
import org.jclouds.abiquo.domain.network.UnmanagedNetwork;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
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;
|
||||
|
||||
private String virtualDatacenter;
|
||||
|
||||
private Ip< ? , ? >[] ips;
|
||||
|
||||
private UnmanagedNetwork[] unmanagedIps;
|
||||
|
||||
private Network< ? > gatewayNetwork;
|
||||
|
||||
@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);
|
||||
options.virtualDatacenter(virtualDatacenter);
|
||||
options.ips(ips);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the virtual datacenter where the virtual machine must be deployed.
|
||||
*
|
||||
* @return The template options with the virtual machine must be deployed.
|
||||
*/
|
||||
public AbiquoTemplateOptions virtualDatacenter(final String virtualDatacenter)
|
||||
{
|
||||
this.virtualDatacenter = virtualDatacenter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getVirtualDatacenter()
|
||||
{
|
||||
return virtualDatacenter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ip addresses for the virtual machine.
|
||||
*
|
||||
* @return The template options with the ip addresses configuration.
|
||||
*/
|
||||
public AbiquoTemplateOptions ips(final Ip< ? , ? >... ips)
|
||||
{
|
||||
this.ips = ips;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Ip< ? , ? >[] getIps()
|
||||
{
|
||||
return ips;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ip addresses that must be selected from unmanaged networks.
|
||||
*
|
||||
* @return The template options with the ip addresses that must be selected from unmanaged
|
||||
* networks.
|
||||
*/
|
||||
public AbiquoTemplateOptions unmanagedIps(final UnmanagedNetwork... unmanagedIps)
|
||||
{
|
||||
this.unmanagedIps = unmanagedIps;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UnmanagedNetwork[] getUnmanagedIps()
|
||||
{
|
||||
return unmanagedIps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the gateway network for the virtual machine.
|
||||
*
|
||||
* @return The template options with the gateway network configuration.
|
||||
*/
|
||||
public AbiquoTemplateOptions gatewayNetwork(final Network< ? > gatewayNetwork)
|
||||
{
|
||||
this.gatewayNetwork = gatewayNetwork;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Network< ? > getGatewayNetwork()
|
||||
{
|
||||
return gatewayNetwork;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbiquoTemplateOptions#virtualDatacenter(String)
|
||||
*/
|
||||
public static AbiquoTemplateOptions virtualDatacenter(final String virtualDatacenter)
|
||||
{
|
||||
AbiquoTemplateOptions options = new AbiquoTemplateOptions();
|
||||
return options.virtualDatacenter(virtualDatacenter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbiquoTemplateOptions#ips(Ip...)
|
||||
*/
|
||||
public static AbiquoTemplateOptions ips(final Ip< ? , ? >... ips)
|
||||
{
|
||||
AbiquoTemplateOptions options = new AbiquoTemplateOptions();
|
||||
return options.ips(ips);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbiquoTemplateOptions#unmanagedIps(UnmanagedNetwork...)
|
||||
*/
|
||||
public AbiquoTemplateOptions unmanagedIps(final UnmanagedNetwork... unmanagedIps)
|
||||
{
|
||||
AbiquoTemplateOptions options = new AbiquoTemplateOptions();
|
||||
return options.unmanagedIps(unmanagedIps);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbiquoTemplateOptions#gatewayNetwork(Network)
|
||||
*/
|
||||
public static AbiquoTemplateOptions gatewayNetwork(final Network< ? > gatewayNetwork)
|
||||
{
|
||||
AbiquoTemplateOptions options = new AbiquoTemplateOptions();
|
||||
return options.gatewayNetwork(gatewayNetwork);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,251 @@
|
|||
/**
|
||||
* 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 java.util.Arrays;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
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.enterprise.Enterprise;
|
||||
import org.jclouds.abiquo.domain.enterprise.User;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
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.infrastructure.DatacenterPredicates;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
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.Predicate;
|
||||
|
||||
/**
|
||||
* Defines the connection between the {@link AbiquoApi} implementation and the jclouds
|
||||
* {@link ComputeService}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class AbiquoComputeServiceAdapter
|
||||
implements
|
||||
ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplate, VirtualMachineTemplate, Datacenter>
|
||||
{
|
||||
@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 AbiquoComputeServiceHelper helper;
|
||||
|
||||
@Inject
|
||||
public AbiquoComputeServiceAdapter(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final AdministrationService adminService, final CloudService cloudService,
|
||||
final MonitoringService monitoringService, final AbiquoComputeServiceHelper helper)
|
||||
{
|
||||
super();
|
||||
this.context = checkNotNull(context, "context");
|
||||
this.adminService = checkNotNull(adminService, "adminService");
|
||||
this.cloudService = checkNotNull(cloudService, "cloudService");
|
||||
this.monitoringService = checkNotNull(monitoringService, "monitoringService");
|
||||
this.helper = checkNotNull(helper, "helper");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeAndInitialCredentials<VirtualMachine> createNodeWithGroupEncodedIntoName(
|
||||
final String tag, final String name, final Template template)
|
||||
{
|
||||
AbiquoTemplateOptions options = template.getOptions().as(AbiquoTemplateOptions.class);
|
||||
|
||||
User user = adminService.getCurrentUser();
|
||||
Enterprise enterprise = adminService.getCurrentEnterprise();
|
||||
|
||||
Datacenter datacenter =
|
||||
enterprise.findAllowedDatacenter(DatacenterPredicates.id(Integer.valueOf(template
|
||||
.getLocation().getId())));
|
||||
|
||||
VirtualMachineTemplate virtualMachineTemplate =
|
||||
enterprise.getTemplateInRepository(datacenter,
|
||||
Integer.valueOf(template.getImage().getId()));
|
||||
|
||||
VirtualDatacenter vdc =
|
||||
helper.getOrCreateVirtualDatacenter(user, enterprise, datacenter,
|
||||
virtualMachineTemplate, options);
|
||||
|
||||
// Load the virtual appliance or create it
|
||||
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
|
||||
helper.configureNetwork(vm, options.getGatewayNetwork(), options.getIps() == null ? null
|
||||
: Arrays.asList(options.getIps()),
|
||||
options.getUnmanagedIps() == null ? null : Arrays.asList(options.getUnmanagedIps()));
|
||||
|
||||
VirtualMachineMonitor monitor = monitoringService.getVirtualMachineMonitor();
|
||||
vm.deploy();
|
||||
monitor.awaitCompletionDeploy(vm);
|
||||
|
||||
return new NodeAndInitialCredentials<VirtualMachine>(vm, vm.getId().toString(), template
|
||||
.getImage().getDefaultCredentials());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<VirtualMachineTemplate> listHardwareProfiles()
|
||||
{
|
||||
// Abiquo does not have the hardwre profiles concept. Users can consume CPU and RAM
|
||||
// resources limited only by the Enterprise or Virtual datacenter limits.
|
||||
return listImages();
|
||||
}
|
||||
|
||||
@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<Datacenter> listLocations()
|
||||
{
|
||||
Enterprise enterprise = adminService.getCurrentEnterprise();
|
||||
return enterprise.listAllowedDatacenters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualMachine getNode(final String id)
|
||||
{
|
||||
// FIXME: Try to avoid calling the cloudService.findVirtualMachine. Navigate the hierarchy
|
||||
// instead.
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,256 @@
|
|||
/**
|
||||
* 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.filter;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Iterables.getFirst;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.compute.exception.NotEnoughResourcesException;
|
||||
import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions;
|
||||
import org.jclouds.abiquo.domain.cloud.Conversion;
|
||||
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.enterprise.Enterprise;
|
||||
import org.jclouds.abiquo.domain.enterprise.User;
|
||||
import org.jclouds.abiquo.domain.exception.AbiquoException;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.domain.network.Ip;
|
||||
import org.jclouds.abiquo.domain.network.Network;
|
||||
import org.jclouds.abiquo.domain.network.PrivateNetwork;
|
||||
import org.jclouds.abiquo.domain.network.UnmanagedNetwork;
|
||||
import org.jclouds.abiquo.features.services.CloudService;
|
||||
import org.jclouds.abiquo.predicates.cloud.VirtualDatacenterPredicates;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.model.enumerator.ConversionState;
|
||||
import com.abiquo.model.enumerator.HypervisorType;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
/**
|
||||
* Helper methods to perform {@link AbiquoComputeServiceAdapter} operations.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class AbiquoComputeServiceHelper
|
||||
{
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private CloudService cloudService;
|
||||
|
||||
@Inject
|
||||
public AbiquoComputeServiceHelper(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final CloudService cloudService)
|
||||
{
|
||||
super();
|
||||
this.context = checkNotNull(context, "context");
|
||||
this.cloudService = checkNotNull(cloudService, "cloudService");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a virtual datacenter where the given template can be deployed.
|
||||
* <p>
|
||||
* If no compatible virtual datacenter is found, one will be created, if possible.
|
||||
*
|
||||
* @param user The current user.
|
||||
* @param enterprise The enterprise of the current user.
|
||||
* @param datacenter The datacenter of the template.
|
||||
* @param template The template to deploy.
|
||||
* @param options The template options
|
||||
* @return The virtual datacenter to be used to deploy the template or <code>null</code> if none
|
||||
* was found and a compatible one could not be created.
|
||||
*/
|
||||
public VirtualDatacenter getOrCreateVirtualDatacenter(final User user,
|
||||
final Enterprise enterprise, final Datacenter datacenter,
|
||||
final VirtualMachineTemplate template, final AbiquoTemplateOptions options)
|
||||
{
|
||||
Iterable<VirtualDatacenter> compatibles =
|
||||
findCompatibleVirtualDatacenters(datacenter, template);
|
||||
|
||||
VirtualDatacenter vdc =
|
||||
options.getVirtualDatacenter() == null ? getFirst(compatibles, null) : find(
|
||||
compatibles, VirtualDatacenterPredicates.name(options.getVirtualDatacenter()));
|
||||
|
||||
if (vdc == null)
|
||||
{
|
||||
vdc =
|
||||
createCompatibleVirtualDatacenter(user, enterprise, datacenter, template,
|
||||
options.getVirtualDatacenter());
|
||||
if (vdc == null)
|
||||
{
|
||||
throw new NotEnoughResourcesException("There are not resources to deploy the given template");
|
||||
}
|
||||
}
|
||||
|
||||
return vdc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the virtual datacenters compatible with the given template.
|
||||
*
|
||||
* @param datacenter The datacenter of the template.
|
||||
* @param template The template to deploy.
|
||||
* @return The virtual datacenters compatible with the given template.
|
||||
*/
|
||||
public Iterable<VirtualDatacenter> findCompatibleVirtualDatacenters(
|
||||
final Datacenter datacenter, final VirtualMachineTemplate template)
|
||||
{
|
||||
Iterable<VirtualDatacenter> vdcs =
|
||||
cloudService.listVirtualDatacenters(VirtualDatacenterPredicates.datacenter(datacenter));
|
||||
|
||||
return filter(vdcs, new Predicate<VirtualDatacenter>()
|
||||
{
|
||||
@Override
|
||||
public boolean apply(final VirtualDatacenter vdc)
|
||||
{
|
||||
return isTemplateCompatibleWithHypervisor(template, vdc.getHypervisorType());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure networking resources for the given virtual machine.
|
||||
*
|
||||
* @param vm The virtual machine to configure.
|
||||
* @param gatewayNetwork The network to be used as a gateway.
|
||||
* @param ips The ips to attach to the virtual machine.
|
||||
*/
|
||||
public void configureNetwork(final VirtualMachine vm,
|
||||
@Nullable final Network< ? > gatewayNetwork,
|
||||
@Nullable final List<Ip< ? , ? extends Network< ? >>> ips,
|
||||
@Nullable final List<UnmanagedNetwork> unmanagedIps)
|
||||
{
|
||||
if (ips != null)
|
||||
{
|
||||
// TODO: External ips don't have the right link
|
||||
// (http://jira.abiquo.com/browse/ABICLOUDPREMIUM-3650)
|
||||
|
||||
if (gatewayNetwork == null)
|
||||
{
|
||||
// By default the network of the first ip will be used as a gateway
|
||||
vm.setNics(ips, unmanagedIps);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.setNics(gatewayNetwork, ips, unmanagedIps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new virtual datacenter compatible with the given template.
|
||||
*
|
||||
* @param user The current user.
|
||||
* @param enterprise The enterprise of the current user.
|
||||
* @param datacenter The datacenter of the template.
|
||||
* @param template The template to deploy.
|
||||
* @return
|
||||
*/
|
||||
private VirtualDatacenter createCompatibleVirtualDatacenter(final User user,
|
||||
final Enterprise enterprise, final Datacenter datacenter,
|
||||
final VirtualMachineTemplate template, final String name)
|
||||
{
|
||||
PrivateNetwork defaultNetwork =
|
||||
PrivateNetwork.builder(context).name("DefaultNetwork").gateway("192.168.1.1")
|
||||
.address("192.168.1.0").mask(24).build();
|
||||
|
||||
VirtualDatacenter vdc =
|
||||
VirtualDatacenter.builder(context, datacenter, enterprise).network(defaultNetwork)
|
||||
.build();
|
||||
|
||||
// Find the first hypervisor in the datacenter compatible with the template
|
||||
for (HypervisorType type : HypervisorType.values())
|
||||
{
|
||||
if (isTemplateCompatibleWithHypervisor(template, type))
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Trying to create a virtual datacenter of type %s", type.name());
|
||||
vdc.setName(name != null ? name : "JC-" + type.name());
|
||||
vdc.setHypervisorType(type);
|
||||
vdc.save();
|
||||
|
||||
logger.info("Virtual datacenter created");
|
||||
|
||||
return vdc;
|
||||
}
|
||||
catch (AbiquoException ex)
|
||||
{
|
||||
// Just catch the error thrown when no hypervisors of the given type are
|
||||
// available in the datacenter
|
||||
if (ex.hasError("VDC-1"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.warn("Could not create a compatible virtual datacenter for template of type %s",
|
||||
template.getDiskFormatType().name());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given template type is compatible with the given hypervisor type.
|
||||
*
|
||||
* @param template The template to check.
|
||||
* @param type The type of the hypervisor.
|
||||
* @return Boolean indicating if the given template type is compatible with the given hypervisor
|
||||
* type.
|
||||
*/
|
||||
private static boolean isTemplateCompatibleWithHypervisor(
|
||||
final VirtualMachineTemplate template, final HypervisorType type)
|
||||
{
|
||||
boolean compatible = type.isCompatible(template.getDiskFormatType());
|
||||
if (!compatible)
|
||||
{
|
||||
List<Conversion> compatibleConversions =
|
||||
template.listConversions(type, ConversionState.FINISHED);
|
||||
compatible = compatibleConversions != null && !compatibleConversions.isEmpty();
|
||||
}
|
||||
return compatible;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/**
|
||||
* 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 java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.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.abiquo.suppliers.GetCurrentEnterprise;
|
||||
import org.jclouds.abiquo.suppliers.GetCurrentUser;
|
||||
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.Utils;
|
||||
import org.jclouds.rest.config.BinderUtils;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* 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 bindAsyncClient()
|
||||
{
|
||||
super.bindAsyncClient();
|
||||
BinderUtils.bindAsyncClient(binder(), AbiquoHttpAsyncClient.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindClient()
|
||||
{
|
||||
super.bindClient();
|
||||
BinderUtils.bindClient(binder(), AbiquoHttpClient.class, AbiquoHttpAsyncClient.class,
|
||||
ImmutableMap.<Class< ? >, Class< ? >> of(AbiquoHttpClient.class,
|
||||
AbiquoHttpAsyncClient.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
super.configure();
|
||||
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 GetCurrentUser getCurrentUser)
|
||||
{
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
getCurrentUser, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
public Supplier<Enterprise> getCurrentEnterprise(
|
||||
final AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) final long seconds,
|
||||
final GetCurrentEnterprise getCurrentEnterprise)
|
||||
{
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
getCurrentEnterprise, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,195 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* 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.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
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 Lists.newLinkedList(filter(listTasks(), filter));
|
||||
}
|
||||
|
||||
public AsyncTask findTask(final Predicate<AsyncTask> filter)
|
||||
{
|
||||
return Iterables.getFirst(filter(listTasks(), filter), null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
/**
|
||||
* 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.transform;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
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.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.Lists;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
Constructor<W> cons =
|
||||
wrapperClass.getDeclaredConstructor(RestContext.class, target.getClass());
|
||||
if (!cons.isAccessible())
|
||||
{
|
||||
cons.setAccessible(true);
|
||||
}
|
||||
return cons.newInstance(context, target);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new WrapperException(wrapperClass, target, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Lists.newLinkedList(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 Lists.newLinkedList(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)
|
||||
{
|
||||
List<T> dtos = Lists.newLinkedList();
|
||||
for (WrapperDto<T> wrapper : collection)
|
||||
{
|
||||
dtos.addAll(wrapper.getCollection());
|
||||
}
|
||||
return dtos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = new ArrayList<AsyncTask>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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);
|
||||
}
|
||||
|
||||
// Domain methods
|
||||
|
||||
public void refresh()
|
||||
{
|
||||
RESTLink link =
|
||||
checkNotNull(target.searchLink("edit"), ValidationErrors.MISSING_REQUIRED_LINK + "edit");
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = checkNotNull(utils.getAbiquoHttpClient().get(link), "conversion");
|
||||
|
||||
ParseXMLWithJAXB<ConversionDto> parser =
|
||||
new ParseXMLWithJAXB<ConversionDto>(utils.getXml(),
|
||||
TypeLiteral.get(ConversionDto.class));
|
||||
|
||||
target = parser.apply(response);
|
||||
}
|
||||
|
||||
// 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() + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
/**
|
||||
* 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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,403 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @resturn 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 Lists.newLinkedList(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);
|
||||
}
|
||||
|
||||
// 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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,680 @@
|
|||
/**
|
||||
* 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.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* 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 dataceter 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 Lists.newLinkedList(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 Lists.newLinkedList(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 sotrage 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 Lists.newLinkedList(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 Lists.newLinkedList(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 Lists.newLinkedList(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> listAvailableTempaltes(
|
||||
final Predicate<VirtualMachineTemplate> filter)
|
||||
{
|
||||
return Lists.newLinkedList(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 Lists.newLinkedList(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 Lists.newLinkedList(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 releaseePublicIp(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() + "]";
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,407 @@
|
|||
/**
|
||||
* 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.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.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
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 makePeristent(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 makePeristent(vdc, storageLink, persistentTemplateName, persistentVolumeName);
|
||||
}
|
||||
|
||||
private AsyncTask makePeristent(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 Lists.newLinkedList(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);
|
||||
}
|
||||
|
||||
// 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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,250 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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 folumes. */
|
||||
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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,186 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,191 @@
|
|||
/**
|
||||
* 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
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/Currency+Resource">
|
||||
* http://community.abiquo.com/display/ABI20/Currency+Resource</a>
|
||||
*/
|
||||
|
||||
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
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-Deleteacurrency"
|
||||
* > http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-
|
||||
* Deleteacurrency</a>
|
||||
*/
|
||||
public void delete()
|
||||
{
|
||||
context.getApi().getPricingApi().deleteCurrency(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-Createacurrency"
|
||||
* > http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-
|
||||
* Createacurrency</a>
|
||||
*/
|
||||
public void save()
|
||||
{
|
||||
target = context.getApi().getPricingApi().createCurrency(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-Updateanexistingcurrency"
|
||||
* > http://community.abiquo.com/display/ABI20/Currency+Resource#CurrencyResource-
|
||||
* Updateanexistingcurrency</a>
|
||||
*/
|
||||
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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
* 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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* 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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* 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 "SystemPorperty [getName()=" + getName() + ", getValue()=" + getValue() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* 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 inaactive 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,250 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* 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 Lists.newLinkedList(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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,236 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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.Lists;
|
||||
|
||||
/**
|
||||
* 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 Lists.newLinkedList(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() + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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() + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,509 @@
|
|||
/**
|
||||
* 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.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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.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> listPermitedVirtualDatacenters()
|
||||
{
|
||||
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 Lists.newArrayList(listVirtualDatacenters.execute(ids));
|
||||
}
|
||||
|
||||
public List<VirtualDatacenter> listPermitedVirtualDatacenters(
|
||||
final Predicate<VirtualDatacenter> filter)
|
||||
{
|
||||
return Lists.newLinkedList(filter(listPermitedVirtualDatacenters(), filter));
|
||||
}
|
||||
|
||||
public VirtualDatacenter findPermitedVirtualDatacenter(final Predicate<VirtualDatacenter> filter)
|
||||
{
|
||||
return Iterables.getFirst(filter(listPermitedVirtualDatacenters(), 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 datancers from the user's enterprise.
|
||||
*/
|
||||
public void setPermitedVirtualDatacenters(final List<VirtualDatacenter> vdcs)
|
||||
{
|
||||
List<Integer> ids = new ArrayList<Integer>();
|
||||
|
||||
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 Lists.newLinkedList(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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,393 @@
|
|||
/**
|
||||
* 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() + ", stackstrace="
|
||||
+ getStacktrace() + ", performedBy=" + getPerformedBy() + ", severity=" + getSeverity()
|
||||
+ "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,196 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
/**
|
||||
* 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.Lists;
|
||||
|
||||
/**
|
||||
* Abiquo API exception.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class AbiquoException extends RuntimeException
|
||||
{
|
||||
/** Serial UID. */
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** The HTTP statuc. */
|
||||
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 Lists.newLinkedList(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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* 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 = 1L;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* 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 = 1L;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,356 @@
|
|||
/**
|
||||
* 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 java.util.StringTokenizer;
|
||||
|
||||
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.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;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/** List of available virtual switches provided by discover operation **/
|
||||
protected List<String> virtualSwitches;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected AbstractPhysicalMachine(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final MachineDto target)
|
||||
{
|
||||
super(context, target);
|
||||
extractVirtualSwitches();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// 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 String getVirtualSwitch()
|
||||
{
|
||||
return target.getVirtualSwitch();
|
||||
}
|
||||
|
||||
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 void setVirtualSwitch(final String virtualSwitch)
|
||||
{
|
||||
target.setVirtualSwitch(virtualSwitch);
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
// Aux operations
|
||||
|
||||
/**
|
||||
* Converts the tokenized String provided by the node collector API to a list of Strings and
|
||||
* stores it at the attribute switches.
|
||||
*/
|
||||
protected void extractVirtualSwitches()
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(getVirtualSwitch(), "/");
|
||||
this.virtualSwitches = Lists.newArrayList();
|
||||
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
this.virtualSwitches.add(st.nextToken());
|
||||
}
|
||||
|
||||
if (virtualSwitches.size() > 0)
|
||||
{
|
||||
this.setVirtualSwitch(virtualSwitches.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the virtual switches available. One of them needs to be selected.
|
||||
*/
|
||||
public List<String> getAvailableVirtualSwitches()
|
||||
{
|
||||
return virtualSwitches;
|
||||
}
|
||||
|
||||
public String findAvailableVirtualSwitch(final String vswitch)
|
||||
{
|
||||
return find(virtualSwitches, Predicates.equalTo(vswitch));
|
||||
}
|
||||
|
||||
@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() + ", virtualSwitch=" + getVirtualSwitch() + ", description="
|
||||
+ getDescription() + ", availableVirtualSwitches=" + getAvailableVirtualSwitches()
|
||||
+ "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,176 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* 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.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.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
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* 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.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.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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* 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.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.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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,549 @@
|
|||
/**
|
||||
* 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.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.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Lists.newLinkedList(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 sinchronizing 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
|
||||
* sinchronizing 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 Lists.newLinkedList(filter(listVirtualMachines(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single virtual machine in the physical machine matching the given filter sinchronizing
|
||||
* 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, description;
|
||||
|
||||
private Integer virtualRamInMb;
|
||||
|
||||
private Integer virtualRamUsedInMb = DEFAULT_VRAM_USED;
|
||||
|
||||
private Integer virtualCpuCores;
|
||||
|
||||
private Integer virtualCpusUsed = DEFAULT_VCPU_USED;
|
||||
|
||||
private String virtualSwitch;
|
||||
|
||||
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 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 virtualSwitch(final String virtualSwitch)
|
||||
{
|
||||
this.virtualSwitch = virtualSwitch;
|
||||
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 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);
|
||||
dto.setVirtualSwitch(virtualSwitch);
|
||||
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);
|
||||
|
||||
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())
|
||||
.virtualSwitch(in.getVirtualSwitch()).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());
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,786 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* 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 Lists.newLinkedList(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 Lists.newLinkedList(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 Lists.newLinkedList(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 Lists.newLinkedList(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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
* 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.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.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() + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,421 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* 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 Lists.newLinkedList(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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,277 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,532 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.domain.infrastructure.options.StoragePoolOptions;
|
||||
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.DatacenterDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.StoragePoolDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.StoragePoolsDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.TiersDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link StorageDeviceDto}. The Storage Device Resource offers the
|
||||
* functionality of managing the external storage.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/StorageDeviceResource">
|
||||
* http://community.abiquo.com/display/ABI20/StorageDeviceResource</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class StorageDevice extends DomainWrapper<StorageDeviceDto>
|
||||
{
|
||||
/** The datacenter where the storage device is. */
|
||||
private Datacenter datacenter;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected StorageDevice(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final StorageDeviceDto target)
|
||||
{
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the storage device.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-Deleteastoragedevice"
|
||||
* > http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-
|
||||
* Deleteastoragedevice</a>
|
||||
*/
|
||||
public void delete()
|
||||
{
|
||||
context.getApi().getInfrastructureApi().deleteStorageDevice(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new storage device.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-Createastoragedevice"
|
||||
* > http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-
|
||||
* Createastoragedevice</a>
|
||||
*/
|
||||
public void save()
|
||||
{
|
||||
target =
|
||||
context.getApi().getInfrastructureApi()
|
||||
.createStorageDevice(datacenter.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update storage device information in the server with the data from this device.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-Updateastoragedevice"
|
||||
* > http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-
|
||||
* Updateastoragedevice</a>
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
target = context.getApi().getInfrastructureApi().updateStorageDevice(target);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* Retrieve the datacenter where this storage device 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);
|
||||
DatacenterDto dto = context.getApi().getInfrastructureApi().getDatacenter(datacenterId);
|
||||
datacenter = wrap(context, Datacenter.class, dto);
|
||||
return datacenter;
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
/**
|
||||
* Retrieve the list of storage pools in this device (synchronized with the device).
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievestoragepools"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Retrievestoragepools</a>
|
||||
* @return Synchronized list of storage pools in this device.
|
||||
*/
|
||||
public List<StoragePool> listRemoteStoragePools()
|
||||
{
|
||||
StoragePoolsDto storagePools =
|
||||
context.getApi().getInfrastructureApi()
|
||||
.listStoragePools(target, StoragePoolOptions.builder().sync(true).build());
|
||||
|
||||
List<StoragePool> storagePoolList =
|
||||
wrap(context, StoragePool.class, storagePools.getCollection());
|
||||
|
||||
for (StoragePool storagePool : storagePoolList)
|
||||
{
|
||||
storagePool.storageDevice = this;
|
||||
}
|
||||
|
||||
return storagePoolList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of storage pools in this device (synchronized with the device).
|
||||
*
|
||||
* @param filter Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievestoragepools"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Retrievestoragepools</a>
|
||||
* @return Filtered synchronized list of storage pools in this device.
|
||||
*/
|
||||
public List<StoragePool> listRemoteStoragePools(final Predicate<StoragePool> filter)
|
||||
{
|
||||
return Lists.newLinkedList(filter(listRemoteStoragePools(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first storage pool matching the filter within the list of storage pools in this
|
||||
* device (synchronized with the device).
|
||||
*
|
||||
* @param filter Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievestoragepools"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Retrievestoragepools</a>
|
||||
* @return First storage pool (synchronized) matching the filter or <code>null</code> if there
|
||||
* is none.
|
||||
*/
|
||||
public StoragePool findRemoteStoragePool(final Predicate<StoragePool> filter)
|
||||
{
|
||||
return Iterables.getFirst(filter(listRemoteStoragePools(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of storage pools in this device from Abiquo database (may not be
|
||||
* synchronized with the device).
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievestoragepools"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Retrievestoragepools</a>
|
||||
* @return Unsynchronized list of storage pools in this device.
|
||||
*/
|
||||
public List<StoragePool> listStoragePools()
|
||||
{
|
||||
StoragePoolsDto storagePools =
|
||||
context.getApi().getInfrastructureApi()
|
||||
.listStoragePools(target, StoragePoolOptions.builder().sync(false).build());
|
||||
return wrap(context, StoragePool.class, storagePools.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of storage pools in this device from Abiquo database (may not be
|
||||
* synchronized with the device).
|
||||
*
|
||||
* @param filter Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievestoragepools"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Retrievestoragepools</a>
|
||||
* @return Filtered unsynchronized list of storage pools in this device.
|
||||
*/
|
||||
public List<StoragePool> listStoragePools(final Predicate<StoragePool> filter)
|
||||
{
|
||||
return Lists.newLinkedList(filter(listStoragePools(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first storage pool matching the filter within the list of storage pools in this
|
||||
* device (unsynchronized with the device).
|
||||
*
|
||||
* @param filter Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievestoragepools"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Retrievestoragepools</a>
|
||||
* @return First storage pool (unsynchronized) matching the filter or <code>null</code> if there
|
||||
* is none.
|
||||
*/
|
||||
public StoragePool findStoragePool(final Predicate<StoragePool> filter)
|
||||
{
|
||||
return Iterables.getFirst(filter(listStoragePools(), filter), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single storage pool in this device from Abiquo database.
|
||||
*
|
||||
* @param id Unique ID of the storage device in this datacenter.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievearegisteredpool"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Retrievearegisteredpool</a>
|
||||
* @return Storage pool with the given id or <code>null</code> if it does not exist.
|
||||
*/
|
||||
public StoragePool getStoragePool(final String id)
|
||||
{
|
||||
StoragePoolDto storagePool =
|
||||
context.getApi().getInfrastructureApi().getStoragePool(target, id);
|
||||
return wrap(context, StoragePool.class, storagePool);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of tiers in the datacenter using this device.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TierResource#TierResource-Retrievethelistoftiers"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/TierResource#TierResource-Retrievethelistoftiers
|
||||
* </a>
|
||||
* @return List of tiers in the datacenter using this device.
|
||||
*/
|
||||
public List<Tier> listTiersFromDatacenter()
|
||||
{
|
||||
DatacenterDto datacenter;
|
||||
|
||||
if (this.datacenter == null)
|
||||
{
|
||||
datacenter = new DatacenterDto();
|
||||
datacenter.setId(target.getIdFromLink(ParentLinkName.DATACENTER));
|
||||
}
|
||||
else
|
||||
{
|
||||
datacenter = this.getDatacenter().unwrap();
|
||||
}
|
||||
|
||||
TiersDto dto = context.getApi().getInfrastructureApi().listTiers(datacenter);
|
||||
return DomainWrapper.wrap(context, Tier.class, dto.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of tiers in the datacenter using this device.
|
||||
*
|
||||
* @param filter Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/TierResource#TierResource-Retrievethelistoftiers"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/TierResource#TierResource-Retrievethelistoftiers
|
||||
* </a>
|
||||
* @return Filtered list of tiers in the datacenter using this device.
|
||||
*/
|
||||
public List<Tier> listTiersFromDatacenter(final Predicate<Tier> filter)
|
||||
{
|
||||
return Lists.newLinkedList(filter(listTiersFromDatacenter(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first tier matching the filter within the list of tiers in the datacenter.
|
||||
*
|
||||
* @param filter Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-Retrievethelistofstoragedevices"
|
||||
* > http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-
|
||||
* Retrievethelistofstoragedevices</a>
|
||||
* @return First tier matching the filter or <code>null</code> if there is none.
|
||||
*/
|
||||
public Tier findTierInDatacenter(final Predicate<Tier> filter)
|
||||
{
|
||||
return Iterables.getFirst(filter(listTiersFromDatacenter(), filter), null);
|
||||
}
|
||||
|
||||
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 Datacenter datacenter;
|
||||
|
||||
private String iscsiIp;
|
||||
|
||||
private Integer iscsiPort;
|
||||
|
||||
private String managementIp;
|
||||
|
||||
private Integer managementPort;
|
||||
|
||||
private String name;
|
||||
|
||||
private String password;
|
||||
|
||||
private String type;
|
||||
|
||||
private String username;
|
||||
|
||||
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 iscsiIp(final String iscsiIp)
|
||||
{
|
||||
this.iscsiIp = iscsiIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder iscsiPort(final int iscsiPort)
|
||||
{
|
||||
this.iscsiPort = iscsiPort;
|
||||
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 managementPort(final int managementPort)
|
||||
{
|
||||
this.managementPort = managementPort;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder managementIp(final String managementIp)
|
||||
{
|
||||
this.managementIp = managementIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(final String type)
|
||||
{
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder username(final String username)
|
||||
{
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StorageDevice build()
|
||||
{
|
||||
StorageDeviceDto dto = new StorageDeviceDto();
|
||||
dto.setIscsiIp(iscsiIp);
|
||||
dto.setIscsiPort(iscsiPort);
|
||||
dto.setManagementIp(managementIp);
|
||||
dto.setManagementPort(managementPort);
|
||||
dto.setName(name);
|
||||
dto.setPassword(password);
|
||||
dto.setStorageTechnology(type);
|
||||
dto.setUsername(username);
|
||||
StorageDevice storageDevice = new StorageDevice(context, dto);
|
||||
storageDevice.datacenter = datacenter;
|
||||
return storageDevice;
|
||||
}
|
||||
|
||||
public static Builder fromStorageDevice(final StorageDevice in)
|
||||
{
|
||||
Builder builder =
|
||||
StorageDevice.builder(in.context, in.getDatacenter()).iscsiIp(in.getIscsiIp())
|
||||
.iscsiPort(in.getIscsiPort()).managementIp(in.getManagementIp())
|
||||
.managementPort(in.getManagementPort()).name(in.getName())
|
||||
.password(in.getPassword()).type(in.getType()).username(in.getUsername());
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId()
|
||||
{
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getIscsiIp()
|
||||
{
|
||||
return target.getIscsiIp();
|
||||
}
|
||||
|
||||
public int getIscsiPort()
|
||||
{
|
||||
return target.getIscsiPort();
|
||||
}
|
||||
|
||||
public String getManagementIp()
|
||||
{
|
||||
return target.getManagementIp();
|
||||
}
|
||||
|
||||
public int getManagementPort()
|
||||
{
|
||||
return target.getManagementPort();
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
return target.getPassword();
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return target.getStorageTechnology();
|
||||
}
|
||||
|
||||
public String getUsername()
|
||||
{
|
||||
return target.getUsername();
|
||||
}
|
||||
|
||||
public void setIscsiIp(final String iscsiIp)
|
||||
{
|
||||
target.setIscsiIp(iscsiIp);
|
||||
}
|
||||
|
||||
public void setIscsiPort(final int iscsiPort)
|
||||
{
|
||||
target.setIscsiPort(iscsiPort);
|
||||
}
|
||||
|
||||
public void setManagementIp(final String managementIp)
|
||||
{
|
||||
target.setManagementIp(managementIp);
|
||||
}
|
||||
|
||||
public void setManagementPort(final int managementPort)
|
||||
{
|
||||
target.setManagementPort(managementPort);
|
||||
}
|
||||
|
||||
public void setName(final String name)
|
||||
{
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public void setPassword(final String password)
|
||||
{
|
||||
target.setPassword(password);
|
||||
}
|
||||
|
||||
public void setType(final String type)
|
||||
{
|
||||
target.setStorageTechnology(type);
|
||||
}
|
||||
|
||||
public void setUsername(final String username)
|
||||
{
|
||||
target.setUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "StorageDevice [id=" + getId() + ", iscsiIp=" + getIscsiIp() + ", iscsiPort="
|
||||
+ getIscsiPort() + ", managementIp=" + getManagementIp() + ", managementPort="
|
||||
+ getManagementPort() + ", name=" + getName() + ", password=" + getPassword()
|
||||
+ ", type=" + getType() + ", user=" + getUsername() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.storage.StorageDeviceMetadataDto;
|
||||
|
||||
/**
|
||||
* metadata describing a Storage Device.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class StorageDeviceMetadata extends DomainWrapper<StorageDeviceMetadataDto>
|
||||
{
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected StorageDeviceMetadata(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final StorageDeviceMetadataDto target)
|
||||
{
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return target.getType();
|
||||
}
|
||||
|
||||
public int getDefaultManagementPort()
|
||||
{
|
||||
return target.getDefaultManagementPort();
|
||||
}
|
||||
|
||||
public int getDefaultIscsiPort()
|
||||
{
|
||||
return target.getDefaultIscsiPort();
|
||||
}
|
||||
|
||||
public boolean requiresAuthentication()
|
||||
{
|
||||
return target.isRequiresAuthentication();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,376 @@
|
|||
/**
|
||||
* 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.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.domain.DomainWrapper;
|
||||
import org.jclouds.abiquo.domain.config.Privilege;
|
||||
import org.jclouds.abiquo.domain.infrastructure.options.StoragePoolOptions;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
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.storage.StorageDeviceDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.StoragePoolDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.TierDto;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link StoragePoolDto}. The Storage Pool Resource allows you to
|
||||
* perform any administrative task for remote pools.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/StoragePoolResource">
|
||||
* http://community.abiquo.com/display/ABI20/StoragePoolResource</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class StoragePool extends DomainWrapper<StoragePoolDto>
|
||||
{
|
||||
/** The default value for the used space. */
|
||||
private static final long DEFAULT_USED_SIZE = 0;
|
||||
|
||||
/** The datacenter where the storage device is. */
|
||||
// Package protected to allow the storage device to be set automatically when discovering the
|
||||
// pools in a device.
|
||||
StorageDevice storageDevice;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected StoragePool(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final StoragePoolDto target)
|
||||
{
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* Delete the storage pool.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Deleteastoragepool"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Deleteastoragepool</a>
|
||||
*/
|
||||
public void delete()
|
||||
{
|
||||
context.getApi().getInfrastructureApi().deleteStoragePool(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a storage pool. Create a storage pool means registering an existing storage pool
|
||||
* obtained from {@link StorageDevice#listRemoteStoragePools} method and saving it. The Storage
|
||||
* Pools must be associated with a Tier using {@link #setTier}.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Createastoragepoolwithatierlink"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Createastoragepoolwithatierlink</a>
|
||||
*/
|
||||
public void save()
|
||||
{
|
||||
target =
|
||||
context.getApi().getInfrastructureApi()
|
||||
.createStoragePool(storageDevice.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update pool information in the server with the data from this pool. Storage pool parameters
|
||||
* cannot be updated by a user, so the parameters are only a representation of the remote pool.
|
||||
* Although the whole storage pool entity is sent to the API in the update call, the only thing
|
||||
* a user can change is the tier that the pool belongs to by calling {@link #setTier}.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Storage+Pool+Resource#StoragePoolResource-UpdateaStoragePool"
|
||||
* > http://community.abiquo.com/display/ABI20/Storage+Pool+Resource#StoragePoolResource-
|
||||
* UpdateaStoragePool</a>
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
target = context.getApi().getInfrastructureApi().updateStoragePool(target);
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
{
|
||||
target =
|
||||
context.getApi().getInfrastructureApi()
|
||||
.refreshStoragePool(target, StoragePoolOptions.builder().sync(true).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the tier in which the pool will be added.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Createastoragepoolwithatierlink"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Createastoragepoolwithatierlink</a>
|
||||
*/
|
||||
public void setTier(final Tier tier)
|
||||
{
|
||||
checkNotNull(tier, ValidationErrors.NULL_RESOURCE + Privilege.class);
|
||||
checkNotNull(tier.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + Tier.class);
|
||||
|
||||
this.updateLink(target, ParentLinkName.TIER, tier.unwrap(), "edit");
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* Get the device where the pool belongs.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-Retrieveastoragedevice"
|
||||
* > http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-
|
||||
* Retrieveastoragedevice</a>
|
||||
*/
|
||||
public StorageDevice getStorageDevice()
|
||||
{
|
||||
RESTLink link =
|
||||
checkNotNull(target.searchLink(ParentLinkName.STORAGE_DEVICE),
|
||||
ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.STORAGE_DEVICE);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<StorageDeviceDto> parser =
|
||||
new ParseXMLWithJAXB<StorageDeviceDto>(utils.getXml(),
|
||||
TypeLiteral.get(StorageDeviceDto.class));
|
||||
|
||||
return wrap(context, StorageDevice.class, parser.apply(response));
|
||||
}
|
||||
|
||||
// Children access
|
||||
|
||||
/**
|
||||
* Get the tier assigned to the pool. The storage pool needs to be persisted in Abiquo first.
|
||||
*
|
||||
* @return The tier assinged to this storage pool.
|
||||
*/
|
||||
public Tier getTier()
|
||||
{
|
||||
RESTLink link =
|
||||
checkNotNull(target.searchLink(ParentLinkName.TIER),
|
||||
ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.TIER);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<TierDto> parser =
|
||||
new ParseXMLWithJAXB<TierDto>(utils.getXml(), TypeLiteral.get(TierDto.class));
|
||||
|
||||
return wrap(context, Tier.class, parser.apply(response));
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final StorageDevice storageDevice)
|
||||
{
|
||||
return new Builder(context, storageDevice);
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private RestContext<AbiquoApi, AbiquoAsyncApi> context;
|
||||
|
||||
private StorageDevice storageDevice;
|
||||
|
||||
private Long availableSizeInMb;
|
||||
|
||||
// The enabled flag is still not used. It will be added when Abiquo includes anstorage
|
||||
// allocator
|
||||
|
||||
// private Boolean enabled;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long totalSizeInMb;
|
||||
|
||||
private Long usedSizeInMb = DEFAULT_USED_SIZE;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final StorageDevice storageDevice)
|
||||
{
|
||||
super();
|
||||
checkNotNull(storageDevice, ValidationErrors.NULL_RESOURCE + StorageDevice.class);
|
||||
this.storageDevice = storageDevice;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder storageDevice(final StorageDevice storageDevice)
|
||||
{
|
||||
checkNotNull(storageDevice, ValidationErrors.NULL_RESOURCE + StorageDevice.class);
|
||||
this.storageDevice = storageDevice;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This value is no longer used in Abiquo and will be removed in future
|
||||
* versions.
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder availableSizeInMb(final long availableSizeInMb)
|
||||
{
|
||||
this.availableSizeInMb = availableSizeInMb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(final String name)
|
||||
{
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
// The enabled flag is still not used. It will be added when Abiquo includes anstorage
|
||||
// allocator
|
||||
|
||||
// public Builder enabled(final boolean enabled)
|
||||
// {
|
||||
// this.enabled = enabled;
|
||||
// return this;
|
||||
// }
|
||||
|
||||
public Builder totalSizeInMb(final long totalSizeInMb)
|
||||
{
|
||||
this.totalSizeInMb = totalSizeInMb;
|
||||
if (availableSizeInMb == null)
|
||||
{
|
||||
availableSizeInMb = totalSizeInMb;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This value is no longer used in Abiquo and will be removed in future
|
||||
* versions.
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder usedSizeInMb(final long usedSizeInMb)
|
||||
{
|
||||
this.usedSizeInMb = usedSizeInMb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StoragePool build()
|
||||
{
|
||||
StoragePoolDto dto = new StoragePoolDto();
|
||||
dto.setAvailableSizeInMb(availableSizeInMb);
|
||||
|
||||
// The enabled flag is still not used. It will be added when Abiquo includes anstorage
|
||||
// allocator
|
||||
// dto.setEnabled(enabled);
|
||||
|
||||
dto.setName(name);
|
||||
dto.setTotalSizeInMb(totalSizeInMb);
|
||||
dto.setUsedSizeInMb(usedSizeInMb);
|
||||
StoragePool storagePool = new StoragePool(context, dto);
|
||||
storagePool.storageDevice = storageDevice;
|
||||
return storagePool;
|
||||
}
|
||||
|
||||
public static Builder fromStoragePool(final StoragePool in)
|
||||
{
|
||||
Builder builder =
|
||||
StoragePool.builder(in.context, in.getStorageDevice())
|
||||
.availableSizeInMb(in.getAvailableSizeInMb())/* .enabled(in.getEnabled()) */
|
||||
.totalSizeInMb(in.getTotalSizeInMb()).usedSizeInMb(in.getUsedSizeInMb());
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
/**
|
||||
* @deprecated This value is no longer used in Abiquo and will be removed in future versions.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getAvailableSizeInMb()
|
||||
{
|
||||
return target.getAvailableSizeInMb();
|
||||
}
|
||||
|
||||
// The enabled flag is still not used. It will be added when Abiquo includes anstorage
|
||||
// allocator
|
||||
|
||||
// public boolean getEnabled()
|
||||
// {
|
||||
// return target.getEnabled();
|
||||
// }
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public long getTotalSizeInMb()
|
||||
{
|
||||
return target.getTotalSizeInMb();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This value is no longer used in Abiquo and will be removed in future versions.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getUsedSizeInMb()
|
||||
{
|
||||
return target.getUsedSizeInMb();
|
||||
}
|
||||
|
||||
// The enabled flag is still not used. It will be added when Abiquo includes anstorage
|
||||
// allocator
|
||||
|
||||
// public void setEnabled(final boolean enabled)
|
||||
// {
|
||||
// target.setEnabled(enabled);
|
||||
// }
|
||||
|
||||
public void setName(final String name)
|
||||
{
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
public void setTotalSizeInMb(final long totalSizeInMb)
|
||||
{
|
||||
target.setTotalSizeInMb(totalSizeInMb);
|
||||
}
|
||||
|
||||
// Readonly property
|
||||
public String getUUID()
|
||||
{
|
||||
return target.getIdStorage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "StoragePool [name=" + getName() + ", totalSizeInMb=" + getTotalSizeInMb()
|
||||
+ ", uuid=" + getUUID() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
/**
|
||||
* 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.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.abiquo.reference.rest.ParentLinkName;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.DatacenterDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.StoragePoolsDto;
|
||||
import com.abiquo.server.core.infrastructure.storage.TierDto;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to {@link TierDto}. The Tier Resource offers the functionality of
|
||||
* managing the logic of QoS volume management. These are only logical levels of QoS and the real
|
||||
* QoS (networking speed, volume replication, availability) must be configured manually in the
|
||||
* infrastructure.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/TierResource">
|
||||
* http://community.abiquo.com/display/ABI20/TierResource</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class Tier extends DomainWrapper<TierDto>
|
||||
{
|
||||
/** The datacenter where the tier belongs. */
|
||||
private Datacenter datacenter;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Tier(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final TierDto target)
|
||||
{
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
/**
|
||||
* Update tier information in the server with the data from this tier.
|
||||
*
|
||||
* @see API: <a
|
||||
* href="http://community.abiquo.com/display/ABI20/TierResource#TierResource-Updateatier">
|
||||
* http://community.abiquo.com/display/ABI20/TierResource#TierResource-Updateatier</a>
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
target = context.getApi().getInfrastructureApi().updateTier(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list of storage pools in this tier.
|
||||
*
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievestoragepools"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Retrievestoragepools</a>
|
||||
* @return List of storage pools in this tier.
|
||||
*/
|
||||
public List<StoragePool> listStoragePools()
|
||||
{
|
||||
StoragePoolsDto storagePools =
|
||||
context.getApi().getInfrastructureApi().listStoragePools(target);
|
||||
return wrap(context, StoragePool.class, storagePools.getCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a filtered list of storage pools in this tier.
|
||||
*
|
||||
* @param filter Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievestoragepools"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Retrievestoragepools</a>
|
||||
* @return Filtered list of storage pools in this tier.
|
||||
*/
|
||||
public List<StoragePool> listStoragePools(final Predicate<StoragePool> filter)
|
||||
{
|
||||
return Lists.newLinkedList(filter(listStoragePools(), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first storage pool matching the filter within the list of pools in this tier.
|
||||
*
|
||||
* @param filter Filter to be applied to the list.
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievestoragepools"
|
||||
* > http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-
|
||||
* Retrievestoragepools</a>
|
||||
* @return First storage pool matching the filter or <code>null</code> if there is none.
|
||||
*/
|
||||
public StoragePool findStoragePool(final Predicate<StoragePool> filter)
|
||||
{
|
||||
return Iterables.getFirst(filter(listStoragePools(), filter), null);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
/**
|
||||
* Retrieve the datacenter where this tier 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);
|
||||
DatacenterDto dto = context.getApi().getInfrastructureApi().getDatacenter(datacenterId);
|
||||
datacenter = wrap(context, Datacenter.class, dto);
|
||||
return datacenter;
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return target.getDescription();
|
||||
}
|
||||
|
||||
public boolean getEnabled()
|
||||
{
|
||||
return target.getEnabled();
|
||||
}
|
||||
|
||||
public Integer getId()
|
||||
{
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public void setDescription(final String description)
|
||||
{
|
||||
target.setDescription(description);
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean enabled)
|
||||
{
|
||||
target.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void setName(final String name)
|
||||
{
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Tier [id=" + getId() + ", description=" + getDescription() + ", enabled="
|
||||
+ getEnabled() + ", name=" + getName() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* 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.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query datacenters.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class DatacenterOptions extends BaseHttpRequestOptions
|
||||
{
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException
|
||||
{
|
||||
DatacenterOptions options = new DatacenterOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private String ip;
|
||||
|
||||
public Builder ip(final String ip)
|
||||
{
|
||||
this.ip = ip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DatacenterOptions build()
|
||||
{
|
||||
DatacenterOptions options = new DatacenterOptions();
|
||||
if (ip != null)
|
||||
{
|
||||
options.queryParameters.put("ip", ip);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* 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.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query ipmi config.
|
||||
*
|
||||
* @author scastro
|
||||
*/
|
||||
public class IpmiOptions extends BaseHttpRequestOptions
|
||||
{
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException
|
||||
{
|
||||
IpmiOptions options = new IpmiOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* Set the optional hypervisor port.
|
||||
*/
|
||||
public Builder port(final int port)
|
||||
{
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IpmiOptions build()
|
||||
{
|
||||
IpmiOptions options = new IpmiOptions();
|
||||
if (port != null)
|
||||
{
|
||||
options.queryParameters.put("port", port.toString());
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* 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.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query machines.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class MachineOptions extends BaseHttpRequestOptions
|
||||
{
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException
|
||||
{
|
||||
MachineOptions options = new MachineOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private Integer port;
|
||||
|
||||
private Boolean sync;
|
||||
|
||||
/**
|
||||
* Set the optional hypervisor port.
|
||||
*/
|
||||
public Builder port(final int port)
|
||||
{
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the optional sync param.
|
||||
*/
|
||||
public Builder sync(final boolean sync)
|
||||
{
|
||||
this.sync = sync;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MachineOptions build()
|
||||
{
|
||||
MachineOptions options = new MachineOptions();
|
||||
if (port != null)
|
||||
{
|
||||
options.queryParameters.put("port", port.toString());
|
||||
}
|
||||
|
||||
if (sync != null)
|
||||
{
|
||||
options.queryParameters.put("sync", sync.toString());
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/**
|
||||
* 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.options;
|
||||
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Available options to query storage pools.
|
||||
*
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
|
||||
@EnterpriseEdition
|
||||
public class StoragePoolOptions extends BaseHttpRequestOptions
|
||||
{
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException
|
||||
{
|
||||
StoragePoolOptions options = new StoragePoolOptions();
|
||||
options.queryParameters.putAll(queryParameters);
|
||||
return options;
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private Boolean sync;
|
||||
|
||||
/**
|
||||
* Set the optional sync param.
|
||||
*/
|
||||
public Builder sync(final boolean sync)
|
||||
{
|
||||
this.sync = sync;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StoragePoolOptions build()
|
||||
{
|
||||
StoragePoolOptions options = new StoragePoolOptions();
|
||||
if (sync != null)
|
||||
{
|
||||
options.queryParameters.put("sync", sync.toString());
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* 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.network;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.abiquo.server.core.infrastructure.network.AbstractInfrastructureIpDto;
|
||||
|
||||
/**
|
||||
* Adds generic high level functionality to {@link AbstractInfrastructureIpDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public abstract class AbstractPublicIp<T extends AbstractInfrastructureIpDto, N extends Network< ? >>
|
||||
extends Ip<T, N>
|
||||
{
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected AbstractPublicIp(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final T target)
|
||||
{
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public boolean isAvailable()
|
||||
{
|
||||
return target.isAvailable();
|
||||
}
|
||||
|
||||
public boolean isQuarantine()
|
||||
{
|
||||
return target.isQuarantine();
|
||||
}
|
||||
|
||||
public void setAvailable(final boolean available)
|
||||
{
|
||||
target.setAvailable(available);
|
||||
}
|
||||
|
||||
public void setQuarantine(final boolean quarantine)
|
||||
{
|
||||
target.setQuarantine(quarantine);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* 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.network;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
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.NetworkType;
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.infrastructure.network.ExternalIpDto;
|
||||
import com.abiquo.server.core.infrastructure.network.VLANNetworkDto;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Adds generic high level functionality to {@link ExternalIpDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public class ExternalIp extends AbstractPublicIp<ExternalIpDto, ExternalNetwork>
|
||||
{
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected ExternalIp(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final ExternalIpDto target)
|
||||
{
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
@Override
|
||||
public ExternalNetwork getNetwork()
|
||||
{
|
||||
RESTLink link =
|
||||
checkNotNull(target.searchLink(ParentLinkName.EXTERNAL_NETWORK),
|
||||
ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.EXTERNAL_NETWORK);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<VLANNetworkDto> parser =
|
||||
new ParseXMLWithJAXB<VLANNetworkDto>(utils.getXml(),
|
||||
TypeLiteral.get(VLANNetworkDto.class));
|
||||
|
||||
return wrap(context, ExternalNetwork.class, parser.apply(response));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkType getNetworkType()
|
||||
{
|
||||
return NetworkType.EXTERNAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "ExternalIp [networkType=" + getNetworkType() + ", available=" + isAvailable()
|
||||
+ ", quarantine=" + isQuarantine() + ", id=" + getId() + ", ip=" + getIp() + ", mac="
|
||||
+ getMac() + ", name=" + getName() + ", networkName=" + getNetworkName() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,259 @@
|
|||
/**
|
||||
* 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.network;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.abiquo.AbiquoAsyncApi;
|
||||
import org.jclouds.abiquo.AbiquoApi;
|
||||
import org.jclouds.abiquo.domain.enterprise.Enterprise;
|
||||
import org.jclouds.abiquo.domain.infrastructure.Datacenter;
|
||||
import org.jclouds.abiquo.domain.network.options.IpOptions;
|
||||
import org.jclouds.abiquo.reference.ValidationErrors;
|
||||
import org.jclouds.abiquo.reference.annotations.EnterpriseEdition;
|
||||
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.NetworkType;
|
||||
import com.abiquo.model.rest.RESTLink;
|
||||
import com.abiquo.server.core.enterprise.EnterpriseDto;
|
||||
import com.abiquo.server.core.infrastructure.DatacenterDto;
|
||||
import com.abiquo.server.core.infrastructure.network.ExternalIpDto;
|
||||
import com.abiquo.server.core.infrastructure.network.ExternalIpsDto;
|
||||
import com.abiquo.server.core.infrastructure.network.VLANNetworkDto;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Adds high level functionality to external {@link VLANNetworkDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
* @see API: <a href="http://community.abiquo.com/display/ABI20/Public+Network+Resource">
|
||||
* http://community.abiquo.com/display/ABI20/Public+Network+Resource</a>
|
||||
*/
|
||||
@EnterpriseEdition
|
||||
public class ExternalNetwork extends Network<ExternalIp>
|
||||
{
|
||||
/** The datacenter where the network belongs. */
|
||||
private Datacenter datacenter;
|
||||
|
||||
/** The enterprise where the network belongs. */
|
||||
private Enterprise enterprise;
|
||||
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected ExternalNetwork(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final VLANNetworkDto target)
|
||||
{
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource-DeleteanExternalNetwork"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource
|
||||
* -DeleteanExternalNetwork</a>
|
||||
*/
|
||||
@Override
|
||||
public void delete()
|
||||
{
|
||||
context.getApi().getInfrastructureApi().deleteNetwork(target);
|
||||
target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource-CreateanewExternalNetwork"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource
|
||||
* -CreateanewExternalNetwork</a>
|
||||
*/
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
this.addEnterpriseLink();
|
||||
target =
|
||||
context.getApi().getInfrastructureApi().createNetwork(datacenter.unwrap(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* " http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource-UpdateanExternalNetwork"
|
||||
* >
|
||||
* http://community.abiquo.com/display/ABI20/Public+Network+Resource#PublicNetworkResource
|
||||
* -UpdateanExternalNetwork</a>
|
||||
*/
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
target = context.getApi().getInfrastructureApi().updateNetwork(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see API: <a href=
|
||||
* "http://community.abiquo.com/display/ABI20/Public+IPs+Resource#PublicIPsResource-ReturnthelistofIPsforaPublicNetwork"
|
||||
* > http://community.abiquo.com/display/ABI20/Public+IPs+Resource#PublicIPsResource-
|
||||
* ReturnthelistofIPsforaPublicNetwork</a>
|
||||
*/
|
||||
@Override
|
||||
public List<ExternalIp> listIps(final IpOptions options)
|
||||
{
|
||||
ExternalIpsDto ips =
|
||||
context.getApi().getInfrastructureApi().listExternalIps(target, options);
|
||||
return wrap(context, ExternalIp.class, ips.getCollection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalIp getIp(final Integer id)
|
||||
{
|
||||
ExternalIpDto ip = context.getApi().getInfrastructureApi().getExternalIp(target, id);
|
||||
return wrap(context, ExternalIp.class, ip);
|
||||
}
|
||||
|
||||
// Parent access
|
||||
|
||||
public Enterprise getEnterprise()
|
||||
{
|
||||
RESTLink link =
|
||||
checkNotNull(target.searchLink(ParentLinkName.ENTERPRISE),
|
||||
ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.ENTERPRISE);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<EnterpriseDto> parser =
|
||||
new ParseXMLWithJAXB<EnterpriseDto>(utils.getXml(),
|
||||
TypeLiteral.get(EnterpriseDto.class));
|
||||
|
||||
enterprise = wrap(context, Enterprise.class, parser.apply(response));
|
||||
return enterprise;
|
||||
}
|
||||
|
||||
public Datacenter getDatacenter()
|
||||
{
|
||||
RESTLink link =
|
||||
checkNotNull(target.searchLink(ParentLinkName.DATACENTER),
|
||||
ValidationErrors.MISSING_REQUIRED_LINK + " " + ParentLinkName.DATACENTER);
|
||||
|
||||
ExtendedUtils utils = (ExtendedUtils) context.getUtils();
|
||||
HttpResponse response = utils.getAbiquoHttpClient().get(link);
|
||||
|
||||
ParseXMLWithJAXB<DatacenterDto> parser =
|
||||
new ParseXMLWithJAXB<DatacenterDto>(utils.getXml(),
|
||||
TypeLiteral.get(DatacenterDto.class));
|
||||
|
||||
datacenter = wrap(context, Datacenter.class, parser.apply(response));
|
||||
return datacenter;
|
||||
}
|
||||
|
||||
private void addEnterpriseLink()
|
||||
{
|
||||
checkNotNull(enterprise, ValidationErrors.NULL_RESOURCE + Enterprise.class);
|
||||
checkNotNull(enterprise.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in "
|
||||
+ Enterprise.class);
|
||||
|
||||
RESTLink link = enterprise.unwrap().getEditLink();
|
||||
checkNotNull(link, ValidationErrors.MISSING_REQUIRED_LINK);
|
||||
|
||||
target.addLink(new RESTLink("enterprise", link.getHref()));
|
||||
}
|
||||
|
||||
// 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 NetworkBuilder<Builder>
|
||||
{
|
||||
private Datacenter datacenter;
|
||||
|
||||
private Enterprise enterprise;
|
||||
|
||||
public Builder(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
|
||||
final Datacenter datacenter, final Enterprise enterprise)
|
||||
{
|
||||
super(context);
|
||||
checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Datacenter.class);
|
||||
checkNotNull(datacenter, ValidationErrors.NULL_RESOURCE + Enterprise.class);
|
||||
this.datacenter = datacenter;
|
||||
this.enterprise = enterprise;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Builder datacenter(final Datacenter datacenter)
|
||||
{
|
||||
this.datacenter = datacenter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder enterprise(final Enterprise enterprise)
|
||||
{
|
||||
this.enterprise = enterprise;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExternalNetwork build()
|
||||
{
|
||||
VLANNetworkDto dto = new VLANNetworkDto();
|
||||
dto.setName(name);
|
||||
dto.setTag(tag);
|
||||
dto.setGateway(gateway);
|
||||
dto.setAddress(address);
|
||||
dto.setMask(mask);
|
||||
dto.setPrimaryDNS(primaryDNS);
|
||||
dto.setSecondaryDNS(secondaryDNS);
|
||||
dto.setSufixDNS(sufixDNS);
|
||||
dto.setDefaultNetwork(defaultNetwork == null ? Boolean.FALSE : defaultNetwork);
|
||||
dto.setUnmanaged(Boolean.FALSE);
|
||||
dto.setType(NetworkType.EXTERNAL);
|
||||
|
||||
ExternalNetwork network = new ExternalNetwork(context, dto);
|
||||
network.datacenter = datacenter;
|
||||
network.enterprise = enterprise;
|
||||
|
||||
return network;
|
||||
}
|
||||
|
||||
public static Builder fromExternalNetwork(final ExternalNetwork in)
|
||||
{
|
||||
return ExternalNetwork.builder(in.context, in.datacenter, in.enterprise)
|
||||
.name(in.getName()).tag(in.getTag()).gateway(in.getGateway())
|
||||
.address(in.getAddress()).mask(in.getMask()).primaryDNS(in.getPrimaryDNS())
|
||||
.secondaryDNS(in.getSecondaryDNS()).sufixDNS(in.getSufixDNS())
|
||||
.defaultNetwork(in.getDefaultNetwork());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "External " + super.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* 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.network;
|
||||
|
||||
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.NetworkType;
|
||||
import com.abiquo.server.core.infrastructure.network.AbstractIpDto;
|
||||
|
||||
/**
|
||||
* Adds generic high level functionality to {@link AbstractIpDto}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @author Francesc Montserrat
|
||||
*/
|
||||
public abstract class Ip<T extends AbstractIpDto, N extends Network< ? >> extends DomainWrapper<T>
|
||||
{
|
||||
/**
|
||||
* Constructor to be used only by the builder.
|
||||
*/
|
||||
protected Ip(final RestContext<AbiquoApi, AbiquoAsyncApi> context, final T target)
|
||||
{
|
||||
super(context, target);
|
||||
}
|
||||
|
||||
// Domain operations
|
||||
|
||||
public abstract N getNetwork();
|
||||
|
||||
public abstract NetworkType getNetworkType();
|
||||
|
||||
// Delegate methods
|
||||
|
||||
public Integer getId()
|
||||
{
|
||||
return target.getId();
|
||||
}
|
||||
|
||||
public String getIp()
|
||||
{
|
||||
return target.getIp();
|
||||
}
|
||||
|
||||
public String getMac()
|
||||
{
|
||||
return target.getMac();
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public String getNetworkName()
|
||||
{
|
||||
return target.getNetworkName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Ip [id=" + getId() + ", ip=" + getIp() + ", mac=" + getMac() + ", name="
|
||||
+ getName() + ", networkName=" + getNetworkName() + "]";
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue