mirror of https://github.com/apache/jclouds.git
Issue 464: started read-only features
This commit is contained in:
parent
6f545c0277
commit
1b91cca8c1
|
@ -0,0 +1,135 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Copyright (C) 2010 Cloud Conscious, LLC <info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
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.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT 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.jclouds</groupId>
|
||||
<artifactId>jclouds-project</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../../project/pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>org.jclouds.api</groupId>
|
||||
<artifactId>cloudstack</artifactId>
|
||||
<name>jclouds cloudstack core</name>
|
||||
<description>jclouds components to access cloudstack</description>
|
||||
|
||||
<!-- bootstrapping: need to fetch the project POM -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jclouds-rimu-snapshots-nexus</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<properties>
|
||||
<test.cloudstack.endpoint>http://localhost:8080/client/api</test.cloudstack.endpoint>
|
||||
<test.cloudstack.apiversion>2.2</test.cloudstack.apiversion>
|
||||
<test.cloudstack.identity>FIXME_apiKey</test.cloudstack.identity>
|
||||
<test.cloudstack.credential>FIXME_secretKey</test.cloudstack.credential>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.driver</groupId>
|
||||
<artifactId>jclouds-jsch</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
<artifactId>jsch</artifactId>
|
||||
<version>0.1.42</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.14</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.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>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>test.cloudstack.endpoint</name>
|
||||
<value>${test.cloudstack.endpoint}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>test.cloudstack.apiversion</name>
|
||||
<value>${test.cloudstack.apiversion}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>test.cloudstack.identity</name>
|
||||
<value>${test.cloudstack.identity}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>test.cloudstack.credential</name>
|
||||
<value>${test.cloudstack.credential}</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack;
|
||||
|
||||
import org.jclouds.cloudstack.features.NetworkAsyncClient;
|
||||
import org.jclouds.cloudstack.features.OfferingAsyncClient;
|
||||
import org.jclouds.cloudstack.features.TemplateAsyncClient;
|
||||
import org.jclouds.cloudstack.features.ZoneAsyncClient;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to CloudStack via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see CloudStackClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface CloudStackAsyncClient {
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Zone features.
|
||||
*/
|
||||
@Delegate
|
||||
ZoneAsyncClient getZoneClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Template features.
|
||||
*/
|
||||
@Delegate
|
||||
TemplateAsyncClient getTemplateClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Service, Disk, and Network Offering features.
|
||||
*/
|
||||
@Delegate
|
||||
OfferingAsyncClient getOfferingClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Network features.
|
||||
*/
|
||||
@Delegate
|
||||
NetworkAsyncClient getNetworkClient();
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.features.NetworkClient;
|
||||
import org.jclouds.cloudstack.features.OfferingClient;
|
||||
import org.jclouds.cloudstack.features.TemplateClient;
|
||||
import org.jclouds.cloudstack.features.ZoneClient;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack.
|
||||
* <p/>
|
||||
*
|
||||
* @see CloudStackAsyncClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface CloudStackClient {
|
||||
/**
|
||||
* Provides synchronous access to Zone features.
|
||||
*/
|
||||
@Delegate
|
||||
ZoneClient getZoneClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Template features.
|
||||
*/
|
||||
@Delegate
|
||||
TemplateClient getTemplateClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Service, Disk, and Network Offering features.
|
||||
*/
|
||||
@Delegate
|
||||
OfferingClient getOfferingClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Network features.
|
||||
*/
|
||||
@Delegate
|
||||
NetworkClient getNetworkClient();
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.cloudstack.config.CloudStackRestClientModule;
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class CloudStackContextBuilder extends
|
||||
RestContextBuilder<CloudStackClient, CloudStackAsyncClient> {
|
||||
|
||||
public CloudStackContextBuilder(Properties props) {
|
||||
super(CloudStackClient.class, CloudStackAsyncClient.class, props);
|
||||
}
|
||||
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new CloudStackRestClientModule());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.PropertiesBuilder;
|
||||
|
||||
/**
|
||||
* Builds properties used in cloudstack Clients
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class CloudStackPropertiesBuilder extends PropertiesBuilder {
|
||||
@Override
|
||||
protected Properties defaultProperties() {
|
||||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_API_VERSION, "2.2");
|
||||
return properties;
|
||||
}
|
||||
|
||||
public CloudStackPropertiesBuilder(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.cloudstack.CloudStackAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.features.NetworkAsyncClient;
|
||||
import org.jclouds.cloudstack.features.NetworkClient;
|
||||
import org.jclouds.cloudstack.features.OfferingAsyncClient;
|
||||
import org.jclouds.cloudstack.features.OfferingClient;
|
||||
import org.jclouds.cloudstack.features.TemplateAsyncClient;
|
||||
import org.jclouds.cloudstack.features.TemplateClient;
|
||||
import org.jclouds.cloudstack.features.ZoneAsyncClient;
|
||||
import org.jclouds.cloudstack.features.ZoneClient;
|
||||
import org.jclouds.cloudstack.handlers.CloudStackErrorHandler;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Configures the cloudstack connection.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public class CloudStackRestClientModule extends RestClientModule<CloudStackClient, CloudStackAsyncClient> {
|
||||
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
|
||||
.put(ZoneClient.class, ZoneAsyncClient.class)//
|
||||
.put(TemplateClient.class, TemplateAsyncClient.class)//
|
||||
.put(OfferingClient.class, OfferingAsyncClient.class)//
|
||||
.put(NetworkClient.class, NetworkAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
public CloudStackRestClientModule() {
|
||||
super(CloudStackClient.class, CloudStackAsyncClient.class, DELEGATE_MAP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindErrorHandlers() {
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(CloudStackErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(CloudStackErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(CloudStackErrorHandler.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,217 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class DiskOffering {
|
||||
private String id;
|
||||
private String name;
|
||||
@SerializedName("displaytext")
|
||||
private String displayText;
|
||||
private Date created;
|
||||
private String domain;
|
||||
@SerializedName("domainid")
|
||||
private String domainId;
|
||||
@SerializedName("disksize")
|
||||
private int diskSize;
|
||||
@SerializedName("iscustomized")
|
||||
private boolean customized;
|
||||
private String tags;
|
||||
|
||||
public DiskOffering(String id, String name, String displayText, Date created, String domain, String domainId,
|
||||
int diskSize, boolean customized, Set<String> tags) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.displayText = displayText;
|
||||
this.created = created;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.diskSize = diskSize;
|
||||
this.customized = customized;
|
||||
this.tags = Joiner.on(',').join(tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
*
|
||||
*/
|
||||
DiskOffering() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the id of the disk offering
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the disk offering
|
||||
*/
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return an alternate display text of the disk offering.
|
||||
*/
|
||||
public String getDisplayText() {
|
||||
return displayText;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the date this disk offering was created
|
||||
*/
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Domain name for the offering
|
||||
*/
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the domain id of the disk offering
|
||||
*/
|
||||
public String getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the size of the disk offering in GB
|
||||
*/
|
||||
public int getDiskSize() {
|
||||
return diskSize;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ha support in the disk offering
|
||||
*/
|
||||
public boolean isCustomized() {
|
||||
return customized;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the tags for the disk offering
|
||||
*/
|
||||
public Set<String> getTags() {
|
||||
return tags != null ? ImmutableSet.copyOf(Splitter.on(',').split(tags)) : ImmutableSet.<String> of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((created == null) ? 0 : created.hashCode());
|
||||
result = prime * result + (customized ? 1231 : 1237);
|
||||
result = prime * result + diskSize;
|
||||
result = prime * result + ((displayText == null) ? 0 : displayText.hashCode());
|
||||
result = prime * result + ((domain == null) ? 0 : domain.hashCode());
|
||||
result = prime * result + ((domainId == null) ? 0 : domainId.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((tags == null) ? 0 : tags.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;
|
||||
DiskOffering other = (DiskOffering) obj;
|
||||
if (created == null) {
|
||||
if (other.created != null)
|
||||
return false;
|
||||
} else if (!created.equals(other.created))
|
||||
return false;
|
||||
if (customized != other.customized)
|
||||
return false;
|
||||
if (diskSize != other.diskSize)
|
||||
return false;
|
||||
if (displayText == null) {
|
||||
if (other.displayText != null)
|
||||
return false;
|
||||
} else if (!displayText.equals(other.displayText))
|
||||
return false;
|
||||
if (domain == null) {
|
||||
if (other.domain != null)
|
||||
return false;
|
||||
} else if (!domain.equals(other.domain))
|
||||
return false;
|
||||
if (domainId == null) {
|
||||
if (other.domainId != null)
|
||||
return false;
|
||||
} else if (!domainId.equals(other.domainId))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (tags == null) {
|
||||
if (other.tags != null)
|
||||
return false;
|
||||
} else if (!tags.equals(other.tags))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created + ", diskSize="
|
||||
+ diskSize + ", iscustomized=" + customized + ", domain=" + domain + ", domainId=" + domainId
|
||||
+ ", tags=" + tags + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see NetworkOfferingClient#listNetworkOfferings
|
||||
*/
|
||||
public enum GuestIPType {
|
||||
|
||||
/**
|
||||
* guest IP address will be issued by Dhcp server in the guest virtual network. Dhcp role is
|
||||
* played by domain router.
|
||||
*/
|
||||
VIRTUAL,
|
||||
/**
|
||||
* traffic directly to the network and VMs created here are assigned an IP directly from the
|
||||
* network as configured
|
||||
*/
|
||||
DIRECT,
|
||||
|
||||
UNRECOGNIZED;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
|
||||
}
|
||||
|
||||
public static GuestIPType fromValue(String type) {
|
||||
try {
|
||||
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,564 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Network {
|
||||
private String id;
|
||||
private String account;
|
||||
@SerializedName("broadcastdomaintype")
|
||||
private String broadcastDomainType;
|
||||
@SerializedName("broadcasturi")
|
||||
private URI broadcastURI;
|
||||
@SerializedName("displaytext")
|
||||
private String displayText;
|
||||
@SerializedName("dns1")
|
||||
private String DNS1;
|
||||
@SerializedName("dns2")
|
||||
private String DNS2;
|
||||
private String domain;
|
||||
@Nullable
|
||||
@SerializedName("domainid")
|
||||
private String domainId;
|
||||
@SerializedName("endip")
|
||||
private String endIP;
|
||||
private String gateway;
|
||||
@SerializedName("isdefault")
|
||||
private boolean isDefault;
|
||||
@SerializedName("isshared")
|
||||
private boolean isShared;
|
||||
@SerializedName("issystem")
|
||||
private boolean isSystem;
|
||||
private String netmask;
|
||||
@SerializedName("networkdomain")
|
||||
private String networkDomain;
|
||||
@SerializedName("networkofferingavailability")
|
||||
private String networkOfferingAvailability;
|
||||
@SerializedName("networkofferingid")
|
||||
private String networkOfferingDisplayText;
|
||||
@SerializedName("networkofferingid")
|
||||
private String networkOfferingId;
|
||||
@SerializedName("networkofferingname")
|
||||
private String networkOfferingName;
|
||||
private String related;
|
||||
@SerializedName("startip")
|
||||
private String startIP;
|
||||
private String name;
|
||||
private String state;
|
||||
@SerializedName("type")
|
||||
private GuestIPType guestIPType;
|
||||
@SerializedName("vlan")
|
||||
private String VLAN;
|
||||
@SerializedName("traffictype")
|
||||
private TrafficType trafficType;
|
||||
@SerializedName("zoneid")
|
||||
private String zoneId;
|
||||
@SerializedName("service")
|
||||
private Set<? extends NetworkService> services = ImmutableSet.<NetworkService> of();
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
*
|
||||
*/
|
||||
Network() {
|
||||
|
||||
}
|
||||
|
||||
public Network(String id, String account, String broadcastDomainType, URI broadcastURI, String displayText,
|
||||
List<String> DNS, String domain, String domainId, String endIP, String gateway, boolean isDefault,
|
||||
boolean isShared, boolean isSystem, String netmask, String networkDomain,
|
||||
String networkOfferingAvailability, String networkOfferingDisplayText, String networkOfferingId,
|
||||
String networkOfferingName, String related, String startIP, String name, String state, GuestIPType type,
|
||||
String vLAN, TrafficType trafficType, String zoneId, Set<? extends NetworkService> services) {
|
||||
this.id = id;
|
||||
this.account = account;
|
||||
this.broadcastDomainType = broadcastDomainType;
|
||||
this.broadcastURI = broadcastURI;
|
||||
this.displayText = displayText;
|
||||
this.DNS1 = checkNotNull(DNS, "DNS").size() > 0 ? DNS.get(0) : null;
|
||||
this.DNS2 = DNS.size() > 1 ? DNS.get(1) : null;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.endIP = endIP;
|
||||
this.gateway = gateway;
|
||||
this.isDefault = isDefault;
|
||||
this.isShared = isShared;
|
||||
this.isSystem = isSystem;
|
||||
this.netmask = netmask;
|
||||
this.networkDomain = networkDomain;
|
||||
this.networkOfferingAvailability = networkOfferingAvailability;
|
||||
this.networkOfferingDisplayText = networkOfferingDisplayText;
|
||||
this.networkOfferingId = networkOfferingId;
|
||||
this.networkOfferingName = networkOfferingName;
|
||||
this.related = related;
|
||||
this.startIP = startIP;
|
||||
this.name = name;
|
||||
this.state = state;
|
||||
this.guestIPType = type;
|
||||
this.VLAN = vLAN;
|
||||
this.trafficType = trafficType;
|
||||
this.zoneId = zoneId;
|
||||
this.services = ImmutableSet.copyOf(checkNotNull(services, "services"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return network id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the account to which the template beLongs
|
||||
*/
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Broadcast domain type of the network
|
||||
*/
|
||||
public String getBroadcastDomainType() {
|
||||
return broadcastDomainType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return broadcast uri of the network
|
||||
*/
|
||||
public URI getBroadcastURI() {
|
||||
return broadcastURI;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the display text of the zone
|
||||
*/
|
||||
public String getDisplayText() {
|
||||
return displayText;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the external DNS for the network
|
||||
*/
|
||||
public List<String> getDNS() {
|
||||
Builder<String> builder = ImmutableList.builder();
|
||||
if (DNS1 != null && !"".equals(DNS1))
|
||||
builder.add(DNS1);
|
||||
if (DNS2 != null && !"".equals(DNS2))
|
||||
builder.add(DNS2);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Domain name for the Vms in the zone
|
||||
*/
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ID of the containing domain, null for public zones
|
||||
*/
|
||||
@Nullable
|
||||
public String getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the end ip of the network
|
||||
*/
|
||||
public String getEndIP() {
|
||||
return endIP;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the network's gateway
|
||||
*/
|
||||
public String getGateway() {
|
||||
return gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if network offering is default, false otherwise
|
||||
*/
|
||||
public boolean isDefault() {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if network offering is shared, false otherwise
|
||||
*/
|
||||
public boolean isShared() {
|
||||
return isShared;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if network offering is system, false otherwise
|
||||
*/
|
||||
public boolean isSystem() {
|
||||
return isSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return network name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the GuestIPType of the network
|
||||
*/
|
||||
public GuestIPType getGuestIPType() {
|
||||
return guestIPType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return state of the network
|
||||
*/
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the vlan range of the zone
|
||||
*/
|
||||
public String getVLAN() {
|
||||
return VLAN;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the traffic type for this network offering
|
||||
*/
|
||||
public TrafficType getTrafficType() {
|
||||
return trafficType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the network's netmask
|
||||
*/
|
||||
public String getNetmask() {
|
||||
return netmask;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the network domain
|
||||
*/
|
||||
public String getNetworkDomain() {
|
||||
return networkDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return availability of the network offering the network is created from
|
||||
*/
|
||||
public String getNetworkOfferingAvailability() {
|
||||
return networkOfferingAvailability;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return display text of the network offering the network is created from
|
||||
*/
|
||||
public String getNetworkOfferingDisplayText() {
|
||||
return networkOfferingDisplayText;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return network offering id the network is created from
|
||||
*/
|
||||
public String getNetworkOfferingId() {
|
||||
return networkOfferingId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return name of the network offering the network is created from
|
||||
*/
|
||||
public String getNetworkOfferingName() {
|
||||
return networkOfferingName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return related to what other network configuration
|
||||
*/
|
||||
public String getRelated() {
|
||||
return related;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the start ip of the network
|
||||
*/
|
||||
public String getStartIP() {
|
||||
return startIP;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return zone id of the network
|
||||
*/
|
||||
public String getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the list of services
|
||||
*/
|
||||
public Set<? extends NetworkService> getServices() {
|
||||
return services;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((DNS1 == null) ? 0 : DNS1.hashCode());
|
||||
result = prime * result + ((DNS2 == null) ? 0 : DNS2.hashCode());
|
||||
result = prime * result + ((VLAN == null) ? 0 : VLAN.hashCode());
|
||||
result = prime * result + ((account == null) ? 0 : account.hashCode());
|
||||
result = prime * result + ((broadcastDomainType == null) ? 0 : broadcastDomainType.hashCode());
|
||||
result = prime * result + ((broadcastURI == null) ? 0 : broadcastURI.hashCode());
|
||||
result = prime * result + ((displayText == null) ? 0 : displayText.hashCode());
|
||||
result = prime * result + ((domain == null) ? 0 : domain.hashCode());
|
||||
result = prime * result + ((domainId == null) ? 0 : domainId.hashCode());
|
||||
result = prime * result + ((endIP == null) ? 0 : endIP.hashCode());
|
||||
result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + (isDefault ? 1231 : 1237);
|
||||
result = prime * result + (isShared ? 1231 : 1237);
|
||||
result = prime * result + (isSystem ? 1231 : 1237);
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((netmask == null) ? 0 : netmask.hashCode());
|
||||
result = prime * result + ((networkDomain == null) ? 0 : networkDomain.hashCode());
|
||||
result = prime * result + ((networkOfferingAvailability == null) ? 0 : networkOfferingAvailability.hashCode());
|
||||
result = prime * result + ((networkOfferingDisplayText == null) ? 0 : networkOfferingDisplayText.hashCode());
|
||||
result = prime * result + ((networkOfferingId == null) ? 0 : networkOfferingId.hashCode());
|
||||
result = prime * result + ((networkOfferingName == null) ? 0 : networkOfferingName.hashCode());
|
||||
result = prime * result + ((related == null) ? 0 : related.hashCode());
|
||||
result = prime * result + ((services == null) ? 0 : services.hashCode());
|
||||
result = prime * result + ((startIP == null) ? 0 : startIP.hashCode());
|
||||
result = prime * result + ((state == null) ? 0 : state.hashCode());
|
||||
result = prime * result + ((trafficType == null) ? 0 : trafficType.hashCode());
|
||||
result = prime * result + ((guestIPType == null) ? 0 : guestIPType.hashCode());
|
||||
result = prime * result + ((zoneId == null) ? 0 : zoneId.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;
|
||||
Network other = (Network) obj;
|
||||
if (DNS1 == null) {
|
||||
if (other.DNS1 != null)
|
||||
return false;
|
||||
} else if (!DNS1.equals(other.DNS1))
|
||||
return false;
|
||||
if (DNS2 == null) {
|
||||
if (other.DNS2 != null)
|
||||
return false;
|
||||
} else if (!DNS2.equals(other.DNS2))
|
||||
return false;
|
||||
if (VLAN == null) {
|
||||
if (other.VLAN != null)
|
||||
return false;
|
||||
} else if (!VLAN.equals(other.VLAN))
|
||||
return false;
|
||||
if (account == null) {
|
||||
if (other.account != null)
|
||||
return false;
|
||||
} else if (!account.equals(other.account))
|
||||
return false;
|
||||
if (broadcastDomainType == null) {
|
||||
if (other.broadcastDomainType != null)
|
||||
return false;
|
||||
} else if (!broadcastDomainType.equals(other.broadcastDomainType))
|
||||
return false;
|
||||
if (broadcastURI == null) {
|
||||
if (other.broadcastURI != null)
|
||||
return false;
|
||||
} else if (!broadcastURI.equals(other.broadcastURI))
|
||||
return false;
|
||||
if (displayText == null) {
|
||||
if (other.displayText != null)
|
||||
return false;
|
||||
} else if (!displayText.equals(other.displayText))
|
||||
return false;
|
||||
if (domain == null) {
|
||||
if (other.domain != null)
|
||||
return false;
|
||||
} else if (!domain.equals(other.domain))
|
||||
return false;
|
||||
if (domainId == null) {
|
||||
if (other.domainId != null)
|
||||
return false;
|
||||
} else if (!domainId.equals(other.domainId))
|
||||
return false;
|
||||
if (endIP == null) {
|
||||
if (other.endIP != null)
|
||||
return false;
|
||||
} else if (!endIP.equals(other.endIP))
|
||||
return false;
|
||||
if (gateway == null) {
|
||||
if (other.gateway != null)
|
||||
return false;
|
||||
} else if (!gateway.equals(other.gateway))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (isDefault != other.isDefault)
|
||||
return false;
|
||||
if (isShared != other.isShared)
|
||||
return false;
|
||||
if (isSystem != other.isSystem)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (netmask == null) {
|
||||
if (other.netmask != null)
|
||||
return false;
|
||||
} else if (!netmask.equals(other.netmask))
|
||||
return false;
|
||||
if (networkDomain == null) {
|
||||
if (other.networkDomain != null)
|
||||
return false;
|
||||
} else if (!networkDomain.equals(other.networkDomain))
|
||||
return false;
|
||||
if (networkOfferingAvailability == null) {
|
||||
if (other.networkOfferingAvailability != null)
|
||||
return false;
|
||||
} else if (!networkOfferingAvailability.equals(other.networkOfferingAvailability))
|
||||
return false;
|
||||
if (networkOfferingDisplayText == null) {
|
||||
if (other.networkOfferingDisplayText != null)
|
||||
return false;
|
||||
} else if (!networkOfferingDisplayText.equals(other.networkOfferingDisplayText))
|
||||
return false;
|
||||
if (networkOfferingId == null) {
|
||||
if (other.networkOfferingId != null)
|
||||
return false;
|
||||
} else if (!networkOfferingId.equals(other.networkOfferingId))
|
||||
return false;
|
||||
if (networkOfferingName == null) {
|
||||
if (other.networkOfferingName != null)
|
||||
return false;
|
||||
} else if (!networkOfferingName.equals(other.networkOfferingName))
|
||||
return false;
|
||||
if (related == null) {
|
||||
if (other.related != null)
|
||||
return false;
|
||||
} else if (!related.equals(other.related))
|
||||
return false;
|
||||
if (services == null) {
|
||||
if (other.services != null)
|
||||
return false;
|
||||
} else if (!services.equals(other.services))
|
||||
return false;
|
||||
if (startIP == null) {
|
||||
if (other.startIP != null)
|
||||
return false;
|
||||
} else if (!startIP.equals(other.startIP))
|
||||
return false;
|
||||
if (state == null) {
|
||||
if (other.state != null)
|
||||
return false;
|
||||
} else if (!state.equals(other.state))
|
||||
return false;
|
||||
if (trafficType == null) {
|
||||
if (other.trafficType != null)
|
||||
return false;
|
||||
} else if (!trafficType.equals(other.trafficType))
|
||||
return false;
|
||||
if (guestIPType == null) {
|
||||
if (other.guestIPType != null)
|
||||
return false;
|
||||
} else if (!guestIPType.equals(other.guestIPType))
|
||||
return false;
|
||||
if (zoneId == null) {
|
||||
if (other.zoneId != null)
|
||||
return false;
|
||||
} else if (!zoneId.equals(other.zoneId))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Network [id=" + id + ", state=" + state + ", name=" + name + ", displayText=" + displayText + ", guestIPType="
|
||||
+ guestIPType + ", trafficType=" + trafficType + ", DNS=" + getDNS() + ", VLAN=" + VLAN + ", account="
|
||||
+ account + ", startIP=" + startIP + ", endIP=" + endIP + ", netmask=" + netmask + ", gateway="
|
||||
+ gateway + ", broadcastDomainType=" + broadcastDomainType + ", broadcastURI=" + broadcastURI
|
||||
+ ", services=" + services + ", domain=" + domain + ", domainId=" + domainId + ", isDefault="
|
||||
+ isDefault + ", isShared=" + isShared + ", isSystem=" + isSystem + ", related=" + related + ", zoneId="
|
||||
+ zoneId + ", networkDomain=" + networkDomain + ", networkOfferingAvailability="
|
||||
+ networkOfferingAvailability + ", networkOfferingDisplayText=" + networkOfferingDisplayText
|
||||
+ ", networkOfferingId=" + networkOfferingId + ", networkOfferingName=" + networkOfferingName + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,239 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class NetworkOffering {
|
||||
private String id;
|
||||
private String name;
|
||||
@SerializedName("displaytext")
|
||||
private String displayText;
|
||||
private Date created;
|
||||
private String availability;
|
||||
@SerializedName("maxconnections")
|
||||
private Integer maxConnections;
|
||||
@SerializedName("isdefault")
|
||||
private boolean isDefault;
|
||||
@SerializedName("specifyvlan")
|
||||
private boolean supportsVLAN;
|
||||
@SerializedName("traffictype")
|
||||
private TrafficType trafficType;
|
||||
private String tags;
|
||||
|
||||
public NetworkOffering(String id, String name, String displayText, @Nullable Date created, String availability,
|
||||
boolean supportsVLAN, @Nullable Integer maxConnections, boolean isDefault, TrafficType trafficType,
|
||||
Set<String> tags) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.displayText = displayText;
|
||||
this.created = created;
|
||||
this.availability = availability;
|
||||
this.supportsVLAN = supportsVLAN;
|
||||
this.maxConnections = maxConnections;
|
||||
this.isDefault = isDefault;
|
||||
this.trafficType = trafficType;
|
||||
this.tags = Joiner.on(',').join(tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
*
|
||||
*/
|
||||
NetworkOffering() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the id of the network offering
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the network offering
|
||||
*/
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return an alternate display text of the network offering.
|
||||
*/
|
||||
public String getDisplayText() {
|
||||
return displayText;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the date this network offering was created
|
||||
*/
|
||||
@Nullable
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Availability name for the offering
|
||||
*/
|
||||
public String getAvailability() {
|
||||
return availability;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if network offering supports vlans, false otherwise
|
||||
*/
|
||||
public boolean supportsVLAN() {
|
||||
return supportsVLAN;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the max number of concurrent connection the network offering supports
|
||||
*/
|
||||
@Nullable
|
||||
public Integer getMaxConnections() {
|
||||
return maxConnections;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if network offering is default, false otherwise
|
||||
*/
|
||||
public boolean isDefault() {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the traffic type for this network offering
|
||||
*/
|
||||
public TrafficType getTrafficType() {
|
||||
return trafficType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the tags for the network offering
|
||||
*/
|
||||
public Set<String> getTags() {
|
||||
return tags != null ? ImmutableSet.copyOf(Splitter.on(',').split(tags)) : ImmutableSet.<String> of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((availability == null) ? 0 : availability.hashCode());
|
||||
result = prime * result + ((created == null) ? 0 : created.hashCode());
|
||||
result = prime * result + ((displayText == null) ? 0 : displayText.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + (isDefault ? 1231 : 1237);
|
||||
result = prime * result + ((maxConnections == null) ? 0 : maxConnections.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + (supportsVLAN ? 1231 : 1237);
|
||||
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
|
||||
result = prime * result + ((trafficType == null) ? 0 : trafficType.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;
|
||||
NetworkOffering other = (NetworkOffering) obj;
|
||||
if (availability == null) {
|
||||
if (other.availability != null)
|
||||
return false;
|
||||
} else if (!availability.equals(other.availability))
|
||||
return false;
|
||||
if (created == null) {
|
||||
if (other.created != null)
|
||||
return false;
|
||||
} else if (!created.equals(other.created))
|
||||
return false;
|
||||
if (displayText == null) {
|
||||
if (other.displayText != null)
|
||||
return false;
|
||||
} else if (!displayText.equals(other.displayText))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (isDefault != other.isDefault)
|
||||
return false;
|
||||
if (maxConnections == null) {
|
||||
if (other.maxConnections != null)
|
||||
return false;
|
||||
} else if (!maxConnections.equals(other.maxConnections))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (supportsVLAN != other.supportsVLAN)
|
||||
return false;
|
||||
if (tags == null) {
|
||||
if (other.tags != null)
|
||||
return false;
|
||||
} else if (!tags.equals(other.tags))
|
||||
return false;
|
||||
if (trafficType == null) {
|
||||
if (other.trafficType != null)
|
||||
return false;
|
||||
} else if (!trafficType.equals(other.trafficType))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created
|
||||
+ ", maxConnections=" + maxConnections + ", trafficType=" + trafficType + ", isDefault=" + isDefault
|
||||
+ ", availability=" + availability + ", supportsVLAN=" + supportsVLAN + ", tags=" + tags + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class NetworkService {
|
||||
public static class Capability {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
Capability() {
|
||||
|
||||
}
|
||||
|
||||
public Capability(String name, String value) {
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.value = checkNotNull(value, "value");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.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;
|
||||
NetworkService.Capability other = (NetworkService.Capability) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=" + name + ", value=" + value + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String name;
|
||||
@SerializedName("capability")
|
||||
private Set<? extends NetworkService.Capability> capabilities = ImmutableSet.of();
|
||||
|
||||
NetworkService() {
|
||||
|
||||
}
|
||||
|
||||
public NetworkService(String name, Set<? extends NetworkService.Capability> capabilities) {
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.capabilities = ImmutableSet.copyOf(checkNotNull(capabilities, "capabilities"));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Set<? extends NetworkService.Capability> getCapabilities() {
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((capabilities == null) ? 0 : capabilities.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.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;
|
||||
NetworkService other = (NetworkService) obj;
|
||||
if (capabilities == null) {
|
||||
if (other.capabilities != null)
|
||||
return false;
|
||||
} else if (!capabilities.equals(other.capabilities))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=" + name + ", capabilities=" + capabilities + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.cloudstack.features.TemplateClient;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see TemplateClient#listZones
|
||||
*/
|
||||
public enum NetworkType {
|
||||
BASIC,
|
||||
|
||||
ADVANCED,
|
||||
|
||||
UNRECOGNIZED;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
|
||||
}
|
||||
|
||||
public static NetworkType fromValue(String type) {
|
||||
try {
|
||||
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,261 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ServiceOffering {
|
||||
private String id;
|
||||
private String name;
|
||||
@SerializedName("displaytext")
|
||||
private String displayText;
|
||||
private Date created;
|
||||
private String domain;
|
||||
@SerializedName("domainid")
|
||||
private String domainId;
|
||||
@SerializedName("cpunumber")
|
||||
private int cpuNumber;
|
||||
@SerializedName("cpuspeed")
|
||||
private int cpuSpeed;
|
||||
private int memory;
|
||||
@SerializedName("offerha")
|
||||
private boolean haSupport;
|
||||
@SerializedName("storagetype")
|
||||
private StorageType storageType;
|
||||
private String tags;
|
||||
|
||||
public ServiceOffering(String id, String name, String displayText, Date created, String domain, String domainId,
|
||||
int cpuNumber, int cpuSpeed, int memory, boolean haSupport, StorageType storageType, Set<String> tags) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.displayText = displayText;
|
||||
this.created = created;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.cpuNumber = cpuNumber;
|
||||
this.cpuSpeed = cpuSpeed;
|
||||
this.memory = memory;
|
||||
this.haSupport = haSupport;
|
||||
this.storageType = storageType;
|
||||
this.tags = Joiner.on(',').join(tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
*
|
||||
*/
|
||||
ServiceOffering() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the id of the service offering
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the service offering
|
||||
*/
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return an alternate display text of the service offering.
|
||||
*/
|
||||
public String getDisplayText() {
|
||||
return displayText;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the date this service offering was created
|
||||
*/
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Domain name for the offering
|
||||
*/
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the domain id of the service offering
|
||||
*/
|
||||
public String getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the number of CPU
|
||||
*/
|
||||
public int getCpuNumber() {
|
||||
return cpuNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the clock rate CPU speed in Mhz
|
||||
*/
|
||||
public int getCpuSpeed() {
|
||||
return cpuSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the memory in MB
|
||||
*/
|
||||
public int getMemory() {
|
||||
return memory;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ha support in the service offering
|
||||
*/
|
||||
public boolean supportsHA() {
|
||||
return haSupport;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the storage type for this service offering
|
||||
*/
|
||||
public StorageType getStorageType() {
|
||||
return storageType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the tags for the service offering
|
||||
*/
|
||||
public Set<String> getTags() {
|
||||
return tags != null ? ImmutableSet.copyOf(Splitter.on(',').split(tags)) : ImmutableSet.<String> of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + cpuNumber;
|
||||
result = prime * result + cpuSpeed;
|
||||
result = prime * result + ((created == null) ? 0 : created.hashCode());
|
||||
result = prime * result + ((displayText == null) ? 0 : displayText.hashCode());
|
||||
result = prime * result + ((domain == null) ? 0 : domain.hashCode());
|
||||
result = prime * result + ((domainId == null) ? 0 : domainId.hashCode());
|
||||
result = prime * result + (haSupport ? 1231 : 1237);
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + memory;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((storageType == null) ? 0 : storageType.hashCode());
|
||||
result = prime * result + ((tags == null) ? 0 : tags.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;
|
||||
ServiceOffering other = (ServiceOffering) obj;
|
||||
if (cpuNumber != other.cpuNumber)
|
||||
return false;
|
||||
if (cpuSpeed != other.cpuSpeed)
|
||||
return false;
|
||||
if (created == null) {
|
||||
if (other.created != null)
|
||||
return false;
|
||||
} else if (!created.equals(other.created))
|
||||
return false;
|
||||
if (displayText == null) {
|
||||
if (other.displayText != null)
|
||||
return false;
|
||||
} else if (!displayText.equals(other.displayText))
|
||||
return false;
|
||||
if (domain == null) {
|
||||
if (other.domain != null)
|
||||
return false;
|
||||
} else if (!domain.equals(other.domain))
|
||||
return false;
|
||||
if (domainId == null) {
|
||||
if (other.domainId != null)
|
||||
return false;
|
||||
} else if (!domainId.equals(other.domainId))
|
||||
return false;
|
||||
if (haSupport != other.haSupport)
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (memory != other.memory)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (storageType == null) {
|
||||
if (other.storageType != null)
|
||||
return false;
|
||||
} else if (!storageType.equals(other.storageType))
|
||||
return false;
|
||||
if (tags == null) {
|
||||
if (other.tags != null)
|
||||
return false;
|
||||
} else if (!tags.equals(other.tags))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", created=" + created + ", cpuNumber="
|
||||
+ cpuNumber + ", cpuSpeed=" + cpuSpeed + ", memory=" + memory + ", storageType=" + storageType
|
||||
+ ", haSupport=" + haSupport + ", domain=" + domain + ", domainId=" + domainId + ", tags=" + tags + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.cloudstack.features.OfferingClient;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see OfferingClient#listServiceOfferings
|
||||
*/
|
||||
public enum StorageType {
|
||||
LOCAL,
|
||||
|
||||
SHARED,
|
||||
|
||||
UNRECOGNIZED;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
|
||||
}
|
||||
|
||||
public static StorageType fromValue(String type) {
|
||||
try {
|
||||
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,538 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Template {
|
||||
|
||||
public enum Type {
|
||||
|
||||
USER, BUILTIN, UNRECOGNIZED;
|
||||
|
||||
public static Type fromValue(String type) {
|
||||
try {
|
||||
return valueOf(checkNotNull(type, "type"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Format {
|
||||
|
||||
VHD, QCOW2, OVA, UNRECOGNIZED;
|
||||
|
||||
public static Format fromValue(String format) {
|
||||
try {
|
||||
return valueOf(checkNotNull(format, "format"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String id;
|
||||
@SerializedName("displaytext")
|
||||
private String displayText;
|
||||
private String domain;
|
||||
@SerializedName("domainid")
|
||||
private String domainId;
|
||||
private String account;
|
||||
@SerializedName("accountid")
|
||||
private String accountId;
|
||||
@SerializedName("zonename")
|
||||
private String zone;
|
||||
@SerializedName("zoneid")
|
||||
private String zoneId;
|
||||
@SerializedName("ostypename")
|
||||
private String OSType;
|
||||
@SerializedName("ostypeid")
|
||||
private String OSTypeId;
|
||||
private String name;
|
||||
@SerializedName("templatetype")
|
||||
private Type type;
|
||||
private String status;
|
||||
private Format format;
|
||||
private String hypervisor;
|
||||
private Long size;
|
||||
private Date created;
|
||||
private Date removed;
|
||||
@SerializedName("crossZones")
|
||||
private boolean crossZones;
|
||||
@SerializedName("bootable")
|
||||
private boolean bootable;
|
||||
@SerializedName("isextractable")
|
||||
private boolean extractable;
|
||||
@SerializedName("isfeatured")
|
||||
private boolean featured;
|
||||
@SerializedName("ispublic")
|
||||
private boolean ispublic;
|
||||
@SerializedName("isready")
|
||||
private boolean ready;
|
||||
@SerializedName("passwordenabled")
|
||||
private boolean passwordEnabled;
|
||||
@Nullable
|
||||
@SerializedName("jobid")
|
||||
private String jobId;
|
||||
@SerializedName("jobstatus")
|
||||
private String jobStatus;
|
||||
|
||||
public Template(String id, String displayText, String domain, String domainId, String account, String accountId,
|
||||
String zone, String zoneId, String oSType, String oSTypeId, String name, Type type, String status,
|
||||
Format format, String hypervisor, Long size, Date created, Date removed, boolean crossZones,
|
||||
boolean bootable, boolean extractable, boolean featured, boolean ispublic, boolean ready,
|
||||
boolean passwordEnabled, String jobId, String jobStatus) {
|
||||
this.id = id;
|
||||
this.displayText = displayText;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.account = account;
|
||||
this.accountId = accountId;
|
||||
this.zone = zone;
|
||||
this.zoneId = zoneId;
|
||||
this.OSType = oSType;
|
||||
this.OSTypeId = oSTypeId;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.status = status;
|
||||
this.format = format;
|
||||
this.hypervisor = hypervisor;
|
||||
this.size = size;
|
||||
this.created = created;
|
||||
this.removed = removed;
|
||||
this.crossZones = crossZones;
|
||||
this.bootable = bootable;
|
||||
this.extractable = extractable;
|
||||
this.featured = featured;
|
||||
this.ispublic = ispublic;
|
||||
this.ready = ready;
|
||||
this.passwordEnabled = passwordEnabled;
|
||||
this.jobId = jobId;
|
||||
this.jobStatus = jobStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
*
|
||||
*/
|
||||
Template() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Template id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the display text of the template
|
||||
*/
|
||||
public String getDisplayText() {
|
||||
return displayText;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the domain to which the template beLongs
|
||||
*/
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ID of the domain to which the template beLongs
|
||||
*/
|
||||
public String getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the account to which the template beLongs
|
||||
*/
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ID of the account to which the template beLongs
|
||||
*/
|
||||
public String getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the zone to which the template beLongs
|
||||
*/
|
||||
public String getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ID of the zone to which the template beLongs
|
||||
*/
|
||||
public String getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the OS type to which the template beLongs
|
||||
*/
|
||||
public String getOSType() {
|
||||
return OSType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ID of the OS type to which the template beLongs
|
||||
*/
|
||||
public String getOSTypeId() {
|
||||
return OSTypeId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Template name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the format of the template.
|
||||
*/
|
||||
public Format getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the hypervisor on which the template runs
|
||||
*/
|
||||
public String getHypervisor() {
|
||||
return hypervisor;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the size of the template in kilobytes
|
||||
*/
|
||||
public Long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the type of the template
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the date this template was created
|
||||
*/
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the date this template was removed
|
||||
*/
|
||||
public Date getRemoved() {
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the template is managed across all Zones, false otherwise
|
||||
*/
|
||||
public boolean isCrossZones() {
|
||||
return crossZones;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the ISO is bootable, false otherwise
|
||||
*/
|
||||
public boolean isBootable() {
|
||||
return bootable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the template is extractable, false otherwise
|
||||
*/
|
||||
public boolean isExtractable() {
|
||||
return extractable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if this template is a featured template, false otherwise
|
||||
*/
|
||||
public boolean isFeatured() {
|
||||
return featured;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if this template is a public template, false otherwise
|
||||
*/
|
||||
public boolean isPublic() {
|
||||
return ispublic;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the template is ready to be deployed from, false otherwise
|
||||
*/
|
||||
public boolean isReady() {
|
||||
return ready;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the reset password feature is enabled, false otherwise
|
||||
*/
|
||||
public boolean isPasswordEnabled() {
|
||||
return passwordEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return shows the current pending asynchronous job ID, or null if current pending jobs are
|
||||
* acting on the template
|
||||
*/
|
||||
@Nullable
|
||||
public String getJobId() {
|
||||
return jobId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return shows the current pending asynchronous job status
|
||||
*/
|
||||
public String getJobStatus() {
|
||||
return jobStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((OSType == null) ? 0 : OSType.hashCode());
|
||||
result = prime * result + ((OSTypeId == null) ? 0 : OSTypeId.hashCode());
|
||||
result = prime * result + ((account == null) ? 0 : account.hashCode());
|
||||
result = prime * result + ((accountId == null) ? 0 : accountId.hashCode());
|
||||
result = prime * result + (bootable ? 1231 : 1237);
|
||||
result = prime * result + ((created == null) ? 0 : created.hashCode());
|
||||
result = prime * result + (crossZones ? 1231 : 1237);
|
||||
result = prime * result + ((displayText == null) ? 0 : displayText.hashCode());
|
||||
result = prime * result + ((domain == null) ? 0 : domain.hashCode());
|
||||
result = prime * result + ((domainId == null) ? 0 : domainId.hashCode());
|
||||
result = prime * result + (extractable ? 1231 : 1237);
|
||||
result = prime * result + (featured ? 1231 : 1237);
|
||||
result = prime * result + ((format == null) ? 0 : format.hashCode());
|
||||
result = prime * result + ((hypervisor == null) ? 0 : hypervisor.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + (ispublic ? 1231 : 1237);
|
||||
result = prime * result + ((jobId == null) ? 0 : jobId.hashCode());
|
||||
result = prime * result + ((jobStatus == null) ? 0 : jobStatus.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + (passwordEnabled ? 1231 : 1237);
|
||||
result = prime * result + (ready ? 1231 : 1237);
|
||||
result = prime * result + ((removed == null) ? 0 : removed.hashCode());
|
||||
result = prime * result + ((size == null) ? 0 : size.hashCode());
|
||||
result = prime * result + ((status == null) ? 0 : status.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
result = prime * result + ((zone == null) ? 0 : zone.hashCode());
|
||||
result = prime * result + ((zoneId == null) ? 0 : zoneId.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;
|
||||
Template other = (Template) obj;
|
||||
if (OSType == null) {
|
||||
if (other.OSType != null)
|
||||
return false;
|
||||
} else if (!OSType.equals(other.OSType))
|
||||
return false;
|
||||
if (OSTypeId == null) {
|
||||
if (other.OSTypeId != null)
|
||||
return false;
|
||||
} else if (!OSTypeId.equals(other.OSTypeId))
|
||||
return false;
|
||||
if (account == null) {
|
||||
if (other.account != null)
|
||||
return false;
|
||||
} else if (!account.equals(other.account))
|
||||
return false;
|
||||
if (accountId == null) {
|
||||
if (other.accountId != null)
|
||||
return false;
|
||||
} else if (!accountId.equals(other.accountId))
|
||||
return false;
|
||||
if (bootable != other.bootable)
|
||||
return false;
|
||||
if (created == null) {
|
||||
if (other.created != null)
|
||||
return false;
|
||||
} else if (!created.equals(other.created))
|
||||
return false;
|
||||
if (crossZones != other.crossZones)
|
||||
return false;
|
||||
if (displayText == null) {
|
||||
if (other.displayText != null)
|
||||
return false;
|
||||
} else if (!displayText.equals(other.displayText))
|
||||
return false;
|
||||
if (domain == null) {
|
||||
if (other.domain != null)
|
||||
return false;
|
||||
} else if (!domain.equals(other.domain))
|
||||
return false;
|
||||
if (domainId == null) {
|
||||
if (other.domainId != null)
|
||||
return false;
|
||||
} else if (!domainId.equals(other.domainId))
|
||||
return false;
|
||||
if (extractable != other.extractable)
|
||||
return false;
|
||||
if (featured != other.featured)
|
||||
return false;
|
||||
if (format == null) {
|
||||
if (other.format != null)
|
||||
return false;
|
||||
} else if (!format.equals(other.format))
|
||||
return false;
|
||||
if (hypervisor == null) {
|
||||
if (other.hypervisor != null)
|
||||
return false;
|
||||
} else if (!hypervisor.equals(other.hypervisor))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (ispublic != other.ispublic)
|
||||
return false;
|
||||
if (jobId == null) {
|
||||
if (other.jobId != null)
|
||||
return false;
|
||||
} else if (!jobId.equals(other.jobId))
|
||||
return false;
|
||||
if (jobStatus == null) {
|
||||
if (other.jobStatus != null)
|
||||
return false;
|
||||
} else if (!jobStatus.equals(other.jobStatus))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (passwordEnabled != other.passwordEnabled)
|
||||
return false;
|
||||
if (ready != other.ready)
|
||||
return false;
|
||||
if (removed == null) {
|
||||
if (other.removed != null)
|
||||
return false;
|
||||
} else if (!removed.equals(other.removed))
|
||||
return false;
|
||||
if (size == null) {
|
||||
if (other.size != null)
|
||||
return false;
|
||||
} else if (!size.equals(other.size))
|
||||
return false;
|
||||
if (status == null) {
|
||||
if (other.status != null)
|
||||
return false;
|
||||
} else if (!status.equals(other.status))
|
||||
return false;
|
||||
if (type == null) {
|
||||
if (other.type != null)
|
||||
return false;
|
||||
} else if (!type.equals(other.type))
|
||||
return false;
|
||||
if (zone == null) {
|
||||
if (other.zone != null)
|
||||
return false;
|
||||
} else if (!zone.equals(other.zone))
|
||||
return false;
|
||||
if (zoneId == null) {
|
||||
if (other.zoneId != null)
|
||||
return false;
|
||||
} else if (!zoneId.equals(other.zoneId))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", name=" + name + ", displayText=" + displayText + ", format=" + format + ", type=" + type
|
||||
+ ", hypervisor=" + hypervisor + ", size=" + size + ", status=" + status + ", created=" + created
|
||||
+ ", removed=" + removed + ", OSType=" + OSType + ", OSTypeId=" + OSTypeId + ", account=" + account
|
||||
+ ", accountId=" + accountId + ", domain=" + domain + ", domainId=" + domainId + ", zone=" + zone
|
||||
+ ", zoneId=" + zoneId + ", ready=" + ready + ", bootable=" + bootable + ", crossZones=" + crossZones
|
||||
+ ", extractable=" + extractable + ", featured=" + featured + ", ispublic=" + ispublic
|
||||
+ ", passwordEnabled=" + passwordEnabled + ", jobId=" + jobId + ", jobStatus=" + jobStatus + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import org.jclouds.cloudstack.features.TemplateClient;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see TemplateClient#listTemplates
|
||||
*/
|
||||
public enum TemplateFilter {
|
||||
/**
|
||||
* templates that are featured and are public
|
||||
*/
|
||||
FEATURED,
|
||||
/**
|
||||
* templates that have been registered/created by the owner
|
||||
*/
|
||||
SELF,
|
||||
/**
|
||||
* templates that have been registered/created by the owner that can be used to deploy a new VM
|
||||
*/
|
||||
SELF_EXECUTABLE,
|
||||
/**
|
||||
* all templates that can be used to deploy a new VM
|
||||
*/
|
||||
EXECUTABLE,
|
||||
/**
|
||||
* templates that are public
|
||||
*/
|
||||
COMMUNITY;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see NetworkOfferingClient#listNetworkOfferings
|
||||
*/
|
||||
public enum TrafficType {
|
||||
|
||||
/**
|
||||
* traffic to the public internet
|
||||
*/
|
||||
PUBLIC,
|
||||
/**
|
||||
* VM-to-VM traffic and VMs are assigned a virtual IP created by CloudStack
|
||||
*/
|
||||
GUEST,
|
||||
/**
|
||||
* System network that only Admin can view, and only when isSystem is specified.
|
||||
*/
|
||||
STORAGE,
|
||||
/**
|
||||
* System network that only Admin can view, and only when isSystem is specified.
|
||||
*/
|
||||
MANAGEMENT,
|
||||
/**
|
||||
* System network that only Admin can view, and only when isSystem is specified.
|
||||
*/
|
||||
CONTROL,
|
||||
|
||||
UNRECOGNIZED;
|
||||
@Override
|
||||
public String toString() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
|
||||
}
|
||||
|
||||
public static TrafficType fromValue(String type) {
|
||||
try {
|
||||
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,306 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Zone {
|
||||
private String id;
|
||||
private String description;
|
||||
@SerializedName("displaytext")
|
||||
private String displayText;
|
||||
@SerializedName("dns1")
|
||||
private String DNS1;
|
||||
@SerializedName("dns2")
|
||||
private String DNS2;
|
||||
private String domain;
|
||||
@Nullable
|
||||
@SerializedName("domainid")
|
||||
private String domainId;
|
||||
@SerializedName("guestcidraddress")
|
||||
private String guestCIDRAddress;
|
||||
@SerializedName("internaldns1")
|
||||
private String internalDNS1;
|
||||
@SerializedName("internaldns2")
|
||||
private String internalDNS2;
|
||||
private String name;
|
||||
@SerializedName("networktype")
|
||||
private NetworkType networkType;
|
||||
private String status;
|
||||
@SerializedName("vlan")
|
||||
private String VLAN;
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
*
|
||||
*/
|
||||
Zone() {
|
||||
|
||||
}
|
||||
|
||||
public Zone(String id, String description, String displayText, List<String> DNS, String domain, String domainId,
|
||||
String guestCIDRAddress, List<String> internalDNS, String name, NetworkType networkType, String status,
|
||||
String vLAN) {
|
||||
this.id = id;
|
||||
this.description = description;
|
||||
this.displayText = displayText;
|
||||
this.DNS1 = checkNotNull(DNS, "DNS").size() > 0 ? DNS.get(0) : null;
|
||||
this.DNS2 = DNS.size() > 1 ? DNS.get(1) : null;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.guestCIDRAddress = guestCIDRAddress;
|
||||
this.internalDNS1 = checkNotNull(internalDNS, "internalDNS").size() > 0 ? internalDNS.get(0) : null;
|
||||
this.internalDNS2 = internalDNS.size() > 1 ? internalDNS.get(1) : null;
|
||||
this.name = name;
|
||||
this.networkType = networkType;
|
||||
this.status = status;
|
||||
this.VLAN = vLAN;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Zone id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Zone description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the display text of the zone
|
||||
*/
|
||||
public String getDisplayText() {
|
||||
return displayText;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the external DNS for the Zone
|
||||
*/
|
||||
public List<String> getDNS() {
|
||||
Builder<String> builder = ImmutableList.builder();
|
||||
if (DNS1 != null && !"".equals(DNS1))
|
||||
builder.add(DNS1);
|
||||
if (DNS2 != null && !"".equals(DNS2))
|
||||
builder.add(DNS2);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Domain name for the Vms in the zone
|
||||
*/
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the ID of the containing domain, null for public zones
|
||||
*/
|
||||
@Nullable
|
||||
public String getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the guest CIDR address for the Zone
|
||||
*/
|
||||
public String getGuestCIDRAddress() {
|
||||
return guestCIDRAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the internal DNS for the Zone
|
||||
*/
|
||||
public List<String> getInternalDNS() {
|
||||
Builder<String> builder = ImmutableList.builder();
|
||||
if (internalDNS1 != null && !"".equals(internalDNS1))
|
||||
builder.add(internalDNS1);
|
||||
if (internalDNS2 != null && !"".equals(internalDNS2))
|
||||
builder.add(internalDNS2);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Zone name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the network type of the zone; can be Basic or Advanced
|
||||
*/
|
||||
public NetworkType getNetworkType() {
|
||||
return networkType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the vlan range of the zone
|
||||
*/
|
||||
public String getVLAN() {
|
||||
return VLAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((DNS1 == null) ? 0 : DNS1.hashCode());
|
||||
result = prime * result + ((DNS2 == null) ? 0 : DNS2.hashCode());
|
||||
result = prime * result + ((VLAN == null) ? 0 : VLAN.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((displayText == null) ? 0 : displayText.hashCode());
|
||||
result = prime * result + ((domain == null) ? 0 : domain.hashCode());
|
||||
result = prime * result + ((domainId == null) ? 0 : domainId.hashCode());
|
||||
result = prime * result + ((guestCIDRAddress == null) ? 0 : guestCIDRAddress.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((internalDNS1 == null) ? 0 : internalDNS1.hashCode());
|
||||
result = prime * result + ((internalDNS2 == null) ? 0 : internalDNS2.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((networkType == null) ? 0 : networkType.hashCode());
|
||||
result = prime * result + ((status == null) ? 0 : status.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;
|
||||
Zone other = (Zone) obj;
|
||||
if (DNS1 == null) {
|
||||
if (other.DNS1 != null)
|
||||
return false;
|
||||
} else if (!DNS1.equals(other.DNS1))
|
||||
return false;
|
||||
if (DNS2 == null) {
|
||||
if (other.DNS2 != null)
|
||||
return false;
|
||||
} else if (!DNS2.equals(other.DNS2))
|
||||
return false;
|
||||
if (VLAN == null) {
|
||||
if (other.VLAN != null)
|
||||
return false;
|
||||
} else if (!VLAN.equals(other.VLAN))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (displayText == null) {
|
||||
if (other.displayText != null)
|
||||
return false;
|
||||
} else if (!displayText.equals(other.displayText))
|
||||
return false;
|
||||
if (domain == null) {
|
||||
if (other.domain != null)
|
||||
return false;
|
||||
} else if (!domain.equals(other.domain))
|
||||
return false;
|
||||
if (domainId == null) {
|
||||
if (other.domainId != null)
|
||||
return false;
|
||||
} else if (!domainId.equals(other.domainId))
|
||||
return false;
|
||||
if (guestCIDRAddress == null) {
|
||||
if (other.guestCIDRAddress != null)
|
||||
return false;
|
||||
} else if (!guestCIDRAddress.equals(other.guestCIDRAddress))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (internalDNS1 == null) {
|
||||
if (other.internalDNS1 != null)
|
||||
return false;
|
||||
} else if (!internalDNS1.equals(other.internalDNS1))
|
||||
return false;
|
||||
if (internalDNS2 == null) {
|
||||
if (other.internalDNS2 != null)
|
||||
return false;
|
||||
} else if (!internalDNS2.equals(other.internalDNS2))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (networkType == null) {
|
||||
if (other.networkType != null)
|
||||
return false;
|
||||
} else if (!networkType.equals(other.networkType))
|
||||
return false;
|
||||
if (status == null) {
|
||||
if (other.status != null)
|
||||
return false;
|
||||
} else if (!status.equals(other.status))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", status=" + status + ", name=" + name + ", description=" + description + ", displayText="
|
||||
+ displayText + ", domain=" + domain + ", domainId=" + domainId + ", networkType=" + networkType
|
||||
+ ", guestCIDRAddress=" + guestCIDRAddress + ", VLAN=" + VLAN + ", DNS=" + getDNS() + ", internalDNS="
|
||||
+ getInternalDNS() + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListNetworksOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to cloudstack via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see NetworkClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface NetworkAsyncClient {
|
||||
|
||||
/**
|
||||
* @see NetworkClient#listNetworks
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listNetworks")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Network>> listNetworks(ListNetworksOptions... options);
|
||||
|
||||
/**
|
||||
* @see NetworkClient#getNetwork
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listNetworks")
|
||||
@Unwrap(depth = 3, edgeCollection = Set.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Network> getNetwork(@QueryParam("id") String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
import org.jclouds.cloudstack.options.ListNetworksOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack network features.
|
||||
* <p/>
|
||||
*
|
||||
* @see NetworkAsyncClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface NetworkClient {
|
||||
/**
|
||||
* Lists networks
|
||||
*
|
||||
* @param options
|
||||
* if present, how to constrain the list.
|
||||
* @return networks matching query, or empty set, if no networks are found
|
||||
*/
|
||||
Set<Network> listNetworks(ListNetworksOptions... options);
|
||||
|
||||
/**
|
||||
* get a specific network by id
|
||||
*
|
||||
* @param id
|
||||
* network to get
|
||||
* @return network or null if not found
|
||||
*/
|
||||
Network getNetwork(String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.cloudstack.domain.DiskOffering;
|
||||
import org.jclouds.cloudstack.domain.NetworkOffering;
|
||||
import org.jclouds.cloudstack.domain.ServiceOffering;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to cloudstack via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see OfferingClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface OfferingAsyncClient {
|
||||
|
||||
/**
|
||||
* @see OfferingClient#listServiceOfferings
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listServiceOfferings")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<ServiceOffering>> listServiceOfferings(ListServiceOfferingsOptions... options);
|
||||
|
||||
/**
|
||||
* @see OfferingClient#getServiceOffering
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listServiceOfferings")
|
||||
@Unwrap(depth = 3, edgeCollection = Set.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<ServiceOffering> getServiceOffering(@QueryParam("id") String id);
|
||||
|
||||
/**
|
||||
* @see OfferingClient#listDiskOfferings
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listDiskOfferings")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<DiskOffering>> listDiskOfferings(ListDiskOfferingsOptions... options);
|
||||
|
||||
/**
|
||||
* @see OfferingClient#getDiskOffering
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listDiskOfferings")
|
||||
@Unwrap(depth = 3, edgeCollection = Set.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<DiskOffering> getDiskOffering(@QueryParam("id") String id);
|
||||
|
||||
/**
|
||||
* @see NetworkOfferingClient#listNetworkOfferings
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listNetworkOfferings")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<NetworkOffering>> listNetworkOfferings(ListNetworkOfferingsOptions... options);
|
||||
|
||||
/**
|
||||
* @see NetworkOfferingClient#getNetworkOffering
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listNetworkOfferings")
|
||||
@Unwrap(depth = 3, edgeCollection = Set.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<NetworkOffering> getNetworkOffering(@QueryParam("id") String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.DiskOffering;
|
||||
import org.jclouds.cloudstack.domain.NetworkOffering;
|
||||
import org.jclouds.cloudstack.domain.ServiceOffering;
|
||||
import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack zone features.
|
||||
* <p/>
|
||||
*
|
||||
* @see OfferingAsyncClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface OfferingClient {
|
||||
/**
|
||||
* Lists service offerings
|
||||
*
|
||||
* @param options
|
||||
* if present, how to constrain the list.
|
||||
* @return service offerings matching query, or empty set, if no service offerings are found
|
||||
*/
|
||||
Set<ServiceOffering> listServiceOfferings(ListServiceOfferingsOptions... options);
|
||||
|
||||
/**
|
||||
* get a specific service offering by id
|
||||
*
|
||||
* @param id
|
||||
* offering to get
|
||||
* @return service offering or null if not found
|
||||
*/
|
||||
ServiceOffering getServiceOffering(String id);
|
||||
|
||||
/**
|
||||
* Lists disk offerings
|
||||
*
|
||||
* @param options
|
||||
* if present, how to constrain the list.
|
||||
* @return disk offerings matching query, or empty set, if no disk offerings are found
|
||||
*/
|
||||
Set<DiskOffering> listDiskOfferings(ListDiskOfferingsOptions... options);
|
||||
|
||||
/**
|
||||
* get a specific disk offering by id
|
||||
*
|
||||
* @param id
|
||||
* offering to get
|
||||
* @return disk offering or null if not found
|
||||
*/
|
||||
DiskOffering getDiskOffering(String id);
|
||||
|
||||
/**
|
||||
* Lists service offerings
|
||||
*
|
||||
* @param options
|
||||
* if present, how to constrain the list.
|
||||
* @return service offerings matching query, or empty set, if no service offerings are found
|
||||
*/
|
||||
Set<NetworkOffering> listNetworkOfferings(ListNetworkOfferingsOptions... options);
|
||||
|
||||
/**
|
||||
* get a specific service offering by id
|
||||
*
|
||||
* @param id
|
||||
* offering to get
|
||||
* @return service offering or null if not found
|
||||
*/
|
||||
NetworkOffering getNetworkOffering(String id);
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Template;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListTemplatesOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to cloudstack via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see TemplateClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface TemplateAsyncClient {
|
||||
|
||||
/**
|
||||
* @see TemplateClient#listTemplates
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = { "command", "templatefilter" }, values = { "listTemplates", "executable" })
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Template>> listTemplates();
|
||||
|
||||
/**
|
||||
* @see TemplateClient#listTemplates(ListTemplatesOptions)
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listTemplates")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Template>> listTemplates(ListTemplatesOptions options);
|
||||
|
||||
/**
|
||||
* @see TemplateClient#getTemplate
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = { "command", "templatefilter" }, values = { "listTemplates", "executable" })
|
||||
@Unwrap(depth = 3, edgeCollection = Set.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Template> getTemplate(@QueryParam("id") String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Template;
|
||||
import org.jclouds.cloudstack.domain.TemplateFilter;
|
||||
import org.jclouds.cloudstack.options.ListTemplatesOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack template features.
|
||||
* <p/>
|
||||
*
|
||||
* @see TemplateAsyncClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface TemplateClient {
|
||||
/**
|
||||
* List all executable templates.
|
||||
*
|
||||
* @return all executable templates, or empty set, if no templates are found
|
||||
*/
|
||||
Set<Template> listTemplates();
|
||||
|
||||
/**
|
||||
* List all public, private, and privileged templates.
|
||||
*
|
||||
* @param options
|
||||
* if present, how to constrain the list, defaults to all executable templates
|
||||
* @return templates matching query, or empty set, if no templates are found
|
||||
* @see TemplateFilter
|
||||
*/
|
||||
Set<Template> listTemplates(ListTemplatesOptions options);
|
||||
|
||||
/**
|
||||
* get a specific template by id
|
||||
*
|
||||
* @param id
|
||||
* template to get
|
||||
* @return template or null if not found
|
||||
*/
|
||||
Template getTemplate(String id);
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Zone;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListZonesOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to cloudstack via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see ZoneClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface ZoneAsyncClient {
|
||||
|
||||
/**
|
||||
* @see ZoneClient#listZones
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listZones")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Zone>> listZones(ListZonesOptions... options);
|
||||
|
||||
/**
|
||||
* @see ZoneClient#getZone
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listZones")
|
||||
@Unwrap(depth = 3, edgeCollection = Set.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Zone> getZone(@QueryParam("id") String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Zone;
|
||||
import org.jclouds.cloudstack.options.ListZonesOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack zone features.
|
||||
* <p/>
|
||||
*
|
||||
* @see ZoneAsyncClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface ZoneClient {
|
||||
/**
|
||||
* Lists zones
|
||||
*
|
||||
* @param options
|
||||
* if present, how to constrain the list.
|
||||
* @return zones matching query, or empty set, if no zones are found
|
||||
*/
|
||||
Set<Zone> listZones(ListZonesOptions... options);
|
||||
|
||||
/**
|
||||
* get a specific zone by id
|
||||
*
|
||||
* @param id
|
||||
* zone to get
|
||||
* @return zone or null if not found
|
||||
*/
|
||||
Zone getZone(String id);
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.filters;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.crypto.CryptoStreams;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpRequestFilter;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.internal.SignatureWire;
|
||||
import org.jclouds.http.utils.ModifyRequest;
|
||||
import org.jclouds.io.InputSuppliers;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.RequestSigner;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.ImmutableMultimap.Builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see <a href= "http://download.cloud.com/releases/2.2/api/user/2.2api_security_details.html" />
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class QuerySigner implements HttpRequestFilter, RequestSigner {
|
||||
|
||||
private final SignatureWire signatureWire;
|
||||
private final String accessKey;
|
||||
private final String secretKey;
|
||||
private final Crypto crypto;
|
||||
private final HttpUtils utils;
|
||||
private final Provider<UriBuilder> builder;
|
||||
|
||||
@Resource
|
||||
@Named(Constants.LOGGER_SIGNATURE)
|
||||
private Logger signatureLog = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public QuerySigner(SignatureWire signatureWire, @Named(Constants.PROPERTY_IDENTITY) String accessKey,
|
||||
@Named(Constants.PROPERTY_CREDENTIAL) String secretKey, Crypto crypto, HttpUtils utils,
|
||||
Provider<UriBuilder> builder) {
|
||||
this.signatureWire = signatureWire;
|
||||
this.accessKey = accessKey;
|
||||
this.secretKey = secretKey;
|
||||
this.crypto = crypto;
|
||||
this.utils = utils;
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
public HttpRequest filter(HttpRequest request) throws HttpException {
|
||||
checkNotNull(request, "request must be present");
|
||||
Multimap<String, String> decodedParams = ModifyRequest.parseQueryToMap(request.getEndpoint().getQuery());
|
||||
addSigningParams(decodedParams);
|
||||
String stringToSign = createStringToSign(request, decodedParams);
|
||||
String signature = sign(stringToSign);
|
||||
addSignature(decodedParams, signature);
|
||||
request = request.toBuilder().endpoint(
|
||||
builder.get().uri(request.getEndpoint()).replaceQuery(ModifyRequest.makeQueryLine(decodedParams, null))
|
||||
.build()).build();
|
||||
utils.logRequest(signatureLog, request, "<<");
|
||||
return request;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void addSignature(Multimap<String, String> params, String signature) {
|
||||
params.replaceValues("signature", ImmutableList.of(signature));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public String sign(String stringToSign) {
|
||||
String signature;
|
||||
try {
|
||||
signature = CryptoStreams.base64(CryptoStreams.mac(InputSuppliers.of(stringToSign), crypto.hmacSHA1(secretKey
|
||||
.getBytes())));
|
||||
if (signatureWire.enabled())
|
||||
signatureWire.input(Strings2.toInputStream(signature));
|
||||
} catch (Exception e) {
|
||||
throw new HttpException("error signing request", e);
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams) {
|
||||
utils.logRequest(signatureLog, request, ">>");
|
||||
Builder<String, String> builder = ImmutableMultimap.<String, String> builder();
|
||||
|
||||
for (String key : ImmutableSortedSet.copyOf(decodedParams.keySet()))
|
||||
builder.put(key.toLowerCase(), Iterables.getOnlyElement(decodedParams.get(key)).toLowerCase());
|
||||
|
||||
String stringToSign = ModifyRequest.makeQueryLine(builder.build(), null);
|
||||
if (signatureWire.enabled())
|
||||
signatureWire.output(stringToSign);
|
||||
return stringToSign;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void addSigningParams(Multimap<String, String> params) {
|
||||
params.replaceValues("apiKey", ImmutableList.of(accessKey));
|
||||
params.removeAll("signature");
|
||||
}
|
||||
|
||||
public String createStringToSign(HttpRequest input) {
|
||||
Multimap<String, String> decodedParams = ModifyRequest.parseQueryToMap(input.getEndpoint().getQuery());
|
||||
addSigningParams(decodedParams);
|
||||
return createStringToSign(input, decodedParams);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.handlers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class CloudStackErrorHandler implements HttpErrorHandler {
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
public void handleError(HttpCommand command, HttpResponse response) {
|
||||
// it is important to always read fully and close streams
|
||||
String message = parseMessage(response);
|
||||
Exception exception = message != null ? new HttpResponseException(command, response, message)
|
||||
: new HttpResponseException(command, response);
|
||||
try {
|
||||
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
|
||||
response.getStatusLine());
|
||||
switch (response.getStatusCode()) {
|
||||
case 400:
|
||||
exception = new IllegalArgumentException(message, exception);
|
||||
break;
|
||||
case 401:
|
||||
exception = new AuthorizationException(message, exception);
|
||||
break;
|
||||
case 404:
|
||||
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
}
|
||||
break;
|
||||
case 405:
|
||||
exception = new IllegalArgumentException(message, exception);
|
||||
break;
|
||||
case 409:
|
||||
exception = new IllegalStateException(message, exception);
|
||||
break;
|
||||
}
|
||||
} finally {
|
||||
if (response.getPayload() != null)
|
||||
Closeables.closeQuietly(response.getPayload().getInput());
|
||||
command.setException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public String parseMessage(HttpResponse response) {
|
||||
if (response.getPayload() == null)
|
||||
return null;
|
||||
try {
|
||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
response.getPayload().getInput().close();
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options used to control what disk offerings are returned
|
||||
*
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/user/listDiskOfferings.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ListDiskOfferingsOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListDiskOfferingsOptions NONE = new ListDiskOfferingsOptions();
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the ID of the disk offering
|
||||
*/
|
||||
public ListDiskOfferingsOptions id(String id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domainId
|
||||
* the ID of the domain associated with the disk offering
|
||||
*/
|
||||
public ListDiskOfferingsOptions domainId(String domainId) {
|
||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the disk offering name
|
||||
*/
|
||||
public ListDiskOfferingsOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListDiskOfferingsOptions#name
|
||||
*/
|
||||
public static ListDiskOfferingsOptions name(String name) {
|
||||
ListDiskOfferingsOptions options = new ListDiskOfferingsOptions();
|
||||
return options.name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDiskOfferingsOptions#domainId
|
||||
*/
|
||||
public static ListDiskOfferingsOptions domainId(String id) {
|
||||
ListDiskOfferingsOptions options = new ListDiskOfferingsOptions();
|
||||
return options.domainId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListDiskOfferingsOptions#id
|
||||
*/
|
||||
public static ListDiskOfferingsOptions id(String id) {
|
||||
ListDiskOfferingsOptions options = new ListDiskOfferingsOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import org.jclouds.cloudstack.domain.TrafficType;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options used to control what network offerings are returned
|
||||
*
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/user/listNetworkOfferings.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ListNetworkOfferingsOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListNetworkOfferingsOptions NONE = new ListNetworkOfferingsOptions();
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the ID of the network offering
|
||||
*/
|
||||
public ListNetworkOfferingsOptions id(String id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the network offering name
|
||||
*/
|
||||
public ListNetworkOfferingsOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param displayText
|
||||
* network offerings by display text
|
||||
*/
|
||||
public ListNetworkOfferingsOptions displayText(String displayText) {
|
||||
this.queryParameters.replaceValues("displaytext", ImmutableSet.of(displayText));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param availability
|
||||
* the availability of network offering. Default value is Required
|
||||
*/
|
||||
public ListNetworkOfferingsOptions availability(String availability) {
|
||||
this.queryParameters.replaceValues("availability", ImmutableSet.of(availability));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isDefault
|
||||
* true if network offering is default, false otherwise
|
||||
*/
|
||||
public ListNetworkOfferingsOptions isDefault(boolean isDefault) {
|
||||
this.queryParameters.replaceValues("isdefault", ImmutableSet.of(isDefault + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isShared
|
||||
* true if network offering is shared, false otherwise
|
||||
*/
|
||||
public ListNetworkOfferingsOptions isShared(boolean isShared) {
|
||||
this.queryParameters.replaceValues("isshared", ImmutableSet.of(isShared + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param specifyVLAN
|
||||
* True if we allow the network supports vlan, false otherwise. If you create network
|
||||
* using this offering, you must specify vlan.
|
||||
*/
|
||||
public ListNetworkOfferingsOptions specifyVLAN(boolean specifyVLAN) {
|
||||
this.queryParameters.replaceValues("specifyvlan", ImmutableSet.of(specifyVLAN + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param trafficType
|
||||
* type of the traffic
|
||||
*/
|
||||
public ListNetworkOfferingsOptions trafficType(TrafficType trafficType) {
|
||||
this.queryParameters.replaceValues("traffictype", ImmutableSet.of(trafficType.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
/**
|
||||
* @see ListNetworkOfferingsOptions#specifyVLAN
|
||||
*/
|
||||
public static ListNetworkOfferingsOptions specifyVLAN(boolean specifyVLAN) {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions();
|
||||
return options.specifyVLAN(specifyVLAN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworkOfferingsOptions#isDefault
|
||||
*/
|
||||
public static ListNetworkOfferingsOptions isDefault(boolean isDefault) {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions();
|
||||
return options.isDefault(isDefault);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworkOfferingsOptions#isShared
|
||||
*/
|
||||
public static ListNetworkOfferingsOptions isShared(boolean isShared) {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions();
|
||||
return options.isShared(isShared);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworkOfferingsOptions#displayText
|
||||
*/
|
||||
public static ListNetworkOfferingsOptions displayText(String displayText) {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions();
|
||||
return options.displayText(displayText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworkOfferingsOptions#name
|
||||
*/
|
||||
public static ListNetworkOfferingsOptions name(String name) {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions();
|
||||
return options.name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworkOfferingsOptions#availability
|
||||
*/
|
||||
public static ListNetworkOfferingsOptions availability(String availability) {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions();
|
||||
return options.availability(availability);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworkOfferingsOptions#id
|
||||
*/
|
||||
public static ListNetworkOfferingsOptions id(String id) {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworkOfferingsOptions#trafficType
|
||||
*/
|
||||
public static ListNetworkOfferingsOptions trafficType(TrafficType trafficType) {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions();
|
||||
return options.trafficType(trafficType);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,197 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import org.jclouds.cloudstack.domain.NetworkType;
|
||||
import org.jclouds.cloudstack.domain.TrafficType;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options used to control what networks information is returned
|
||||
*
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/user/listNetworks.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ListNetworksOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListNetworksOptions NONE = new ListNetworksOptions();
|
||||
|
||||
/**
|
||||
* @param isDefault
|
||||
* true if network is default, false otherwise
|
||||
*/
|
||||
public ListNetworksOptions isDefault(boolean isDefault) {
|
||||
this.queryParameters.replaceValues("isdefault", ImmutableSet.of(isDefault + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isShared
|
||||
* true if network is shared, false otherwise
|
||||
*/
|
||||
public ListNetworksOptions isShared(boolean isShared) {
|
||||
this.queryParameters.replaceValues("isshared", ImmutableSet.of(isShared + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isSystem
|
||||
* true if network is system, false otherwise
|
||||
*/
|
||||
public ListNetworksOptions isSystem(boolean isSystem) {
|
||||
this.queryParameters.replaceValues("issystem", ImmutableSet.of(isSystem + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* the type of the network
|
||||
*/
|
||||
public ListNetworksOptions type(NetworkType type) {
|
||||
this.queryParameters.replaceValues("type", ImmutableSet.of(type.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* list networks by id
|
||||
*/
|
||||
public ListNetworksOptions id(String id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param account
|
||||
* account who will own the VLAN. If VLAN is Zone wide, this parameter should be
|
||||
* ommited
|
||||
*/
|
||||
public ListNetworksOptions account(String account) {
|
||||
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domainId
|
||||
* domain ID of the account owning a VLAN
|
||||
*/
|
||||
public ListNetworksOptions domainId(String domainId) {
|
||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param zoneId
|
||||
* the Zone ID of the network
|
||||
*/
|
||||
public ListNetworksOptions zoneId(String zoneId) {
|
||||
this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param trafficType
|
||||
* type of the traffic
|
||||
*/
|
||||
public ListNetworksOptions trafficType(TrafficType trafficType) {
|
||||
this.queryParameters.replaceValues("traffictype", ImmutableSet.of(trafficType.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
/**
|
||||
* @see ListNetworksOptions#isDefault
|
||||
*/
|
||||
public static ListNetworksOptions isDefault(boolean isDefault) {
|
||||
ListNetworksOptions options = new ListNetworksOptions();
|
||||
return options.isDefault(isDefault);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworksOptions#isShared
|
||||
*/
|
||||
public static ListNetworksOptions isShared(boolean isShared) {
|
||||
ListNetworksOptions options = new ListNetworksOptions();
|
||||
return options.isShared(isShared);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworksOptions#isSystem
|
||||
*/
|
||||
public static ListNetworksOptions isSystem(boolean isSystem) {
|
||||
ListNetworksOptions options = new ListNetworksOptions();
|
||||
return options.isSystem(isSystem);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworksOptions#type
|
||||
*/
|
||||
public static ListNetworksOptions type(NetworkType type) {
|
||||
ListNetworksOptions options = new ListNetworksOptions();
|
||||
return options.type(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworksOptions#domainId
|
||||
*/
|
||||
public static ListNetworksOptions domainId(String id) {
|
||||
ListNetworksOptions options = new ListNetworksOptions();
|
||||
return options.domainId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworksOptions#account
|
||||
*/
|
||||
public static ListNetworksOptions account(String account) {
|
||||
ListNetworksOptions options = new ListNetworksOptions();
|
||||
return options.account(account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworksOptions#id
|
||||
*/
|
||||
public static ListNetworksOptions id(String id) {
|
||||
ListNetworksOptions options = new ListNetworksOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworksOptions#zoneId
|
||||
*/
|
||||
public static ListNetworksOptions zoneId(String id) {
|
||||
ListNetworksOptions options = new ListNetworksOptions();
|
||||
return options.zoneId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListNetworksOptions#trafficType
|
||||
*/
|
||||
public static ListNetworksOptions trafficType(TrafficType trafficType) {
|
||||
ListNetworksOptions options = new ListNetworksOptions();
|
||||
return options.trafficType(trafficType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options used to control what service offerings are returned
|
||||
*
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/user/listServiceOfferings.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ListServiceOfferingsOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListServiceOfferingsOptions NONE = new ListServiceOfferingsOptions();
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the ID of the service offering
|
||||
*/
|
||||
public ListServiceOfferingsOptions id(String id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domainId
|
||||
* the ID of the domain associated with the service offering
|
||||
*/
|
||||
public ListServiceOfferingsOptions domainId(String domainId) {
|
||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the service offering name
|
||||
*/
|
||||
public ListServiceOfferingsOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param virtualMachineId
|
||||
* the ID of the virtual machine. Pass this in if you want to see the available service
|
||||
* offering that a virtual machine can be changed to.
|
||||
*/
|
||||
public ListServiceOfferingsOptions virtualMachineId(String virtualMachineId) {
|
||||
this.queryParameters.replaceValues("virtualmachineid", ImmutableSet.of(virtualMachineId));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListServiceOfferingsOptions#name
|
||||
*/
|
||||
public static ListServiceOfferingsOptions name(String name) {
|
||||
ListServiceOfferingsOptions options = new ListServiceOfferingsOptions();
|
||||
return options.name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListServiceOfferingsOptions#domainId
|
||||
*/
|
||||
public static ListServiceOfferingsOptions domainId(String id) {
|
||||
ListServiceOfferingsOptions options = new ListServiceOfferingsOptions();
|
||||
return options.domainId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListServiceOfferingsOptions#id
|
||||
*/
|
||||
public static ListServiceOfferingsOptions id(String id) {
|
||||
ListServiceOfferingsOptions options = new ListServiceOfferingsOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListServiceOfferingsOptions#virtualMachineId
|
||||
*/
|
||||
public static ListServiceOfferingsOptions virtualMachineId(String virtualMachineId) {
|
||||
ListServiceOfferingsOptions options = new ListServiceOfferingsOptions();
|
||||
return options.virtualMachineId(virtualMachineId);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import org.jclouds.cloudstack.domain.TemplateFilter;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options used to control what templates information is returned
|
||||
*
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/user/listTemplates.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ListTemplatesOptions extends BaseHttpRequestOptions {
|
||||
public ListTemplatesOptions() {
|
||||
filter(TemplateFilter.EXECUTABLE);
|
||||
}
|
||||
|
||||
public static final ListTemplatesOptions NONE = new ListTemplatesOptions();
|
||||
|
||||
/**
|
||||
* @param filter
|
||||
* how to constrain the list
|
||||
*/
|
||||
public ListTemplatesOptions filter(TemplateFilter filter) {
|
||||
this.queryParameters.replaceValues("templatefilter", ImmutableSet.of(filter.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the template ID
|
||||
*/
|
||||
public ListTemplatesOptions id(String id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param account
|
||||
* account id
|
||||
* @param domain
|
||||
* domain id
|
||||
*/
|
||||
public ListTemplatesOptions accountInDomain(String account, String domain) {
|
||||
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
||||
return domainId(domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the template name
|
||||
*/
|
||||
public ListTemplatesOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domainId
|
||||
* list all templates in specified domain. If used with the account parameter, lists
|
||||
* all templates for an account in the specified domain.
|
||||
*/
|
||||
public ListTemplatesOptions domainId(String domainId) {
|
||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param zoneId
|
||||
* list templates by zoneId.
|
||||
*/
|
||||
public ListTemplatesOptions zoneId(String zoneId) {
|
||||
this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hypervisor
|
||||
* the hypervisor for which to restrict the search
|
||||
*/
|
||||
public ListTemplatesOptions hypervisor(String hypervisor) {
|
||||
this.queryParameters.replaceValues("hypervisor", ImmutableSet.of(hypervisor));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListTemplatesOptions#filter
|
||||
*/
|
||||
public static ListTemplatesOptions filter(TemplateFilter filter) {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions();
|
||||
return options.filter(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListTemplatesOptions#domainId
|
||||
*/
|
||||
public static ListTemplatesOptions domainId(String id) {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions();
|
||||
return options.domainId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListTemplatesOptions#accountInDomain
|
||||
*/
|
||||
public static ListTemplatesOptions accountInDomain(String account, String domain) {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions();
|
||||
return options.accountInDomain(account, domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListTemplatesOptions#id
|
||||
*/
|
||||
public static ListTemplatesOptions id(String id) {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListTemplatesOptions#name
|
||||
*/
|
||||
public static ListTemplatesOptions name(String name) {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions();
|
||||
return options.name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListTemplatesOptions#zoneId
|
||||
*/
|
||||
public static ListTemplatesOptions zoneId(String id) {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions();
|
||||
return options.zoneId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListTemplatesOptions#hypervisor
|
||||
*/
|
||||
public static ListTemplatesOptions hypervisor(String hypervisor) {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions();
|
||||
return options.hypervisor(hypervisor);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options used to control what zones information is returned
|
||||
*
|
||||
* @see <a href="http://download.cloud.com/releases/2.2/api/user/listZones.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ListZonesOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final ListZonesOptions NONE = new ListZonesOptions();
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the ID of the zone
|
||||
*/
|
||||
public ListZonesOptions id(String id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domainId
|
||||
* the ID of the domain associated with the zone
|
||||
*/
|
||||
public ListZonesOptions domainId(String domainId) {
|
||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param available
|
||||
* true if you want to retrieve all available Zones. False if you only want to return
|
||||
* the Zones from which you have at least one VM. Default is false.
|
||||
*/
|
||||
public ListZonesOptions available(boolean available) {
|
||||
this.queryParameters.replaceValues("available", ImmutableSet.of(available + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListZonesOptions#available
|
||||
*/
|
||||
public static ListZonesOptions available(boolean available) {
|
||||
ListZonesOptions options = new ListZonesOptions();
|
||||
return options.available(available);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListZonesOptions#domainId
|
||||
*/
|
||||
public static ListZonesOptions domainId(String id) {
|
||||
ListZonesOptions options = new ListZonesOptions();
|
||||
return options.domainId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListZonesOptions#id
|
||||
*/
|
||||
public static ListZonesOptions id(String id) {
|
||||
ListZonesOptions options = new ListZonesOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.jclouds.cloudstack.features.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CloudStackAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "CloudStackAsyncClientTest")
|
||||
public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<CloudStackAsyncClient> {
|
||||
|
||||
private CloudStackAsyncClient asyncClient;
|
||||
private CloudStackClient syncClient;
|
||||
|
||||
public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
assert syncClient.getZoneClient() != null;
|
||||
assert syncClient.getTemplateClient() != null;
|
||||
assert syncClient.getOfferingClient() != null;
|
||||
assert syncClient.getNetworkClient() != null;
|
||||
}
|
||||
|
||||
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
assert asyncClient.getZoneClient() != null;
|
||||
assert asyncClient.getTemplateClient() != null;
|
||||
assert asyncClient.getOfferingClient() != null;
|
||||
assert asyncClient.getNetworkClient() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<CloudStackAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<CloudStackAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
protected void setupFactory() throws IOException {
|
||||
super.setupFactory();
|
||||
asyncClient = injector.getInstance(CloudStackAsyncClient.class);
|
||||
syncClient = injector.getInstance(CloudStackClient.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
///**
|
||||
// *
|
||||
// * Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
// *
|
||||
// * ====================================================================
|
||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// * you may not use this file except in compliance with the License.
|
||||
// * You may obtain a copy of the License at
|
||||
// *
|
||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||
// *
|
||||
// * Unless required by applicable law or agreed to in writing, software
|
||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// * See the License for the specific language governing permissions and
|
||||
// * limitations under the License.
|
||||
// * ====================================================================
|
||||
// */
|
||||
//
|
||||
//package org.jclouds.cloudstack;
|
||||
//
|
||||
//import static org.testng.Assert.assertEquals;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.logging.Logger;
|
||||
//
|
||||
//import org.jclouds.compute.domain.ExecResponse;
|
||||
//import org.jclouds.cloudstack.domain.Instance;
|
||||
//import org.jclouds.cloudstack.domain.InstanceAction;
|
||||
//import org.jclouds.cloudstack.domain.InstanceState;
|
||||
//import org.jclouds.cloudstack.features.ReadOnlyCloudStackClientLiveTest;
|
||||
//import org.jclouds.cloudstack.options.CreateInstanceOptions;
|
||||
//import org.jclouds.domain.Credentials;
|
||||
//import org.jclouds.http.HttpRequest;
|
||||
//import org.jclouds.net.IPSocket;
|
||||
//import org.jclouds.ssh.SshClient;
|
||||
//import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
//import org.testng.annotations.AfterGroups;
|
||||
//import org.testng.annotations.Test;
|
||||
//
|
||||
//import com.google.common.collect.Iterables;
|
||||
//import com.google.gson.Gson;
|
||||
//import com.google.inject.Guice;
|
||||
//
|
||||
///**
|
||||
// * Tests behavior of {@code CloudStackClient}
|
||||
// *
|
||||
// * @author Adrian Cole
|
||||
// */
|
||||
//@Test(groups = "live", sequential = true, testName = "CloudStackClientLiveTest")
|
||||
//public class CloudStackClientLiveTest extends ReadOnlyCloudStackClientLiveTest {
|
||||
//
|
||||
// protected String prefix = System.getProperty("user.name") + ".test";
|
||||
// protected Instance instance;
|
||||
//
|
||||
// public void testCreateInstance() throws Exception {
|
||||
// Logger.getAnonymousLogger().info("starting instance");
|
||||
// instance = client.createInstance(Iterables.get(client.listImages(), 0).getId(),
|
||||
// CreateInstanceOptions.Builder.named(prefix));
|
||||
// instance = client.getInstance(instance.getHref());
|
||||
// checkStartedInstance();
|
||||
//
|
||||
// Instance newInfo = client.getInstance(instance.getHref());
|
||||
// checkInstanceMatchesGet(newInfo);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// protected void checkInstanceMatchesGet(Instance newInfo) {
|
||||
// assertEquals(newInfo.getHref(), instance.getHref());
|
||||
// }
|
||||
//
|
||||
// protected void checkStartedInstance() {
|
||||
// System.out.println(new Gson().toJson(instance));
|
||||
// assertEquals(instance.getName(), prefix);
|
||||
// assertEquals(instance.getState(), InstanceState.RUNNING);
|
||||
// }
|
||||
//
|
||||
// @Test(dependsOnMethods = "testCreateInstance")
|
||||
// public void testConnectivity() throws Exception {
|
||||
// Logger.getAnonymousLogger().info("awaiting ssh");
|
||||
// // TODO
|
||||
// // assert socketTester.apply(new IPSocket(Iterables.get(instance.getPublicAddresses(), 0),
|
||||
// // 22)) : instance;
|
||||
// // doConnectViaSsh(instance, getSshCredentials(instance));
|
||||
// }
|
||||
//
|
||||
// private Credentials getSshCredentials(Instance instance2) {
|
||||
// // TODO
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public HttpRequest refreshInstanceAndGetAction(InstanceAction action) {
|
||||
// return client.getInstance(instance.getHref()).getActions().get(action);
|
||||
// }
|
||||
//
|
||||
// @Test(dependsOnMethods = "testConnectivity")
|
||||
// public void testLifeCycle() throws Exception {
|
||||
// client.performAction(refreshInstanceAndGetAction(InstanceAction.STOP));
|
||||
// assertEquals(client.getInstance(instance.getHref()).getState(), InstanceState.STOPPED);
|
||||
//
|
||||
// client.performAction(refreshInstanceAndGetAction(InstanceAction.START));
|
||||
// assertEquals(client.getInstance(instance.getHref()).getState(), InstanceState.RUNNING);
|
||||
//
|
||||
// client.performAction(refreshInstanceAndGetAction(InstanceAction.REBOOT));
|
||||
// assertEquals(client.getInstance(instance.getHref()).getState(), InstanceState.RUNNING);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test(dependsOnMethods = "testLifeCycle")
|
||||
// public void testDestroyInstance() throws Exception {
|
||||
// try {
|
||||
// client.performAction(refreshInstanceAndGetAction(InstanceAction.STOP));
|
||||
// assertEquals(client.getInstance(instance.getHref()).getState(), InstanceState.STOPPED);
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// }
|
||||
// client.performAction(refreshInstanceAndGetAction(InstanceAction.DESTROY));
|
||||
// assertEquals(client.getInstance(instance.getHref()), null);
|
||||
// }
|
||||
//
|
||||
// protected void doConnectViaSsh(Instance instance, Credentials creds) throws IOException {
|
||||
// SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class)
|
||||
// .create(new IPSocket(Iterables.get(instance.getPublicAddresses(), 0), 22), creds);
|
||||
// try {
|
||||
// ssh.connect();
|
||||
// ExecResponse hello = ssh.exec("echo hello");
|
||||
// assertEquals(hello.getOutput().trim(), "hello");
|
||||
// System.err.println(ssh.exec("df -k").getOutput());
|
||||
// System.err.println(ssh.exec("mount").getOutput());
|
||||
// System.err.println(ssh.exec("uname -a").getOutput());
|
||||
// } finally {
|
||||
// if (ssh != null)
|
||||
// ssh.disconnect();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @AfterGroups(groups = "live")
|
||||
// @Override
|
||||
// protected void tearDown() {
|
||||
// try {
|
||||
// testDestroyInstance();
|
||||
// } catch (Exception e) {
|
||||
// // no need to check null or anything as we swallow all
|
||||
// }
|
||||
// super.tearDown();
|
||||
// }
|
||||
//
|
||||
//}
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.cloudstack.CloudStackAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.config.CloudStackRestClientModule;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public abstract class BaseCloudStackAsyncClientTest<T> extends RestClientTest<T> {
|
||||
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public static class CloudStackRestClientModuleExtension extends CloudStackRestClientModule {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
assertEquals(request.getFilters().size(), 1);
|
||||
assertEquals(request.getFilters().get(0).getClass(), QuerySigner.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new CloudStackRestClientModuleExtension();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestContextSpec<CloudStackClient, CloudStackAsyncClient> createContextSpec() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("cloudstack.endpoint", "http://localhost:8080/client/api");
|
||||
return new RestContextFactory().createContextSpec("cloudstack", "apiKey", "secretKey", props);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.cloudstack.CloudStackAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BaseCloudStackClientLiveTest {
|
||||
|
||||
protected CloudStackClient client;
|
||||
protected RestContext<CloudStackClient, CloudStackAsyncClient> context;
|
||||
protected String provider = "cloudstack";
|
||||
protected String identity;
|
||||
protected String credential;
|
||||
protected String endpoint;
|
||||
protected String apiversion;
|
||||
protected Predicate<IPSocket> socketTester;
|
||||
|
||||
protected void setupCredentials() {
|
||||
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider
|
||||
+ ".identity must be set. ex. apiKey");
|
||||
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
|
||||
+ ".credential must be set. ex. secretKey");
|
||||
endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider
|
||||
+ ".endpoint must be set. ex. http://localhost:8080/client/api");
|
||||
apiversion = System.getProperty("test." + provider + ".apiversion");
|
||||
}
|
||||
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
|
||||
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
|
||||
overrides.setProperty(provider + ".identity", identity);
|
||||
overrides.setProperty(provider + ".credential", credential);
|
||||
overrides.setProperty(provider + ".endpoint", endpoint);
|
||||
if (apiversion != null)
|
||||
overrides.setProperty(provider + ".apiversion", apiversion);
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@BeforeGroups(groups = "live")
|
||||
public void setupClient() {
|
||||
setupCredentials();
|
||||
Properties overrides = setupProperties();
|
||||
context = new RestContextFactory().createContext(provider, ImmutableSet.<Module> of(new Log4JLoggingModule()),
|
||||
overrides);
|
||||
|
||||
client = context.getApi();
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
if (context != null)
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jclouds.cloudstack.domain.NetworkType;
|
||||
import org.jclouds.cloudstack.options.ListNetworksOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code NetworkAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "NetworkAsyncClientTest")
|
||||
public class NetworkAsyncClientTest extends BaseCloudStackAsyncClientTest<NetworkAsyncClient> {
|
||||
public void testListNetworks() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = NetworkAsyncClient.class.getMethod("listNetworks", ListNetworksOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listNetworks HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testListNetworksOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = NetworkAsyncClient.class.getMethod("listNetworks", ListNetworksOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListNetworksOptions.Builder.type(NetworkType.ADVANCED).domainId(
|
||||
"domainId").id("id"));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listNetworks&type=Advanced&domainid=domainId&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetNetwork() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = NetworkAsyncClient.class.getMethod("getNetwork", String.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, "id");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listNetworks&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<NetworkAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<NetworkAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cloudstack.domain.GuestIPType;
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
import org.jclouds.cloudstack.options.ListNetworksOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code NetworkClientLiveTest}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "NetworkClientLiveTest")
|
||||
public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListNetworks() throws Exception {
|
||||
Set<Network> response = client.getNetworkClient().listNetworks();
|
||||
assert null != response;
|
||||
long networkCount = response.size();
|
||||
assertTrue(networkCount >= 0);
|
||||
for (Network network : response) {
|
||||
Network newDetails = Iterables.getOnlyElement(client.getNetworkClient().listNetworks(
|
||||
ListNetworksOptions.Builder.id(network.getId())));
|
||||
assertEquals(network, newDetails);
|
||||
assertEquals(network, client.getNetworkClient().getNetwork(network.getId()));
|
||||
assert network.getId() != null : network;
|
||||
assert network.getName() != null : network;
|
||||
assert network.getDNS().size() != 0 : network;
|
||||
assert network.getGuestIPType() != null && network.getGuestIPType() != GuestIPType.UNRECOGNIZED : network;
|
||||
assert network.getAccount() != null : network;
|
||||
assert network.getBroadcastDomainType() != null : network;
|
||||
// TODO understand when this is null and for what reason
|
||||
// assert network.getBroadcastURI() != null : network;
|
||||
assert network.getDisplayText() != null : network;
|
||||
assert network.getNetworkDomain() != null : network;
|
||||
assert network.getNetworkOfferingAvailability() != null : network;
|
||||
assert network.getNetworkOfferingDisplayText() != null : network;
|
||||
assert network.getNetworkOfferingId() != null : network;
|
||||
assert network.getNetworkOfferingName() != null : network;
|
||||
assert network.getRelated() != null : network;
|
||||
assert network.getServices().size() != 0 : network;
|
||||
assert network.getState() != null : network;
|
||||
assert network.getTrafficType() != null : network;
|
||||
assert network.getZoneId() != null : network;
|
||||
assert network.getDomain() != null : network;
|
||||
assert network.getDomainId() != null : network;
|
||||
switch (network.getGuestIPType()) {
|
||||
case VIRTUAL:
|
||||
assert network.getNetmask() == null : network;
|
||||
assert network.getGateway() == null : network;
|
||||
assert network.getVLAN() == null : network;
|
||||
assert network.getStartIP() == null : network;
|
||||
assert network.getEndIP() == null : network;
|
||||
break;
|
||||
case DIRECT:
|
||||
assert network.getNetmask() != null : network;
|
||||
assert network.getGateway() != null : network;
|
||||
assert network.getVLAN() != null : network;
|
||||
assert network.getStartIP() != null : network;
|
||||
assert network.getEndIP() != null : network;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code OfferingAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "ServiceOfferingAsyncClientTest")
|
||||
public class OfferingAsyncClientTest extends BaseCloudStackAsyncClientTest<OfferingAsyncClient> {
|
||||
public void testListDiskOfferings() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = OfferingAsyncClient.class.getMethod("listDiskOfferings", ListDiskOfferingsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listDiskOfferings HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testListDiskOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = OfferingAsyncClient.class.getMethod("listDiskOfferings", ListDiskOfferingsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListDiskOfferingsOptions.Builder.domainId("domainId")
|
||||
.id("id"));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listDiskOfferings&domainid=domainId&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetDiskOffering() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = OfferingAsyncClient.class.getMethod("getDiskOffering", String.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, "id");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listDiskOfferings&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testListNetworkOfferings() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = OfferingAsyncClient.class.getMethod("listNetworkOfferings", ListNetworkOfferingsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listNetworkOfferings HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testListNetworkOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = OfferingAsyncClient.class.getMethod("listNetworkOfferings", ListNetworkOfferingsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListNetworkOfferingsOptions.Builder.availability(
|
||||
"Default").isShared(true).id("id"));
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listNetworkOfferings&availability=Default&isshared=true&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetNetworkOffering() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = OfferingAsyncClient.class.getMethod("getNetworkOffering", String.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, "id");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listNetworkOfferings&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testListServiceOfferings() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = OfferingAsyncClient.class.getMethod("listServiceOfferings", ListServiceOfferingsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listServiceOfferings HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testListServiceOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = OfferingAsyncClient.class.getMethod("listServiceOfferings", ListServiceOfferingsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListServiceOfferingsOptions.Builder.virtualMachineId(
|
||||
"vmId").domainId("domainId").id("id"));
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listServiceOfferings&virtualmachineid=vmId&domainid=domainId&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetServiceOffering() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = OfferingAsyncClient.class.getMethod("getServiceOffering", String.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, "id");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listServiceOfferings&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<OfferingAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<OfferingAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cloudstack.domain.DiskOffering;
|
||||
import org.jclouds.cloudstack.domain.NetworkOffering;
|
||||
import org.jclouds.cloudstack.domain.ServiceOffering;
|
||||
import org.jclouds.cloudstack.domain.StorageType;
|
||||
import org.jclouds.cloudstack.domain.TrafficType;
|
||||
import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code OfferingClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "OfferingClientLiveTest")
|
||||
public class OfferingClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListDiskOfferings() throws Exception {
|
||||
Set<DiskOffering> response = client.getOfferingClient().listDiskOfferings();
|
||||
assert null != response;
|
||||
long offeringCount = response.size();
|
||||
assertTrue(offeringCount >= 0);
|
||||
for (DiskOffering offering : response) {
|
||||
DiskOffering newDetails = Iterables.getOnlyElement(client.getOfferingClient().listDiskOfferings(
|
||||
ListDiskOfferingsOptions.Builder.id(offering.getId())));
|
||||
assertEquals(offering, newDetails);
|
||||
assertEquals(offering, client.getOfferingClient().getDiskOffering(offering.getId()));
|
||||
assert offering.getId() != null : offering;
|
||||
assert offering.getName() != null : offering;
|
||||
assert offering.getCreated() != null : offering;
|
||||
assert offering.getDisplayText() != null : offering;
|
||||
assert offering.getDiskSize() > 0 || (offering.getDiskSize() == 0 && offering.isCustomized()) : offering;
|
||||
assert offering.getTags() != null : offering;
|
||||
}
|
||||
}
|
||||
|
||||
public void testListServiceOfferings() throws Exception {
|
||||
Set<ServiceOffering> response = client.getOfferingClient().listServiceOfferings();
|
||||
assert null != response;
|
||||
long offeringCount = response.size();
|
||||
assertTrue(offeringCount >= 0);
|
||||
for (ServiceOffering offering : response) {
|
||||
ServiceOffering newDetails = Iterables.getOnlyElement(client.getOfferingClient().listServiceOfferings(
|
||||
ListServiceOfferingsOptions.Builder.id(offering.getId())));
|
||||
assertEquals(offering, newDetails);
|
||||
assertEquals(offering, client.getOfferingClient().getServiceOffering(offering.getId()));
|
||||
assert offering.getId() != null : offering;
|
||||
assert offering.getName() != null : offering;
|
||||
assert offering.getCreated() != null : offering;
|
||||
assert offering.getDisplayText() != null : offering;
|
||||
assert offering.getCpuNumber() > 0 : offering;
|
||||
assert offering.getCpuSpeed() > 0 : offering;
|
||||
assert offering.getMemory() > 0 : offering;
|
||||
assert offering.getStorageType() != null && StorageType.UNRECOGNIZED != offering.getStorageType() : offering;
|
||||
assert offering.getTags() != null : offering;
|
||||
}
|
||||
}
|
||||
|
||||
public void testListNetworkOfferings() throws Exception {
|
||||
Set<NetworkOffering> response = client.getOfferingClient().listNetworkOfferings();
|
||||
assert null != response;
|
||||
long offeringCount = response.size();
|
||||
assertTrue(offeringCount >= 0);
|
||||
for (NetworkOffering offering : response) {
|
||||
NetworkOffering newDetails = Iterables.getOnlyElement(client.getOfferingClient().listNetworkOfferings(
|
||||
ListNetworkOfferingsOptions.Builder.id(offering.getId())));
|
||||
assertEquals(offering, newDetails);
|
||||
assertEquals(offering, client.getOfferingClient().getNetworkOffering(offering.getId()));
|
||||
assert offering.getId() != null : offering;
|
||||
assert offering.getName() != null : offering;
|
||||
assert offering.getDisplayText() != null : offering;
|
||||
assert offering.getMaxConnections() == null || offering.getMaxConnections() > 0 : offering;
|
||||
assert offering.getTrafficType() != null && TrafficType.UNRECOGNIZED != offering.getTrafficType() : offering;
|
||||
assert offering.getTags() != null : offering;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jclouds.cloudstack.domain.TemplateFilter;
|
||||
import org.jclouds.cloudstack.options.ListTemplatesOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TemplateAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "TemplateAsyncClientTest")
|
||||
public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest<TemplateAsyncClient> {
|
||||
public void testListTemplates() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TemplateAsyncClient.class.getMethod("listTemplates");
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listTemplates&templatefilter=executable HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testListTemplatesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TemplateAsyncClient.class.getMethod("listTemplates", ListTemplatesOptions.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListTemplatesOptions.Builder.accountInDomain(
|
||||
"accountId", "domainId").hypervisor("xen").filter(TemplateFilter.FEATURED));
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listTemplates&account=accountId&domainid=domainId&hypervisor=xen&templatefilter=featured HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetTemplate() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TemplateAsyncClient.class.getMethod("getTemplate", String.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, "id");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listTemplates&templatefilter=executable&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<TemplateAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<TemplateAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Template;
|
||||
import org.jclouds.cloudstack.options.ListTemplatesOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TemplateClientLiveTest}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "TemplateClientLiveTest")
|
||||
public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListTemplates() throws Exception {
|
||||
Set<Template> response = client.getTemplateClient().listTemplates();
|
||||
assert null != response;
|
||||
long zoneCount = response.size();
|
||||
assertTrue(zoneCount >= 0);
|
||||
for (Template template : response) {
|
||||
Template newDetails = Iterables.getOnlyElement(client.getTemplateClient().listTemplates(
|
||||
ListTemplatesOptions.Builder.id(template.getId())));
|
||||
assertEquals(template, newDetails);
|
||||
assertEquals(template, client.getTemplateClient().getTemplate(template.getId()));
|
||||
assert template.getId() != null : template;
|
||||
assert template.getName() != null : template;
|
||||
assert template.getDisplayText() != null : template;
|
||||
assert template.getCreated() != null : template;
|
||||
assert template.getFormat() != null && template.getFormat() != Template.Format.UNRECOGNIZED : template;
|
||||
assert template.getOSType() != null : template;
|
||||
assert template.getOSTypeId() != null : template;
|
||||
assert template.getAccount() != null : template;
|
||||
assert template.getZone() != null : template;
|
||||
assert template.getZoneId() != null : template;
|
||||
assert template.getStatus() != null : template;
|
||||
assert template.getType() != null && template.getType() != Template.Type.UNRECOGNIZED : template;
|
||||
assert template.getHypervisor() != null : template;
|
||||
assert template.getDomain() != null : template;
|
||||
assert template.getDomainId() != null : template;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jclouds.cloudstack.options.ListZonesOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ZoneAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "ZoneAsyncClientTest")
|
||||
public class ZoneAsyncClientTest extends BaseCloudStackAsyncClientTest<ZoneAsyncClient> {
|
||||
public void testListZones() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ZoneAsyncClient.class.getMethod("listZones", ListZonesOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listZones HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// now make sure request filters apply by replaying
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listZones&apiKey=apiKey&signature=hNz838u4Z1ofz9vRaqYo9GDv1Io%3D HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testListZonesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ZoneAsyncClient.class.getMethod("listZones", ListZonesOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListZonesOptions.Builder.available(true).domainId(
|
||||
"domainId").id("id"));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listZones&available=true&domainid=domainId&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetZone() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ZoneAsyncClient.class.getMethod("getZone", String.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, "id");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listZones&id=id HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<ZoneAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<ZoneAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cloudstack.domain.NetworkType;
|
||||
import org.jclouds.cloudstack.domain.Zone;
|
||||
import org.jclouds.cloudstack.options.ListZonesOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ZoneClientLiveTest}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "ZoneClientLiveTest")
|
||||
public class ZoneClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListZones() throws Exception {
|
||||
Set<Zone> response = client.getZoneClient().listZones();
|
||||
assert null != response;
|
||||
long zoneCount = response.size();
|
||||
assertTrue(zoneCount >= 0);
|
||||
for (Zone zone : response) {
|
||||
Zone newDetails = Iterables.getOnlyElement(client.getZoneClient().listZones(
|
||||
ListZonesOptions.Builder.id(zone.getId())));
|
||||
assertEquals(zone, newDetails);
|
||||
assertEquals(zone, client.getZoneClient().getZone(zone.getId()));
|
||||
assert zone.getId() != null : zone;
|
||||
assert zone.getName() != null : zone;
|
||||
assert zone.getDNS().size() != 0 : zone;
|
||||
assert zone.getInternalDNS().size() != 0 : zone;
|
||||
assert zone.getNetworkType() != null && zone.getNetworkType() != NetworkType.UNRECOGNIZED : zone;
|
||||
switch (zone.getNetworkType()) {
|
||||
case ADVANCED:
|
||||
assert zone.getVLAN() != null : zone;
|
||||
assert zone.getDomain() == null : zone;
|
||||
assert zone.getDomainId() == null : zone;
|
||||
assert zone.getGuestCIDRAddress() != null : zone;
|
||||
break;
|
||||
case BASIC:
|
||||
assert zone.getVLAN() == null : zone;
|
||||
assert zone.getDomain() != null : zone;
|
||||
assert zone.getDomainId() != null : zone;
|
||||
assert zone.getGuestCIDRAddress() == null : zone;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.filters;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.PropertiesBuilder;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RequestSigner;
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code QuerySigner}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "QuerySignerTest")
|
||||
public class QuerySignerTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final RestContextSpec<Map, List> DUMMY_SPEC = new RestContextSpec<Map, List>("cloudstack",
|
||||
"http://localhost:8080/client/api", "2.2", "", "apiKey", "secretKey", Map.class, List.class,
|
||||
PropertiesBuilder.class, (Class) RestContextBuilder.class, ImmutableList.<Module> of(new MockModule(),
|
||||
new NullLoggingModule(), new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(RequestSigner.class).to(QuerySigner.class);
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
@Test
|
||||
void testCreateStringToSign() {
|
||||
QuerySigner filter = RestContextFactory.createContextBuilder(DUMMY_SPEC).buildInjector().getInstance(
|
||||
QuerySigner.class);
|
||||
|
||||
assertEquals(filter.createStringToSign(HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("http://localhost:8080/client/api?command=listZones")).build()),
|
||||
"apikey=apikey&command=listzones");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFilter() {
|
||||
QuerySigner filter = RestContextFactory.createContextBuilder(DUMMY_SPEC).buildInjector().getInstance(
|
||||
QuerySigner.class);
|
||||
|
||||
assertEquals(
|
||||
filter.filter(
|
||||
HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("http://localhost:8080/client/api?command=listZones")).build())
|
||||
.getRequestLine(),
|
||||
"GET http://localhost:8080/client/api?command=listZones&apiKey=apiKey&signature=2UG8AcnMaozL3BINdjgkJ%2BRzjEY%3D HTTP/1.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFilterTwice() {
|
||||
QuerySigner filter = RestContextFactory.createContextBuilder(DUMMY_SPEC).buildInjector().getInstance(
|
||||
QuerySigner.class);
|
||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("http://localhost:8080/client/api?command=listZones")).build();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
request = filter.filter(request);
|
||||
assertEquals(
|
||||
request.getRequestLine(),
|
||||
"GET http://localhost:8080/client/api?command=listZones&apiKey=apiKey&signature=2UG8AcnMaozL3BINdjgkJ%2BRzjEY%3D HTTP/1.1");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.handlers;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.reportMatcher;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.easymock.IArgumentMatcher;
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class CloudStackErrorHandlerTest {
|
||||
|
||||
@Test
|
||||
public void test400MakesIllegalArgumentException() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 400, "", "Bad Request",
|
||||
IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test401MakesAuthorizationException() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 401, "", "Unauthorized",
|
||||
AuthorizationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test404MakesResourceNotFoundException() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 404, "", "Not Found",
|
||||
ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test405MakesIllegalArgumentException() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 405, "", "Method Not Allowed",
|
||||
IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test409MakesIllegalStateException() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 409, "", "Conflict", IllegalStateException.class);
|
||||
}
|
||||
|
||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
|
||||
Class<? extends Exception> expected) {
|
||||
assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected);
|
||||
}
|
||||
|
||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
|
||||
String content, Class<? extends Exception> expected) {
|
||||
|
||||
CloudStackErrorHandler function = Guice.createInjector().getInstance(CloudStackErrorHandler.class);
|
||||
|
||||
HttpCommand command = createMock(HttpCommand.class);
|
||||
HttpRequest request = new HttpRequest(method, uri);
|
||||
HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Strings2
|
||||
.toInputStream(content)));
|
||||
response.getPayload().getContentMetadata().setContentType(contentType);
|
||||
|
||||
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
|
||||
command.setException(classEq(expected));
|
||||
|
||||
replay(command);
|
||||
|
||||
function.handleError(command, response);
|
||||
|
||||
verify(command);
|
||||
}
|
||||
|
||||
public static Exception classEq(final Class<? extends Exception> in) {
|
||||
reportMatcher(new IArgumentMatcher() {
|
||||
|
||||
@Override
|
||||
public void appendTo(StringBuffer buffer) {
|
||||
buffer.append("classEq(");
|
||||
buffer.append(in);
|
||||
buffer.append(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object arg) {
|
||||
return arg.getClass() == in;
|
||||
}
|
||||
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import static org.jclouds.cloudstack.options.ListDiskOfferingsOptions.Builder.domainId;
|
||||
import static org.jclouds.cloudstack.options.ListDiskOfferingsOptions.Builder.id;
|
||||
import static org.jclouds.cloudstack.options.ListDiskOfferingsOptions.Builder.name;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListDiskOfferingsOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListDiskOfferingsOptionsTest {
|
||||
|
||||
public void testId() {
|
||||
ListDiskOfferingsOptions options = new ListDiskOfferingsOptions().id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testIdStatic() {
|
||||
ListDiskOfferingsOptions options = id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testName() {
|
||||
ListDiskOfferingsOptions options = new ListDiskOfferingsOptions().name("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("name"));
|
||||
}
|
||||
|
||||
public void testNameStatic() {
|
||||
ListDiskOfferingsOptions options = name("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("name"));
|
||||
}
|
||||
|
||||
public void testDomainId() {
|
||||
ListDiskOfferingsOptions options = new ListDiskOfferingsOptions().domainId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testDomainIdStatic() {
|
||||
ListDiskOfferingsOptions options = domainId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.availability;
|
||||
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.displayText;
|
||||
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.id;
|
||||
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.isDefault;
|
||||
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.isShared;
|
||||
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.specifyVLAN;
|
||||
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.trafficType;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.cloudstack.domain.TrafficType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListNetworkOfferingsOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListNetworkOfferingsOptionsTest {
|
||||
|
||||
public void testIsDefault() {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions().isDefault(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isdefault"));
|
||||
}
|
||||
|
||||
public void testIsDefaultStatic() {
|
||||
ListNetworkOfferingsOptions options = isDefault(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isdefault"));
|
||||
}
|
||||
|
||||
|
||||
public void testIsShared() {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions().isShared(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isshared"));
|
||||
}
|
||||
|
||||
public void testIsSharedStatic() {
|
||||
ListNetworkOfferingsOptions options = isShared(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isshared"));
|
||||
}
|
||||
|
||||
public void testId() {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions().id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testIdStatic() {
|
||||
ListNetworkOfferingsOptions options = id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testSpecifyVLAN() {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions().specifyVLAN(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("specifyvlan"));
|
||||
}
|
||||
|
||||
public void testSpecifyVLANStatic() {
|
||||
ListNetworkOfferingsOptions options = specifyVLAN(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("specifyvlan"));
|
||||
}
|
||||
|
||||
public void testAvailability() {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions().availability("moo");
|
||||
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("availability"));
|
||||
}
|
||||
|
||||
public void testAvailabilityStatic() {
|
||||
ListNetworkOfferingsOptions options = availability("moo");
|
||||
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("availability"));
|
||||
}
|
||||
|
||||
public void testTrafficType() {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions().trafficType(TrafficType.GUEST);
|
||||
assertEquals(ImmutableList.of("Guest"), options.buildQueryParameters().get("traffictype"));
|
||||
}
|
||||
|
||||
public void testTrafficTypeStatic() {
|
||||
ListNetworkOfferingsOptions options = trafficType(TrafficType.GUEST);
|
||||
assertEquals(ImmutableList.of("Guest"), options.buildQueryParameters().get("traffictype"));
|
||||
}
|
||||
|
||||
public void testName() {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions().id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testNameStatic() {
|
||||
ListNetworkOfferingsOptions options = id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testDisplayText() {
|
||||
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions().displayText("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("displaytext"));
|
||||
}
|
||||
|
||||
public void testDisplayTextStatic() {
|
||||
ListNetworkOfferingsOptions options = displayText("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("displaytext"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.account;
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.domainId;
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.id;
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.isDefault;
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.isShared;
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.isSystem;
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.trafficType;
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.type;
|
||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.zoneId;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.cloudstack.domain.NetworkType;
|
||||
import org.jclouds.cloudstack.domain.TrafficType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListNetworksOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListNetworksOptionsTest {
|
||||
|
||||
public void testIsDefault() {
|
||||
ListNetworksOptions options = new ListNetworksOptions().isDefault(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isdefault"));
|
||||
}
|
||||
|
||||
public void testIsDefaultStatic() {
|
||||
ListNetworksOptions options = isDefault(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isdefault"));
|
||||
}
|
||||
|
||||
public void testIsSystem() {
|
||||
ListNetworksOptions options = new ListNetworksOptions().isSystem(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("issystem"));
|
||||
}
|
||||
|
||||
public void testIsSystemStatic() {
|
||||
ListNetworksOptions options = isSystem(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("issystem"));
|
||||
}
|
||||
|
||||
public void testIsShared() {
|
||||
ListNetworksOptions options = new ListNetworksOptions().isShared(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isshared"));
|
||||
}
|
||||
|
||||
public void testIsSharedStatic() {
|
||||
ListNetworksOptions options = isShared(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isshared"));
|
||||
}
|
||||
|
||||
public void testId() {
|
||||
ListNetworksOptions options = new ListNetworksOptions().id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testIdStatic() {
|
||||
ListNetworksOptions options = id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testDomainId() {
|
||||
ListNetworksOptions options = new ListNetworksOptions().domainId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testDomainIdStatic() {
|
||||
ListNetworksOptions options = domainId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testAccountId() {
|
||||
ListNetworksOptions options = new ListNetworksOptions().account("moo");
|
||||
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("account"));
|
||||
}
|
||||
|
||||
public void testAccountIdStatic() {
|
||||
ListNetworksOptions options = account("moo");
|
||||
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("account"));
|
||||
}
|
||||
|
||||
public void testTrafficType() {
|
||||
ListNetworksOptions options = new ListNetworksOptions().trafficType(TrafficType.GUEST);
|
||||
assertEquals(ImmutableList.of("Guest"), options.buildQueryParameters().get("traffictype"));
|
||||
}
|
||||
|
||||
public void testTrafficTypeStatic() {
|
||||
ListNetworksOptions options = trafficType(TrafficType.GUEST);
|
||||
assertEquals(ImmutableList.of("Guest"), options.buildQueryParameters().get("traffictype"));
|
||||
}
|
||||
|
||||
public void testName() {
|
||||
ListNetworksOptions options = new ListNetworksOptions().id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testNameStatic() {
|
||||
ListNetworksOptions options = id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testZoneId() {
|
||||
ListNetworksOptions options = new ListNetworksOptions().zoneId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("zoneid"));
|
||||
}
|
||||
|
||||
public void testZoneIdStatic() {
|
||||
ListNetworksOptions options = zoneId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("zoneid"));
|
||||
}
|
||||
|
||||
public void testType() {
|
||||
ListNetworksOptions options = new ListNetworksOptions().type(NetworkType.ADVANCED);
|
||||
assertEquals(ImmutableList.of("Advanced"), options.buildQueryParameters().get("type"));
|
||||
}
|
||||
|
||||
public void testTypeStatic() {
|
||||
ListNetworksOptions options = type(NetworkType.ADVANCED);
|
||||
assertEquals(ImmutableList.of("Advanced"), options.buildQueryParameters().get("type"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import static org.jclouds.cloudstack.options.ListServiceOfferingsOptions.Builder.domainId;
|
||||
import static org.jclouds.cloudstack.options.ListServiceOfferingsOptions.Builder.id;
|
||||
import static org.jclouds.cloudstack.options.ListServiceOfferingsOptions.Builder.name;
|
||||
import static org.jclouds.cloudstack.options.ListServiceOfferingsOptions.Builder.virtualMachineId;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListServiceOfferingsOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListServiceOfferingsOptionsTest {
|
||||
|
||||
public void testId() {
|
||||
ListServiceOfferingsOptions options = new ListServiceOfferingsOptions().id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testIdStatic() {
|
||||
ListServiceOfferingsOptions options = id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testName() {
|
||||
ListServiceOfferingsOptions options = new ListServiceOfferingsOptions().name("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("name"));
|
||||
}
|
||||
|
||||
public void testNameStatic() {
|
||||
ListServiceOfferingsOptions options = name("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("name"));
|
||||
}
|
||||
|
||||
public void testDomainId() {
|
||||
ListServiceOfferingsOptions options = new ListServiceOfferingsOptions().domainId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testDomainIdStatic() {
|
||||
ListServiceOfferingsOptions options = domainId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testVirtualMachineId() {
|
||||
ListServiceOfferingsOptions options = new ListServiceOfferingsOptions().virtualMachineId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("virtualmachineid"));
|
||||
}
|
||||
|
||||
public void testVirtualMachineIdStatic() {
|
||||
ListServiceOfferingsOptions options = virtualMachineId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("virtualmachineid"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import static org.jclouds.cloudstack.options.ListTemplatesOptions.Builder.accountInDomain;
|
||||
import static org.jclouds.cloudstack.options.ListTemplatesOptions.Builder.domainId;
|
||||
import static org.jclouds.cloudstack.options.ListTemplatesOptions.Builder.filter;
|
||||
import static org.jclouds.cloudstack.options.ListTemplatesOptions.Builder.hypervisor;
|
||||
import static org.jclouds.cloudstack.options.ListTemplatesOptions.Builder.id;
|
||||
import static org.jclouds.cloudstack.options.ListTemplatesOptions.Builder.zoneId;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.cloudstack.domain.TemplateFilter;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListTemplatesOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListTemplatesOptionsTest {
|
||||
|
||||
public void testId() {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions().id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testIdStatic() {
|
||||
ListTemplatesOptions options = id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testDomainId() {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions().domainId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testDomainIdStatic() {
|
||||
ListTemplatesOptions options = domainId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testAccountInDomainId() {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions().accountInDomain("moo", "goo");
|
||||
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("account"));
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testAccountInDomainIdStatic() {
|
||||
ListTemplatesOptions options = accountInDomain("moo", "goo");
|
||||
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("account"));
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testHypervisor() {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions().hypervisor("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("hypervisor"));
|
||||
}
|
||||
|
||||
public void testHypervisorStatic() {
|
||||
ListTemplatesOptions options = hypervisor("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("hypervisor"));
|
||||
}
|
||||
|
||||
public void testName() {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions().id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testNameStatic() {
|
||||
ListTemplatesOptions options = id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testZoneId() {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions().zoneId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("zoneid"));
|
||||
}
|
||||
|
||||
public void testZoneIdStatic() {
|
||||
ListTemplatesOptions options = zoneId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("zoneid"));
|
||||
}
|
||||
|
||||
public void testFilterDefault() {
|
||||
assertEquals(ImmutableList.of("executable"), new ListTemplatesOptions().buildQueryParameters().get(
|
||||
"templatefilter"));
|
||||
}
|
||||
|
||||
public void testFilter() {
|
||||
ListTemplatesOptions options = new ListTemplatesOptions().filter(TemplateFilter.SELF_EXECUTABLE);
|
||||
assertEquals(ImmutableList.of("self-executable"), options.buildQueryParameters().get("templatefilter"));
|
||||
}
|
||||
|
||||
public void testFilterStatic() {
|
||||
ListTemplatesOptions options = filter(TemplateFilter.SELF_EXECUTABLE);
|
||||
assertEquals(ImmutableList.of("self-executable"), options.buildQueryParameters().get("templatefilter"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import static org.jclouds.cloudstack.options.ListZonesOptions.Builder.available;
|
||||
import static org.jclouds.cloudstack.options.ListZonesOptions.Builder.domainId;
|
||||
import static org.jclouds.cloudstack.options.ListZonesOptions.Builder.id;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListZonesOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListZonesOptionsTest {
|
||||
|
||||
public void testId() {
|
||||
ListZonesOptions options = new ListZonesOptions().id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testAvailable() {
|
||||
ListZonesOptions options = new ListZonesOptions().available(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("available"));
|
||||
}
|
||||
|
||||
public void testDomainId() {
|
||||
ListZonesOptions options = new ListZonesOptions().domainId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testIdStatic() {
|
||||
ListZonesOptions options = id("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testAvailableStatic() {
|
||||
ListZonesOptions options = available(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("available"));
|
||||
}
|
||||
|
||||
public void testDomainIdStatic() {
|
||||
ListZonesOptions options = domainId("goo");
|
||||
assertEquals(ImmutableList.of("goo"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2010 Cloud Conscious, LLC.
|
||||
<info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 Unless required by
|
||||
applicable law or agreed to in writing, software distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions
|
||||
and limitations under the License.
|
||||
====================================================================
|
||||
-->
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<!--
|
||||
For more configuration infromation and examples see the Apache
|
||||
Log4j website: http://logging.apache.org/log4j/
|
||||
-->
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
|
||||
debug="false">
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds-wire.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds-compute.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="SSHFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds-ssh.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="COMPUTEFILE" />
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCSSH" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="SSHFILE" />
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="FILE" />
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="WIREFILE" />
|
||||
</appender>
|
||||
|
||||
<!-- ================ -->
|
||||
<!-- Limit categories -->
|
||||
<!-- ================ -->
|
||||
|
||||
<category name="org.jclouds">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNC" />
|
||||
</category>
|
||||
|
||||
<category name="jclouds.headers">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
<category name="jclouds.ssh">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCSSH" />
|
||||
</category>
|
||||
|
||||
<category name="jclouds.wire">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
<category name="jclouds.compute">
|
||||
<priority value="TRACE" />
|
||||
<appender-ref ref="ASYNCCOMPUTE" />
|
||||
</category>
|
||||
<!-- ======================= -->
|
||||
<!-- Setup the Root category -->
|
||||
<!-- ======================= -->
|
||||
|
||||
<root>
|
||||
<priority value="WARN" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
Loading…
Reference in New Issue