JCLOUDS-780 Remove vcloud.

This commit is contained in:
Adrian Cole 2014-11-16 21:55:50 -08:00
parent 054189d009
commit 6f974f34b5
330 changed files with 10 additions and 30391 deletions

View File

@ -68,11 +68,6 @@
<artifactId>cloudservers</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds.api</groupId>
<artifactId>vcloud</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds.provider</groupId>
<artifactId>gogrid</artifactId>

View File

@ -57,7 +57,7 @@ Here are the properties:
* group - primary group of the machine. ex. hadoop
* tags - optional; list of arbitrary tags.
* note this list is not yet in jclouds NodeMetadata
* username - primary login user. ex. ubuntu, vcloud, toor, root
* username - primary login user. ex. ubuntu, toor, root
* sudo_password - optional; when a script is run with the "runAsRoot" option true, yet the
username is not root, a sudo command is invoked. If sudo_password
is set, the contents will be passed to sudo -S.

View File

@ -36,7 +36,6 @@
<module>s3</module>
<module>ec2</module>
<module>sqs</module>
<module>vcloud</module>
<module>elasticstack</module>
<module>atmos</module>
<module>swift</module>

View File

@ -1,6 +0,0 @@
#
# The jclouds API for VMware vCloud (http://www.vmware.com/products/vcloud/).
#
# TODO: Implementation status.
# TODO: Supported features.
# TODO: Usage example.

View File

@ -1,128 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF 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.
-->
<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.apache.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.apache.jclouds.api</groupId>
<artifactId>vcloud</artifactId>
<name>jclouds vcloud api</name>
<description>jclouds components to access an implementation of VMWare vCloud</description>
<packaging>bundle</packaging>
<properties>
<test.vcloud.endpoint>FIXME_ENDPOINT</test.vcloud.endpoint>
<test.vcloud.api-version>1.0</test.vcloud.api-version>
<test.vcloud.build-version />
<test.vcloud.identity>FIXME_IDENTITY</test.vcloud.identity>
<test.vcloud.credential>FIXME_CREDENTIAL</test.vcloud.credential>
<test.vcloud.template />
<jclouds.osgi.export>org.jclouds.vcloud*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}",
org.jclouds.rest.internal;version="${project.version}",
org.jclouds*;version="${project.version}",
*
</jclouds.osgi.import>
</properties>
<dependencies>
<dependency>
<groupId>com.jamesmurty.utils</groupId>
<artifactId>java-xmlbuilder</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<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.vcloud.endpoint>${test.vcloud.endpoint}</test.vcloud.endpoint>
<test.vcloud.api-version>${test.vcloud.api-version}</test.vcloud.api-version>
<test.vcloud.build-version>${test.vcloud.build-version}</test.vcloud.build-version>
<test.vcloud.identity>${test.vcloud.identity}</test.vcloud.identity>
<test.vcloud.credential>${test.vcloud.credential}</test.vcloud.credential>
<test.vcloud.template>${test.vcloud.template}</test.vcloud.template>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -1,34 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud;
import org.jclouds.vcloud.domain.Task;
public class TaskInErrorStateException extends RuntimeException {
private final Task task;
public TaskInErrorStateException(Task task) {
super("error on task: " + task + " error: " + task.getError());
this.task = task;
}
public Task getTask() {
return task;
}
}

View File

@ -1,34 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud;
import org.jclouds.vcloud.domain.Task;
public class TaskStillRunningException extends RuntimeException {
private final Task task;
public TaskStillRunningException(Task task) {
super("task still running: " + task);
this.task = task;
}
public Task getTask() {
return task;
}
}

View File

@ -1,90 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud;
import java.io.Closeable;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.vcloud.features.CatalogApi;
import org.jclouds.vcloud.features.NetworkApi;
import org.jclouds.vcloud.features.OrgApi;
import org.jclouds.vcloud.features.TaskApi;
import org.jclouds.vcloud.features.VAppApi;
import org.jclouds.vcloud.features.VAppTemplateApi;
import org.jclouds.vcloud.features.VDCApi;
import org.jclouds.vcloud.features.VmApi;
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="http://communities.vmware.com/community/developer/forums/vcloudapi" />
*/
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public interface VCloudApi extends Closeable {
/**
* Provides asynchronous access to VApp Template features.
*
*/
@Delegate
VAppTemplateApi getVAppTemplateApi();
/**
* Provides synchronous access to VApp features.
*/
@Delegate
VAppApi getVAppApi();
/**
* Provides synchronous access to Vm features.
*/
@Delegate
VmApi getVmApi();
/**
* Provides synchronous access to Catalog features.
*/
@Delegate
CatalogApi getCatalogApi();
/**
* Provides synchronous access to Task features.
*/
@Delegate
TaskApi getTaskApi();
/**
* Provides synchronous access to VDC features.
*/
@Delegate
VDCApi getVDCApi();
/**
* Provides synchronous access to Network features.
*/
@Delegate
NetworkApi getNetworkApi();
/**
* Provides synchronous access to Org features.
*/
@Delegate
OrgApi getOrgApi();
}

View File

@ -1,101 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
import static org.jclouds.reflect.Reflection2.typeToken;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.net.URI;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.rest.internal.BaseHttpApiMetadata;
import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule;
import org.jclouds.vcloud.config.VCloudHttpApiModule;
import org.jclouds.vcloud.domain.network.FenceMode;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Implementation of {@link ApiMetadata} for VCloud 1.0 API
*/
public class VCloudApiMetadata extends BaseHttpApiMetadata<VCloudApi> {
@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
}
public VCloudApiMetadata() {
this(new Builder());
}
protected VCloudApiMetadata(Builder builder) {
super(builder);
}
public static Properties defaultProperties() {
Properties properties = BaseHttpApiMetadata.defaultProperties();
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1");
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE,
String.format("http://www.vmware.com/vcloud/v${%s}", PROPERTY_VCLOUD_VERSION_SCHEMA));
properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + "");
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
properties.setProperty("jclouds.dns_name_length_min", "1");
properties.setProperty("jclouds.dns_name_length_max", "80");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString());
// TODO integrate this with the {@link ComputeTimeouts} instead of having
// a single timeout for
// everything.
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 1200l * 1000l + "");
properties.setProperty(PROPERTY_SESSION_INTERVAL, 300 + "");
// CIM ostype does not include version info
properties.setProperty(TEMPLATE, "osFamily=UBUNTU,os64Bit=true");
return properties;
}
public static class Builder extends BaseHttpApiMetadata.Builder<VCloudApi, Builder> {
protected Builder() {
id("vcloud")
.name("VCloud 1.0 API")
.identityName("User at Organization (user@org)")
.credentialName("Password")
.documentation(URI.create("http://www.vmware.com/support/pubs/vcd_pubs.html"))
.version("1.0")
.defaultProperties(VCloudApiMetadata.defaultProperties())
.view(typeToken(ComputeServiceContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(VCloudHttpApiModule.class, VCloudComputeServiceContextModule.class));
}
@Override
public VCloudApiMetadata build() {
return new VCloudApiMetadata(this);
}
@Override
protected Builder self() {
return this;
}
}
}

View File

@ -1,215 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud;
import javax.ws.rs.core.MediaType;
/**
* Resource Types used in VCloud
*
* @see MediaType
*/
public final class VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.error+xml"
*/
public static final String ERROR_XML = "application/vnd.vmware.vcloud.error+xml";
/**
* "application/vnd.vmware.vcloud.error+xml"
*/
public static final MediaType ERROR_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.error+xml");
/**
* "application/vnd.vmware.vcloud.vcloud+xml"
*/
public static final String VCLOUD_XML = "application/vnd.vmware.vcloud.vcloud+xml";
/**
* "application/vnd.vmware.vcloud.vcloud+xml"
*/
public static final MediaType VCLOUD_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vcloud+xml");
/**
* "application/vnd.vmware.vcloud.orgList+xml"
*/
public static final String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml";
/**
* "application/vnd.vmware.vcloud.orgList+xml"
*/
public static final MediaType ORGLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.orgList+xml");
/**
* "application/vnd.vmware.vcloud.org+xml"
*/
public static final String ORG_XML = "application/vnd.vmware.vcloud.org+xml";
/**
* "application/vnd.vmware.vcloud.org+xml"
*/
public static final MediaType ORG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.org+xml");
/**
* "application/vnd.vmware.vcloud.vdc+xml"
*/
public static final String VDC_XML = "application/vnd.vmware.vcloud.vdc+xml";
/**
* "application/vnd.vmware.vcloud.vdc+xml"
*/
public static final MediaType VDC_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vdc+xml");
/**
* "application/vnd.vmware.vcloud.catalog+xml"
*/
public static final String CATALOG_XML = "application/vnd.vmware.vcloud.catalog+xml";
/**
* "application/vnd.vmware.vcloud.catalog+xml"
*/
public static final MediaType CATALOG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.catalog+xml");
/**
* "application/vnd.vmware.vcloud.tasksList+xml"
*/
public static final String TASKSLIST_XML = "application/vnd.vmware.vcloud.tasksList+xml";
/**
* "application/vnd.vmware.vcloud.tasksList+xml"
*/
public static final MediaType TASKSLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.tasksList+xml");
/**
* "application/vnd.vmware.vcloud.catalogItem+xml"
*/
public static final String CATALOGITEM_XML = "application/vnd.vmware.vcloud.catalogItem+xml";
/**
* "application/vnd.vmware.vcloud.catalogItem+xml"
*/
public static final MediaType CATALOGITEM_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.catalogItem+xml");
/**
* "application/vnd.vmware.vcloud.networkConnectionSection+xml"
*/
public static final String NETWORKCONNECTIONSECTION_XML = "application/vnd.vmware.vcloud.networkConnectionSection+xml";
/**
* "application/vnd.vmware.vcloud.networkConnectionSection+xml"
*/
public static final MediaType NETWORKCONNECTIONSECTION_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.networkConnectionSection+xml");
/**
* "application/vnd.vmware.vcloud.virtualHardwareSection+xml"
*/
public static final String VIRTUALHARDWARESECTION_XML = "application/vnd.vmware.vcloud.virtualHardwareSection+xml";
/**
* "application/vnd.vmware.vcloud.virtualHardwareSection+xml"
*/
public static final MediaType VIRTUALHARDWARESECTION_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.virtualHardwareSection+xml");
/**
* "application/vnd.vmware.vcloud.guestCustomizationSection+xml"
*/
public static final String GUESTCUSTOMIZATIONSECTION_XML = "application/vnd.vmware.vcloud.guestCustomizationSection+xml";
/**
* "application/vnd.vmware.vcloud.guestCustomizationSection+xml"
*/
public static final MediaType GUESTCUSTOMIZATIONSECTION_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.guestCustomizationSection+xml");
/**
* "application/vnd.vmware.vcloud.networkSection+xml"
*/
public static final String NETWORKSECTION_XML = "application/vnd.vmware.vcloud.networkSection+xml";
/**
* "application/vnd.vmware.vcloud.networkSection+xml"
*/
public static final MediaType NETWORKSECTION_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.networkSection+xml");
/**
* "application/vnd.vmware.vcloud.task+xml"
*/
public static final String TASK_XML = "application/vnd.vmware.vcloud.task+xml";
/**
* "application/vnd.vmware.vcloud.task+xml"
*/
public static final MediaType TASK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.task+xml");
/**
* "application/vnd.vmware.vcloud.undeployVAppParams+xml"
*/
public static final String UNDEPLOYVAPPPARAMS_XML = "application/vnd.vmware.vcloud.undeployVAppParams+xml";
/**
* "application/vnd.vmware.vcloud.undeployVAppParams+xml"
*/
public static final MediaType UNDEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.undeployVAppParams+xml");
/**
* "application/vnd.vmware.vcloud.deployVAppParams+xml"
*/
public static final String DEPLOYVAPPPARAMS_XML = "application/vnd.vmware.vcloud.deployVAppParams+xml";
/**
* "application/vnd.vmware.vcloud.deployVAppParams+xml"
*/
public static final MediaType DEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.deployVAppParams+xml");
/**
* "application/vnd.vmware.vcloud.vApp+xml"
*/
public static final String VAPP_XML = "application/vnd.vmware.vcloud.vApp+xml";
/**
* "application/vnd.vmware.vcloud.vApp+xml"
*/
public static final MediaType VAPP_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vApp+xml");
/**
* "application/vnd.vmware.vcloud.vm+xml"
*/
public static final String VM_XML = "application/vnd.vmware.vcloud.vm+xml";
/**
* "application/vnd.vmware.vcloud.vm+xml"
*/
public static final MediaType VM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vm+xml");
/**
* "application/vnd.vmware.vcloud.vAppTemplate+xml"
*/
public static final String VAPPTEMPLATE_XML = "application/vnd.vmware.vcloud.vAppTemplate+xml";
/**
* "application/vnd.vmware.vcloud.vAppTemplate+xml"
*/
public static final MediaType VAPPTEMPLATE_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.vAppTemplate+xml");
/**
* "application/vnd.vmware.vcloud.network+xml"
*/
public static final String NETWORK_XML = "application/vnd.vmware.vcloud.network+xml";
/**
* "application/vnd.vmware.vcloud.network+xml"
*/
public static final MediaType NETWORK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.network+xml");
/**
* "application/vnd.vmware.vcloud.rasdItem+xml"
*/
public static final String RASDITEM_XML = "application/vnd.vmware.vcloud.rasdItem+xml";
/**
* "application/vnd.vmware.vcloud.rasdItem+xml"
*/
public static final MediaType RASDITEM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.rasdItem+xml");
private VCloudMediaType() {
throw new AssertionError("intentionally unimplemented");
}
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.vcloud.domain.VCloudError;
/**
* Encapsulates an VCloud Error.
*/
public class VCloudResponseException extends HttpResponseException {
private org.jclouds.vcloud.domain.VCloudError error;
public VCloudResponseException(HttpCommand command, HttpResponse response, VCloudError error) {
super(String.format("request %s failed with code %s, error: %s", command.getCurrentRequest().getRequestLine(), response
.getStatusCode(), error.toString()), command, response);
this.setError(error);
}
public VCloudResponseException(HttpCommand command, HttpResponse response, VCloudError error, Throwable cause) {
super(String.format("request %1$s failed with error: %2$s", command.getCurrentRequest().getRequestLine(), error
.toString()), command, response, cause);
this.setError(error);
}
public VCloudResponseException(String message, HttpCommand command, HttpResponse response, VCloudError error) {
super(message, command, response);
this.setError(error);
}
public VCloudResponseException(String message, HttpCommand command, HttpResponse response, VCloudError error,
Throwable cause) {
super(message, command, response, cause);
this.setError(error);
}
public void setError(VCloudError error) {
this.error = error;
}
public VCloudError getError() {
return error;
}
}

View File

@ -1,34 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* A VCloud Session Token
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface VCloudToken {
}

View File

@ -1,35 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud;
import java.io.Closeable;
import java.net.URI;
import java.util.SortedMap;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloud.xml.SupportedVersionsHandler;
public interface VCloudVersionsApi extends Closeable {
@GET
@XMLResponseParser(SupportedVersionsHandler.class)
@Path("/versions")
SortedMap<String, URI> getSupportedVersions();
}

View File

@ -1,74 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Properties;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToStringPayload;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
@Singleton
public class BindCPUCountToXmlPayload extends BindToStringPayload {
protected final String ns;
protected final String schema;
@Inject
public BindCPUCountToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
}
private static final String RESOURCE_ALLOCATION_NS = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData";
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
checkArgument(checkNotNull(payload, "cpuCount") instanceof Integer, "this binder is only valid for Integers!");
Integer cpuCount = Integer.class.cast(payload);
XMLBuilder cpuItem;
try {
cpuItem = XMLBuilder.create("Item").a("xmlns", ns).a("xmlns:rasd", RESOURCE_ALLOCATION_NS);
cpuItem.e("rasd:AllocationUnits").t("hertz * 10^6");
cpuItem.e("rasd:Description").t("Number of Virtual CPUs");
cpuItem.e("rasd:ElementName").t(cpuCount.toString() + " virtual CPU(s)");
cpuItem.e("rasd:InstanceID").t("4");
cpuItem.e("rasd:ResourceType").t(ResourceType.PROCESSOR.value());
cpuItem.e("rasd:VirtualQuantity").t(cpuCount.toString());
cpuItem.e("rasd:Weight").t("0");
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
request = super.bindToRequest(request, cpuItem.asString(outputProperties));
} catch (Exception e) {
Throwables.propagate(e);
}
return request;
}
}

View File

@ -1,119 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Map;
import java.util.Properties;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.options.CaptureVAppOptions;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
@Singleton
public class BindCaptureVAppParamsToXmlPayload implements MapBinder {
protected final String ns;
protected final String schema;
private final BindToStringPayload stringBinder;
@Inject
public BindCaptureVAppParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
this.stringBinder = stringBinder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
String templateName = checkNotNull(postParams.remove("templateName"), "templateName").toString();
String vApp = checkNotNull(postParams.remove("vApp"), "vApp").toString();
CaptureVAppOptions options = findOptionsInArgsOrNull(gRequest);
if (options == null) {
options = new CaptureVAppOptions();
}
try {
return stringBinder.bindToRequest(request, generateXml(templateName, vApp, options));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
throw new RuntimeException(e);
} catch (TransformerException e) {
throw new RuntimeException(e);
}
}
protected String generateXml(String templateName, String vApp, CaptureVAppOptions options)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(templateName);
if (options.getDescription() != null)
rootBuilder.e("Description").text(options.getDescription());
rootBuilder.e("Source").a("href", vApp).a("type", VCloudMediaType.VAPP_XML);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
}
protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("CaptureVAppParams").a("name", name).a("xmlns", ns)
.a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema);
return rootBuilder;
}
protected CaptureVAppOptions findOptionsInArgsOrNull(GeneratedHttpRequest gRequest) {
for (Object arg : gRequest.getInvocation().getArgs()) {
if (arg instanceof CaptureVAppOptions) {
return (CaptureVAppOptions) arg;
} else if (arg instanceof CaptureVAppOptions[]) {
CaptureVAppOptions[] options = (CaptureVAppOptions[]) arg;
return (options.length > 0) ? options[0] : null;
}
}
return null;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException("CaptureVAppParams is needs parameters");
}
protected String ifNullDefaultTo(String value, String defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
}
}

View File

@ -1,121 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.options.CatalogItemOptions;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
@Singleton
public class BindCatalogItemToXmlPayload implements MapBinder {
protected final String ns;
protected final String schema;
private final BindToStringPayload stringBinder;
@Inject
public BindCatalogItemToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
this.stringBinder = stringBinder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
String name = checkNotNull(postParams.get("name"), "name").toString();
URI entity = URI.create(checkNotNull(postParams.get("Entity"), "Entity").toString());
CatalogItemOptions options = findOptionsInArgsOrNew(gRequest);
try {
return stringBinder.bindToRequest(request, generateXml(name, entity, options));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
throw new RuntimeException(e);
} catch (TransformerException e) {
throw new RuntimeException(e);
}
}
protected String generateXml(String templateName, URI entity, CatalogItemOptions options)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(templateName);
if (options.getDescription() != null)
rootBuilder.e("Description").t(options.getDescription());
rootBuilder.e("Entity").a("href", entity.toASCIIString());
for (Entry<String, String> entry : options.getProperties().entrySet()) {
rootBuilder.e("Property").a("key", entry.getKey()).t(entry.getValue());
}
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
}
protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("CatalogItem").a("name", name).a("xmlns", ns).a("xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema);
return rootBuilder;
}
protected CatalogItemOptions findOptionsInArgsOrNew(GeneratedHttpRequest gRequest) {
for (Object arg : gRequest.getInvocation().getArgs()) {
if (arg instanceof CatalogItemOptions) {
return CatalogItemOptions.class.cast(arg);
} else if (arg.getClass().isArray()) {
Object[] array = (Object[]) arg;
if (array.length > 0 && array[0] instanceof CatalogItemOptions)
return CatalogItemOptions.class.cast(array[0]);
}
}
return new CatalogItemOptions();
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException("CatalogItem is needs parameters");
}
protected String ifNullDefaultTo(String value, String defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
}
}

View File

@ -1,128 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Map;
import java.util.Properties;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.options.CloneOptions;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
@Singleton
public abstract class BindCloneParamsToXmlPayload<O extends CloneOptions> implements MapBinder {
protected final String ns;
protected final String schema;
private final BindToStringPayload stringBinder;
protected abstract String getRootElement();
protected abstract String getSourceMediaType();
protected abstract Class<O> getOptionClass();
@Inject
public BindCloneParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
this.stringBinder = stringBinder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
String name = checkNotNull(postParams.get("name"), "name").toString();
String source = checkNotNull(postParams.get("Source"), "Source").toString();
boolean isSourceDelete = Boolean.parseBoolean((String) postParams.get("IsSourceDelete"));
O options = findOptionsInArgsOrNew(gRequest);
return stringBinder.bindToRequest(request, generateXml(name, source, isSourceDelete, options));
}
protected String generateXml(String name, String source, boolean isSourceDelete, O options) {
XMLBuilder rootBuilder = buildRoot(name, options);
addElementsUnderRoot(rootBuilder, source, options, isSourceDelete);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
try {
return rootBuilder.asString(outputProperties);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
protected void addElementsUnderRoot(XMLBuilder rootBuilder, String source, O options, boolean isSourceDelete) {
if (options.getDescription() != null)
rootBuilder.e("Description").text(options.getDescription());
rootBuilder.e("Source").a("href", source).a("type", getSourceMediaType());
if (isSourceDelete)
rootBuilder.e("IsSourceDelete").t("true");
}
protected XMLBuilder buildRoot(String name, O options) {
try {
return XMLBuilder.create(getRootElement()).a("xmlns", ns).a("xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema).a("name",
name);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
@SuppressWarnings("unchecked")
protected O findOptionsInArgsOrNew(GeneratedHttpRequest gRequest) {
for (Object arg : gRequest.getInvocation().getArgs()) {
if (getOptionClass().isInstance(arg)) {
return (O) arg;
} else if (arg.getClass().isArray()) {
Object[] array = (Object[]) arg;
if (array.length > 0 && getOptionClass().isInstance(array[0]))
return (O) array[0];
}
}
try {
return getOptionClass().newInstance();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException("CloneParams is needs parameters");
}
protected String ifNullDefaultTo(String value, String defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
}
}

View File

@ -1,60 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.options.CloneVAppOptions;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
@Singleton
public class BindCloneVAppParamsToXmlPayload extends BindCloneParamsToXmlPayload<CloneVAppOptions> {
@Inject
public BindCloneVAppParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
super(stringBinder, ns, schema);
}
@Override
protected Class<CloneVAppOptions> getOptionClass() {
return CloneVAppOptions.class;
}
@Override
protected String getRootElement() {
return "CloneVAppParams";
}
@Override
protected String getSourceMediaType() {
return VCloudMediaType.VAPP_XML;
}
protected XMLBuilder buildRoot(String name, CloneVAppOptions options) {
return super.buildRoot(name, options).a("deploy", options.isDeploy() + "").a("powerOn", options.isPowerOn() + "");
}
}

View File

@ -1,55 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
import com.google.inject.Inject;
@Singleton
public class BindCloneVAppTemplateParamsToXmlPayload extends BindCloneParamsToXmlPayload<CloneVAppTemplateOptions> {
@Inject
public BindCloneVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
super(stringBinder, schema, schema);
}
@Override
protected Class<CloneVAppTemplateOptions> getOptionClass() {
return CloneVAppTemplateOptions.class;
}
@Override
protected String getRootElement() {
return "CloneVAppTemplateParams";
}
@Override
protected String getSourceMediaType() {
return VCloudMediaType.VAPPTEMPLATE_XML;
}
}

View File

@ -1,37 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.rest.binders.BindToStringPayload;
import com.google.inject.Inject;
@Singleton
public class BindDeployVAppParamsToXmlPayload extends BindParamsToXmlPayload {
@Inject
public BindDeployVAppParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns) {
super("DeployVAppParams", stringBinder, ns);
}
}

View File

@ -1,107 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Properties;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.logging.Logger;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
@Singleton
public class BindGuestCustomizationSectionToXmlPayload extends BindToStringPayload {
@Resource
protected Logger logger = Logger.NULL;
protected final String ns;
protected final String schema;
@Inject
public BindGuestCustomizationSectionToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
checkArgument(checkNotNull(payload, "GuestCustomizationSection") instanceof GuestCustomizationSection,
"this binder is only valid for GuestCustomizationSection!");
GuestCustomizationSection guest = GuestCustomizationSection.class.cast(payload);
XMLBuilder guestCustomizationSection;
try {
guestCustomizationSection = XMLBuilder.create("GuestCustomizationSection").a("xmlns", ns).a("xmlns:ovf",
"http://schemas.dmtf.org/ovf/envelope/1").a("type", guest.getType()).a("href",
guest.getHref().toASCIIString()).a("ovf:required", "false");
guestCustomizationSection.e("ovf:Info").t(guest.getInfo());
if (guest.isEnabled() != null)
guestCustomizationSection.e("Enabled").t(guest.isEnabled().toString());
if (guest.shouldChangeSid() != null)
guestCustomizationSection.e("ChangeSid").t(guest.shouldChangeSid().toString());
if (guest.getVirtualMachineId() != null)
guestCustomizationSection.e("VirtualMachineId").t(guest.getVirtualMachineId().toString());
if (guest.isJoinDomainEnabled() != null)
guestCustomizationSection.e("JoinDomainEnabled").t(guest.isJoinDomainEnabled().toString());
if (guest.shouldUseOrgSettings() != null)
guestCustomizationSection.e("UseOrgSettings").t(guest.shouldUseOrgSettings().toString());
if (guest.getDomainName() != null)
guestCustomizationSection.e("DomainName").t(guest.getDomainName().toString());
if (guest.getDomainUserName() != null)
guestCustomizationSection.e("DomainUserName").t(guest.getDomainUserName().toString());
if (guest.getDomainUserPassword() != null)
guestCustomizationSection.e("DomainUserPassword").t(guest.getDomainUserPassword().toString());
if (guest.isAdminPasswordEnabled() != null)
guestCustomizationSection.e("AdminPasswordEnabled").t(guest.isAdminPasswordEnabled().toString());
if (guest.isAdminPasswordAuto() != null)
guestCustomizationSection.e("AdminPasswordAuto").t(guest.isAdminPasswordAuto().toString());
// if (guest.getAdminPassword() != null)
// guestCustomizationSection.e("AdminPassword").t(guest.getAdminPassword().toString());
if (guest.isResetPasswordRequired() != null)
guestCustomizationSection.e("ResetPasswordRequired").t(guest.isResetPasswordRequired().toString());
if (guest.getCustomizationScript() != null)
guestCustomizationSection.e("CustomizationScript").t(guest.getCustomizationScript());
if (guest.getComputerName() != null)
guestCustomizationSection.e("ComputerName").t(guest.getComputerName().toString());
if (guest.getEdit() != null)
guestCustomizationSection.e("Link").a("rel", "edit").a("type", guest.getType()).a("href",
guest.getHref().toASCIIString());
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
request = super.bindToRequest(request, guestCustomizationSection.asString(outputProperties));
request.getPayload().getContentMetadata().setContentType(guest.getType());
} catch (Exception e) {
Throwables.propagate(e);
}
return request;
}
}

View File

@ -1,216 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.jclouds.http.HttpRequest;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSet;
import com.jamesmurty.utils.XMLBuilder;
@Singleton
public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder {
protected final String ns;
protected final String schema;
protected final BindToStringPayload stringBinder;
protected final Supplier<ReferenceType> defaultNetwork;
protected final FenceMode defaultFenceMode;
protected final LoadingCache<URI, VAppTemplate> templateCache;
protected final Function<VAppTemplate, String> defaultNetworkNameInTemplate;
@Inject
public BindInstantiateVAppTemplateParamsToXmlPayload(LoadingCache<URI, VAppTemplate> templateCache,
@Network Function<VAppTemplate, String> defaultNetworkNameInTemplate, BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
@Network Supplier<ReferenceType> network, FenceMode fenceMode) {
this.templateCache = templateCache;
this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate;
this.ns = ns;
this.schema = schema;
this.stringBinder = stringBinder;
this.defaultNetwork = network;
this.defaultFenceMode = fenceMode;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
String name = checkNotNull(postParams.remove("name"), "name").toString();
URI template = URI.create(checkNotNull(postParams.remove("template"), "template").toString());
Set<NetworkConfig> networkConfig = null;
NetworkConfigDecorator networkConfigDecorator = new NetworkConfigDecorator(templateCache.getUnchecked(template),
defaultNetwork.get().getHref(), defaultFenceMode, defaultNetworkNameInTemplate);
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
if (options != null) {
if (!options.getNetworkConfig().isEmpty())
networkConfig = ImmutableSet
.copyOf(transform(options.getNetworkConfig(), networkConfigDecorator));
} else {
options = new InstantiateVAppTemplateOptions();
}
if (networkConfig == null)
networkConfig = ImmutableSet.of(networkConfigDecorator.apply(null));
try {
return stringBinder.bindToRequest(request, generateXml(name, options.getDescription(), options.shouldDeploy(),
options.shouldPowerOn(), template, networkConfig));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
throw new RuntimeException(e);
} catch (TransformerException e) {
throw new RuntimeException(e);
}
}
@VisibleForTesting
Set<Vm> ifCustomizationScriptIsSetGetVmsInTemplate(String customizationScript, final URI template) {
Set<Vm> vms = ImmutableSet.of();
if (customizationScript != null) {
VAppTemplate vAppTemplate = templateCache.getUnchecked(template);
checkArgument(vAppTemplate != null, "vAppTemplate %s not found!", template);
vms = vAppTemplate.getChildren();
checkArgument(!vms.isEmpty(), "no vms found in vAppTemplate %s", vAppTemplate);
}
return vms;
}
protected static final class NetworkConfigDecorator implements Function<NetworkConfig, NetworkConfig> {
private final VAppTemplate template;
private final URI defaultNetwork;
private final FenceMode defaultFenceMode;
private final Function<VAppTemplate, String> defaultNetworkNameInTemplate;
protected NetworkConfigDecorator(VAppTemplate template, URI defaultNetwork, FenceMode defaultFenceMode,
Function<VAppTemplate, String> defaultNetworkNameInTemplate) {
this.template = checkNotNull(template, "template");
this.defaultNetwork = checkNotNull(defaultNetwork, "defaultNetwork");
this.defaultFenceMode = checkNotNull(defaultFenceMode, "defaultFenceMode");
this.defaultNetworkNameInTemplate = checkNotNull(defaultNetworkNameInTemplate, "defaultNetworkNameInTemplate");
}
@Override
public NetworkConfig apply(NetworkConfig from) {
if (from == null)
return new NetworkConfig(defaultNetworkNameInTemplate.apply(template), defaultNetwork, defaultFenceMode);
URI network = ifNullDefaultTo(from.getParentNetwork(), defaultNetwork);
FenceMode fenceMode = ifNullDefaultTo(from.getFenceMode(), defaultFenceMode);
// using conditional statement instead of ifNullDefaultTo so that we lazy invoke the
// function, as it is an expensive one.
String networkName = from.getNetworkName() != null ? from.getNetworkName() : defaultNetworkNameInTemplate
.apply(template);
return new NetworkConfig(networkName, network, fenceMode);
}
}
protected String generateXml(String name, @Nullable String description, boolean deploy, boolean powerOn,
URI template, Iterable<NetworkConfig> networkConfig)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(name).a("deploy", deploy + "").a("powerOn", powerOn + "");
if (description != null)
rootBuilder.e("Description").t(description);
XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
addNetworkConfig(instantiationParamsBuilder, networkConfig);
rootBuilder.e("Source").a("href", template.toASCIIString());
rootBuilder.e("AllEULAsAccepted").t("true");
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
}
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder,
Iterable<NetworkConfig> networkConfig) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection");
networkConfigBuilder.e("ovf:Info").t("Configuration parameters for logical networks");
for (NetworkConfig n : networkConfig) {
XMLBuilder configurationBuilder = networkConfigBuilder.e("NetworkConfig").a("networkName", n.getNetworkName())
.e("Configuration");
configurationBuilder.e("ParentNetwork").a("href", n.getParentNetwork().toASCIIString());
if (n.getFenceMode() != null) {
configurationBuilder.e("FenceMode").t(n.getFenceMode().toString());
}
}
}
protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
return XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name).a("xmlns", ns)
.a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
}
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest gRequest) {
for (Object arg : gRequest.getInvocation().getArgs()) {
if (arg instanceof InstantiateVAppTemplateOptions) {
return (InstantiateVAppTemplateOptions) arg;
} else if (arg instanceof InstantiateVAppTemplateOptions[]) {
InstantiateVAppTemplateOptions[] options = (InstantiateVAppTemplateOptions[]) arg;
return (options.length > 0) ? options[0] : null;
}
}
return null;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
}
public static <T> T ifNullDefaultTo(T value, T defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
}
}

View File

@ -1,75 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Properties;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToStringPayload;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
@Singleton
public class BindMemoryToXmlPayload extends BindToStringPayload {
protected final String ns;
protected final String schema;
@Inject
public BindMemoryToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
}
private static final String RESOURCE_ALLOCATION_NS = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData";
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
checkArgument(checkNotNull(payload, "memoryInMB") instanceof Integer, "this binder is only valid for Integers!");
Integer memoryInMB = Integer.class.cast(payload);
XMLBuilder cpuItem;
try {
cpuItem = XMLBuilder.create("Item").a("xmlns", ns).a("xmlns:rasd", RESOURCE_ALLOCATION_NS);
cpuItem.e("rasd:AllocationUnits").t("byte * 2^20");
cpuItem.e("rasd:Description").t("Memory Size");
cpuItem.e("rasd:ElementName").t(memoryInMB.toString() + " MB of memory");
cpuItem.e("rasd:InstanceID").t("5");
cpuItem.e("rasd:Reservation").t("0");
cpuItem.e("rasd:ResourceType").t(ResourceType.MEMORY.value());
cpuItem.e("rasd:VirtualQuantity").t(memoryInMB.toString());
cpuItem.e("rasd:Weight").t("0");
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
request = super.bindToRequest(request, cpuItem.asString(outputProperties));
} catch (Exception e) {
Throwables.propagate(e);
}
return request;
}
}

View File

@ -1,101 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Properties;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.logging.Logger;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.vcloud.domain.NetworkConnection;
import org.jclouds.vcloud.domain.NetworkConnectionSection;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
@Singleton
public class BindNetworkConnectionSectionToXmlPayload extends BindToStringPayload {
@Resource
protected Logger logger = Logger.NULL;
protected final String ns;
protected final String schema;
@Inject
public BindNetworkConnectionSectionToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
checkArgument(checkNotNull(payload, "NetworkConnectionSection") instanceof NetworkConnectionSection,
"this binder is only valid for NetworkConnectionSection!");
NetworkConnectionSection net = NetworkConnectionSection.class.cast(payload);
XMLBuilder networkConnectionSection;
try {
networkConnectionSection = XMLBuilder.create("NetworkConnectionSection").a("xmlns", ns)
.a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1").a("type", net.getType())
.a("href", net.getHref().toASCIIString()).a("ovf:required", "false");
networkConnectionSection.e("ovf:Info").t(net.getInfo());
if (net.getPrimaryNetworkConnectionIndex() != null)
networkConnectionSection.e("PrimaryNetworkConnectionIndex").t(
net.getPrimaryNetworkConnectionIndex().toString());
for (NetworkConnection networkConnection : net.getConnections()) {
XMLBuilder networkConnectionSectionChild = networkConnectionSection.e("NetworkConnection").a("network",
networkConnection.getNetwork());
networkConnectionSectionChild.e("NetworkConnectionIndex").t(
networkConnection.getNetworkConnectionIndex() + "");
if (networkConnection.getExternalIpAddress() != null)
networkConnectionSectionChild.e("ExternalIpAddress").t(networkConnection.getExternalIpAddress());
if (networkConnection.getIpAddress() != null)
networkConnectionSectionChild.e("IpAddress").t(networkConnection.getIpAddress());
networkConnectionSectionChild.e("IsConnected").t(networkConnection.isConnected() + "");
if (networkConnection.getMACAddress() != null)
networkConnectionSectionChild.e("MACAddress").t(networkConnection.getMACAddress());
if (networkConnection.getIpAddressAllocationMode() != null)
networkConnectionSectionChild.e("IpAddressAllocationMode").t(
networkConnection.getIpAddressAllocationMode().toString());
}
if (net.getEdit() != null)
networkConnectionSection.e("Link").a("rel", "edit").a("type", net.getType())
.a("href", net.getHref().toASCIIString());
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
request = super.bindToRequest(request, networkConnectionSection.asString(outputProperties));
request.getPayload().getContentMetadata().setContentType(net.getType());
} catch (Exception e) {
Throwables.propagate(e);
}
return request;
}
}

View File

@ -1,76 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
@Singleton
public class BindParamsToXmlPayload implements MapBinder {
protected final String ns;
protected final BindToStringPayload stringBinder;
protected final String element;
@Inject
public BindParamsToXmlPayload(String element, BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns) {
this.element = element;
this.ns = ns;
this.stringBinder = stringBinder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
try {
return stringBinder.bindToRequest(request, generateXml(postParams));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private String generateXml(Map<String, Object> postParams) throws ParserConfigurationException,
FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = XMLBuilder.create(element);
for (Entry<String, Object> entry : postParams.entrySet())
rootBuilder.a(entry.getKey(), (String) entry.getValue());
rootBuilder.a("xmlns", ns);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalArgumentException("incorrect usage");
}
}

View File

@ -1,37 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.rest.binders.BindToStringPayload;
import com.google.inject.Inject;
@Singleton
public class BindUndeployVAppParamsToXmlPayload extends BindParamsToXmlPayload {
@Inject
public BindUndeployVAppParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns) {
super("UndeployVAppParams", stringBinder, ns);
}
}

View File

@ -1,75 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Catalog;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
@Singleton
public class OrgNameAndCatalogNameToEndpoint implements MapBinder {
private final Supplier<Map<String, Org>> orgMap;
private final Supplier<ReferenceType> defaultOrg;
private final Supplier<ReferenceType> defaultCatalog;
@Inject
public OrgNameAndCatalogNameToEndpoint(Supplier<Map<String, Org>> orgMap,
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg,
@Catalog Supplier<ReferenceType> defaultCatalog) {
this.orgMap = orgMap;
this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog;
}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Object org = postParams.get("orgName");
Object catalog = postParams.get("catalogName");
if (org == null && catalog == null)
return (R) request.toBuilder().endpoint(defaultCatalog.get().getHref()).build();
else if (org == null)
org = defaultOrg.get().getName();
try {
Map<String, ReferenceType> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();
URI endpoint = catalog == null ? Iterables.getLast(catalogs.values()).getHref() : catalogs.get(catalog).getHref();
return (R) request.toBuilder().endpoint(endpoint).build();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + catalog + " not found in " + orgMap.get());
}
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException(getClass() + " needs parameters");
}
}

View File

@ -1,74 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
@Singleton
public class OrgNameAndVDCNameToEndpoint implements MapBinder {
private final Supplier<Map<String, Org>> orgNameToVDCEndpoint;
private final Supplier<ReferenceType> defaultOrg;
private final Supplier<ReferenceType> defaultVDC;
@Inject
public OrgNameAndVDCNameToEndpoint(Supplier<Map<String, Org>> orgNameToVDCEndpoint,
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
this.orgNameToVDCEndpoint = orgNameToVDCEndpoint;
this.defaultOrg = defaultOrg;
this.defaultVDC = defaultVDC;
}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Object org = postParams.get("orgName");
Object vdc = postParams.get("vdcName");
if (org == null && vdc == null)
return (R) request.toBuilder().endpoint(defaultVDC.get().getHref()).build();
else if (org == null)
org = defaultOrg.get().getName();
try {
Map<String, ReferenceType> vdcs = checkNotNull(orgNameToVDCEndpoint.get().get(org)).getVDCs();
URI endpoint = vdc == null ? Iterables.getLast(vdcs.values()).getHref() : vdcs.get(vdc).getHref();
return (R) request.toBuilder().endpoint(endpoint).build();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + vdc + " not found in " + orgNameToVDCEndpoint.get());
}
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException(getClass() + " needs parameters");
}
}

View File

@ -1,73 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Supplier;
@Singleton
public class OrgNameCatalogNameItemNameToEndpoint implements MapBinder {
private final Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap;
private final Supplier<ReferenceType> defaultOrg;
private final Supplier<ReferenceType> defaultCatalog;
@Inject
public OrgNameCatalogNameItemNameToEndpoint(
Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap,
@Org Supplier<ReferenceType> defaultOrg, @Catalog Supplier<ReferenceType> defaultCatalog) {
this.orgCatalogMap = orgCatalogMap;
this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog;
}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Object org = postParams.get("orgName");
Object catalog = postParams.get("catalogName");
Object catalogItem = postParams.get("itemName");
if (org == null)
org = defaultOrg.get().getName();
if (catalog == null)
catalog = defaultCatalog.get().getName();
try {
Map<String, org.jclouds.vcloud.domain.Catalog> catalogs = checkNotNull(orgCatalogMap.get().get(org));
return (R) request.toBuilder().endpoint(catalogs.get(catalog).get(catalogItem).getHref()).build();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + catalog + "/" + catalogItem + " not found in "
+ orgCatalogMap.get());
}
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException(getClass() + " needs parameters");
}
}

View File

@ -1,86 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Supplier;
@Singleton
public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements MapBinder {
private final Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> orgCatalogItemMap;
private final Supplier<ReferenceType> defaultOrg;
private final Supplier<ReferenceType> defaultCatalog;
@Inject
public OrgNameCatalogNameVAppTemplateNameToEndpoint(
Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> orgCatalogItemMap,
@Org Supplier<ReferenceType> defaultOrg, @Catalog Supplier<ReferenceType> defaultCatalog) {
this.orgCatalogItemMap = orgCatalogItemMap;
this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog;
}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Object org = postParams.get("orgName");
Object catalog = postParams.get("catalogName");
Object catalogItem = postParams.get("itemName");
if (org == null)
org = defaultOrg.get().getName();
if (catalog == null)
catalog = defaultCatalog.get().getName();
Map<String, Map<String, Map<String, CatalogItem>>> orgCatalogItemMap = this.orgCatalogItemMap.get();
if (!orgCatalogItemMap.containsKey(org))
throw new NoSuchElementException("org: " + org + " not found in " + orgCatalogItemMap.keySet());
Map<String, Map<String, CatalogItem>> catalogs = orgCatalogItemMap.get(org);
if (!catalogs.containsKey(catalog))
throw new NoSuchElementException("catalog: " + org + "/" + catalog + " not found in " + catalogs.keySet());
Map<String, CatalogItem> catalogMap = catalogs.get(catalog);
if (!catalogMap.containsKey(catalogItem))
throw new NoSuchElementException("item: " + org + "/" + catalog + "/" + catalogItem + " not found in "
+ catalogMap.keySet());
CatalogItem item = catalogMap.get(catalogItem);
URI endpoint = checkNotNull(item.getEntity(),
"item: " + org + "/" + catalog + "/" + catalogItem + " has no entity").getHref();
return (R) request.toBuilder().endpoint(endpoint).build();
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException(getClass() + " needs parameters");
}
}

View File

@ -1,50 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Supplier;
@Singleton
public class OrgNameVDCNameNetworkNameToEndpoint extends OrgNameVDCNameResourceNameToEndpoint {
@Inject
public OrgNameVDCNameNetworkNameToEndpoint(
Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
@Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
super(orgVDCMap, defaultOrg, defaultVDC);
}
protected URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource,
org.jclouds.vcloud.domain.VDC vDCObject) {
ReferenceType resourceEntity = vDCObject.getAvailableNetworks().get(resource);
if (resourceEntity == null)
throw new NoSuchElementException("network " + resource + " in vdc " + vDC + ", org " + org + " not found in "
+ vDCObject.getAvailableNetworks().keySet());
return resourceEntity.getHref();
}
}

View File

@ -1,50 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Supplier;
@Singleton
public class OrgNameVDCNameResourceEntityNameToEndpoint extends OrgNameVDCNameResourceNameToEndpoint {
@Inject
public OrgNameVDCNameResourceEntityNameToEndpoint(
Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
@Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
super(orgVDCMap, defaultOrg, defaultVDC);
}
protected URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource,
org.jclouds.vcloud.domain.VDC vDCObject) {
ReferenceType resourceEntity = vDCObject.getResourceEntities().get(resource);
if (resourceEntity == null)
throw new NoSuchElementException("entity " + resource + " in vdc " + vDC + ", org " + org + " not found in "
+ vDCObject.getResourceEntities().keySet());
return resourceEntity.getHref();
}
}

View File

@ -1,77 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.binders;
import static com.google.common.base.Preconditions.checkState;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Supplier;
public abstract class OrgNameVDCNameResourceNameToEndpoint implements MapBinder {
protected final Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
protected final Supplier<ReferenceType> defaultOrg;
protected final Supplier<ReferenceType> defaultVDC;
@Inject
public OrgNameVDCNameResourceNameToEndpoint(
Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
@Org Supplier<ReferenceType> defaultOrg, @org.jclouds.vcloud.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
this.orgVDCMap = orgVDCMap;
this.defaultOrg = defaultOrg;
this.defaultVDC = defaultVDC;
}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Object org = postParams.get("orgName");
Object vDC = postParams.get("vdcName");
Object resource = postParams.get("resourceName");
if (org == null)
org = defaultOrg.get().getName();
if (vDC == null)
vDC = defaultVDC.get().getName();
Map<String, Map<String, org.jclouds.vcloud.domain.VDC>> orgToVDCs = orgVDCMap.get();
checkState(orgToVDCs != null, "could not get map of org name to vdcs!");
Map<String, org.jclouds.vcloud.domain.VDC> vDCs = orgToVDCs.get(org);
if (vDCs == null)
throw new NoSuchElementException("org " + org + " not found in " + orgToVDCs.keySet());
org.jclouds.vcloud.domain.VDC vDCObject = vDCs.get(vDC);
if (vDCObject == null)
throw new NoSuchElementException("vdc " + vDC + " in org " + org + " not found in " + vDCs.keySet());
URI endpoint = getEndpointOfResourceInVDC(org, vDC, resource, vDCObject);
return (R) request.toBuilder().endpoint(endpoint).build();
}
protected abstract URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource, VDC vDCObject);
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException(getClass() + " needs parameters");
}
}

View File

@ -1,37 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.config;
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
import org.jclouds.domain.Location;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
/**
* Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
* bound.
*/
public class VCloudComputeServiceContextModule extends
ComputeServiceAdapterContextModule<VApp, VAppTemplate, VAppTemplate, Location> {
@Override
protected void configure() {
super.configure();
install(new VCloudComputeServiceDependenciesModule());
}
}

View File

@ -1,150 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.config;
import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.vcloud.compute.functions.HardwareForVApp;
import org.jclouds.vcloud.compute.functions.HardwareForVAppTemplate;
import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate;
import org.jclouds.vcloud.compute.functions.VAppToNodeMetadata;
import org.jclouds.vcloud.compute.internal.VCloudTemplateBuilderImpl;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.jclouds.vcloud.compute.strategy.VCloudComputeServiceAdapter;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.functions.VAppTemplatesInOrg;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
public class VCloudComputeServiceDependenciesModule extends AbstractModule {
@VisibleForTesting
public static final Map<Status, NodeMetadata.Status> toPortableNodeStatus = ImmutableMap
.<Status, NodeMetadata.Status> builder()
.put(Status.OFF, NodeMetadata.Status.SUSPENDED)
.put(Status.ON, NodeMetadata.Status.RUNNING)
.put(Status.RESOLVED, NodeMetadata.Status.PENDING)
.put(Status.MIXED, NodeMetadata.Status.PENDING)
.put(Status.UNKNOWN, NodeMetadata.Status.UNRECOGNIZED)
.put(Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED)
.put(Status.DEPLOYED, NodeMetadata.Status.PENDING)
.put(Status.SUSPENDED, NodeMetadata.Status.SUSPENDED)
.put(Status.WAITING_FOR_INPUT, NodeMetadata.Status.PENDING)
.put(Status.INCONSISTENT, NodeMetadata.Status.PENDING)
.put(Status.ERROR, NodeMetadata.Status.ERROR)
.put(Status.UNRESOLVED, NodeMetadata.Status.PENDING).build();
@Singleton
@Provides
protected Map<Status, NodeMetadata.Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
@VisibleForTesting
public static final Map<Status, Image.Status> toPortableImageStatus = ImmutableMap
.<Status, Image.Status> builder()
.put(Status.RESOLVED, Image.Status.AVAILABLE)
.put(Status.OFF, Image.Status.AVAILABLE)
.put(Status.MIXED, Image.Status.PENDING)
.put(Status.UNKNOWN, Image.Status.UNRECOGNIZED)
.put(Status.UNRECOGNIZED, Image.Status.UNRECOGNIZED)
.put(Status.DEPLOYED, Image.Status.PENDING)
.put(Status.PENDING_DESCRIPTOR, Image.Status.PENDING)
.put(Status.COPYING, Image.Status.PENDING)
.put(Status.PENDING_CONTENTS, Image.Status.PENDING)
.put(Status.QUARANTINED, Image.Status.PENDING)
.put(Status.QUARANTINE_EXPIRED, Image.Status.ERROR)
.put(Status.REJECTED, Image.Status.ERROR)
.put(Status.TRANSFER_TIMEOUT, Image.Status.ERROR)
.put(Status.ERROR, Image.Status.ERROR)
.put(Status.UNRESOLVED, Image.Status.PENDING).build();
@Singleton
@Provides
protected Map<Status, Image.Status> toPortableImageStatus() {
return toPortableImageStatus;
}
@SuppressWarnings("unchecked")
@Override
protected void configure() {
bind(new TypeLiteral<ComputeServiceAdapter<VApp, VAppTemplate, VAppTemplate, Location>>() {
}).to(VCloudComputeServiceAdapter.class);
bind(new TypeLiteral<Function<VApp, NodeMetadata>>() {
}).to(VAppToNodeMetadata.class);
bind(TemplateOptions.class).to(VCloudTemplateOptions.class);
bind(TemplateBuilder.class).to(VCloudTemplateBuilderImpl.class);
bind(new TypeLiteral<Function<VApp, Hardware>>() {
}).to(new TypeLiteral<HardwareForVApp>() {
});
bind(new TypeLiteral<Function<Org, Iterable<VAppTemplate>>>() {
}).to(VAppTemplatesInOrg.class);
bind(new TypeLiteral<Function<VAppTemplate, Image>>() {
}).to(ImageForVAppTemplate.class);
bind(new TypeLiteral<Function<VAppTemplate, Hardware>>() {
}).to(HardwareForVAppTemplate.class);
// we aren't converting from a provider-specific type
bind(new TypeLiteral<Function<Location, Location>>() {
}).to(Class.class.cast(IdentityFunction.class));
}
@Provides
@Singleton
public Supplier<NetworkConfig> networkConfig(@Network Supplier<ReferenceType> network,
final FenceMode defaultFenceMode) {
return Suppliers.compose(new Function<ReferenceType, NetworkConfig>() {
@Override
public NetworkConfig apply(ReferenceType input) {
return new NetworkConfig(input.getName(), input.getHref(), defaultFenceMode);
}
}, network);
}
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.functions;
import java.net.URI;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
@Singleton
public class FindLocationForResource implements Function<ReferenceType, Location> {
@Resource
protected Logger logger = Logger.NULL;
final Supplier<Set<? extends Location>> locations;
@Inject
public FindLocationForResource(@Memoized Supplier<Set<? extends Location>> locations) {
this.locations = locations;
}
/**
* searches for a location associated with this resource.
*
* @throws NoSuchElementException
* if not found
*/
public Location apply(ReferenceType resource) {
for (Location input : locations.get()) {
do {
// The "name" isn't always present, ex inside a vApp we have a rel
// link that only includes href and type.
if (URI.create(input.getId()).equals(resource.getHref()))
return input;
} while ((input = input.getParent()) != null);
}
throw new NoSuchElementException(String.format("resource: %s not found in locations: %s", resource,
locations.get()));
}
}

View File

@ -1,68 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.ovf.VirtualHardwareSection;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Vm;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
public class HardwareForVApp implements Function<VApp, Hardware> {
@Resource
protected Logger logger = Logger.NULL;
private final Function<ReferenceType, Location> findLocationForResource;
private final VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
@Inject
protected HardwareForVApp(Function<ReferenceType, Location> findLocationForResource,
VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");
}
@Override
public Hardware apply(VApp from) {
checkNotNull(from, "VApp");
// TODO make this work with composite vApps
Vm vm = from.getChildren().isEmpty() ? null : Iterables.get(from.getChildren(), 0);
if (vm == null)
return null;
VirtualHardwareSection hardware = vm.getVirtualHardwareSection();
HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems());
builder.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC()));
builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage(
ImagePredicates.idEquals(from.getHref().toASCIIString()));
builder.hypervisor("VMware");
return builder.build();
}
}

View File

@ -1,81 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.logging.Logger;
import org.jclouds.ovf.Envelope;
import org.jclouds.ovf.VirtualHardwareSection;
import org.jclouds.vcloud.domain.VAppTemplate;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
@Singleton
public class HardwareForVAppTemplate implements Function<VAppTemplate, Hardware> {
@Resource
protected Logger logger = Logger.NULL;
private final Function<VAppTemplate, Envelope> templateToEnvelope;
private final FindLocationForResource findLocationForResource;
private final VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
@Inject
protected HardwareForVAppTemplate(Function<VAppTemplate, Envelope> templateToEnvelope,
FindLocationForResource findLocationForResource,
VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
this.templateToEnvelope = checkNotNull(templateToEnvelope, "templateToEnvelope");
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");
}
@Override
public Hardware apply(VAppTemplate from) {
checkNotNull(from, "VAppTemplate");
Envelope ovf = templateToEnvelope.apply(from);
if (ovf.getVirtualSystem().getVirtualHardwareSections().size() > 1) {
logger.warn("multiple hardware choices found. using first", ovf);
}
VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getVirtualHardwareSections(), 0);
HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems());
if (from.getVDC() != null) {
builder.location(findLocationForResource.apply(from.getVDC()));
} else {
// otherwise, it could be in a public catalog, which is not assigned to a VDC
}
builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage(
ImagePredicates.idEquals(from.getHref().toASCIIString()));
builder.hypervisor("VMware");
return builder.build();
}
protected String getName(String name) {
return name;
}
}

View File

@ -1,79 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.ovf.Envelope;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VAppTemplate;
import com.google.common.base.Function;
@Singleton
public class ImageForVAppTemplate implements Function<VAppTemplate, Image> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final Map<Status, Image.Status> toPortableImageStatus;
private final Function<VAppTemplate, Envelope> templateToEnvelope;
private final FindLocationForResource findLocationForResource;
@Inject
protected ImageForVAppTemplate(Map<Status, Image.Status> toPortableImageStatus, Function<VAppTemplate, Envelope> templateToEnvelope,
FindLocationForResource findLocationForResource) {
this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus");
this.templateToEnvelope = checkNotNull(templateToEnvelope, "templateToEnvelope");
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
}
@Override
public Image apply(VAppTemplate from) {
checkNotNull(from, "VAppTemplate");
Envelope ovf = templateToEnvelope.apply(from);
ImageBuilder builder = new ImageBuilder();
builder.ids(from.getHref().toASCIIString());
builder.uri(from.getHref());
builder.name(from.getName());
if (from.getVDC() != null) {
builder.location(findLocationForResource.apply(from.getVDC()));
} else {
// otherwise, it could be in a public catalog, which is not assigned to a VDC
}
builder.description(from.getDescription() != null ? from.getDescription() : from.getName());
builder.operatingSystem(CIMOperatingSystem.toComputeOs(ovf));
builder.status(toPortableImageStatus.get(from.getStatus()));
return builder.build();
}
}

View File

@ -1,111 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.not;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.compute.util.ComputeServiceUtils.addMetadataAndParseTagsFromCommaDelimitedValue;
import static org.jclouds.compute.util.ComputeServiceUtils.groupFromMapOrName;
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getCredentialsFrom;
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getIpsFromVApp;
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.toComputeOs;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger;
import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VApp;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
@Singleton
public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
@Resource
protected static Logger logger = Logger.NULL;
protected final FindLocationForResource findLocationForResourceInVDC;
protected final Function<VApp, Hardware> hardwareForVApp;
protected final Map<Status, NodeMetadata.Status> vAppStatusToNodeStatus;
protected final Map<String, Credentials> credentialStore;
protected final GroupNamingConvention nodeNamingConvention;
@Inject
protected VAppToNodeMetadata(Map<Status, NodeMetadata.Status> vAppStatusToNodeStatus, Map<String, Credentials> credentialStore,
FindLocationForResource findLocationForResourceInVDC, Function<VApp, Hardware> hardwareForVApp,
GroupNamingConvention.Factory namingConvention) {
this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix();
this.hardwareForVApp = checkNotNull(hardwareForVApp, "hardwareForVApp");
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
this.vAppStatusToNodeStatus = checkNotNull(vAppStatusToNodeStatus, "vAppStatusToNodeStatus");
}
public NodeMetadata apply(VApp from) {
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(from.getHref().toASCIIString());
builder.uri(from.getHref());
builder.name(from.getName());
String groupName = "";
Map<String, String> metadataMap;
if (!isNullOrEmpty(from.getDescription())
&& from.getDescription().indexOf('=') != -1
&& from.getDescription().indexOf('\n') != -1) {
try {
metadataMap = Splitter.on('\n').withKeyValueSeparator("=").split(from.getDescription());
addMetadataAndParseTagsFromCommaDelimitedValue(builder, metadataMap);
} catch (IllegalArgumentException iae) {
// no op
metadataMap = ImmutableMap.of();
}
} else {
metadataMap = ImmutableMap.of();
}
builder.hostname(from.getName());
builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
builder.group(groupFromMapOrName(metadataMap, from.getName(), nodeNamingConvention));
builder.operatingSystem(toComputeOs(from, null));
builder.hardware(hardwareForVApp.apply(from));
builder.status(vAppStatusToNodeStatus.get(from.getStatus()));
Set<String> addresses = getIpsFromVApp(from);
builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));
// normally, we don't affect the credential store when reading vApps.
// However, login user, etc, is actually in the metadata, so lets see
Credentials fromApi = getCredentialsFrom(from);
if (fromApi != null && !credentialStore.containsKey("node#" + from.getHref().toASCIIString()))
credentialStore.put("node#" + from.getHref().toASCIIString(), fromApi);
return builder.build();
}
}

View File

@ -1,40 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.functions;
import javax.inject.Singleton;
import org.jclouds.cim.ResourceAllocationSettingData;
import org.jclouds.cim.functions.HardwareBuilderFromResourceAllocations;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.vcloud.domain.ovf.VCloudHardDisk;
@Singleton
public class VCloudHardwareBuilderFromResourceAllocations extends HardwareBuilderFromResourceAllocations {
@Override
public Volume apply(ResourceAllocationSettingData from) {
if (from instanceof VCloudHardDisk) {
VCloudHardDisk vDisk = VCloudHardDisk.class.cast(from);
return new VolumeImpl(from.getAddressOnParent() + "", Volume.Type.LOCAL, vDisk.getCapacity() / 1024f, null,
"0".equals(from.getAddressOnParent()), true);
} else {
return super.apply(from);
}
}
}

View File

@ -1,74 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.ovf.Envelope;
import org.jclouds.vcloud.domain.VAppTemplate;
import com.google.common.base.Function;
import com.google.common.cache.LoadingCache;
@Singleton
public class ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException implements
Function<VAppTemplate, Envelope> {
@Resource
protected Logger logger = Logger.NULL;
private final LoadingCache<URI, Envelope> envelopes;
@Inject
protected ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException(LoadingCache<URI, Envelope> envelopes) {
this.envelopes = checkNotNull(envelopes, "envelopes");
}
@Override
public Envelope apply(VAppTemplate from) {
checkArgument(from.getChildren().size() == 1, "multiple vms are not supported: %s", from);
checkArgument(from.getNetworkSection().getNetworks().size() == 1,
"multiple network connections are not supported: %s", from);
checkArgument(from.isOvfDescriptorUploaded(), "ovf descriptor is not uploaded: %s", from);
Envelope ovf = getOVFForVAppTemplateAndValidate(from);
return ovf;
}
private Envelope getOVFForVAppTemplateAndValidate(VAppTemplate from) throws IllegalArgumentException {
Envelope ovf;
try {
ovf = envelopes.get(from.getHref());
checkArgument(!ovf.getVirtualSystem().getVirtualHardwareSections().isEmpty(),
"no hardware sections exist in ovf %s", ovf);
} catch (ExecutionException e) {
throw new IllegalArgumentException("no ovf envelope found for: " + from, e);
}
return ovf;
}
}

View File

@ -1,45 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.internal;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.strategy.GetImageStrategy;
import org.jclouds.compute.suppliers.ImageCacheSupplier;
import org.jclouds.domain.Location;
import com.google.common.base.Supplier;
public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl {
@Inject
protected VCloudTemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
ImageCacheSupplier images, @Memoized Supplier<Set<? extends Hardware>> sizes,
Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, GetImageStrategy getImageStrategy) {
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider, getImageStrategy);
}
}

View File

@ -1,348 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.options;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.emptyToNull;
import java.net.URI;
import java.util.Map;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* Contains options supported in the {@code ComputeService#runNode} operation on
* the "vcloud" provider. <h2>
* Usage</h2> The recommended way to instantiate a VCloudTemplateOptions object
* is to statically import VCloudTemplateOptions.* and invoke a static creation
* method followed by an instance mutator (if needed):
* <p/>
* <code>
* import static org.jclouds.compute.options.VCloudTemplateOptions.Builder.*;
* <p/>
* ComputeService client = // get connection
* templateBuilder.options(inboundPorts(22, 80, 8080, 443));
* Set<NodeMetadata> set = client.createNodesInGroup(tag, 2, templateBuilder.build());
* <code>
*/
public class VCloudTemplateOptions extends TemplateOptions implements Cloneable {
@Override
public VCloudTemplateOptions clone() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
copyTo(options);
return options;
}
@Override
public void copyTo(TemplateOptions to) {
super.copyTo(to);
if (to instanceof VCloudTemplateOptions) {
VCloudTemplateOptions eTo = VCloudTemplateOptions.class.cast(to);
if (getCustomizationScript() != null)
eTo.customizationScript(getCustomizationScript());
if (getDescription() != null)
eTo.description(getDescription());
if (getIpAddressAllocationMode() != null)
eTo.ipAddressAllocationMode(getIpAddressAllocationMode());
if (getIpAddressAllocationMode() != null)
eTo.ipAddressAllocationMode(getIpAddressAllocationMode());
if (getParentNetwork() != null)
eTo.parentNetwork(getParentNetwork());
if (getFenceMode() != null)
eTo.fenceMode(getFenceMode());
}
}
private String description = null;
private String customizationScript = null;
private IpAddressAllocationMode ipAddressAllocationMode = null;
private URI parentNetwork = null;
private FenceMode fenceMode = null;
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
VCloudTemplateOptions that = VCloudTemplateOptions.class.cast(o);
return super.equals(that) && equal(this.description, that.description)
&& equal(this.customizationScript, that.customizationScript)
&& equal(this.ipAddressAllocationMode, that.ipAddressAllocationMode)
&& equal(this.parentNetwork, that.parentNetwork);
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), description, customizationScript, ipAddressAllocationMode,
parentNetwork);
}
@Override
public ToStringHelper string() {
return super.string().add("description", description).add("customizationScript", customizationScript)
.add("ipAddressAllocationMode", ipAddressAllocationMode).add("parentNetwork", parentNetwork);
}
/**
* Optional description. Used for the Description of the vApp created by this
* instantiation.
*/
public VCloudTemplateOptions description(String description) {
this.description = description;
return this;
}
/**
* Specifies the customizationScript used to run instances with
*/
public VCloudTemplateOptions customizationScript(String customizationScript) {
this.customizationScript = checkNotNull(emptyToNull(customizationScript), "customizationScript must be defined");
return this;
}
/**
* Specifies the ipAddressAllocationMode used to for network interfaces on
* the VMs
*/
public VCloudTemplateOptions ipAddressAllocationMode(IpAddressAllocationMode ipAddressAllocationMode) {
this.ipAddressAllocationMode = ipAddressAllocationMode;
return this;
}
/**
* Specifies the parentNetwork to connect the the network interfaces on the
* VMs to.
*
* @see InstantiateVAppTemplateOptions#addNetworkConfig
*/
public VCloudTemplateOptions parentNetwork(URI parentNetwork) {
this.parentNetwork = parentNetwork;
return this;
}
/**
* How to connect to the parent network
*
* @see InstantiateVAppTemplateOptions#addNetworkConfig
*/
public VCloudTemplateOptions fenceMode(FenceMode fenceMode) {
this.fenceMode = fenceMode;
return this;
}
public static class Builder {
/**
* @see VCloudTemplateOptions#description
*/
public static VCloudTemplateOptions description(String description) {
return new VCloudTemplateOptions().description(description);
}
/**
* @see VCloudTemplateOptions#customizationScript
*/
public static VCloudTemplateOptions customizationScript(String customizationScript) {
return new VCloudTemplateOptions().customizationScript(customizationScript);
}
/**
* @see VCloudTemplateOptions#ipAddressAllocationMode
*/
public static VCloudTemplateOptions ipAddressAllocationMode(IpAddressAllocationMode ipAddressAllocationMode) {
return new VCloudTemplateOptions().ipAddressAllocationMode(ipAddressAllocationMode);
}
/**
* @see VCloudTemplateOptions#parentNetwork(URI parentNetwork)
*/
public static VCloudTemplateOptions parentNetwork(URI parentNetwork) {
return new VCloudTemplateOptions().parentNetwork(parentNetwork);
}
/**
* @see VCloudTemplateOptions#fenceMode(FenceMode)
*/
public static VCloudTemplateOptions fenceMode(FenceMode fenceMode) {
return new VCloudTemplateOptions().fenceMode(fenceMode);
}
// methods that only facilitate returning the correct object type
/**
* @see TemplateOptions#inboundPorts
*/
public static VCloudTemplateOptions inboundPorts(int... ports) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.inboundPorts(ports));
}
/**
* @see TemplateOptions#port
*/
public static VCloudTemplateOptions blockOnPort(int port, int seconds) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.blockOnPort(port, seconds));
}
/**
* @see TemplateOptions#userMetadata(Map)
*/
public static VCloudTemplateOptions userMetadata(Map<String, String> userMetadata) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.userMetadata(userMetadata));
}
/**
* @see TemplateOptions#userMetadata(String, String)
*/
public static VCloudTemplateOptions userMetadata(String key, String value) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.userMetadata(key, value));
}
/**
* @see TemplateOptions#nodeNames(Iterable)
*/
public static VCloudTemplateOptions nodeNames(Iterable<String> nodeNames) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.nodeNames(nodeNames));
}
/**
* @see TemplateOptions#networks(Iterable)
*/
public static VCloudTemplateOptions networks(Iterable<String> networks) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.networks(networks));
}
}
/**
* @return description of the vApp
*/
public String getDescription() {
return description;
}
/**
* @return customizationScript on the vms
*/
public String getCustomizationScript() {
return customizationScript;
}
/**
* @return ipAddressAllocationMode on the vms
*/
public IpAddressAllocationMode getIpAddressAllocationMode() {
return ipAddressAllocationMode;
}
/**
* @return parentNetwork to connect to the vms
*/
public URI getParentNetwork() {
return parentNetwork;
}
/**
* @return FenceMode to connect the parent network with
*/
public FenceMode getFenceMode() {
return fenceMode;
}
// methods that only facilitate returning the correct object type
/**
* @see TemplateOptions#blockOnPort
*/
@Override
public VCloudTemplateOptions blockOnPort(int port, int seconds) {
return VCloudTemplateOptions.class.cast(super.blockOnPort(port, seconds));
}
/**
*
* special thing is that we do assume if you are passing groups that you have
* everything you need already defined. for example, our option inboundPorts
* normally creates ingress rules accordingly but if we notice you've
* specified securityGroups, we do not mess with rules at all
*
* @see TemplateOptions#inboundPorts
*/
@Override
public VCloudTemplateOptions inboundPorts(int... ports) {
return VCloudTemplateOptions.class.cast(super.inboundPorts(ports));
}
/**
* @see TemplateOptions#authorizePublicKey(String)
*/
@Override
public VCloudTemplateOptions authorizePublicKey(String publicKey) {
return VCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
}
/**
* @see TemplateOptions#installPrivateKey(String)
*/
@Override
public VCloudTemplateOptions installPrivateKey(String privateKey) {
return VCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
}
/**
* {@inheritDoc}
*/
@Override
public VCloudTemplateOptions userMetadata(Map<String, String> userMetadata) {
return VCloudTemplateOptions.class.cast(super.userMetadata(userMetadata));
}
/**
* {@inheritDoc}
*/
@Override
public VCloudTemplateOptions userMetadata(String key, String value) {
return VCloudTemplateOptions.class.cast(super.userMetadata(key, value));
}
/**
* {@inheritDoc}
*/
@Override
public VCloudTemplateOptions nodeNames(Iterable<String> nodeNames) {
return VCloudTemplateOptions.class.cast(super.nodeNames(nodeNames));
}
/**
* {@inheritDoc}
*/
@Override
public VCloudTemplateOptions networks(Iterable<String> networks) {
return VCloudTemplateOptions.class.cast(super.networks(networks));
}
}

View File

@ -1,299 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.strategy;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.get;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue;
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getCredentialsFrom;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
import java.net.URI;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.logging.Logger;
import org.jclouds.ovf.Network;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.BuildVersion;
import org.jclouds.vcloud.TaskStillRunningException;
import org.jclouds.vcloud.VCloudApi;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.NetworkConnection;
import org.jclouds.vcloud.domain.NetworkConnectionSection;
import org.jclouds.vcloud.domain.NetworkConnectionSection.Builder;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSet;
@Singleton
public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final VCloudApi client;
protected final Predicate<URI> successTester;
protected final LoadingCache<URI, VAppTemplate> vAppTemplates;
protected final NetworkConfigurationForNetworkAndOptions networkConfigurationForNetworkAndOptions;
protected final String buildVersion;
@Inject
protected InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn(VCloudApi client,
Predicate<URI> successTester, LoadingCache<URI, VAppTemplate> vAppTemplates, NetworkConfigurationForNetworkAndOptions networkConfigurationForNetworkAndOptions,
@BuildVersion String buildVersion) {
this.client = client;
this.successTester = successTester;
this.vAppTemplates = vAppTemplates;
this.networkConfigurationForNetworkAndOptions = networkConfigurationForNetworkAndOptions;
this.buildVersion = buildVersion;
}
/**
* per john ellis at bluelock, vCloud Director 1.5 is more strict than earlier versions.
* <p/>
* It appears to be 15 characters to match Windows' hostname limitation. Must be alphanumeric, at
* least one non-number character and hyphens and underscores are the only non-alpha character
* allowed.
*/
public static enum ComputerNameValidator {
INSTANCE;
private DnsNameValidator validator;
ComputerNameValidator() {
this.validator = new DnsNameValidator(3, 15);
}
public void validate(@Nullable String t) throws IllegalArgumentException {
this.validator.validate(t);
}
}
public NodeAndInitialCredentials<VApp> createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
// no sense waiting until failures occur later
ComputerNameValidator.INSTANCE.validate(name);
VApp vAppResponse = instantiateVAppFromTemplate(name, template);
waitForTask(vAppResponse.getTasks().get(0));
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
// vm data is available after instantiate completes
vAppResponse = client.getVAppApi().getVApp(vAppResponse.getHref());
// per above check, we know there is only a single VM
Vm vm = get(vAppResponse.getChildren(), 0);
template.getOptions().userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group);
VCloudTemplateOptions vOptions = VCloudTemplateOptions.class.cast(template.getOptions());
// note we cannot do tasks in parallel or VCD will throw "is busy" errors
// note we must do this before any other customizations as there is a dependency on
// valid naming conventions before you can perform commands such as updateCPUCount
logger.trace(">> updating customization vm(%s) name->(%s)", vm.getName(), name);
waitForTask(updateVmWithNameAndCustomizationScript(vm, name, vOptions.getCustomizationScript()));
logger.trace("<< updated customization vm(%s)", name);
ensureVmHasAllocationModeOrPooled(vAppResponse, vOptions.getIpAddressAllocationMode());
int cpuCount = (int) getCores(template.getHardware());
logger.trace(">> updating cpuCount(%d) vm(%s)", cpuCount, vm.getName());
waitForTask(updateCPUCountOfVm(vm, cpuCount));
logger.trace("<< updated cpuCount vm(%s)", vm.getName());
int memoryMB = template.getHardware().getRam();
logger.trace(">> updating memoryMB(%d) vm(%s)", memoryMB, vm.getName());
waitForTask(updateMemoryMBOfVm(vm, memoryMB));
logger.trace("<< updated memoryMB vm(%s)", vm.getName());
logger.trace(">> deploying vApp(%s)", vAppResponse.getName());
waitForTask(client.getVAppApi().deployVApp(vAppResponse.getHref()));
logger.trace("<< deployed vApp(%s)", vAppResponse.getName());
// only after deploy is the password valid
vAppResponse = client.getVAppApi().getVApp(vAppResponse.getHref());
logger.trace(">> powering on vApp(%s)", vAppResponse.getName());
client.getVAppApi().powerOnVApp(vAppResponse.getHref());
return new NodeAndInitialCredentials<VApp>(vAppResponse, vAppResponse.getHref().toASCIIString(),
getCredentialsFrom(vAppResponse));
}
@VisibleForTesting
protected VApp instantiateVAppFromTemplate(String name, Template template) {
VCloudTemplateOptions vOptions = VCloudTemplateOptions.class.cast(template.getOptions());
URI templateId = URI.create(template.getImage().getId());
VAppTemplate vAppTemplate = vAppTemplates.getUnchecked(templateId);
if (vAppTemplate.getChildren().size() > 1)
throw new UnsupportedOperationException("we currently do not support multiple vms in a vAppTemplate "
+ vAppTemplate);
if (vAppTemplate.getNetworkSection().getNetworks().size() > 1)
throw new UnsupportedOperationException(
"we currently do not support multiple network connections in a vAppTemplate " + vAppTemplate);
Network networkToConnect = get(vAppTemplate.getNetworkSection().getNetworks(), 0);
NetworkConfig config = networkConfigurationForNetworkAndOptions.apply(networkToConnect, vOptions);
// note that in VCD 1.5, the network name after instantiation will be the same as the parent
InstantiateVAppTemplateOptions options = addNetworkConfig(config);
// TODO make disk size specifiable
// disk((long) ((template.getHardware().getVolumes().get(0).getSize()) *
// 1024 * 1024l));
String description = VCloudTemplateOptions.class.cast(template.getOptions()).getDescription();
if (description == null) {
Map<String, String> md = metadataAndTagsAsCommaDelimitedValue(template.getOptions());
description = Joiner.on('\n').withKeyValueSeparator("=").join(md);
}
options.description(description);
options.deploy(false);
options.powerOn(false);
URI VDC = URI.create(template.getLocation().getId());
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VApp vAppResponse = client.getVAppTemplateApi().createVAppInVDCByInstantiatingTemplate(name, VDC, templateId,
options);
return vAppResponse;
}
// TODO: filtering on "none" is a hack until we can filter on
// vAppTemplate.getNetworkConfigSection().getNetworkConfigs() where
// name = getChildren().NetworkConnectionSection.connection where ipallocationmode == none
static Predicate<Network> networkWithNoIpAllocation = new Predicate<Network>() {
@Override
public boolean apply(Network input) {
return "none".equals(input.getName());
}
};
public void waitForTask(Task task) {
if (!successTester.apply(task.getHref())) {
throw new TaskStillRunningException(task);
}
}
/**
* Naming constraints modifying a VM on a VApp in vCloud Director (at least v1.5) can be more
* strict than those in a vAppTemplate. For example, while it is possible to instantiate a
* vAppTemplate with a VM named (incorrectly) {@code Ubuntu_10.04}, you must change the name to a
* valid (alphanumeric underscore) name before you can update it.
*/
public Task updateVmWithNameAndCustomizationScript(Vm vm, String name, @Nullable String customizationScript) {
GuestCustomizationSection guestConfiguration = vm.getGuestCustomizationSection();
guestConfiguration.setComputerName(name);
if (customizationScript != null) {
// In version 1.0.0, the api returns a script that loses newlines, so we cannot append to a
// customization script.
// TODO: parameterize whether to overwrite or append existing customization
if (!buildVersion.startsWith("1.0.0") && !"".endsWith(buildVersion)
&& guestConfiguration.getCustomizationScript() != null)
customizationScript = guestConfiguration.getCustomizationScript() + "\n" + customizationScript;
guestConfiguration.setCustomizationScript(customizationScript);
}
return client.getVmApi().updateGuestCustomizationOfVm(guestConfiguration, vm.getHref());
}
public void ensureVmHasAllocationModeOrPooled(VApp vApp, @Nullable IpAddressAllocationMode ipAllocationMode) {
Network networkToConnect = find(vApp.getNetworkSection().getNetworks(), not(networkWithNoIpAllocation));
Vm vm = get(vApp.getChildren(), 0);
NetworkConnectionSection net = vm.getNetworkConnectionSection();
checkArgument(!net.getConnections().isEmpty(), "no connections on vm %s", vm);
NetworkConnection toConnect = findWithPoolAllocationOrFirst(net);
if (ipAllocationMode == null)
ipAllocationMode = toConnect.getIpAddressAllocationMode();
// make sure that we are in fact allocating ips
if (ipAllocationMode == IpAddressAllocationMode.NONE)
ipAllocationMode = IpAddressAllocationMode.POOL;
if (toConnect.isConnected() && toConnect.getIpAddressAllocationMode() == ipAllocationMode
&& toConnect.getNetwork().equals(networkToConnect.getName())) {
// then we don't need to change the network settings, and can save a call
} else {
Builder builder = net.toBuilder();
builder.connections(ImmutableSet.of(toConnect.toBuilder().network(networkToConnect.getName()).connected(true)
.ipAddressAllocationMode(ipAllocationMode).build()));
logger.trace(">> updating networkConnection vm(%s)", vm.getName());
waitForTask(client.getVmApi().updateNetworkConnectionOfVm(builder.build(), vm.getHref()));
logger.trace("<< updated networkConnection vm(%s)", vm.getName());
}
}
private NetworkConnection findWithPoolAllocationOrFirst(NetworkConnectionSection net) {
return find(net.getConnections(), new Predicate<NetworkConnection>() {
@Override
public boolean apply(NetworkConnection input) {
return input.getIpAddressAllocationMode() == IpAddressAllocationMode.POOL;
}
}, get(net.getConnections(), 0));
}
public Task updateCPUCountOfVm(Vm vm, int cpuCount) {
return client.getVmApi().updateCPUCountOfVm(cpuCount, vm.getHref());
}
public Task updateMemoryMBOfVm(Vm vm, int memoryInMB) {
return client.getVmApi().updateMemoryMBOfVm(memoryInMB, vm.getHref());
}
}

View File

@ -1,76 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.strategy;
import java.net.URI;
import javax.inject.Inject;
import org.jclouds.ovf.Network;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import com.google.common.annotations.Beta;
import com.google.common.base.Supplier;
@Beta
public class NetworkConfigurationForNetworkAndOptions {
protected final Supplier<NetworkConfig> defaultNetworkConfig;
protected final FenceMode defaultFenceMode;
@Inject
protected NetworkConfigurationForNetworkAndOptions(Supplier<NetworkConfig> defaultNetworkConfig,
FenceMode defaultFenceMode) {
this.defaultNetworkConfig = defaultNetworkConfig;
this.defaultFenceMode = defaultFenceMode;
}
/**
*
* returns a {@link NetworkConfig} used to instantiate a vAppTemplate to
* either the default parent (org) network, or one specified by options.
*
* @param networkToConnect
* network defined in the VAppTemplate you wish to connect to
* @param vOptions
* options to override defaults with
* @return
*/
public NetworkConfig apply(Network networkToConnect, VCloudTemplateOptions vOptions) {
NetworkConfig config;
URI userDefinedParentNetwork = vOptions.getParentNetwork();
FenceMode fenceMode = vOptions.getFenceMode() != null ? vOptions.getFenceMode() : defaultFenceMode;
if (userDefinedParentNetwork != null) {
config = NetworkConfig.builder().networkName("jclouds").fenceMode(fenceMode)
.parentNetwork(userDefinedParentNetwork).build();
} else {
config = defaultNetworkConfig.get().toBuilder().fenceMode(fenceMode).build();
}
// if we only have a disconnected network, we are adding a new section
// for the upstream
if (InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.networkWithNoIpAllocation
.apply(networkToConnect)) {
// TODO: remove the disconnected entry
} else {
config = config.toBuilder().networkName(networkToConnect.getName()).build();
}
return config;
}
}

View File

@ -1,262 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.contains;
import static com.google.common.collect.Iterables.filter;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.ovf.Envelope;
import org.jclouds.util.Throwables2;
import org.jclouds.vcloud.TaskInErrorStateException;
import org.jclouds.vcloud.TaskStillRunningException;
import org.jclouds.vcloud.VCloudApi;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.suppliers.VAppTemplatesSupplier;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
/**
* defines the connection between the {@link org.jclouds.vcloud.VCloudApi} implementation and the jclouds
* {@link ComputeService}
*/
@Singleton
public class VCloudComputeServiceAdapter implements ComputeServiceAdapter<VApp, VAppTemplate, VAppTemplate, Location> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final VCloudApi client;
protected final Predicate<URI> successTester;
protected final InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn booter;
protected final Supplier<Map<String, Org>> nameToOrg;
protected final Supplier<Set<VAppTemplate>> templates;
protected final Function<VAppTemplate, Envelope> templateToEnvelope;
@Inject
protected VCloudComputeServiceAdapter(VCloudApi client, Predicate<URI> successTester,
InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn booter,
Supplier<Map<String, Org>> nameToOrg, VAppTemplatesSupplier templates,
Function<VAppTemplate, Envelope> templateToEnvelope) {
this.client = checkNotNull(client, "client");
this.successTester = checkNotNull(successTester, "successTester");
this.booter = checkNotNull(booter, "booter");
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
this.templates = checkNotNull(templates, "templates");
this.templateToEnvelope = checkNotNull(templateToEnvelope, "templateToEnvelope");
}
@Override
public NodeAndInitialCredentials<VApp> createNodeWithGroupEncodedIntoName(String group, String name,
Template template) {
return booter.createNodeWithGroupEncodedIntoName(group, name, template);
}
@Override
public Iterable<VAppTemplate> listHardwareProfiles() {
return supportedTemplates();
}
private Iterable<VAppTemplate> supportedTemplates() {
return filter(templates.get(), new Predicate<VAppTemplate>() {
@Override
public boolean apply(VAppTemplate from) {
try {
templateToEnvelope.apply(from);
} catch (IllegalArgumentException e) {
logger.warn("Unsupported: " + e.getMessage());
return false;
} catch (RuntimeException e) {
IllegalArgumentException e2 = Throwables2.getFirstThrowableOfType(e, IllegalArgumentException.class);
if (e2 != null) {
logger.warn("Unsupported: " + e2.getMessage());
return false;
} else {
throw e;
}
}
return true;
}
});
}
@Override
public Iterable<VAppTemplate> listImages() {
return supportedTemplates();
}
@Override
public Iterable<VApp> listNodes() {
// TODO: parallel or cache
Builder<VApp> nodes = ImmutableSet.builder();
for (Org org : nameToOrg.get().values()) {
for (ReferenceType vdc : org.getVDCs().values()) {
for (ReferenceType resource : client.getVDCApi().getVDC(vdc.getHref()).getResourceEntities().values()) {
if (resource.getType().equals(VCloudMediaType.VAPP_XML)) {
addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);
}
}
}
}
return nodes.build();
}
@Override
public Iterable<VApp> listNodesByIds(final Iterable<String> ids) {
return filter(listNodes(), new Predicate<VApp>() {
@Override
public boolean apply(VApp vm) {
return contains(ids, vm.getHref().toASCIIString());
}
});
}
@VisibleForTesting
void addVAppToSetRetryingIfNotYetPresent(Builder<VApp> nodes, ReferenceType vdc, ReferenceType resource) {
VApp node = null;
int i = 0;
while (node == null && i++ < 3) {
try {
node = client.getVAppApi().getVApp(resource.getHref());
nodes.add(node);
} catch (NullPointerException e) {
logger.warn("vApp %s not yet present in vdc %s", resource.getName(), vdc.getName());
}
}
}
@Override
public Iterable<Location> listLocations() {
// Not using the adapter to determine locations
return ImmutableSet.<Location>of();
}
@Override
public VApp getNode(String in) {
URI id = URI.create(in);
return client.getVAppApi().getVApp(id);
}
@Override
public VAppTemplate getImage(String in) {
URI id = URI.create(in);
return client.getVAppTemplateApi().getVAppTemplate(id);
}
@Override
public void destroyNode(String id) {
URI vappId = URI.create(checkNotNull(id, "node.id"));
VApp vApp = cancelAnyRunningTasks(vappId);
if (vApp.getStatus() != Status.OFF) {
logger.debug(">> powering off VApp vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
try {
waitForTask(client.getVAppApi().powerOffVApp(vApp.getHref()));
vApp = client.getVAppApi().getVApp(vApp.getHref());
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
} catch (IllegalStateException e) {
logger.warn(e, "<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
}
logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
try {
waitForTask(client.getVAppApi().undeployVApp(vApp.getHref()));
vApp = client.getVAppApi().getVApp(vApp.getHref());
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
} catch (IllegalStateException e) {
logger.warn(e, "<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
}
}
logger.debug(">> deleting vApp(%s)", vApp.getHref());
waitForTask(client.getVAppApi().deleteVApp(vApp.getHref()));
logger.debug("<< deleted vApp(%s)", vApp.getHref());
}
VApp waitForPendingTasksToComplete(URI vappId) {
VApp vApp = client.getVAppApi().getVApp(vappId);
if (vApp.getTasks().isEmpty())
return vApp;
for (Task task : vApp.getTasks())
waitForTask(task);
return client.getVAppApi().getVApp(vappId);
}
VApp cancelAnyRunningTasks(URI vappId) {
VApp vApp = client.getVAppApi().getVApp(vappId);
if (vApp.getTasks().isEmpty())
return vApp;
for (Task task : vApp.getTasks()) {
try {
client.getTaskApi().cancelTask(task.getHref());
waitForTask(task);
} catch (TaskInErrorStateException e) {
}
}
return client.getVAppApi().getVApp(vappId);
}
public void waitForTask(Task task) {
if (!successTester.apply(task.getHref()))
throw new TaskStillRunningException(task);
}
@Override
public void rebootNode(String in) {
URI id = URI.create(checkNotNull(in, "node.id"));
waitForTask(client.getVAppApi().resetVApp(id));
}
@Override
public void resumeNode(String in) {
URI id = URI.create(checkNotNull(in, "node.id"));
waitForTask(client.getVAppApi().powerOnVApp(id));
}
@Override
public void suspendNode(String in) {
URI id = URI.create(checkNotNull(in, "node.id"));
waitForTask(client.getVAppApi().powerOffVApp(id));
}
}

View File

@ -1,112 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.compute.util;
import static com.google.common.collect.Iterables.filter;
import java.util.Set;
import org.jclouds.cim.CIMPredicates;
import org.jclouds.cim.ResourceAllocationSettingData;
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.vcloud.domain.NetworkConnection;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkAdapter;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Iterables;
public class VCloudComputeUtils {
public static OperatingSystem toComputeOs(VApp vApp, OperatingSystem defaultOs) {
CIMOperatingSystem cimOs = toComputeOs(vApp);
return cimOs != null ? cimOs : defaultOs;
}
public static CIMOperatingSystem toComputeOs(VApp vApp) {
// TODO we need to change the design so that it doesn't assume single-vms
return !vApp.getChildren().isEmpty() ? toComputeOs(Iterables.get(vApp.getChildren(), 0)) : null;
}
public static CIMOperatingSystem toComputeOs(Vm vm) {
return CIMOperatingSystem.toComputeOs(vm.getOperatingSystemSection());
}
public static String getVirtualSystemIdentifierOfFirstVMIn(VApp vApp) {
return !vApp.getChildren().isEmpty() ? getVirtualSystemIdentifierOf(Iterables.get(vApp.getChildren(), 0)) : null;
}
public static String getVirtualSystemIdentifierOf(Vm vm) {
if (vm.getVirtualHardwareSection() != null && vm.getVirtualHardwareSection().getSystem() != null)
return vm.getVirtualHardwareSection().getSystem().getVirtualSystemIdentifier();
return null;
}
public static LoginCredentials getCredentialsFrom(VApp vApp) {
return !vApp.getChildren().isEmpty() ? getCredentialsFrom(Iterables.get(vApp.getChildren(), 0)) : null;
}
public static LoginCredentials getCredentialsFrom(VAppTemplate vApp) {
return !vApp.getChildren().isEmpty() ? getCredentialsFrom(Iterables.get(vApp.getChildren(), 0)) : null;
}
public static LoginCredentials getCredentialsFrom(Vm vm) {
LoginCredentials.Builder builder = LoginCredentials.builder();
if (vm.getGuestCustomizationSection() != null)
builder.password(vm.getGuestCustomizationSection().getAdminPassword());
return builder.build();
}
public static Set<String> getIpsFromVApp(VApp vApp) {
// TODO make this work with composite vApps
if (vApp.getChildren().isEmpty())
return ImmutableSet.of();
Builder<String> ips = ImmutableSet.builder();
Vm vm = Iterables.get(vApp.getChildren(), 0);
// TODO: figure out how to differentiate public from private ip addresses
// assumption is that we'll do this from the network object, which may
// have
// enough data to tell whether or not it is a public network without
// string
// parsing. At worst, we could have properties set per cloud provider to
// declare the networks which are public, then check against these in
// networkconnection.getNetwork
if (vm.getNetworkConnectionSection() != null) {
for (NetworkConnection connection : vm.getNetworkConnectionSection().getConnections()) {
if (connection.getIpAddress() != null)
ips.add(connection.getIpAddress());
if (connection.getExternalIpAddress() != null)
ips.add(connection.getExternalIpAddress());
}
} else {
for (ResourceAllocationSettingData net : filter(vm.getVirtualHardwareSection().getItems(),
CIMPredicates.resourceTypeIn(ResourceType.ETHERNET_ADAPTER))) {
if (net instanceof VCloudNetworkAdapter) {
VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net);
if (vNet.getIpAddress() != null)
ips.add(vNet.getIpAddress());
}
}
}
return ips.build();
}
}

View File

@ -1,59 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CATALOG;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
@Singleton
public class DefaultCatalogForOrg implements Function<ReferenceType, ReferenceType> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<Map<String, Org>> nameToOrg;
@Inject
public DefaultCatalogForOrg(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
@Catalog Predicate<ReferenceType> defaultSelector, Supplier<Map<String, Org>> nameToOrg) {
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_CATALOG,
checkNotNull(defaultSelector, "defaultSelector"));
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
}
@Override
public ReferenceType apply(ReferenceType defaultOrg) {
Org org = nameToOrg.get().get(defaultOrg.getName());
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
return selector.apply(org.getCatalogs().values());
}
}

View File

@ -1,61 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import java.net.URI;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
@Singleton
public class DefaultNetworkForVDC implements Function<ReferenceType, ReferenceType> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<Map<URI, VDC>> uriToVDC;
@Inject
public DefaultNetworkForVDC(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
@Network Predicate<ReferenceType> defaultSelector, Supplier<Map<URI, VDC>> uriToVDC) {
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_NETWORK,
checkNotNull(defaultSelector, "defaultSelector"));
this.uriToVDC = checkNotNull(uriToVDC, "uriToVDC");
}
@Override
public ReferenceType apply(ReferenceType defaultVDC) {
org.jclouds.vcloud.domain.VDC vDC = uriToVDC.get().get(defaultVDC.getHref());
checkState(vDC != null, "could not retrieve VDC at %s", defaultVDC);
return selector.apply(vDC.getAvailableNetworks().values());
}
}

View File

@ -1,54 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
@Singleton
public class DefaultOrgForUser implements Supplier<ReferenceType> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<VCloudSession> session;
@Inject
public DefaultOrgForUser(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
@Org Predicate<ReferenceType> defaultSelector, Supplier<VCloudSession> session) {
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_ORG, checkNotNull(
defaultSelector, "defaultSelector"));
this.session = checkNotNull(session, "session");
}
@Override
public ReferenceType get() {
return selector.apply(session.get().getOrgs().values());
}
}

View File

@ -1,49 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
@Singleton
public class DefaultTasksListForOrg implements Function<ReferenceType, ReferenceType> {
private final Supplier<Map<String, Org>> nameToOrg;
@Inject
public DefaultTasksListForOrg(Supplier<Map<String, Org>> nameToOrg) {
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
}
@Override
public ReferenceType apply(ReferenceType defaultOrg) {
org.jclouds.vcloud.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
return org.getTasksList();
}
}

View File

@ -1,161 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.config;
import java.net.URI;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
public class DefaultVCloudReferencesModule extends AbstractModule {
@Override
protected void configure() {
bind(new TypeLiteral<Supplier<ReferenceType>>() {
}).annotatedWith(Org.class).to(DefaultOrgForUser.class);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.Org
protected Predicate<ReferenceType> provideDefaultOrgSelector(Injector i) {
return Predicates.alwaysTrue();
}
@Provides
@org.jclouds.vcloud.endpoints.TasksList
@Singleton
protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg);
}
@Provides
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.Catalog
protected Predicate<ReferenceType> provideDefaultCatalogSelector(Injector i) {
return i.getInstance(WriteableCatalog.class);
}
@Provides
@Singleton
protected Supplier<Map<URI, org.jclouds.vcloud.domain.Catalog>> provideCatalogsById(
Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>> supplier) {
return Suppliers
.compose(
new Function<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>, Map<URI, org.jclouds.vcloud.domain.Catalog>>() {
@Override
public Map<URI, Catalog> apply(Map<String, Map<String, Catalog>> arg0) {
Builder<URI, Catalog> builder = ImmutableMap.builder();
for (Map<String, Catalog> v1 : arg0.values()) {
for (Catalog v2 : v1.values()) {
builder.put(v2.getHref(), v2);
}
}
return builder.build();
}
}, supplier);
}
@Singleton
public static class WriteableCatalog implements Predicate<ReferenceType> {
@Resource
protected Logger logger = Logger.NULL;
private final Supplier<Map<URI, org.jclouds.vcloud.domain.Catalog>> catalogsByIdSupplier;
@Inject
public WriteableCatalog(Supplier<Map<URI, org.jclouds.vcloud.domain.Catalog>> catalogsByIdSupplier) {
this.catalogsByIdSupplier = catalogsByIdSupplier;
}
@Override
public boolean apply(ReferenceType arg0) {
// TODO: this is inefficient, calculating the index each time, but
// shouldn't be added to constructor as the supplier is an expensive
// call
Map<URI, Catalog> index = catalogsByIdSupplier.get();
Catalog catalog = index.get(arg0.getHref());
if (catalog == null) {
if (logger.isTraceEnabled())
logger.trace("didn't find catalog %s", arg0);
return false;
} else
return !catalog.isReadOnly();
}
}
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(defaultVDCURIForOrg, defaultOrg);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VDC
protected Predicate<ReferenceType> provideDefaultVDCSelector(Injector i) {
return Predicates.alwaysTrue();
}
@Provides
@org.jclouds.vcloud.endpoints.Network
@Singleton
protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
@org.jclouds.vcloud.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.Network
protected Predicate<ReferenceType> provideDefaultNetworkSelector(Injector i) {
return Predicates.alwaysTrue();
}
}

View File

@ -1,59 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
@Singleton
public class DefaultVDCForOrg implements Function<ReferenceType, ReferenceType> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<Map<String, Org>> nameToOrg;
@Inject
public DefaultVDCForOrg(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
@VDC Predicate<ReferenceType> defaultSelector, Supplier<Map<String, Org>> nameToOrg) {
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_VDC,
checkNotNull(defaultSelector, "defaultSelector"));
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
}
@Override
public ReferenceType apply(ReferenceType defaultOrg) {
Org org = nameToOrg.get().get(defaultOrg.getName());
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
return selector.apply(org.getVDCs().values());
}
}

View File

@ -1,536 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Maps.uniqueIndex;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
import static org.jclouds.util.Predicates2.retry;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler;
import org.jclouds.domain.Location;
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.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.ovf.Envelope;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresHttpApi;
import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.rest.config.HttpApiModule;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.VCloudApi;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.VCloudVersionsApi;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.OrgList;
import org.jclouds.vcloud.functions.CatalogItemsInCatalog;
import org.jclouds.vcloud.functions.CatalogItemsInOrg;
import org.jclouds.vcloud.functions.CatalogsInOrg;
import org.jclouds.vcloud.functions.DefaultNetworkNameInTemplate;
import org.jclouds.vcloud.functions.OrgsForLocations;
import org.jclouds.vcloud.functions.OrgsForNames;
import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems;
import org.jclouds.vcloud.functions.VDCsInOrg;
import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse;
import org.jclouds.vcloud.internal.VCloudLoginApi;
import org.jclouds.vcloud.loaders.OVFLoader;
import org.jclouds.vcloud.loaders.VAppTemplateLoader;
import org.jclouds.vcloud.location.DefaultVDC;
import org.jclouds.vcloud.location.OrgAndVDCToLocationSupplier;
import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationSettingDataHandler;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Lists;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
*/
@ConfiguresHttpApi
public class VCloudHttpApiModule extends HttpApiModule<VCloudApi> {
@Provides
@Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, final VCloudLoginApi login) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
new Supplier<VCloudSession>() {
@Override
public VCloudSession get() {
return login.login();
}
@Override
public String toString() {
return Objects.toStringHelper(login).add("method", "login").toString();
}
}, seconds, TimeUnit.SECONDS);
}
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<Iterable<CatalogItem>, Iterable<VAppTemplate>>>() {
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
});
bind(ResourceAllocationSettingDataHandler.class).to(VCloudResourceAllocationSettingDataHandler.class);
installDefaultVCloudEndpointsModule();
bind(new TypeLiteral<Function<ReferenceType, Location>>() {
}).to(new TypeLiteral<FindLocationForResource>() {
});
bind(new TypeLiteral<Function<Org, Iterable<Catalog>>>() {
}).to(new TypeLiteral<CatalogsInOrg>() {
});
bind(new TypeLiteral<Function<Org, Iterable<VDC>>>() {
}).to(new TypeLiteral<VDCsInOrg>() {
});
bind(new TypeLiteral<Function<Iterable<String>, Iterable<Org>>>() {
}).to(new TypeLiteral<OrgsForNames>() {
});
bind(new TypeLiteral<Function<Iterable<Location>, Iterable<Org>>>() {
}).to(new TypeLiteral<OrgsForLocations>() {
});
bind(new TypeLiteral<Function<Catalog, Iterable<CatalogItem>>>() {
}).to(new TypeLiteral<CatalogItemsInCatalog>() {
});
bind(new TypeLiteral<Function<Org, Iterable<CatalogItem>>>() {
}).to(new TypeLiteral<CatalogItemsInOrg>() {
});
bindCacheLoaders();
bind(new TypeLiteral<Function<VAppTemplate, String>>() {
}).annotatedWith(Network.class).to(new TypeLiteral<DefaultNetworkNameInTemplate>() {
});
bind(new TypeLiteral<Function<VAppTemplate, Envelope>>() {
}).to(new TypeLiteral<ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException>() {
});
bindHttpApi(binder(), VCloudApi.class);
bindHttpApi(binder(), VCloudVersionsApi.class);
bindHttpApi(binder(), VCloudLoginApi.class);
}
protected void bindCacheLoaders() {
bind(new TypeLiteral<CacheLoader<URI, VAppTemplate>>() {
}).to(new TypeLiteral<VAppTemplateLoader>() {
});
bind(new TypeLiteral<CacheLoader<URI, Envelope>>() {
}).to(new TypeLiteral<OVFLoader>() {
});
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VDC
protected Supplier<Map<String, String>> provideVDCtoORG(Supplier<Map<String, Org>> orgNameToOrgSupplier) {
return Suppliers.compose(new Function<Map<String, Org>, Map<String, String>>() {
@Override
public Map<String, String> apply(Map<String, Org> arg0) {
Builder<String, String> returnVal = ImmutableMap.builder();
for (Entry<String, Org> orgr : arg0.entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
}
return returnVal.build();
}
}, orgNameToOrgSupplier);
}
@Provides
@Singleton
protected Supplier<Map<String, Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, OrgMapSupplier supplier) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
TimeUnit.SECONDS);
}
@Provides
@Singleton
@OrgList
protected Supplier<URI> provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
return Suppliers.compose(new Function<VCloudSession, URI>() {
@Override
public URI apply(VCloudSession arg0) {
return URI.create(getLast(arg0.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*", "org"));
}
@Override
public String toString() {
return "orgListURI()";
}
}, sessionSupplier);
}
@Singleton
public static class OrgMapSupplier implements Supplier<Map<String, Org>> {
protected final Supplier<VCloudSession> sessionSupplier;
protected final Function<Iterable<String>, Iterable<Org>> organizationsForNames;
@Inject
protected OrgMapSupplier(Supplier<VCloudSession> sessionSupplier,
Function<Iterable<String>, Iterable<Org>> organizationsForNames) {
this.sessionSupplier = sessionSupplier;
this.organizationsForNames = organizationsForNames;
}
@Override
public Map<String, Org> get() {
return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name);
}
}
protected void installDefaultVCloudEndpointsModule() {
install(new DefaultVCloudReferencesModule());
}
@Singleton
public static class OrgCatalogSupplier implements
Supplier<Map<String, Map<String, Catalog>>> {
protected final Supplier<Map<String, Org>> orgSupplier;
protected final Function<Org, Iterable<Catalog>> allCatalogsInOrg;
@Inject
protected OrgCatalogSupplier(Supplier<Map<String, Org>> orgSupplier,
Function<Org, Iterable<Catalog>> allCatalogsInOrg) {
this.orgSupplier = orgSupplier;
this.allCatalogsInOrg = allCatalogsInOrg;
}
@Override
public Map<String, Map<String, Catalog>> get() {
return transformValues(transformValues(orgSupplier.get(), allCatalogsInOrg),
new Function<Iterable<? extends Catalog>, Map<String, Catalog>>() {
@Override
public Map<String, Catalog> apply(Iterable<? extends Catalog> from) {
return ImmutableMap.copyOf(uniqueIndex(from, name));
}
});
}
}
@VCloudToken
@Provides
@Singleton
Supplier<String> provideVCloudToken(Supplier<VCloudSession> cache) {
return Suppliers.compose(new Function<VCloudSession, String>() {
@Override
public String apply(VCloudSession input) {
return checkNotNull(input.getVCloudToken(), "No token present in session");
}
}, cache);
}
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
TimeUnit.SECONDS);
}
@Provides
@Singleton
protected Supplier<Map<URI, VDC>> provideURIToVDC(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
URItoVDC supplier) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
TimeUnit.SECONDS);
}
@Singleton
public static class URItoVDC implements Supplier<Map<URI, VDC>> {
private final Supplier<Map<String, Map<String, VDC>>> orgVDCMap;
@Inject
URItoVDC(Supplier<Map<String, Map<String, VDC>>> orgVDCMap) {
this.orgVDCMap = orgVDCMap;
}
@Override
public Map<URI, VDC> get() {
return uniqueIndex(concat(transform(orgVDCMap.get().values(),
new Function<Map<String, VDC>, Iterable<VDC>>() {
@Override
public Iterable<VDC> apply(
Map<String, VDC> from) {
return from.values();
}
})), new Function<VDC, URI>() {
@Override
public URI apply(VDC from) {
return from.getHref();
}
});
}
}
static final Function<ReferenceType, String> name = new Function<ReferenceType, String>() {
@Override
public String apply(ReferenceType from) {
return from.getName();
}
};
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VCloudLogin
protected Supplier<URI> provideAuthenticationURI(final VCloudVersionsApi versionService,
@ApiVersion final String version) {
return new Supplier<URI>() {
@Override
public URI get() {
SortedMap<String, URI> versions = versionService.getSupportedVersions();
checkState(!versions.isEmpty(), "No versions present");
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
return versions.get(version);
}
public String toString() {
return "login()";
}
};
}
@Singleton
private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> {
private final Supplier<VCloudSession> sessionSupplier;
@Inject
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
this.sessionSupplier = sessionSupplier;
}
@Override
public Map<String, ReferenceType> get() {
return sessionSupplier.get().getOrgs();
}
}
@Provides
@Singleton
protected Supplier<Org> provideOrg(final Supplier<Map<String, Org>> orgSupplier,
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(new Function<ReferenceType, Org>() {
@Override
public Org apply(ReferenceType input) {
return orgSupplier.get().get(input.getName());
}
}, defaultOrg);
}
@Provides
@Singleton
protected Predicate<URI> successTester(Injector injector,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
return retry(injector.getInstance(TaskSuccess.class), completed);
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, Catalog>>> provideOrgCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgCatalogSupplier supplier) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
TimeUnit.SECONDS);
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgVDCSupplier supplier) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
TimeUnit.SECONDS);
}
@Singleton
public static class OrgVDCSupplier implements Supplier<Map<String, Map<String, VDC>>> {
protected final Supplier<Map<String, Org>> orgSupplier;
private final Function<Org, Iterable<VDC>> allVDCsInOrg;
@Inject
protected OrgVDCSupplier(Supplier<Map<String, Org>> orgSupplier,
Function<Org, Iterable<VDC>> allVDCsInOrg) {
this.orgSupplier = orgSupplier;
this.allVDCsInOrg = allVDCsInOrg;
}
@Override
public Map<String, Map<String, VDC>> get() {
return transformValues(transformValues(orgSupplier.get(), allVDCsInOrg),
new Function<Iterable<? extends VDC>, Map<String, VDC>>() {
@Override
public Map<String, VDC> apply(
Iterable<? extends VDC> from) {
return uniqueIndex(Lists.newArrayList(from), name);
}
});
}
}
@Singleton
public static class OrgCatalogItemSupplier implements
Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> {
protected final Supplier<Map<String, Map<String, Catalog>>> catalogSupplier;
protected final Function<Catalog, Iterable<CatalogItem>> allCatalogItemsInCatalog;
@Inject
protected OrgCatalogItemSupplier(
Supplier<Map<String, Map<String, Catalog>>> catalogSupplier,
Function<Catalog, Iterable<CatalogItem>> allCatalogItemsInCatalog) {
this.catalogSupplier = catalogSupplier;
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
}
@Override
public Map<String, Map<String, Map<String, CatalogItem>>> get() {
return transformValues(
catalogSupplier.get(),
new Function<Map<String, Catalog>, Map<String, Map<String, CatalogItem>>>() {
@Override
public Map<String, Map<String, CatalogItem>> apply(
Map<String, Catalog> from) {
return transformValues(
from,
new Function<Catalog, Map<String, CatalogItem>>() {
@Override
public Map<String, CatalogItem> apply(Catalog from) {
return uniqueIndex(filter(allCatalogItemsInCatalog.apply(from), notNull()), name);
}
});
}
});
}
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> provideOrgCatalogItemSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgCatalogItemSupplier supplier) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
TimeUnit.SECONDS);
}
@Provides
@Singleton
protected FenceMode defaultFenceMode(@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
return FenceMode.fromValue(fenceMode);
}
@Provides
@Singleton
protected LoadingCache<URI, VAppTemplate> vAppTemplates(CacheLoader<URI, VAppTemplate> vAppTemplates) {
return CacheBuilder.newBuilder().build(vAppTemplates);
}
@Provides
@Singleton
protected LoadingCache<URI, Envelope> envelopes(CacheLoader<URI, Envelope> envelopes) {
return CacheBuilder.newBuilder().build(envelopes);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseVCloudErrorFromHttpResponse.class);
}
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(DefaultVDC.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(OrgAndVDCToLocationSupplier.class).in(Scopes.SINGLETON);
}
}

View File

@ -1,70 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
* The AllocationModel element defines how resources are allocated in a vDC.
*/
public enum AllocationModel {
/**
* Resources are committed to a vDC only when vApps are created in it
*/
ALLOCATION_VAPP,
/**
* Only a percentage of the resources you allocate are committed to the organization vDC.
*/
ALLOCATION_POOL,
/**
* All the resources you allocate are committed as a pool to the organization vDC. vApps in vDCs
* that support this allocation model can specify values for resource and limit.
*/
RESERVATION_POOL,
/**
* The VCloud API returned a model unsupported in the version 1.0 spec.
*/
UNRECOGNIZED;
public String value() {
switch (this) {
case ALLOCATION_VAPP:
return "AllocationVApp";
case ALLOCATION_POOL:
return "AllocationPool";
case RESERVATION_POOL:
return "ReservationPool";
default:
return "UnrecognizedModel";
}
}
@Override
public String toString() {
return value();
}
public static AllocationModel fromValue(String model) {
try {
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(model, "model")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -1,106 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
/**
* reports storage resource consumption in a vDC.
*/
public class Capacity {
private final String units;
private final long allocated;
private final long limit;
private final int used;
private final long overhead;
public Capacity(String units, long allocated, long limit, int used, long overhead) {
this.units = units;
this.limit = limit;
this.allocated = allocated;
this.used = used;
this.overhead = overhead;
}
public String getUnits() {
return units;
}
public long getAllocated() {
return allocated;
}
public long getLimit() {
return limit;
}
/**
* percentage of the allocation in use.
*/
public int getUsed() {
return used;
}
/**
* number of Units allocated to vShield Manager virtual machines provisioned from this vDC.
*/
public long getOverhead() {
return overhead;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (allocated ^ (allocated >>> 32));
result = prime * result + (int) (limit ^ (limit >>> 32));
result = prime * result + (int) (overhead ^ (overhead >>> 32));
result = prime * result + ((units == null) ? 0 : units.hashCode());
result = prime * result + used;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Capacity other = (Capacity) obj;
if (allocated != other.allocated)
return false;
if (limit != other.limit)
return false;
if (overhead != other.overhead)
return false;
if (units == null) {
if (other.units != null)
return false;
} else if (!units.equals(other.units))
return false;
if (used != other.used)
return false;
return true;
}
@Override
public String toString() {
return "[allocated=" + allocated + ", limit=" + limit + ", overhead=" + overhead + ", units=" + units + ", used="
+ used + "]";
}
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.util.List;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import com.google.inject.ImplementedBy;
@org.jclouds.vcloud.endpoints.Catalog
@ImplementedBy(CatalogImpl.class)
public interface Catalog extends ReferenceType, Map<String, ReferenceType> {
/**
* Reference to the org containing this vDC.
*
* @since vcloud api 1.0
* @return org, or null if this is a version before 1.0 where the org isn't present
*/
ReferenceType getOrg();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* readonly element, true if the catalog is published
*
* @since vcloud api 1.0
*/
boolean isPublished();
/**
* @return true, if the current user cannot modify the catalog
* @since vcloud api 1.0
*/
boolean isReadOnly();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
}

View File

@ -1,34 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.util.Map;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import com.google.inject.ImplementedBy;
@ImplementedBy(CatalogItemImpl.class)
public interface CatalogItem extends ReferenceType {
String getDescription();
ReferenceType getEntity();
Map<String, String> getProperties();
}

View File

@ -1,440 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.net.URI;
import org.jclouds.vcloud.VCloudMediaType;
/**
* The GuestCustomization of a Vm contains customization parameters for the guest operating system
* of the virtual machine.
*/
public class GuestCustomizationSection {
protected final String type;
protected final URI href;
protected String info;
protected Boolean enabled;
protected Boolean changeSid;
protected String virtualMachineId;
protected Boolean joinDomainEnabled;
protected Boolean useOrgSettings;
protected String domainName;
protected String domainUserName;
protected String domainUserPassword;
protected Boolean adminPasswordEnabled;
protected Boolean adminPasswordAuto;
protected String adminPassword;
protected Boolean resetPasswordRequired;
protected String customizationScript;
protected String computerName;
protected final ReferenceType edit;
public GuestCustomizationSection(URI href) {
this.href = href;
this.type = VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML;
this.info = "Specifies Guest OS Customization Settings";
this.edit = null;
}
public GuestCustomizationSection(String type, URI href, String info, Boolean enabled, Boolean changeSid,
String virtualMachineId, Boolean joinDomainEnabled, Boolean useOrgSettings, String domainName,
String domainUserName, String domainUserPassword, Boolean adminPasswordEnabled, Boolean adminPasswordAuto,
String adminPassword, Boolean resetPasswordRequired, String customizationScript, String computerName,
ReferenceType edit) {
this.type = type;
this.href = href;
this.info = info;
this.enabled = enabled;
this.changeSid = changeSid;
this.virtualMachineId = virtualMachineId;
this.joinDomainEnabled = joinDomainEnabled;
this.useOrgSettings = useOrgSettings;
this.domainName = domainName;
this.domainUserName = domainUserName;
this.domainUserPassword = domainUserPassword;
this.adminPasswordEnabled = adminPasswordEnabled;
this.adminPasswordAuto = adminPasswordAuto;
this.adminPassword = adminPassword;
this.resetPasswordRequired = resetPasswordRequired;
this.customizationScript = customizationScript;
this.computerName = computerName;
this.edit = edit;
}
/**
*
* @return media type of this section
*/
public String getType() {
return type;
}
/**
*
* @return URL to access this section
*/
public URI getHref() {
return href;
}
/**
*
* @return
*/
public String getInfo() {
return info;
}
/**
*
* @return if true, to enable guest customization at power on
*/
public Boolean isEnabled() {
return enabled;
}
/**
*
* @return if true, customization will run sysprep to change the Windows SID for this virtual
* machine
*/
public Boolean shouldChangeSid() {
return changeSid;
}
/**
*
* @return unique identifier for this virtual machine
*/
public String getVirtualMachineId() {
return virtualMachineId;
}
/**
*
* @return if true, this virtual machine can join a Windows domain
*/
public Boolean isJoinDomainEnabled() {
return joinDomainEnabled;
}
/**
*
* @return if true, this virtual machine uses the containing organizations default values for
* Windows domain name, domain user name, and domain user password
*/
public Boolean useOrgSettings() {
return useOrgSettings;
}
/**
*
* @return if UseOrgSettings is false, specifies the Windows domain to join
*/
public String getDomainName() {
return domainName;
}
/**
*
* @return if UseOrgSettings is false, specifies the Windows domain user name
*/
public String getDomainUserName() {
return domainUserName;
}
/**
*
* @return if UseOrgSettings is false, specifies the Windows domain users password
*/
public String getDomainUserPassword() {
return domainUserPassword;
}
/**
*
* @return true if the guest OS allows use of a local administrator password
*/
public Boolean isAdminPasswordEnabled() {
return adminPasswordEnabled;
}
/**
*
* @return true if the local administrator password should be automatically generated
*/
public Boolean isAdminPasswordAuto() {
return adminPasswordAuto;
}
/**
*
* @return local administrator password for this virtual machine
*/
public String getAdminPassword() {
return adminPassword;
}
/**
*
* @return if true, the local administrator must reset his password on first use
*/
public Boolean isResetPasswordRequired() {
return resetPasswordRequired;
}
/**
*
* @return the customization script to run
*/
public String getCustomizationScript() {
return customizationScript;
}
/**
*
* @return name of this virtual machine in DNS or Windows domain
*/
public String getComputerName() {
return computerName;
}
/**
*
* @return edit link
*/
public ReferenceType getEdit() {
return edit;
}
@Override
public String toString() {
return "[href=" + getHref() + ", type=" + getType() + ", info=" + getInfo() + ", enabled=" + isEnabled() + "]";
}
@Override
public int hashCode() {
int prime = 31;
int result = 1;
result = prime * result + ((adminPassword == null) ? 0 : adminPassword.hashCode());
result = prime * result + ((adminPasswordAuto == null) ? 0 : adminPasswordAuto.hashCode());
result = prime * result + ((adminPasswordEnabled == null) ? 0 : adminPasswordEnabled.hashCode());
result = prime * result + ((changeSid == null) ? 0 : changeSid.hashCode());
result = prime * result + ((computerName == null) ? 0 : computerName.hashCode());
result = prime * result + ((customizationScript == null) ? 0 : customizationScript.hashCode());
result = prime * result + ((domainName == null) ? 0 : domainName.hashCode());
result = prime * result + ((domainUserName == null) ? 0 : domainUserName.hashCode());
result = prime * result + ((domainUserPassword == null) ? 0 : domainUserPassword.hashCode());
result = prime * result + ((edit == null) ? 0 : edit.hashCode());
result = prime * result + ((enabled == null) ? 0 : enabled.hashCode());
result = prime * result + ((href == null) ? 0 : href.hashCode());
result = prime * result + ((info == null) ? 0 : info.hashCode());
result = prime * result + ((joinDomainEnabled == null) ? 0 : joinDomainEnabled.hashCode());
result = prime * result + ((resetPasswordRequired == null) ? 0 : resetPasswordRequired.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((useOrgSettings == null) ? 0 : useOrgSettings.hashCode());
result = prime * result + ((virtualMachineId == null) ? 0 : virtualMachineId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
GuestCustomizationSection other = (GuestCustomizationSection) obj;
if (adminPassword == null) {
if (other.adminPassword != null)
return false;
} else if (!adminPassword.equals(other.adminPassword))
return false;
if (adminPasswordAuto == null) {
if (other.adminPasswordAuto != null)
return false;
} else if (!adminPasswordAuto.equals(other.adminPasswordAuto))
return false;
if (adminPasswordEnabled == null) {
if (other.adminPasswordEnabled != null)
return false;
} else if (!adminPasswordEnabled.equals(other.adminPasswordEnabled))
return false;
if (changeSid == null) {
if (other.changeSid != null)
return false;
} else if (!changeSid.equals(other.changeSid))
return false;
if (computerName == null) {
if (other.computerName != null)
return false;
} else if (!computerName.equals(other.computerName))
return false;
if (customizationScript == null) {
if (other.customizationScript != null)
return false;
} else if (!customizationScript.equals(other.customizationScript))
return false;
if (domainName == null) {
if (other.domainName != null)
return false;
} else if (!domainName.equals(other.domainName))
return false;
if (domainUserName == null) {
if (other.domainUserName != null)
return false;
} else if (!domainUserName.equals(other.domainUserName))
return false;
if (domainUserPassword == null) {
if (other.domainUserPassword != null)
return false;
} else if (!domainUserPassword.equals(other.domainUserPassword))
return false;
if (edit == null) {
if (other.edit != null)
return false;
} else if (!edit.equals(other.edit))
return false;
if (enabled == null) {
if (other.enabled != null)
return false;
} else if (!enabled.equals(other.enabled))
return false;
if (href == null) {
if (other.href != null)
return false;
} else if (!href.equals(other.href))
return false;
if (info == null) {
if (other.info != null)
return false;
} else if (!info.equals(other.info))
return false;
if (joinDomainEnabled == null) {
if (other.joinDomainEnabled != null)
return false;
} else if (!joinDomainEnabled.equals(other.joinDomainEnabled))
return false;
if (resetPasswordRequired == null) {
if (other.resetPasswordRequired != null)
return false;
} else if (!resetPasswordRequired.equals(other.resetPasswordRequired))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
if (useOrgSettings == null) {
if (other.useOrgSettings != null)
return false;
} else if (!useOrgSettings.equals(other.useOrgSettings))
return false;
if (virtualMachineId == null) {
if (other.virtualMachineId != null)
return false;
} else if (!virtualMachineId.equals(other.virtualMachineId))
return false;
return true;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Boolean getChangeSid() {
return changeSid;
}
public void setChangeSid(Boolean changeSid) {
this.changeSid = changeSid;
}
public Boolean getJoinDomainEnabled() {
return joinDomainEnabled;
}
public void setJoinDomainEnabled(Boolean joinDomainEnabled) {
this.joinDomainEnabled = joinDomainEnabled;
}
public Boolean shouldUseOrgSettings() {
return useOrgSettings;
}
public void setUseOrgSettings(Boolean useOrgSettings) {
this.useOrgSettings = useOrgSettings;
}
public Boolean getAdminPasswordEnabled() {
return adminPasswordEnabled;
}
public void setAdminPasswordEnabled(Boolean adminPasswordEnabled) {
this.adminPasswordEnabled = adminPasswordEnabled;
}
public Boolean getAdminPasswordAuto() {
return adminPasswordAuto;
}
public void setAdminPasswordAuto(Boolean adminPasswordAuto) {
this.adminPasswordAuto = adminPasswordAuto;
}
public Boolean getResetPasswordRequired() {
return resetPasswordRequired;
}
public void setResetPasswordRequired(Boolean resetPasswordRequired) {
this.resetPasswordRequired = resetPasswordRequired;
}
public void setInfo(String info) {
this.info = info;
}
public void setVirtualMachineId(String virtualMachineId) {
this.virtualMachineId = virtualMachineId;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public void setDomainUserName(String domainUserName) {
this.domainUserName = domainUserName;
}
public void setDomainUserPassword(String domainUserPassword) {
this.domainUserPassword = domainUserPassword;
}
public void setAdminPassword(String adminPassword) {
this.adminPassword = adminPassword;
}
public void setCustomizationScript(String customizationScript) {
this.customizationScript = customizationScript;
}
public void setComputerName(String computerName) {
this.computerName = computerName;
}
}

View File

@ -1,96 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.util.Set;
import org.jclouds.cim.ResourceAllocationSettingData;
import org.jclouds.cim.VirtualSystemSettingData;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* The InstantiateVAppTemplateParams element forms the body of an instantiateVappTemplate request.
*/
public class InstantiateVAppTemplateParams {
protected final String info;
protected final VirtualSystemSettingData virtualSystem;
protected final Set<ResourceAllocationSettingData> resourceAllocations = Sets.newLinkedHashSet();
public InstantiateVAppTemplateParams(String info, VirtualSystemSettingData virtualSystem, Iterable<ResourceAllocationSettingData> resourceAllocations) {
this.info = info;
this.virtualSystem = virtualSystem;
Iterables.addAll(this.resourceAllocations, resourceAllocations);
}
public String getInfo() {
return info;
}
public VirtualSystemSettingData getSystem() {
return virtualSystem;
}
public Set<ResourceAllocationSettingData> getResourceAllocationSettingDatas() {
return resourceAllocations;
}
@Override
public String toString() {
return "[info=" + getInfo() + ", virtualSystem=" + getSystem() + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((info == null) ? 0 : info.hashCode());
result = prime * result + ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode());
result = prime * result + ((virtualSystem == null) ? 0 : virtualSystem.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
InstantiateVAppTemplateParams other = (InstantiateVAppTemplateParams) obj;
if (info == null) {
if (other.info != null)
return false;
} else if (!info.equals(other.info))
return false;
if (resourceAllocations == null) {
if (other.resourceAllocations != null)
return false;
} else if (!resourceAllocations.equals(other.resourceAllocations))
return false;
if (virtualSystem == null) {
if (other.virtualSystem != null)
return false;
} else if (!virtualSystem.equals(other.virtualSystem))
return false;
return true;
}
}

View File

@ -1,231 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
/**
* describes a single network connection.
*/
public class NetworkConnection {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String network;
private int networkConnectionIndex;
private String ipAddress;
private String externalIpAddress;
private boolean connected;
private String MACAddress;
private IpAddressAllocationMode ipAddressAllocationMode;
public Builder network(String network) {
this.network = network;
return this;
}
public Builder networkConnectionIndex(int networkConnectionIndex) {
this.networkConnectionIndex = networkConnectionIndex;
return this;
}
public Builder ipAddress(String ipAddress) {
this.ipAddress = ipAddress;
return this;
}
public Builder externalIpAddress(String externalIpAddress) {
this.externalIpAddress = externalIpAddress;
return this;
}
public Builder connected(boolean connected) {
this.connected = connected;
return this;
}
public Builder MACAddress(String MACAddress) {
this.MACAddress = MACAddress;
return this;
}
public Builder ipAddressAllocationMode(IpAddressAllocationMode ipAddressAllocationMode) {
this.ipAddressAllocationMode = ipAddressAllocationMode;
return this;
}
public NetworkConnection build() {
return new NetworkConnection(network, networkConnectionIndex, ipAddress, externalIpAddress, connected,
MACAddress, ipAddressAllocationMode);
}
public static Builder fromNetworkConnection(NetworkConnection in) {
return new Builder().network(in.getNetwork()).networkConnectionIndex(in.getNetworkConnectionIndex())
.ipAddress(in.getIpAddress()).externalIpAddress(in.getExternalIpAddress()).connected(in.isConnected())
.MACAddress(in.getMACAddress()).ipAddressAllocationMode(in.getIpAddressAllocationMode());
}
}
private final String network;
private final int networkConnectionIndex;
@Nullable
private final String ipAddress;
@Nullable
private final String externalIpAddress;
private final boolean connected;
@Nullable
private final String MACAddress;
private final IpAddressAllocationMode ipAddressAllocationMode;
public NetworkConnection(String network, int networkConnectionIndex, @Nullable String ipAddress,
@Nullable String externalIpAddress, boolean connected, @Nullable String MACAddress,
IpAddressAllocationMode ipAddressAllocationMode) {
this.network = network;
this.networkConnectionIndex = networkConnectionIndex;
this.ipAddress = ipAddress;
this.externalIpAddress = externalIpAddress;
this.connected = connected;
this.MACAddress = MACAddress;
this.ipAddressAllocationMode = ipAddressAllocationMode;
}
/**
* @return The name of the network to which this connection connects.
*/
public String getNetwork() {
return network;
}
/**
* @return The value in the rasd:AddressOnParent element of the device supporting this
* connection.
*/
public int getNetworkConnectionIndex() {
return networkConnectionIndex;
}
/**
* @return IP address of this connection
*/
@Nullable
public String getIpAddress() {
return ipAddress;
}
/**
* @return If the network that the NIC is connected to has NAT or port mapping, the external
* address is populated in this element.
*/
@Nullable
public String getExternalIpAddress() {
return externalIpAddress;
}
/**
* @return If the vApp is deployed, specifies the current state of its connection. If the vApp is
* undeployed, specifies whether this connection should be connected at deployment time.
*/
public boolean isConnected() {
return connected;
}
/**
* @return MAC address of this connection
*/
@Nullable
public String getMACAddress() {
return MACAddress;
}
/**
* @return specifies how an IP address is allocated to this connection
*/
public IpAddressAllocationMode getIpAddressAllocationMode() {
return ipAddressAllocationMode;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((MACAddress == null) ? 0 : MACAddress.hashCode());
result = prime * result + (connected ? 1231 : 1237);
result = prime * result + ((externalIpAddress == null) ? 0 : externalIpAddress.hashCode());
result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
result = prime * result + ((ipAddressAllocationMode == null) ? 0 : ipAddressAllocationMode.hashCode());
result = prime * result + ((network == null) ? 0 : network.hashCode());
result = prime * result + networkConnectionIndex;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
NetworkConnection other = (NetworkConnection) obj;
if (MACAddress == null) {
if (other.MACAddress != null)
return false;
} else if (!MACAddress.equals(other.MACAddress))
return false;
if (connected != other.connected)
return false;
if (externalIpAddress == null) {
if (other.externalIpAddress != null)
return false;
} else if (!externalIpAddress.equals(other.externalIpAddress))
return false;
if (ipAddress == null) {
if (other.ipAddress != null)
return false;
} else if (!ipAddress.equals(other.ipAddress))
return false;
if (ipAddressAllocationMode == null) {
if (other.ipAddressAllocationMode != null)
return false;
} else if (!ipAddressAllocationMode.equals(other.ipAddressAllocationMode))
return false;
if (network == null) {
if (other.network != null)
return false;
} else if (!network.equals(other.network))
return false;
if (networkConnectionIndex != other.networkConnectionIndex)
return false;
return true;
}
public Builder toBuilder() {
return Builder.fromNetworkConnection(this);
}
@Override
public String toString() {
return "[network=" + network + ", connected=" + connected + ", ipAddress=" + ipAddress + ", externalIpAddress="
+ externalIpAddress + ", networkConnectionIndex=" + networkConnectionIndex + ", ipAddressAllocationMode="
+ ipAddressAllocationMode + ", MACAddress=" + MACAddress + "]";
}
}

View File

@ -1,218 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
/**
* The NetworkConnectionSection element specifies how a Vm is connected to a vApp network. It
* extends the ovf:NetworkConnection element.
* <p/>
* NOTE The OVF NetworkSection element and the vCloud API NetworkConnectionSection element specify
* many of the same parameters for a network connection. If both are present in a Vm body, the
* values specified in the NetworkConnectionSection override those specified in the NetworkSection.
*/
public class NetworkConnectionSection {
public static Builder builder() {
return new Builder();
}
public static class Builder {
protected String type;
protected URI href;
protected String info;
protected Integer primaryNetworkConnectionIndex;
protected Set<NetworkConnection> connections = ImmutableSet.of();
protected ReferenceType edit;
public Builder type(String type) {
this.type = type;
return this;
}
public Builder href(URI href) {
this.href = href;
return this;
}
public Builder info(String info) {
this.info = info;
return this;
}
public Builder primaryNetworkConnectionIndex(Integer primaryNetworkConnectionIndex) {
this.primaryNetworkConnectionIndex = primaryNetworkConnectionIndex;
return this;
}
public Builder connections(Iterable<NetworkConnection> connections) {
this.connections = ImmutableSet.copyOf(checkNotNull(connections, "connections"));
return this;
}
public Builder edit(ReferenceType edit) {
this.edit = edit;
return this;
}
public NetworkConnectionSection build() {
return new NetworkConnectionSection(type, href, info, primaryNetworkConnectionIndex, connections, edit);
}
public static Builder fromNetworkConnectionSection(NetworkConnectionSection in) {
return new Builder().type(in.getType()).href(in.getHref()).info(in.getInfo())
.primaryNetworkConnectionIndex(in.getPrimaryNetworkConnectionIndex()).connections(in.getConnections())
.edit(in.getEdit());
}
}
protected final String type;
protected final URI href;
protected final String info;
protected final Integer primaryNetworkConnectionIndex;
protected final Set<NetworkConnection> connections;
protected final ReferenceType edit;
public NetworkConnectionSection(String type, URI href, String info, Integer primaryNetworkConnectionIndex,
Iterable<NetworkConnection> connections, ReferenceType edit) {
this.type = type;
this.href = href;
this.info = info;
this.primaryNetworkConnectionIndex = primaryNetworkConnectionIndex;
this.connections = ImmutableSet.copyOf(checkNotNull(connections, "connections"));
this.edit = edit;
}
/**
*
* @return media type of this section
*/
public String getType() {
return type;
}
/**
*
* @return URL to access this section
*/
public URI getHref() {
return href;
}
/**
*
* @return
*/
public String getInfo() {
return info;
}
/**
*
* @return The value of the rasd:AddressOnParent element of the device (NIC) supporting the
* primary network connection to the containing virtual machine.
*/
public Integer getPrimaryNetworkConnectionIndex() {
return primaryNetworkConnectionIndex;
}
/**
*
*/
public Set<NetworkConnection> getConnections() {
return connections;
}
/**
*
*/
public ReferenceType getEdit() {
return edit;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((connections == null) ? 0 : connections.hashCode());
result = prime * result + ((edit == null) ? 0 : edit.hashCode());
result = prime * result + ((href == null) ? 0 : href.hashCode());
result = prime * result + ((info == null) ? 0 : info.hashCode());
result = prime * result
+ ((primaryNetworkConnectionIndex == null) ? 0 : primaryNetworkConnectionIndex.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
NetworkConnectionSection other = (NetworkConnectionSection) obj;
if (connections == null) {
if (other.connections != null)
return false;
} else if (!connections.equals(other.connections))
return false;
if (edit == null) {
if (other.edit != null)
return false;
} else if (!edit.equals(other.edit))
return false;
if (href == null) {
if (other.href != null)
return false;
} else if (!href.equals(other.href))
return false;
if (info == null) {
if (other.info != null)
return false;
} else if (!info.equals(other.info))
return false;
if (primaryNetworkConnectionIndex == null) {
if (other.primaryNetworkConnectionIndex != null)
return false;
} else if (!primaryNetworkConnectionIndex.equals(other.primaryNetworkConnectionIndex))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
public Builder toBuilder() {
return Builder.fromNetworkConnectionSection(this);
}
@Override
public String toString() {
return "[href=" + href + ", connections=" + connections + ", primaryNetworkConnectionIndex="
+ primaryNetworkConnectionIndex + "]";
}
}

View File

@ -1,84 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.util.List;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.OrgImpl;
import com.google.inject.ImplementedBy;
/**
* A vCloud organization is a high-level abstraction that provides a unit of administration for
* objects and resources. As viewed by a user, an organization (represented by an Org element) can
* contain Catalog, Network, and vDC elements. If there are any queued, running, or recently
* completed tasks owned by a member of the organization, it also contains a TasksList element. As
* viewed by an administrator, an organization also contains users, groups, and other information
*/
@ImplementedBy(OrgImpl.class)
public interface Org extends ReferenceType {
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* full name of the organization
*
* @since vcloud api 1.0
*/
@Nullable
String getFullName();
/**
* @since vcloud api 0.8
*/
Map<String, ReferenceType> getCatalogs();
/**
* @since vcloud api 0.8
*/
Map<String, ReferenceType> getVDCs();
/**
* If there are any queued, running, or recently completed tasks owned by a member of the
* organization, it also contains a TasksList.
*
* @since vcloud api 0.8
*/
@Nullable
ReferenceType getTasksList();
/**
* @since vcloud api 1.0
*/
Map<String, ReferenceType> getNetworks();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
}

View File

@ -1,48 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.net.URI;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import com.google.inject.ImplementedBy;
/**
* Many container elements are populated with references to contained objects. Each reference
* consists of a hyperlink, an optional media type, and a name.
*/
@ImplementedBy(ReferenceTypeImpl.class)
public interface ReferenceType extends Comparable<ReferenceType> {
/**
* @return hyperlink to the referenced object
*/
URI getHref();
/**
* @return name of the referenced object.
*
*/
String getName();
/**
* @return object type, expressed as the media type of the XML representing of the object
* @see VCloudMediaType
*/
String getType();
}

View File

@ -1,244 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Objects such as vAppTemplate, vApp, and Vm have a status attribute whose value indicates the
* state of the object. Status for an object, such as a vAppTemplate or vApp, whose Children (Vm
* objects) each have a status of their own, is computed from the status of the Children.
*
* <h2>NOTE</h2>
* <p/>
* The deployment status of an object is indicated by the value of its deployed attribute.
*
* @since vcloud api 0.8
*/
public enum Status {
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} could not be created.
*
* @since vcloud api 1.0
*/
ERROR,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is unresolved.
*
* @since vcloud api 0.8
*/
UNRESOLVED,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is resolved.
*
* @since vcloud api 0.8
*/
RESOLVED,
/**
* The object is deployed.
* <p/>
* note that the documentation does not reference use of this.
*
* @since vcloud api 1.0
*/
DEPLOYED,
/**
* The {@link VApp} or {@link Vm} is suspended.
*
* @since vcloud api 0.8
*/
SUSPENDED,
/**
* The {@link VApp} or {@link Vm} is powered on
*
* @since vcloud api 0.8
*/
ON,
/**
* The {@link VApp} or {@link Vm} waiting for user input.
*
* @since vcloud api 1.0
*/
WAITING_FOR_INPUT,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is in an unknown state.
*
* @since vcloud api 1.0
*/
UNKNOWN,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is in an unrecognized state.
*
* @since vcloud api 1.0
*/
UNRECOGNIZED,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is off.
*
* @since vcloud api 0.8
*/
OFF,
/**
* The {@link VApp} or {@link Vm} is in an inconsistent state.
*
* @since vcloud api 1.0
*/
INCONSISTENT,
/**
* The {@link VAppTemplate} or {@link VApp} have children do not all have the same status.
*
* @since vcloud api 1.0
*/
MIXED,
/**
* The {@link VAppTemplate} Upload initiated, OVF descriptor pending
*
* @since vcloud api 1.0
*/
PENDING_DESCRIPTOR,
/**
* The {@link VAppTemplate} Upload initiated, copying contents
*
* @since vcloud api 1.0
*/
COPYING,
/**
* The {@link VAppTemplate} Upload initiated, disk contents pending
*
* @since vcloud api 1.0
*/
PENDING_CONTENTS,
/**
* The {@link VAppTemplate} Upload has been quarantined
*
* @since vcloud api 1.0
*/
QUARANTINED,
/**
* The {@link VAppTemplate} Upload quarantine period has expired
*
* @since vcloud api 1.0
*/
QUARANTINE_EXPIRED,
/**
* The {@link VAppTemplate} rejected
*
* @since vcloud api 1.0
*/
REJECTED,
/**
* The {@link VAppTemplate} transfer timeout
*
* @since vcloud api 1.0
*/
TRANSFER_TIMEOUT;
public String value() {
switch (this) {
case UNRESOLVED:
return "0";
case RESOLVED:
return "1";
case DEPLOYED:
return "2";
case SUSPENDED:
return "3";
case ON:
return "4";
case WAITING_FOR_INPUT:
return "5";
case UNKNOWN:
return "6";
case UNRECOGNIZED:
return "7";
case OFF:
return "8";
case INCONSISTENT:
return "9";
case MIXED:
return "10";
case PENDING_DESCRIPTOR:
return "11";
case COPYING:
return "12";
case PENDING_CONTENTS:
return "13";
case QUARANTINED:
return "14";
case QUARANTINE_EXPIRED:
return "15";
case REJECTED:
return "16";
case TRANSFER_TIMEOUT:
return "17";
default:
return "7";
}
}
public static Status fromValue(String status) {
try {
return fromValue(Integer.parseInt(checkNotNull(status, "status")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
public static Status fromValue(int v) {
switch (v) {
case 0:
return UNRESOLVED;
case 1:
return RESOLVED;
case 2:
return DEPLOYED;
case 3:
return SUSPENDED;
case 4:
return ON;
case 5:
return WAITING_FOR_INPUT;
case 6:
return UNKNOWN;
case 7:
return UNRECOGNIZED;
case 8:
return OFF;
case 9:
return INCONSISTENT;
case 10:
return MIXED;
case 11:
return PENDING_DESCRIPTOR;
case 12:
return COPYING;
case 13:
return PENDING_CONTENTS;
case 14:
return QUARANTINED;
case 15:
return QUARANTINE_EXPIRED;
case 16:
return REJECTED;
case 17:
return TRANSFER_TIMEOUT;
default:
return UNRECOGNIZED;
}
}
}

View File

@ -1,72 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.util.Date;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.TaskImpl;
import com.google.inject.ImplementedBy;
/**
* Whenever the result of a request cannot be returned immediately, the server creates a Task
* object. Tasks owned by an object such as a vApp or vDC are contained in the Tasks element of the
* objects XML representation. This element is readonly.
*/
@ImplementedBy(TaskImpl.class)
public interface Task extends ReferenceType {
/**
* The current status of the task.
*/
String getOperation();
/**
* The current status of the task.
*/
TaskStatus getStatus();
/**
* date and time when the task was started.
*/
Date getStartTime();
/**
* date and time when the task completed. Does not appear for running tasks.
*/
Date getEndTime();
/**
* date and time at which the task expires. By default, tasks expire 24 hours after their start
* time. Expired tasks cannot be queried.
*/
Date getExpiryTime();
/**
* A link to the object that owns the task. For copy operations, the owner is the copy that is
* being created. For delete operations, the owner is the deleted object, so this element is not
* included. For all other operations, the owner is the object to which the request was made.
*/
ReferenceType getOwner();
/**
* error message or related information returned by the task
*/
@Nullable
VCloudError getError();
}

View File

@ -1,68 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
public enum TaskStatus {
/**
* The task has completed and returned a value indicating success.
*/
SUCCESS,
/**
* The task is running.
*/
RUNNING,
/**
* The task has been queued for execution.
*/
QUEUED,
/**
* The task has completed and returned a value indicating an error.
*/
ERROR,
/**
* not an official status, temporarily in.
*/
CANCELLED, UNRECOGNIZED;
public String value() {
return name().toLowerCase();
}
@Override
public String toString() {
return value();
}
public static TaskStatus fromValue(String status) {
if ("CANCELED".equals(status.toUpperCase())) {
// TODO: ecloud hack
status = "CANCELLED";
} else if ("FAILED".equals(status.toUpperCase())) {
status = "ERROR";
} else if ("COMPLETED".equals(status.toUpperCase())) {
status = "SUCCESS";
}
try {
return valueOf(checkNotNull(status, "status").toUpperCase());
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -1,34 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.net.URI;
import java.util.SortedSet;
import org.jclouds.vcloud.domain.internal.TasksListImpl;
import com.google.inject.ImplementedBy;
@org.jclouds.vcloud.endpoints.TasksList
@ImplementedBy(TasksListImpl.class)
public interface TasksList {
URI getLocation();
SortedSet<Task> getTasks();
}

View File

@ -1,85 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.util.List;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
/**
* A VApp is the result of instantiation of a {@link VAppTemplate}. <h2>note</h2>
* <p/>
* When the {@link #getStatus} is {@link Status#UNRESOLVED}, there will be a task present for the
* instantiation of the VApp.
*/
public interface VApp extends ReferenceType {
/**
* Reference to the vdc containing this vApp.
*
* @since vcloud api 1.0
* @return vdc, or null if this is a version before 1.0 where the org isn't present
*/
ReferenceType getVDC();
/**
* The creation status of the vDC
*
* @since vcloud api 1.0
*/
Status getStatus();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
*
* @return true if the OVF descriptor for the template has been uploaded to the containing vDC.
* @since vcloud api 1.0
*/
boolean isOvfDescriptorUploaded();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
/**
* container for Vm elements representing virtual machines
*
* @since vcloud api 1.0
*/
Set<Vm> getChildren();
/**
* description of the predefined vApp internal networks in this template
*
* @return null if the vApp is not yet instantiated
* @since vcloud api 1.0
*/
@Nullable
VCloudNetworkSection getNetworkSection();
}

View File

@ -1,95 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.util.List;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.VAppTemplateImpl;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
import com.google.inject.ImplementedBy;
/**
* A VAppTemplate is an abstract description of a vApp. It is created when you upload an OVF package
* to a vDC.
*/
@ImplementedBy(VAppTemplateImpl.class)
public interface VAppTemplate extends ReferenceType {
/**
* Reference to the VDC containing this template.
*
* @since vcloud api 1.0
* @return org, or null if this is a version before 1.0 where the vdc isn't present
*/
ReferenceType getVDC();
/**
* @return creation status of the VAppTemplate.
*
* @since vcloud api 1.0
*/
Status getStatus();
/**
* optional description
*
* @since vcloud api 1.0
*/
@Nullable
String getDescription();
/**
* read-only container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
/**
*
* @return true if the OVF descriptor for the template has been uploaded to the containing vDC.
* @since vcloud api 1.0
*/
boolean isOvfDescriptorUploaded();
/**
* read-only identifier created on import
*
* @since vcloud api 1.0
*/
@Nullable
String getVAppScopedLocalId();
/**
* container for Vm elements representing virtual machines
*
* @since vcloud api 1.0
*/
Set<Vm> getChildren();
/**
* description of the predefined vApp internal networks in this template
*
* @return null if the vAppTemplate is still copying
* @since vcloud api 1.0
*/
@Nullable
VCloudNetworkSection getNetworkSection();
}

View File

@ -1,118 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.ErrorImpl;
import com.google.inject.ImplementedBy;
@ImplementedBy(ErrorImpl.class)
public interface VCloudError {
public static enum MinorCode {
/**
* The request was made by a user who had insufficient rights to the object or operation.
*/
ACCESS_TO_RESOURCE_IS_FORBIDDEN,
/**
* The request could not be validated or contained invalid XML.
*/
BAD_REQUEST,
/**
* A conflict was detected between sections of an OVF descriptor.
*/
CONFLICT,
/**
* The entity is busy
*/
BUSY_ENTITY,
/**
* An attempt to instantiate a vAppTemplate or use a vAppTemplate or a Vm in a composition did
* not include an AllEULAsAccepted element with a value of true.
*/
EULA_NOT_ACCEPTED,
/**
* Returned for any failure that cannot be matched to another minor error code.
*/
INTERNAL_SERVER_ERROR,
/**
* One or more references (href attribute values) supplied in the request could not be
* resolved to an object.
*/
INVALID_REFERENCE,
/**
* The HTTP method (GET, PUT, POST, DELETE) is not allowed for the request.
*/
METHOD_NOT_ALLOWED,
/**
* One or more references (href attribute values) supplied in the request could not be
* resolved to an object, or the Contenttype of the request was incorrect.
*/
RESOURCE_NOT_FOUND,
/**
* The request raised an exception that did not match any HTTP status code.
*/
UNKNOWN,
/**
* The wrong content type was specified for the request.
*/
UNSUPPORTED_MEDIA_TYPE, UNRECOGNIZED;
public static MinorCode fromValue(String minorCode) {
try {
return valueOf(checkNotNull(minorCode, "minorCode"));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}
/**
*
* @return message describing the error
*/
String getMessage();
/**
*
* @return matches the HTTP status code
*/
int getMajorErrorCode();
/**
*
* @return error code specific to the failed operation or null if vcloud <0.9
*/
@Nullable
MinorCode getMinorErrorCode();
/**
*
* @return optional additional information about the source of the error
*/
@Nullable
String getVendorSpecificErrorCode();
/**
*
* @return stack trace of the error, if available. This attribute is returned only when a request
* is made by the system administrator.
*/
String getStackTrace();
}

View File

@ -1,25 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.util.Map;
public interface VCloudSession {
String getVCloudToken();
Map<String, ReferenceType> getOrgs();
}

View File

@ -1,144 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.util.List;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import com.google.inject.ImplementedBy;
/**
* A vDC is a deployment environment for vApps. A Vdc element provides a user view of a vDC.
*/
@org.jclouds.vcloud.endpoints.VDC
@ImplementedBy(VDCImpl.class)
public interface VDC extends ReferenceType {
/**
* Reference to the org containing this vDC.
*
* @since vcloud api 1.0
* @return org, or null if this is a version before 1.0 where the org isn't present
*/
ReferenceType getOrg();
/**
* The creation status of the vDC
*
* @since vcloud api 1.0
*/
VDCStatus getStatus();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
/**
* defines how resources are allocated by the vDC. The value of this element is set by the
* administrator who created the vDC. It is readonly to users.
*
* @since vcloud api 1.0
*/
AllocationModel getAllocationModel();
/**
* defines the storage capacity available in the vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support storage capacity
*/
@Nullable
Capacity getStorageCapacity();
/**
* reports CPU resource consumption in a vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support cpu capacity
*/
@Nullable
Capacity getCpuCapacity();
/**
* reports memory resource consumption in a vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support memory capacity
*/
@Nullable
Capacity getMemoryCapacity();
/**
* container for ResourceEntity elements
*
* @since vcloud api 0.8
*/
Map<String, ReferenceType> getResourceEntities();
/**
* container for OrgNetwork elements that represent organization networks contained by the vDC
*
* @since vcloud api 0.8
*/
Map<String, ReferenceType> getAvailableNetworks();
/**
* maximum number of virtual NICs allowed in this vDC. Defaults to 0, which specifies an
* unlimited number.
*
* @since vcloud api 1.0
*/
int getNicQuota();
/**
* maximum number of OrgNetwork objects that can be deployed in this vDC. Defaults to 0, which
* specifies an unlimited number.
*
* @since vcloud api 1.0
*/
int getNetworkQuota();
/**
* maximum number of virtual machines that can be deployed in this vDC. Defaults to 0, which
* specifies an unlimited number.
*
* @since vcloud api 0.8
*/
int getVmQuota();
/**
* true if this vDC is enabled
*
* @since vcloud api 1.0
*/
boolean isEnabled();
}

View File

@ -1,57 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
/**
* The creation status of the vDC
*
* @see VDC#getStatus
*/
public enum VDCStatus {
CREATION_FAILED, NOT_READY, READY, UNKNOWN, UNRECOGNIZED;
public int value() {
switch (this) {
case CREATION_FAILED:
return -1;
case NOT_READY:
return 0;
case READY:
return 1;
case UNKNOWN:
return 2;
default:
return 3;
}
}
public static VDCStatus fromValue(int status) {
switch (status) {
case -1:
return CREATION_FAILED;
case 0:
return NOT_READY;
case 1:
return READY;
case 2:
return UNKNOWN;
default:
return UNRECOGNIZED;
}
}
}

View File

@ -1,106 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain;
import java.util.List;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.VmImpl;
import org.jclouds.vcloud.domain.ovf.VCloudOperatingSystemSection;
import org.jclouds.vcloud.domain.ovf.VCloudVirtualHardwareSection;
import com.google.inject.ImplementedBy;
/**
* A Vm represents a virtual machine, a member of a vApps Children container. <h2>note</h2>
* <p/>
* When the {@link #getStatus} is {@link Status#UNRESOLVED}, there will be a task present for the
* instantiation of the VApp.
*/
@ImplementedBy(VmImpl.class)
public interface Vm extends ReferenceType {
/**
* Reference to the {@link VApp} or {@link VAppTemplate} containing this vm.
*
* @since vcloud api 1.0
*/
ReferenceType getParent();
/**
* @return creation status of the Vm or null, if a part of a VAppTemplate
*
* @since vcloud api 1.0
*/
@Nullable
Status getStatus();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
/**
* @return virtual hardware that comprises this VM, or null, if part of a vApp template
*
* @since vcloud api 1.0
*/
@Nullable
VCloudVirtualHardwareSection getVirtualHardwareSection();
/**
* @return operating system on this VM, or null, if part of a vApp template
*
* @since vcloud api 1.0
*/
@Nullable
VCloudOperatingSystemSection getOperatingSystemSection();
/**
* @return network connections for this VM, or null if it doesn't exist
*
* @since vcloud api 1.0
*/
@Nullable
NetworkConnectionSection getNetworkConnectionSection();
/**
* @return guest customization section for this VM, or null if it doesn't exist
*
* @since vcloud api 1.0
*/
@Nullable
GuestCustomizationSection getGuestCustomizationSection();
/**
* read-only identifier created on import
*
* @since vcloud api 1.0
*/
@Nullable
String getVAppScopedLocalId();
}

View File

@ -1,186 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* Locations of resources in vCloud
*/
public class CatalogImpl extends LinkedHashMap<String, ReferenceType> implements Catalog {
private final String name;
private final String type;
private final URI href;
private final ReferenceType org;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final boolean published;
private final boolean readOnly;
public CatalogImpl(String name, String type, URI href, ReferenceType org, @Nullable String description,
Map<String, ReferenceType> contents, Iterable<Task> tasks, boolean published, boolean readOnly) {
this.name = checkNotNull(name, "name");
this.type = checkNotNull(type, "type");
this.org = org; // TODO: once <1.0 is killed check not null
this.description = description;
this.href = checkNotNull(href, "href");
putAll(checkNotNull(contents, "contents"));
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.published = published;
this.readOnly = readOnly;
}
/**
* {@inheritDoc}
*/
@Override
public URI getHref() {
return href;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getOrg() {
return org;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public String getType() {
return type;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isPublished() {
return published;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isReadOnly() {
return readOnly;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((href == null) ? 0 : href.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((org == null) ? 0 : org.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
CatalogImpl other = (CatalogImpl) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (href == null) {
if (other.href != null)
return false;
} else if (!href.equals(other.href))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (org == null) {
if (other.org != null)
return false;
} else if (!org.equals(other.org))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
@Override
public int compareTo(ReferenceType o) {
return (this == o) ? 0 : getHref().compareTo(o.getHref());
}
}

View File

@ -1,106 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.collect.Maps;
public class CatalogItemImpl extends ReferenceTypeImpl implements CatalogItem {
private final String description;
private final ReferenceType entity;
private final Map<String, String> properties = Maps.newLinkedHashMap();
public CatalogItemImpl(String name, URI id, @Nullable String description, ReferenceType entity,
Map<String, String> properties) {
super(name, VCloudMediaType.CATALOGITEM_XML, id);
this.description = description;
this.entity = checkNotNull(entity, "entity");
this.properties.putAll(checkNotNull(properties, "properties"));
}
@Override
public String getType() {
return VCloudMediaType.CATALOGITEM_XML;
}
public ReferenceType getEntity() {
return entity;
}
@Override
public String getDescription() {
return description;
}
public Map<String, String> getProperties() {
return properties;
}
@Override
public String toString() {
return "CatalogItemImpl [id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description="
+ getDescription() + ", entity=" + entity + ", properties=" + properties + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((entity == null) ? 0 : entity.hashCode());
result = prime * result + ((properties == null) ? 0 : properties.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
CatalogItemImpl other = (CatalogItemImpl) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (entity == null) {
if (other.entity != null)
return false;
} else if (!entity.equals(other.entity))
return false;
if (properties == null) {
if (other.properties != null)
return false;
} else if (!properties.equals(other.properties))
return false;
return true;
}
}

View File

@ -1,114 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.VCloudError;
public class ErrorImpl implements VCloudError {
private final String message;
private final int majorErrorCode;
private final MinorCode minorErrorCode;
@Nullable
private final String vendorSpecificErrorCode;
@Nullable
private final String stackTrace;
public ErrorImpl(String message, int majorErrorCode, @Nullable MinorCode minorErrorCode,
@Nullable String vendorSpecificErrorCode, @Nullable String stackTrace) {
this.message = checkNotNull(message, "message");
this.majorErrorCode = majorErrorCode;
this.minorErrorCode = minorErrorCode; // check null after 0.8 is gone
this.vendorSpecificErrorCode = vendorSpecificErrorCode;
this.stackTrace = stackTrace;
}
public String getMessage() {
return message;
}
public int getMajorErrorCode() {
return majorErrorCode;
}
public MinorCode getMinorErrorCode() {
return minorErrorCode;
}
public String getVendorSpecificErrorCode() {
return vendorSpecificErrorCode;
}
public String getStackTrace() {
return stackTrace;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + majorErrorCode;
result = prime * result + ((message == null) ? 0 : message.hashCode());
result = prime * result + ((minorErrorCode == null) ? 0 : minorErrorCode.hashCode());
result = prime * result + ((stackTrace == null) ? 0 : stackTrace.hashCode());
result = prime * result + ((vendorSpecificErrorCode == null) ? 0 : vendorSpecificErrorCode.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ErrorImpl other = (ErrorImpl) obj;
if (majorErrorCode != other.majorErrorCode)
return false;
if (message == null) {
if (other.message != null)
return false;
} else if (!message.equals(other.message))
return false;
if (minorErrorCode == null) {
if (other.minorErrorCode != null)
return false;
} else if (!minorErrorCode.equals(other.minorErrorCode))
return false;
if (stackTrace == null) {
if (other.stackTrace != null)
return false;
} else if (!stackTrace.equals(other.stackTrace))
return false;
if (vendorSpecificErrorCode == null) {
if (other.vendorSpecificErrorCode != null)
return false;
} else if (!vendorSpecificErrorCode.equals(other.vendorSpecificErrorCode))
return false;
return true;
}
@Override
public String toString() {
return "[majorErrorCode=" + majorErrorCode + ", message=" + message + ", minorErrorCode=" + minorErrorCode
+ ", stackTrace=" + stackTrace + ", vendorSpecificErrorCode=" + vendorSpecificErrorCode + "]";
}
}

View File

@ -1,168 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* Locations of resources in vCloud
*/
public class OrgImpl extends ReferenceTypeImpl implements Org {
private final String fullName;
@Nullable
private final String description;
private final Map<String, ReferenceType> catalogs = Maps.newLinkedHashMap();
private final Map<String, ReferenceType> vdcs = Maps.newLinkedHashMap();
private final Map<String, ReferenceType> networks = Maps.newLinkedHashMap();
private final ReferenceType tasksList;
private final List<Task> tasks = Lists.newArrayList();
public OrgImpl(String name, String type, URI id, String fullName, String description,
Map<String, ReferenceType> catalogs, Map<String, ReferenceType> vdcs, Map<String, ReferenceType> networks,
@Nullable ReferenceType tasksList, Iterable<Task> tasks) {
super(name, type, id);
this.fullName = checkNotNull(fullName, "fullName");
this.description = description;
this.catalogs.putAll(checkNotNull(catalogs, "catalogs"));
this.vdcs.putAll(checkNotNull(vdcs, "vdcs"));
this.networks.putAll(checkNotNull(networks, "networks"));
this.tasksList = tasksList;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
}
@Override
public String getFullName() {
return fullName;
}
@Override
public String getDescription() {
return description;
}
@Override
public Map<String, ReferenceType> getCatalogs() {
return catalogs;
}
@Override
public Map<String, ReferenceType> getVDCs() {
return vdcs;
}
@Override
public Map<String, ReferenceType> getNetworks() {
return networks;
}
@Override
public ReferenceType getTasksList() {
return tasksList;
}
@Override
public List<Task> getTasks() {
return tasks;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((catalogs == null) ? 0 : catalogs.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((fullName == null) ? 0 : fullName.hashCode());
result = prime * result + ((networks == null) ? 0 : networks.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + ((tasksList == null) ? 0 : tasksList.hashCode());
result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
OrgImpl other = (OrgImpl) obj;
if (catalogs == null) {
if (other.catalogs != null)
return false;
} else if (!catalogs.equals(other.catalogs))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (fullName == null) {
if (other.fullName != null)
return false;
} else if (!fullName.equals(other.fullName))
return false;
if (networks == null) {
if (other.networks != null)
return false;
} else if (!networks.equals(other.networks))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
if (tasksList == null) {
if (other.tasksList != null)
return false;
} else if (!tasksList.equals(other.tasksList))
return false;
if (vdcs == null) {
if (other.vdcs != null)
return false;
} else if (!vdcs.equals(other.vdcs))
return false;
return true;
}
@Override
public int compareTo(ReferenceType o) {
return (this == o) ? 0 : getHref().compareTo(o.getHref());
}
@Override
public String toString() {
return "[href=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", fullName=" + fullName
+ ", description=" + description + ", catalogs=" + catalogs + ", networks=" + networks + ", tasksList="
+ tasksList + ", vdcs=" + vdcs + ", tasks=" + tasks + "]";
}
}

View File

@ -1,85 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Objects.equal;
import java.net.URI;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* Location of a Rest resource
*/
public class ReferenceTypeImpl implements ReferenceType {
private final String name;
private final String type;
private final URI href;
public ReferenceTypeImpl(String name, String type, URI href) {
this.name = name;
this.type = type;
this.href = href;
}
@Override
public String getName() {
return name;
}
@Override
public String getType() {
return type;
}
@Override
public URI getHref() {
return href;
}
@Override
public int compareTo(ReferenceType that) {
return (this == that) ? 0 : getHref().compareTo(that.getHref());
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ReferenceTypeImpl that = ReferenceTypeImpl.class.cast(o);
return equal(this.href, that.href);
}
@Override
public int hashCode() {
return Objects.hashCode(href);
}
@Override
public String toString() {
return string().toString();
}
protected ToStringHelper string() {
return Objects.toStringHelper("").omitNullValues().add("href", href).add("name", name).add("type", type);
}
}

View File

@ -1,160 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Date;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus;
import org.jclouds.vcloud.domain.VCloudError;
import com.google.common.base.Objects;
public class TaskImpl extends ReferenceTypeImpl implements Task {
private final String operation;
private final TaskStatus status;
private final Date startTime;
@Nullable
private final Date endTime;
@Nullable
private final Date expiryTime;
private final ReferenceType owner;
@Nullable
private final VCloudError error;
public TaskImpl(URI id, String operation, TaskStatus status, Date startTime, @Nullable Date endTime,
@Nullable Date expiryTime, ReferenceType owner, VCloudError error) {
super(null, VCloudMediaType.TASK_XML, id);
this.operation = operation;
this.status = checkNotNull(status, "status");
this.startTime = startTime;
this.endTime = endTime;
this.expiryTime = expiryTime;
this.owner = owner;
this.error = error;
}
@Override
public TaskStatus getStatus() {
return status;
}
@Override
public Date getStartTime() {
return startTime;
}
@Override
public ReferenceType getOwner() {
return owner;
}
@Override
public Date getEndTime() {
return endTime;
}
@Override
public VCloudError getError() {
return error;
}
@Override
public String toString() {
return Objects.toStringHelper("").omitNullValues().add("href", getHref()).add("name", getName())
.add("owner", owner).add("operation", operation).add("startTime", startTime).add("endTime", endTime)
.add("expiryTime", expiryTime).add("error", error).toString();
}
public Date getExpiryTime() {
return expiryTime;
}
@Override
public String getOperation() {
return operation;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
result = prime * result + ((error == null) ? 0 : error.hashCode());
result = prime * result + ((expiryTime == null) ? 0 : expiryTime.hashCode());
result = prime * result + ((operation == null) ? 0 : operation.hashCode());
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
result = prime * result + ((startTime == null) ? 0 : startTime.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
TaskImpl other = (TaskImpl) obj;
if (endTime == null) {
if (other.endTime != null)
return false;
} else if (!endTime.equals(other.endTime))
return false;
if (error == null) {
if (other.error != null)
return false;
} else if (!error.equals(other.error))
return false;
if (expiryTime == null) {
if (other.expiryTime != null)
return false;
} else if (!expiryTime.equals(other.expiryTime))
return false;
if (operation == null) {
if (other.operation != null)
return false;
} else if (!operation.equals(other.operation))
return false;
if (owner == null) {
if (other.owner != null)
return false;
} else if (!owner.equals(other.owner))
return false;
if (startTime == null) {
if (other.startTime != null)
return false;
} else if (!startTime.equals(other.startTime))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
return true;
}
}

View File

@ -1,78 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import java.net.URI;
import java.util.SortedSet;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList;
/**
* Locations of resources in vCloud
*/
public class TasksListImpl implements TasksList {
private final SortedSet<Task> tasks;
private final URI id;
public TasksListImpl(URI id, SortedSet<Task> tasks) {
this.id = id;
this.tasks = tasks;
}
@Override
public SortedSet<Task> getTasks() {
return tasks;
}
@Override
public URI getLocation() {
return id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TasksListImpl other = (TasksListImpl) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
return true;
}
}

View File

@ -1,163 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
* Locations of resources in vCloud
*/
public class VAppImpl extends ReferenceTypeImpl implements VApp {
private final Status status;
private final ReferenceType vdc;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final boolean ovfDescriptorUploaded;
private final Set<Vm> children = Sets.newLinkedHashSet();
@Nullable
private final VCloudNetworkSection networkSection;
public VAppImpl(String name, String type, URI id, Status status, ReferenceType vdc, @Nullable String description,
Iterable<Task> tasks, boolean ovfDescriptorUploaded, Iterable<Vm> children,
@Nullable VCloudNetworkSection networkSection) {
super(name, type, id);
this.status = checkNotNull(status, "status");
this.vdc = vdc; // TODO: once <1.0 is killed check not null
this.description = description;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.ovfDescriptorUploaded = ovfDescriptorUploaded;
Iterables.addAll(this.children, checkNotNull(children, "children"));
this.networkSection = networkSection; // can be null when copying
}
/**
* {@inheritDoc}
*/
@Override
public Status getStatus() {
return status;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getVDC() {
return vdc;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isOvfDescriptorUploaded() {
return ovfDescriptorUploaded;
}
/**
* {@inheritDoc}
*/
@Override
public Set<Vm> getChildren() {
return children;
}
/**
* {@inheritDoc}
*/
@Override
public VCloudNetworkSection getNetworkSection() {
return networkSection;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + (ovfDescriptorUploaded ? 1231 : 1237);
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + ((vdc == null) ? 0 : vdc.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VAppImpl other = (VAppImpl) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (ovfDescriptorUploaded != other.ovfDescriptorUploaded)
return false;
if (vdc == null) {
if (other.vdc != null)
return false;
} else if (!vdc.equals(other.vdc))
return false;
return true;
}
@Override
public String toString() {
return "[id=" + getHref() + ", name=" + getName() + ", vdc=" + vdc + ", description=" + description + ", status="
+ status + "]";
}
}

View File

@ -1,202 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
* Locations of resources in vCloud
*/
public class VAppTemplateImpl extends ReferenceTypeImpl implements VAppTemplate {
private final Status status;
private final ReferenceType vdc;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final boolean ovfDescriptorUploaded;
private final String vAppScopedLocalId;
private final Set<Vm> children = Sets.newLinkedHashSet();
@Nullable
private final VCloudNetworkSection networkSection;
public VAppTemplateImpl(String name, String type, URI id, Status status, ReferenceType vdc,
@Nullable String description, Iterable<Task> tasks, boolean ovfDescriptorUploaded,
@Nullable String vAppScopedLocalId, Iterable<Vm> children,
@Nullable VCloudNetworkSection networkSection) {
super(name, type, id);
this.status = checkNotNull(status, "status");
this.vdc = vdc; // TODO: once <1.0 is killed check not null
this.description = description;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.vAppScopedLocalId = vAppScopedLocalId;
this.ovfDescriptorUploaded = ovfDescriptorUploaded;
Iterables.addAll(this.children, checkNotNull(children, "children"));
this.networkSection = networkSection; // can be null when copying
}
/**
* {@inheritDoc}
*/
@Override
public Status getStatus() {
return status;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getVDC() {
return vdc;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public String getVAppScopedLocalId() {
return vAppScopedLocalId;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isOvfDescriptorUploaded() {
return ovfDescriptorUploaded;
}
/**
* {@inheritDoc}
*/
@Override
public Set<Vm> getChildren() {
return children;
}
/**
* {@inheritDoc}
*/
@Override
public VCloudNetworkSection getNetworkSection() {
return networkSection;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((children == null) ? 0 : children.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((networkSection == null) ? 0 : networkSection.hashCode());
result = prime * result + (ovfDescriptorUploaded ? 1231 : 1237);
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + ((vAppScopedLocalId == null) ? 0 : vAppScopedLocalId.hashCode());
result = prime * result + ((vdc == null) ? 0 : vdc.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VAppTemplateImpl other = (VAppTemplateImpl) obj;
if (children == null) {
if (other.children != null)
return false;
} else if (!children.equals(other.children))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (networkSection == null) {
if (other.networkSection != null)
return false;
} else if (!networkSection.equals(other.networkSection))
return false;
if (ovfDescriptorUploaded != other.ovfDescriptorUploaded)
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
if (vAppScopedLocalId == null) {
if (other.vAppScopedLocalId != null)
return false;
} else if (!vAppScopedLocalId.equals(other.vAppScopedLocalId))
return false;
if (vdc == null) {
if (other.vdc != null)
return false;
} else if (!vdc.equals(other.vdc))
return false;
return true;
}
@Override
public String toString() {
return "[id=" + getHref() + ", name=" + getName() + ", vdc=" + vdc + ", description=" + description + ", status="
+ status + "]";
}
}

View File

@ -1,289 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.VDCStatus;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* Locations of resources in vCloud
*/
public class VDCImpl extends ReferenceTypeImpl implements VDC {
private final VDCStatus status;
private final ReferenceType org;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final AllocationModel allocationModel;
private final Capacity storageCapacity;
private final Capacity cpuCapacity;
private final Capacity memoryCapacity;
private final Map<String, ReferenceType> resourceEntities = Maps.newLinkedHashMap();
private final Map<String, ReferenceType> availableNetworks = Maps.newLinkedHashMap();
private final int nicQuota;
private final int networkQuota;
private final int vmQuota;
private final boolean isEnabled;
public VDCImpl(String name, String type, URI id, VDCStatus status, ReferenceType org, @Nullable String description,
Iterable<Task> tasks, AllocationModel allocationModel, @Nullable Capacity storageCapacity,
@Nullable Capacity cpuCapacity, @Nullable Capacity memoryCapacity,
Map<String, ReferenceType> resourceEntities, Map<String, ReferenceType> availableNetworks, int nicQuota,
int networkQuota, int vmQuota, boolean isEnabled) {
super(name, type, id);
this.status = checkNotNull(status, "status");
this.org = org; // TODO: once <1.0 is killed check not null
this.description = description;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.allocationModel = checkNotNull(allocationModel, "allocationModel");
this.storageCapacity = storageCapacity; // TODO: once <1.0 is killed check not null
this.cpuCapacity = cpuCapacity; // TODO: once <1.0 is killed check not null
this.memoryCapacity = memoryCapacity; // TODO: once <1.0 is killed check not null
this.resourceEntities.putAll(checkNotNull(resourceEntities, "resourceEntities"));
this.availableNetworks.putAll(checkNotNull(availableNetworks, "availableNetworks"));
this.nicQuota = nicQuota;
this.networkQuota = networkQuota;
this.vmQuota = vmQuota;
this.isEnabled = isEnabled;
}
/**
* {@inheritDoc}
*/
@Override
public VDCStatus getStatus() {
return status;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getOrg() {
return org;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public AllocationModel getAllocationModel() {
return allocationModel;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getStorageCapacity() {
return storageCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getCpuCapacity() {
return cpuCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getMemoryCapacity() {
return memoryCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, ReferenceType> getResourceEntities() {
return resourceEntities;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, ReferenceType> getAvailableNetworks() {
return availableNetworks;
}
/**
* {@inheritDoc}
*/
@Override
public int getNicQuota() {
return nicQuota;
}
/**
* {@inheritDoc}
*/
@Override
public int getNetworkQuota() {
return networkQuota;
}
/**
* {@inheritDoc}
*/
@Override
public int getVmQuota() {
return vmQuota;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isEnabled() {
return isEnabled;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((allocationModel == null) ? 0 : allocationModel.hashCode());
result = prime * result + ((availableNetworks == null) ? 0 : availableNetworks.hashCode());
result = prime * result + ((cpuCapacity == null) ? 0 : cpuCapacity.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + (isEnabled ? 1231 : 1237);
result = prime * result + ((memoryCapacity == null) ? 0 : memoryCapacity.hashCode());
result = prime * result + networkQuota;
result = prime * result + nicQuota;
result = prime * result + ((org == null) ? 0 : org.hashCode());
result = prime * result + ((resourceEntities == null) ? 0 : resourceEntities.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((storageCapacity == null) ? 0 : storageCapacity.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + vmQuota;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VDCImpl other = (VDCImpl) obj;
if (allocationModel == null) {
if (other.allocationModel != null)
return false;
} else if (!allocationModel.equals(other.allocationModel))
return false;
if (availableNetworks == null) {
if (other.availableNetworks != null)
return false;
} else if (!availableNetworks.equals(other.availableNetworks))
return false;
if (cpuCapacity == null) {
if (other.cpuCapacity != null)
return false;
} else if (!cpuCapacity.equals(other.cpuCapacity))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (isEnabled != other.isEnabled)
return false;
if (memoryCapacity == null) {
if (other.memoryCapacity != null)
return false;
} else if (!memoryCapacity.equals(other.memoryCapacity))
return false;
if (networkQuota != other.networkQuota)
return false;
if (nicQuota != other.nicQuota)
return false;
if (org == null) {
if (other.org != null)
return false;
} else if (!org.equals(other.org))
return false;
if (resourceEntities == null) {
if (other.resourceEntities != null)
return false;
} else if (!resourceEntities.equals(other.resourceEntities))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
if (storageCapacity == null) {
if (other.storageCapacity != null)
return false;
} else if (!storageCapacity.equals(other.storageCapacity))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
if (vmQuota != other.vmQuota)
return false;
return true;
}
@Override
public String toString() {
return "[id=" + getHref() + ", name=" + getName() + ", org=" + org + ", description=" + description + ", status="
+ status + ", isEnabled=" + isEnabled + "]";
}
}

View File

@ -1,214 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.NetworkConnectionSection;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.VCloudOperatingSystemSection;
import org.jclouds.vcloud.domain.ovf.VCloudVirtualHardwareSection;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* Locations of resources in vCloud
*/
public class VmImpl extends ReferenceTypeImpl implements Vm {
@Nullable
private final Status status;
private final ReferenceType vApp;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
@Nullable
private final VCloudVirtualHardwareSection hardware;
private final String vAppScopedLocalId;
private final VCloudOperatingSystemSection os;
@Nullable
private final GuestCustomizationSection guestCustomization;
@Nullable
private final NetworkConnectionSection networkConnectionSection;
public VmImpl(String name, String type, URI id, @Nullable Status status, ReferenceType vApp,
@Nullable String description, Iterable<Task> tasks, @Nullable VCloudVirtualHardwareSection hardware,
@Nullable VCloudOperatingSystemSection os, @Nullable NetworkConnectionSection networkConnectionSection,
@Nullable GuestCustomizationSection guestCustomization, @Nullable String vAppScopedLocalId) {
super(name, type, id);
this.status = status;
this.vApp = vApp; // TODO: once <1.0 is killed check not null
this.description = description;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.hardware = hardware;
this.os = os;
this.networkConnectionSection = networkConnectionSection;
this.guestCustomization = guestCustomization;
this.vAppScopedLocalId = vAppScopedLocalId;
}
/**
* {@inheritDoc}
*/
@Override
@Nullable
public Status getStatus() {
return status;
}
/**
* {@inheritDoc}
*/
@Override
public ReferenceType getParent() {
return vApp;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public VCloudVirtualHardwareSection getVirtualHardwareSection() {
return hardware;
}
/**
* {@inheritDoc}
*/
@Override
public VCloudOperatingSystemSection getOperatingSystemSection() {
return os;
}
/**
* {@inheritDoc}
*/
@Override
public NetworkConnectionSection getNetworkConnectionSection() {
return networkConnectionSection;
}
/**
* {@inheritDoc}
*/
@Override
public GuestCustomizationSection getGuestCustomizationSection() {
return guestCustomization;
}
/**
* {@inheritDoc}
*/
@Override
public String getVAppScopedLocalId() {
return vAppScopedLocalId;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((guestCustomization == null) ? 0 : guestCustomization.hashCode());
result = prime * result + ((hardware == null) ? 0 : hardware.hashCode());
result = prime * result + ((networkConnectionSection == null) ? 0 : networkConnectionSection.hashCode());
result = prime * result + ((os == null) ? 0 : os.hashCode());
result = prime * result + ((vApp == null) ? 0 : vApp.hashCode());
result = prime * result + ((vAppScopedLocalId == null) ? 0 : vAppScopedLocalId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VmImpl other = (VmImpl) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (guestCustomization == null) {
if (other.guestCustomization != null)
return false;
} else if (!guestCustomization.equals(other.guestCustomization))
return false;
if (hardware == null) {
if (other.hardware != null)
return false;
} else if (!hardware.equals(other.hardware))
return false;
if (networkConnectionSection == null) {
if (other.networkConnectionSection != null)
return false;
} else if (!networkConnectionSection.equals(other.networkConnectionSection))
return false;
if (os == null) {
if (other.os != null)
return false;
} else if (!os.equals(other.os))
return false;
if (vApp == null) {
if (other.vApp != null)
return false;
} else if (!vApp.equals(other.vApp))
return false;
if (vAppScopedLocalId == null) {
if (other.vAppScopedLocalId != null)
return false;
} else if (!vAppScopedLocalId.equals(other.vAppScopedLocalId))
return false;
return true;
}
@Override
public String toString() {
return "[href=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description
+ ", status=" + status + ", tasks=" + tasks + ", vApp=" + vApp + ", hardware=" + hardware + ", os=" + os
+ ", network=" + networkConnectionSection + ", vAppScopedLocalId=" + vAppScopedLocalId + "]";
}
}

View File

@ -1,106 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network;
import static com.google.common.base.Objects.equal;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
/**
* specifies the properties of the networks DHCP service
*/
public class DhcpService {
private final boolean enabled;
@Nullable
private final Integer defaultLeaseTime;
@Nullable
private final Integer maxLeaseTime;
@Nullable
private final IpRange ipRange;
public DhcpService(boolean enabled, @Nullable Integer defaultLeaseTime, @Nullable Integer maxLeaseTime,
@Nullable IpRange ipRange) {
this.enabled = enabled;
this.defaultLeaseTime = defaultLeaseTime;
this.maxLeaseTime = maxLeaseTime;
this.ipRange = ipRange;
}
/**
* @return true if the service is enabled
*
* @since vcloud api 0.8
*/
public boolean isEnabled() {
return enabled;
}
/**
* default duration of a DHCP address lease
*
* @since vcloud api 0.9
*/
@Nullable
public Integer getDefaultLeaseTime() {
return defaultLeaseTime;
}
/**
* maximum duration of a DHCP address lease.
*
* @since vcloud api 0.9
*/
@Nullable
public Integer getMaxLeaseTime() {
return maxLeaseTime;
}
/**
* @return range of IP addresses available to DHCP clients
*
* @since vcloud api 0.9
*/
@Nullable
public IpRange getIpRange() {
return ipRange;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
DhcpService that = DhcpService.class.cast(o);
return equal(this.enabled, that.enabled) && equal(this.defaultLeaseTime, that.defaultLeaseTime)
&& equal(this.maxLeaseTime, that.maxLeaseTime) && equal(this.ipRange, that.ipRange);
}
@Override
public int hashCode() {
return Objects.hashCode(enabled, defaultLeaseTime, maxLeaseTime, ipRange);
}
@Override
public String toString() {
return Objects.toStringHelper("").omitNullValues().add("enabled", enabled)
.add("defaultLeaseTime", defaultLeaseTime).add("maxLeaseTime", maxLeaseTime).add("ipRange", ipRange)
.toString();
}
}

View File

@ -1,95 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network;
import static com.google.common.base.Objects.equal;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
/**
* The Features element defines the DHCP and firewall features of a network.
*/
public class Features {
@Nullable
private final DhcpService dhcpService;
@Nullable
private final FirewallService firewallService;
@Nullable
private final NatService natService;
public Features(@Nullable DhcpService dhcpService, @Nullable FirewallService firewallService,
@Nullable NatService natService) {
this.dhcpService = dhcpService;
this.firewallService = firewallService;
this.natService = natService;
}
/**
* specifies the properties of the networks DHCP service
*
* @since vcloud api 0.9, but emulated for 0.8
*/
@Nullable
public DhcpService getDhcpService() {
return dhcpService;
}
/**
* defines the firewall service capabilities of the network
*
* @since vcloud api 0.8
*/
@Nullable
public FirewallService getFirewallService() {
return firewallService;
}
/**
* defines the NAT service capabilities of the network
*
* @since vcloud api 0.8
*/
@Nullable
public NatService getNatService() {
return natService;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Features that = Features.class.cast(o);
return equal(this.dhcpService, that.dhcpService) && equal(this.firewallService, that.firewallService)
&& equal(this.natService, that.natService);
}
@Override
public int hashCode() {
return Objects.hashCode(dhcpService, firewallService, natService);
}
@Override
public String toString() {
return Objects.toStringHelper("").omitNullValues().add("dhcpService", dhcpService)
.add("firewallService", firewallService).add("natService", natService).toString();
}
}

View File

@ -1,68 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
*
* The FenceMode element contains one of the following strings that specify how a network is
* connected to its parent network.
*/
public enum FenceMode {
/**
* The two networks are bridged.
* <p/>
* Note that in vcloud 0.8 this was called ALLOW_IN_OUT, and so our implementation automatically
* converts this for you. Use bridged instead of allowInOut.
*
* @since vcloud api 0.9
*/
BRIDGED,
/**
* The two networks are not connected.
*
* @since vcloud api 0.8
*/
ISOLATED,
/**
* The two networks are connected as specified in their NatService elements.
*
* @since vcloud api 0.8
*/
NAT_ROUTED, UNRECOGNIZED;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static FenceMode fromValue(String fenceMode) {
try {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(fenceMode, "fenceMode")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -1,86 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* The FirewallService element defines the firewall service capabilities of a network.
*/
public class FirewallService {
private final boolean enabled;
List<FirewallRule> firewallRules = Lists.newArrayList();
public FirewallService(boolean enabled, Iterable<FirewallRule> firewallRules) {
this.enabled = enabled;
Iterables.addAll(this.firewallRules, checkNotNull(firewallRules, "firewallRules"));
}
/**
* @return Firewall rules for the network
*
* @since vcloud api 0.8
*/
public List<FirewallRule> getFirewallRules() {
return firewallRules;
}
/**
* @return true if the service is enabled
*
* @since vcloud api 0.9
*/
@Nullable
public boolean isEnabled() {
return enabled;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
FirewallService that = FirewallService.class.cast(o);
return equal(this.enabled, that.enabled) && equal(this.firewallRules, that.firewallRules);
}
@Override
public int hashCode() {
return Objects.hashCode(enabled, firewallRules);
}
@Override
public String toString() {
ToStringHelper helper = Objects.toStringHelper("").omitNullValues().add("enabled", enabled);
if (!firewallRules.isEmpty())
helper.add("firewallRules", firewallRules);
return helper.toString();
}
}

View File

@ -1,50 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network;
/**
*
* The IpAddressAllocationMode element specifies how an IP address is allocated to this connection.
*/
public enum IpAddressAllocationMode {
/**
* no IP addressing mode specified
*
* @since vcloud api 1.0
*/
NONE,
/**
* static IP address assigned manually
*
* @since vcloud api 1.0
*/
MANUAL,
/**
* static IP address allocated from a pool
*
* @since vcloud api 1.0
*/
POOL,
/**
* IP address assigned by DHCP
*
* @since vcloud api 1.0
*/
DHCP;
}

View File

@ -1,75 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Objects;
/**
* The IpRange element defines a range of IP addresses available on a network.
*/
public class IpRange {
private final String startAddress;
private final String endAddress;
public IpRange(String startAddress, String endAddress) {
this.startAddress = checkNotNull(startAddress, "startAddress");
this.endAddress = checkNotNull(endAddress, "endAddress");
}
/**
* @return lowest IP address in the range
*
* @since vcloud api 0.9
*/
public String getStartAddress() {
return startAddress;
}
/**
* @return highest IP address in the range
*
* @since vcloud api 0.9
*/
public String getEndAddress() {
return endAddress;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
IpRange that = IpRange.class.cast(o);
return equal(this.startAddress, that.startAddress) && equal(this.endAddress, that.endAddress);
}
@Override
public int hashCode() {
return Objects.hashCode(startAddress, endAddress);
}
@Override
public String toString() {
return Objects.toStringHelper("").omitNullValues().add("startAddress", startAddress)
.add("endAddress", endAddress).toString();
}
}

View File

@ -1,169 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* The IpScope element defines the address range, gateway, netmask, and other properties of the
* network.
*/
public class IpScope {
private final boolean inherited;
@Nullable
private final String gateway;
@Nullable
private final String netmask;
@Nullable
private final String dns1;
@Nullable
private final String dns2;
@Nullable
private final String dnsSuffix;
private final Set<IpRange> ipRanges = Sets.newLinkedHashSet();
private final Set<String> allocatedIpAddresses = Sets.newLinkedHashSet();
public IpScope(boolean inherited, @Nullable String gateway, @Nullable String netmask, @Nullable String dns1,
@Nullable String dns2, @Nullable String dnsSuffix, Iterable<IpRange> ipRanges,
Iterable<String> allocatedIpAddresses) {
this.inherited = inherited;
this.gateway = gateway;
this.netmask = netmask;
this.dns1 = dns1;
this.dns2 = dns2;
this.dnsSuffix = dnsSuffix;
Iterables.addAll(this.ipRanges, checkNotNull(ipRanges, "ipRanges"));
Iterables.addAll(this.allocatedIpAddresses, checkNotNull(allocatedIpAddresses, "allocatedIpAddresses"));
}
/**
* @return true of the values in this IpScope element are inherited from the ParentNetwork of the
* containing Configuration
* @since vcloud api 0.9
*/
public boolean isInherited() {
return inherited;
}
/**
* @return IP address of the network gateway
*
* @since vcloud api 0.8
*/
@Nullable
public String getGateway() {
return gateway;
}
/**
* @return netmask to apply to addresses on the network
*
* @since vcloud api 0.8
*/
@Nullable
public String getNetmask() {
return netmask;
}
/**
* @return IP address of the primary DNS server for this network
*
* @since vcloud api 0.9
*/
@Nullable
public String getDns1() {
return dns1;
}
/**
* @return IP address of the secondary DNS server for this network
*
* @since vcloud api 0.9
*/
@Nullable
public String getDns2() {
return dns2;
}
/**
* @return suffix to be applied when resolving hostnames that are not fullyqualified.
*
* @since vcloud api 0.9
*/
@Nullable
public String getDnsSuffix() {
return dnsSuffix;
}
/**
* @return A container for IpRange elements.
*
* @since vcloud api 0.9
*/
public Set<IpRange> getIpRanges() {
return ipRanges;
}
/**
* @return A list of addresses allocated from any of the specified IpRanges
*
* @since vcloud api 0.9
*/
public Set<String> getAllocatedIpAddresses() {
return allocatedIpAddresses;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
IpScope that = IpScope.class.cast(o);
return equal(this.inherited, that.inherited) && equal(this.gateway, that.gateway)
&& equal(this.netmask, that.netmask) && equal(this.dns1, that.dns1) && equal(this.dns2, that.dns2)
&& equal(this.dnsSuffix, that.dnsSuffix)
&& equal(this.ipRanges, that.ipRanges)
&& equal(this.allocatedIpAddresses, that.allocatedIpAddresses);
}
@Override
public int hashCode() {
return Objects.hashCode(inherited, gateway, netmask, dns1, dns2, dnsSuffix, ipRanges, allocatedIpAddresses);
}
@Override
public String toString() {
ToStringHelper helper = Objects.toStringHelper("").omitNullValues().add("inherited", inherited).add("gateway", gateway)
.add("netmask", netmask).add("dns1", dns1).add("dns2", dns2).add("dnsSuffix", dnsSuffix);
if (!ipRanges.isEmpty())
helper.add("ipRanges", ipRanges);
if (!allocatedIpAddresses.isEmpty())
helper.add("allocatedIpAddresses", allocatedIpAddresses);
return helper.toString();
}
}

View File

@ -1,115 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.network.nat.NatPolicy;
import org.jclouds.vcloud.domain.network.nat.NatRule;
import org.jclouds.vcloud.domain.network.nat.NatType;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* The NatService element defines the network address translation capabilities of a network.
*/
public class NatService {
private final boolean enabled;
@Nullable
private final NatType type;
@Nullable
private final NatPolicy policy;
private final List<NatRule> natRules = Lists.newArrayList();
public NatService(boolean enabled, @Nullable NatType type, @Nullable NatPolicy policy,
Iterable<NatRule> natRules) {
this.enabled = enabled;
this.type = type;
this.policy = policy;
Iterables.addAll(this.natRules, checkNotNull(natRules, "natRules"));
}
/**
* @return Nat rules for the network
*
* @since vcloud api 0.8
*/
public List<NatRule> getNatRules() {
return natRules;
}
/**
* @return true if the service is enabled
*
* @since vcloud api 0.9
*/
public boolean isEnabled() {
return enabled;
}
/**
* @return specifies how Network Address Translation is implemented by the NAT service
*
* @since vcloud api 0.9
*/
@Nullable
public NatType getType() {
return type;
}
/**
* @return specifies how packets are handled by the NAT service.
*
* @since vcloud api 0.9
*/
@Nullable
public NatPolicy getPolicy() {
return policy;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NatService that = NatService.class.cast(o);
return equal(this.enabled, that.enabled) && equal(this.type, that.type)
&& equal(this.policy, that.policy) && equal(this.natRules, that.natRules);
}
@Override
public int hashCode() {
return Objects.hashCode(enabled, type, policy, natRules);
}
@Override
public String toString() {
ToStringHelper helper = Objects.toStringHelper("").omitNullValues().add("enabled", enabled)
.add("type", type).add("policy", policy);
if (!natRules.isEmpty())
helper.add("natRules", natRules);
return helper.toString();
}
}

View File

@ -1,163 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import org.jclouds.javax.annotation.Nullable;
public class NetworkConfig {
public Builder toBuilder() {
return builder().fromNetworkConfig(this);
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String networkName;
private URI parentNetwork;
private FenceMode fenceMode;
public Builder networkName(String networkName) {
this.networkName = networkName;
return this;
}
public Builder parentNetwork(URI parentNetwork) {
this.parentNetwork = parentNetwork;
return this;
}
public Builder fenceMode(FenceMode fenceMode) {
this.fenceMode = fenceMode;
return this;
}
public Builder fromNetworkConfig(NetworkConfig in) {
return networkName(in.getNetworkName()).parentNetwork(in.getParentNetwork()).fenceMode(in.getFenceMode());
}
public NetworkConfig build() {
return new NetworkConfig(networkName, parentNetwork, fenceMode);
}
}
@Nullable
private final String networkName;
private final URI parentNetwork;
@Nullable
private final FenceMode fenceMode;
/**
*
* Create a new NetworkConfig.
*
* @param networkName
* a valid {@networkConfig
* org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection network in the vapp
* template}, or null to have us choose default
* @param parentNetwork
* a valid {@networkConfig org.jclouds.vcloud.domain.Org#getNetworks in
* the Org}
* @param fenceMode
* how to manage the relationship between the two networks
*/
public NetworkConfig(String networkName, URI parentNetwork, FenceMode fenceMode) {
this.networkName = networkName;
this.parentNetwork = checkNotNull(parentNetwork, "parentNetwork");
this.fenceMode = fenceMode;
}
public NetworkConfig(URI parentNetwork) {
this(null, parentNetwork, null);
}
/**
* A name for the network. If the
* {@link org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection} includes a
* {@link NetworkSection.Network} network element, the name you specify for the vApp network must
* match the name specified in that elements name attribute.
*
* @return
*/
public String getNetworkName() {
return networkName;
}
/**
*
* @return A reference to the organization network to which this network connects.
*/
public URI getParentNetwork() {
return parentNetwork;
}
/**
* A value of bridged indicates that this vApp network is connected directly to the organization
* network.
*/
public FenceMode getFenceMode() {
return fenceMode;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode());
result = prime * result + ((parentNetwork == null) ? 0 : parentNetwork.hashCode());
result = prime * result + ((networkName == null) ? 0 : networkName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
NetworkConfig other = (NetworkConfig) obj;
if (fenceMode == null) {
if (other.fenceMode != null)
return false;
} else if (!fenceMode.equals(other.fenceMode))
return false;
if (parentNetwork == null) {
if (other.parentNetwork != null)
return false;
} else if (!parentNetwork.equals(other.parentNetwork))
return false;
if (networkName == null) {
if (other.networkName != null)
return false;
} else if (!networkName.equals(other.networkName))
return false;
return true;
}
@Override
public String toString() {
return "[networkName=" + networkName + ", parentNetwork=" + parentNetwork + ", fenceMode=" + fenceMode + "]";
}
}

View File

@ -1,119 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network;
import java.util.List;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.network.internal.OrgNetworkImpl;
import com.google.inject.ImplementedBy;
/**
* A vDC is a deployment environment for vApps. A Vdc element provides a user view of a vDC.
*/
@org.jclouds.vcloud.endpoints.Network
@ImplementedBy(OrgNetworkImpl.class)
public interface OrgNetwork extends ReferenceType {
/**
* The org this network belongs to.
*
* @since vcloud api 0.9
*/
@Nullable
ReferenceType getOrg();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 0.9
*/
List<Task> getTasks();
/**
*
* @return properties of the network
*
* @since vcloud api 0.9, but emulated for 0.8
*/
Configuration getConfiguration();
/**
* A reference the network pool from which this network is provisioned. This element, which is
* required when creating a NatRouted or Isolated network, is returned in response to a creation
* request but not shown in subsequent GET requests.
*
* @since vcloud api 0.9
*/
@Nullable
ReferenceType getNetworkPool();
/**
* list of external IP addresses that this network can use for NAT.
*
* @since vcloud api 0.9
*/
Set<String> getAllowedExternalIpAddresses();
/**
* The Configuration element specifies properties of a network.
*/
interface Configuration {
/**
* defines the address range, gateway, netmask, and other properties of the network.
*
* @since vcloud api 0.9, but emulated for 0.8
*/
@Nullable
IpScope getIpScope();
/**
* reference to a network to which this network connects
*
* @since vcloud api 0.9
*/
@Nullable
ReferenceType getParentNetwork();
/**
* defines how this network is connected to its ParentNetwork
*
* @since vcloud api 0.8
*/
FenceMode getFenceMode();
/**
* defines a set of network features.
*
* @since vcloud api 0.9, but emulated for 0.8
*/
@Nullable Features getFeatures();
}
}

View File

@ -1,53 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network.firewall;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
* specifies how packets are handled by the firewall
*/
public enum FirewallPolicy {
/**
* drop packets of this type
*/
DROP,
/**
* allow packets of this type to pass through the firewall
*/
ALLOW, UNRECOGNIZED;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static FirewallPolicy fromValue(String policy) {
try {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(policy, "policy")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -1,71 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network.firewall;
import static com.google.common.base.Objects.equal;
import com.google.common.base.Objects;
/**
* The Protocols element specifies the protocols to which firewall rules apply.
*
* @since vcloud api 0.9 emulated for 0.8
*/
public class FirewallProtocols {
private final boolean tcp;
private final boolean udp;
public FirewallProtocols(boolean tcp, boolean udp) {
this.tcp = tcp;
this.udp = udp;
}
/**
* @return true if the firewall rules apply to the TCP protocol
*/
public boolean isTcp() {
return tcp;
}
/**
* @return true if the firewall rules apply to the UDP protocol
*/
public boolean isUdp() {
return udp;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
FirewallProtocols that = FirewallProtocols.class.cast(o);
return equal(this.tcp, that.tcp) && equal(this.udp, that.udp);
}
@Override
public int hashCode() {
return Objects.hashCode(tcp, udp);
}
@Override
public String toString() {
return Objects.toStringHelper("").omitNullValues().add("tcp", tcp).add("udp", udp).toString();
}
}

View File

@ -1,124 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.vcloud.domain.network.firewall;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
/**
* The FirewallRule element defines a single firewall rule.
*
* @since vcloud api 0.8
*/
public class FirewallRule {
private final boolean enabled;
@Nullable
private final String description;
@Nullable
private final FirewallPolicy policy;
@Nullable
private final FirewallProtocols protocols;
private final int port;
private final String destinationIp;
public FirewallRule(boolean enabled, @Nullable String description, @Nullable FirewallPolicy policy,
@Nullable FirewallProtocols protocols, int port, String destinationIp) {
this.enabled = enabled;
this.description = description;
this.policy = policy;
this.protocols = protocols;
this.port = port;
this.destinationIp = checkNotNull(destinationIp, "destinationIp");
}
/**
* @return true if the rule is enabled
*/
public boolean isEnabled() {
return enabled;
}
/**
* @return description of the rule
*/
@Nullable
public String getDescription() {
return description;
}
/**
* @return specifies how packets are handled by the firewall
*/
@Nullable
public FirewallPolicy getPolicy() {
return policy;
}
/**
* @return specifies the protocols to which this firewall rule applies
*/
@Nullable
public FirewallProtocols getProtocols() {
return protocols;
}
/**
* @return specifies the network port to which this firewall rule applies. A value of 1 matches
* any port.
*/
public int getPort() {
return port;
}
/**
* @return specifies the destination IP address, inside the firewall, to which this firewall rule
* applies
*/
public String getDestinationIp() {
return destinationIp;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
FirewallRule that = FirewallRule.class.cast(o);
return equal(this.enabled, that.enabled) && equal(this.description, that.description)
&& equal(this.policy, that.policy) && equal(this.protocols, that.protocols) && equal(this.port, that.port)
&& equal(this.destinationIp, that.destinationIp);
}
@Override
public int hashCode() {
return Objects.hashCode(enabled, description, policy, protocols, port, destinationIp);
}
@Override
public String toString() {
return Objects.toStringHelper("").omitNullValues().add("enabled", enabled).add("description", description)
.add("policy", policy).add("protocols", protocols).add("port", port).add("destinationIp", destinationIp)
.toString();
}
}

Some files were not shown because too many files have changed in this diff Show More