Merge pull request #241 from jsonking/695-Terremark

Issue 695: ssh key client and classes. Network client also
This commit is contained in:
Adrian Cole 2011-12-13 11:02:17 -08:00
commit 840ee92f07
29 changed files with 2616 additions and 12 deletions

View File

@ -39,6 +39,12 @@ public interface TerremarkEnterpriseCloudAsyncClient {
@Delegate
LocationAsyncClient getLocationClient();
/**
* Provides asynchronous access to Network features.
*/
@Delegate
NetworkAsyncClient getNetworkClient();
/**
* Provides asynchronous access to Resource features.
*/
@ -51,6 +57,12 @@ public interface TerremarkEnterpriseCloudAsyncClient {
@Delegate
TaskAsyncClient getTaskClient();
/**
* Provides asynchronous access to SSH Key features.
*/
@Delegate
SSHKeyAsyncClient getSSHKeyClient();
/**
* Provides asynchronous access to VirtualMachine features.
*/

View File

@ -49,6 +49,18 @@ public interface TerremarkEnterpriseCloudClient {
@Delegate
ResourceClient getResourceClient();
/**
* Provides synchronous access to Network features.
*/
@Delegate
NetworkClient getNetworkClient();
/**
* Provides synchronous access to SSH Key features.
*/
@Delegate
SSHKeyClient getSSHKeyClient();
/**
* Provides synchronous access to Task features.
*/

View File

@ -0,0 +1,67 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.binders;
import com.google.common.collect.ImmutableMap;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey;
import org.jclouds.util.Strings2;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
*
* @author Jason King
*/
@Singleton
public class BindSSHKeyToXmlPayload implements Binder {
private final String xmlTemplate;
private final BindToStringPayload stringBinder;
@Inject
BindSSHKeyToXmlPayload(@Named("EditSSHKey") String xmlTemplate,
BindToStringPayload stringBinder) {
this.xmlTemplate = xmlTemplate;
this.stringBinder = stringBinder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object key) {
checkArgument(checkNotNull(key, "key") instanceof SSHKey, "this binder is only valid for SSHKey instances!");
checkNotNull(request, "request");
SSHKey sshKey = SSHKey.class.cast(key);
String name = sshKey.getName();
String isDefault = Boolean.toString(sshKey.isDefaultKey());
String fingerPrint = sshKey.getFingerPrint();
String payload = Strings2.replaceTokens(xmlTemplate,
ImmutableMap.of("name", name, "isDefault", isDefault, "fingerPrint", fingerPrint));
return stringBinder.bindToRequest(request, payload);
}
}

View File

@ -18,8 +18,10 @@
*/
package org.jclouds.tmrk.enterprisecloud.config;
import java.io.IOException;
import java.util.Map;
import com.google.inject.Provides;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.RequiresHttp;
@ -35,6 +37,10 @@ import org.jclouds.tmrk.enterprisecloud.features.*;
import org.jclouds.tmrk.enterprisecloud.handlers.TerremarkEnterpriseCloudErrorHandler;
import com.google.common.collect.ImmutableMap;
import org.jclouds.util.Strings2;
import javax.inject.Named;
import javax.inject.Singleton;
/**
* Configures the TerremarkEnterpriseCloud connection.
@ -48,8 +54,10 @@ public class TerremarkEnterpriseCloudRestClientModule extends
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
.put(LocationClient.class, LocationAsyncClient.class)
.put(NetworkClient.class, NetworkAsyncClient.class)
.put(ResourceClient.class, ResourceAsyncClient.class)
.put(TaskClient.class, TaskAsyncClient.class)
.put(SSHKeyClient.class, SSHKeyAsyncClient.class)
.put(VirtualMachineClient.class, VirtualMachineAsyncClient.class)
.put(TemplateClient.class, TemplateAsyncClient.class)
.build();
@ -75,4 +83,10 @@ public class TerremarkEnterpriseCloudRestClientModule extends
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(BackoffLimitedRetryHandler.class);
}
@Singleton
@Provides
@Named("EditSSHKey")
String provideEditSSHKey() throws IOException {
return Strings2.toStringAndClose(getClass().getResourceAsStream("/EditSSHKey.xml"));
}
}

View File

@ -0,0 +1,158 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.internal;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.Task;
import org.jclouds.tmrk.enterprisecloud.domain.Tasks;
import javax.xml.bind.annotation.XmlElement;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Base Entity class. Extends Resource with Tasks
* <xs:complexType name="EntityType">
* @author Jason King
*
*/
public class Entity<T extends Entity<T>> extends Resource<T> {
public static <T extends Entity<T>> Builder<T> builder() {
return new Builder<T>();
}
public Builder<T> toBuilder() {
return new Builder<T>().fromResource(this);
}
public static class Builder<T extends Entity<T>> extends Resource.Builder<T> {
protected Set<Task> tasks = Sets.newLinkedHashSet();
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.internal.Entity#getTasks
*/
public Builder<T> tasks(Set<Task> tasks) {
this.tasks = ImmutableSet.<Task> copyOf(checkNotNull(tasks, "tasks"));
return this;
}
/**
* @see Resource#getLinks
*/
public Builder<T> links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* @see Resource#getActions
*/
public Builder<T> actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/**
* @see Resource#getActions
*/
public Builder<T> name(String name) {
return Builder.class.cast(super.name(name));
}
public Entity<T> build() {
return new Entity<T>(href, type, name, links, actions, tasks);
}
/**
* {@inheritDoc}
*/
public Builder<T> fromBaseResource(BaseResource<T> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
public Builder<T> fromResource(Resource<T> in) {
return Builder.class.cast(super.fromResource(in));
}
public Builder<T> fromEntity(Entity<T> in) {
return fromResource(in).links(in.getLinks()).actions(in.getActions()).name(in.getName())
.tasks(in.getTasks());
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public Builder<T> fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "Tasks", required = false)
private Tasks tasks = Tasks.builder().build();
protected Entity(URI href, String type, @Nullable String name, Set<Link> links, Set<Action> actions, Set<Task> tasks) {
super(href, type, name, links, actions);
this.tasks = Tasks.builder().tasks(checkNotNull(tasks,"tasks")).build();
}
protected Entity() {
//For JAXB
}
public Set<Task> getTasks() {
return Collections.unmodifiableSet(tasks.getTasks());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Entity entity = (Entity) o;
if (!tasks.equals(entity.tasks)) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + tasks.hashCode();
return result;
}
@Override
public String string() {
return super.string()+", name="+name+", tasks="+tasks;
}
}

View File

@ -0,0 +1,239 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.keys;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.Task;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.Entity;
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Map;
import java.util.Set;
/**
* <xs:complexType name="SshKeyType">
* @author Jason King
*/
@XmlRootElement(name = "SshKey")
public class SSHKey extends Entity<SSHKey> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromSshKey(this);
}
public static class Builder extends Entity.Builder<SSHKey> {
private boolean defaultKey;
private String fingerPrint;
private String privateKey;
/**
* @see SSHKey#isDefaultKey
*/
public Builder defaultKey(boolean defaultKey) {
this.defaultKey = defaultKey;
return this;
}
/**
* @see SSHKey#getFingerPrint
*/
public Builder fingerPrint(String fingerPrint) {
this.fingerPrint = fingerPrint;
return this;
}
/**
* @see SSHKey#getPrivateKey
*/
public Builder privateKey(String privateKey) {
this.privateKey = privateKey;
return this;
}
@Override
public SSHKey build() {
return new SSHKey(href, type, name, links, actions, tasks, defaultKey, fingerPrint, privateKey);
}
public Builder fromSshKey(SSHKey in) {
return fromEntity(in).defaultKey(in.isDefaultKey()).fingerPrint(in.getFingerPrint()).privateKey(in.getPrivateKey());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<SSHKey> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<SSHKey> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromEntity(Entity<SSHKey> in) {
return Builder.class.cast(super.fromEntity(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/**
* {@inheritDoc}
*/
@Override
public Builder tasks(Set<Task> tasks) {
return Builder.class.cast(super.tasks(tasks));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "Default", required = false)
private boolean defaultKey;
@XmlElement(name = "FingerPrint", required = false)
private String fingerPrint;
@XmlElement(name = "PrivateKey", required = false)
private String privateKey;
private SSHKey(URI href, String type, String name, Set<Link> links, Set<Action> actions, Set<Task> tasks,
boolean defaultKey, @Nullable String fingerPrint, @Nullable String privateKey) {
super(href, type, name, links, actions, tasks);
this.defaultKey = defaultKey;
this.fingerPrint = fingerPrint;
this.privateKey = privateKey;
}
private SSHKey() {
//For JAXB
}
public boolean isDefaultKey() {
return defaultKey;
}
public String getFingerPrint() {
return fingerPrint;
}
public String getPrivateKey() {
return privateKey;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
SSHKey sshKey = (SSHKey) o;
if (defaultKey != sshKey.defaultKey) return false;
if (fingerPrint != null ? !fingerPrint.equals(sshKey.fingerPrint) : sshKey.fingerPrint != null)
return false;
if (privateKey != null ? !privateKey.equals(sshKey.privateKey) : sshKey.privateKey != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (defaultKey ? 1 : 0);
result = 31 * result + (fingerPrint != null ? fingerPrint.hashCode() : 0);
result = 31 * result + (privateKey != null ? privateKey.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", defaultKey="+defaultKey+", fingerPrint="+fingerPrint+", privateKey="+privateKey;
}
}

View File

@ -0,0 +1,182 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.keys;
import com.google.common.collect.Sets;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* SshKeys is more than a simple wrapper as it extends Resource.
* @author Jason King
*
*/
@XmlRootElement(name = "SshKeys")
public class SSHKeys extends Resource<SSHKeys> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromTemplates(this);
}
public static class Builder extends Resource.Builder<SSHKeys> {
private Set<SSHKey> sshKeys = Sets.newLinkedHashSet();
/**
* @see SSHKeys#getSSHKeys
*/
public Builder sshKeys(Set<SSHKey> sshKeys) {
this.sshKeys =(checkNotNull(sshKeys,"sshKeys"));
return this;
}
@Override
public SSHKeys build() {
return new SSHKeys(href, type, name, links, actions, sshKeys);
}
public Builder fromTemplates(SSHKeys in) {
return fromResource(in).sshKeys(in.getSSHKeys());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<SSHKeys> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<SSHKeys> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "SshKey", required = false)
private Set<SSHKey> sshKeys = Sets.newLinkedHashSet();
private SSHKeys(URI href, String type, String name, Set<Link> links, Set<Action> actions, Set<SSHKey> sshKeys) {
super(href, type, name, links, actions);
this.sshKeys = checkNotNull(sshKeys,"sshKeys");
}
private SSHKeys() {
//For JAXB
}
public Set<SSHKey> getSSHKeys() {
return sshKeys;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
SSHKeys networks1 = (SSHKeys) o;
if (!sshKeys.equals(networks1.sshKeys)) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + sshKeys.hashCode();
return result;
}
@Override
public String string() {
return super.string()+", sshKeys="+sshKeys;
}
}

View File

@ -41,7 +41,7 @@ public class AssignedIpAddresses extends Resource<AssignedIpAddresses> {
public AssignedIpAddresses(URI href, String type, String name, Actions actions, DeviceNetworks networks) {
super(href, type, name, Sets.<Link>newIdentityHashSet(), actions.getActions());
checkNotNull(networks,"networks");
this.networks = checkNotNull(networks,"networks");
}
public AssignedIpAddresses() {

View File

@ -0,0 +1,221 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.network;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
import javax.xml.bind.annotation.XmlElement;
import java.net.URI;
import java.util.Map;
import java.util.Set;
/**
* <xs:complexType name="IpAddressType">
* @author Jason King
*/
public class IpAddress extends Resource<IpAddress> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromIpAddress(this);
}
public static class Builder extends Resource.Builder<IpAddress> {
private NamedResource host;
private NamedResource detectedOn;
private NamedResource rnatAddress;
/**
* @see IpAddress#getHost
*/
public Builder host(NamedResource host) {
this.host = host;
return this;
}
/**
* @see IpAddress#getDetectedOn
*/
public Builder detectedOn(NamedResource detectedOn) {
this.detectedOn = detectedOn;
return this;
}
/**
* @see IpAddress#getRnatAddress
*/
public Builder rnatAddress(NamedResource rnatAddress) {
this.rnatAddress = rnatAddress;
return this;
}
@Override
public IpAddress build() {
return new IpAddress(href, type, name, links, actions, host, detectedOn, rnatAddress);
}
public Builder fromIpAddress(IpAddress in) {
return fromResource(in).host(in.getHost()).detectedOn(in.getDetectedOn()).rnatAddress(in.getRnatAddress());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<IpAddress> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<IpAddress> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "Host", required = false)
private NamedResource host;
@XmlElement(name = "DetectedOn", required = false)
private NamedResource detectedOn;
@XmlElement(name = "RnatAddress", required = false)
private NamedResource rnatAddress;
private IpAddress(URI href, String type, String name, Set<Link> links,Set<Action> actions,
@Nullable NamedResource host,@Nullable NamedResource detectedOn,@Nullable NamedResource rnatAddress) {
super(href, type, name, links, actions);
this.host = host;
this.detectedOn = detectedOn;
this.rnatAddress = rnatAddress;
}
private IpAddress() {
//For JAXB
}
public NamedResource getHost() {
return host;
}
public NamedResource getDetectedOn() {
return detectedOn;
}
public NamedResource getRnatAddress() {
return rnatAddress;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
IpAddress ipAddress = (IpAddress) o;
if (detectedOn != null ? !detectedOn.equals(ipAddress.detectedOn) : ipAddress.detectedOn != null)
return false;
if (host != null ? !host.equals(ipAddress.host) : ipAddress.host != null)
return false;
if (rnatAddress != null ? !rnatAddress.equals(ipAddress.rnatAddress) : ipAddress.rnatAddress != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (host != null ? host.hashCode() : 0);
result = 31 * result + (detectedOn != null ? detectedOn.hashCode() : 0);
result = 31 * result + (rnatAddress != null ? rnatAddress.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", host="+host+", detectedOn="+detectedOn+", rnatAddress="+rnatAddress;
}
}

View File

@ -0,0 +1,105 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.network;
import com.google.common.collect.Sets;
import javax.xml.bind.annotation.XmlElement;
import java.util.Collections;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* <xs:complexType name="IpAddressesType">
* @author Jason King
*/
public class IpAddresses {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromIpAddresses(this);
}
public static class Builder {
private Set<IpAddress> addresses = Sets.newLinkedHashSet();
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.network.IpAddresses#getIpAddresses
*/
public Builder addresses(Set<IpAddress> addresses) {
this.addresses = Sets.newLinkedHashSet(checkNotNull(addresses, "addresses"));
return this;
}
public Builder addIpAddress(IpAddress address) {
addresses.add(checkNotNull(address, "address"));
return this;
}
public IpAddresses build() {
return new IpAddresses(addresses);
}
public Builder fromIpAddresses(IpAddresses in) {
return addresses(in.getIpAddresses());
}
}
private IpAddresses() {
//For JAXB and builder use
}
private IpAddresses(Set<IpAddress> addresses) {
this.addresses = Sets.newLinkedHashSet(addresses);
}
@XmlElement(name = "IpAddress")
private Set<IpAddress> addresses = Sets.newLinkedHashSet();
public Set<IpAddress> getIpAddresses() {
return Collections.unmodifiableSet(addresses);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IpAddresses that = (IpAddresses) o;
if (!addresses.equals(that.addresses)) return false;
return true;
}
@Override
public int hashCode() {
return addresses.hashCode();
}
public String toString() {
return "["+ addresses.toString()+"]";
}
}

View File

@ -19,26 +19,27 @@
package org.jclouds.tmrk.enterprisecloud.domain.network;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* <xs:complexType name="NetworkReference">
* @author Jason King
*
*/
@XmlRootElement(name = "Network")
public class NetworkReference extends BaseNamedResource<NetworkReference> {
@XmlEnum
public static enum NetworkType {
@ -74,8 +75,21 @@ public class NetworkReference extends BaseNamedResource<NetworkReference> {
public static class Builder extends BaseNamedResource.Builder<NetworkReference> {
private String address;
private NetworkType networkType;
private String broadcastAddress;
private String gatewayAddress;
private NamedResource rnatAddress;
private IpAddresses ipAddresses;
/**
* @see NetworkReference#getAddress
*/
public Builder address(String address) {
this.address = address;
return this;
}
/**
* @see NetworkReference#getNetworkType
*/
@ -84,9 +98,41 @@ public class NetworkReference extends BaseNamedResource<NetworkReference> {
return this;
}
/**
* @see NetworkReference#getBroadcastAddress
*/
public Builder broadcastAddress(String broadcastAddress) {
this.broadcastAddress = broadcastAddress;
return this;
}
/**
* @see NetworkReference#getGatewayAddress
*/
public Builder gatewayAddress(String gatewayAddress) {
this.gatewayAddress = gatewayAddress;
return this;
}
/**
* @see NetworkReference#getRnatAddress
*/
public Builder rnatAddress(NamedResource rnatAddress) {
this.rnatAddress = rnatAddress;
return this;
}
/**
* @see NetworkReference#getIpAddresses
*/
public Builder gatewayAddress(IpAddresses ipAddresses) {
this.ipAddresses = ipAddresses;
return this;
}
@Override
public NetworkReference build() {
return new NetworkReference(href, type, name, networkType);
return new NetworkReference(href, type, name, address, networkType, broadcastAddress, gatewayAddress, rnatAddress, ipAddresses);
}
public Builder fromNetworkReference(NetworkReference in) {
@ -142,26 +188,100 @@ public class NetworkReference extends BaseNamedResource<NetworkReference> {
}
}
@XmlElement(name = "NetworkType")
@XmlElement(name = "Address", required = false)
private String address;
@XmlElement(name = "NetworkType", required = true)
private NetworkType networkType;
private NetworkReference(URI href, String type, String name,@Nullable NetworkType networkType) {
@XmlElement(name = "BroadcastAddress", required = false)
private String broadcastAddress;
@XmlElement(name = "GatewayAddress", required = false)
private String gatewayAddress;
@XmlElement(name = "RnatAddress", required = false)
private NamedResource rnatAddress;
@XmlElement(name = "IpAddresses", required = false)
private IpAddresses ipAddresses;
private NetworkReference(URI href, String type, String name,@Nullable String address, NetworkType networkType,
@Nullable String broadcastAddress, @Nullable String gatewayAddress, @Nullable NamedResource rnatAddress, @Nullable IpAddresses ipAddresses) {
super(href, type, name);
this.networkType = networkType;
this.address = address;
this.networkType = checkNotNull(networkType,"networkType");
this.broadcastAddress = broadcastAddress;
this.gatewayAddress = gatewayAddress;
this.rnatAddress = rnatAddress;
this.ipAddresses = ipAddresses;
}
private NetworkReference() {
//For JAXB
}
@Nullable
public String getAddress() {
return address;
}
public NetworkType getNetworkType() {
return networkType;
}
public String getBroadcastAddress() {
return broadcastAddress;
}
public String getGatewayAddress() {
return gatewayAddress;
}
public NamedResource getRnatAddress() {
return rnatAddress;
}
public IpAddresses getIpAddresses() {
return ipAddresses;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
NetworkReference that = (NetworkReference) o;
if (address != null ? !address.equals(that.address) : that.address != null)
return false;
if (broadcastAddress != null ? !broadcastAddress.equals(that.broadcastAddress) : that.broadcastAddress != null)
return false;
if (gatewayAddress != null ? !gatewayAddress.equals(that.gatewayAddress) : that.gatewayAddress != null)
return false;
if (ipAddresses != null ? !ipAddresses.equals(that.ipAddresses) : that.ipAddresses != null)
return false;
if (networkType != that.networkType) return false;
if (rnatAddress != null ? !rnatAddress.equals(that.rnatAddress) : that.rnatAddress != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (address != null ? address.hashCode() : 0);
result = 31 * result + networkType.hashCode();
result = 31 * result + (broadcastAddress != null ? broadcastAddress.hashCode() : 0);
result = 31 * result + (gatewayAddress != null ? gatewayAddress.hashCode() : 0);
result = 31 * result + (rnatAddress != null ? rnatAddress.hashCode() : 0);
result = 31 * result + (ipAddresses != null ? ipAddresses.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", networkType="+networkType;
return super.string()+", address="+address+", networkType="+networkType+", broadcastAddress="+broadcastAddress+", gatewayAddress="+gatewayAddress+", rnatAddress="+rnatAddress+", ipAddresses="+ipAddresses;
}
}

View File

@ -0,0 +1,182 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.network;
import com.google.common.collect.Sets;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Networks is more than a simple wrapper as it extends Resource.
* @author Jason King
*
*/
@XmlRootElement(name = "Networks")
public class Networks extends Resource<Networks> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromTemplates(this);
}
public static class Builder extends Resource.Builder<Networks> {
private Set<NetworkReference> networks = Sets.newLinkedHashSet();
/**
* @see Networks#getNetworks
*/
public Builder networks(Set<NetworkReference> networks) {
this.networks =(checkNotNull(networks,"networks"));
return this;
}
@Override
public Networks build() {
return new Networks(href, type, name, links, actions, networks);
}
public Builder fromTemplates(Networks in) {
return fromResource(in).networks(in.getNetworks());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<Networks> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<Networks> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "Network", required = false)
private Set<NetworkReference> networks = Sets.newLinkedHashSet();
private Networks(URI href, String type, String name, Set<Link> links, Set<Action> actions, Set<NetworkReference> networks) {
super(href, type, name, links, actions);
this.networks = checkNotNull(networks,"networks");
}
private Networks() {
//For JAXB
}
public Set<NetworkReference> getNetworks() {
return networks;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Networks networks1 = (Networks) o;
if (!networks.equals(networks1.networks)) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + networks.hashCode();
return result;
}
@Override
public String string() {
return super.string()+", networks="+networks;
}
}

View File

@ -0,0 +1,63 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.*;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
import org.jclouds.tmrk.enterprisecloud.domain.network.Networks;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import java.net.URI;
/**
* Provides asynchronous access to various Networks via their REST API.
* <p/>
*
* @see org.jclouds.tmrk.enterprisecloud.features.NetworkClient
* @see <a href=
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
* />
* @author Jason King
*/
@RequestFilters(BasicAuthentication.class)
@Headers(keys = "x-tmrk-version", values = "{jclouds.api-version}")
public interface NetworkAsyncClient {
/**
* @see org.jclouds.tmrk.enterprisecloud.features.NetworkClient#getNetworks
*/
@GET
@Consumes("application/vnd.tmrk.cloud.network; type=collection")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
public ListenableFuture<Networks> getNetworks(@EndpointParam URI uri);
/**
* @see org.jclouds.tmrk.enterprisecloud.features.NetworkClient#getNetwork
*/
@GET
@Consumes("application/vnd.tmrk.cloud.network")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
public ListenableFuture<NetworkReference> getNetwork(@EndpointParam URI uri);
}

View File

@ -0,0 +1,60 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.concurrent.Timeout;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
import org.jclouds.tmrk.enterprisecloud.domain.network.Networks;
import java.net.URI;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to various Resources.
* <p/>
*
* @see org.jclouds.tmrk.enterprisecloud.features.NetworkAsyncClient
* @see <a href=
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
* />
* @author Jason King
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface NetworkClient {
/**
* The Get Networks call returns information regarding networks in an environment.
* @param uri the uri of the call based upon the environment
* e.g. /cloudapi/ecloud/networks/environments/{id}
* @return the Networks
*/
public Networks getNetworks(URI uri);
/**
* The Get Networks by ID call returns information regarding the usage of all
* IP addresses on a specified network defined in an environment.
* @param uri the uri of the call based upon the network
* e.g. /cloudapi/ecloud/networks/{id}
* @return the NetworkReference
*/
public NetworkReference getNetwork(URI uri);
}

View File

@ -0,0 +1,97 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.*;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.tmrk.enterprisecloud.binders.BindSSHKeyToXmlPayload;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKeys;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.net.URI;
/**
* Provides asynchronous access to ssh keys via their REST API.
* <p/>
*
* @see SSHKeyClient
* @see <a href=
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
* />
* @author Jason King
*/
@RequestFilters(BasicAuthentication.class)
@Headers(keys = "x-tmrk-version", values = "{jclouds.api-version}")
public interface SSHKeyAsyncClient {
/**
* @see SSHKeyClient#getSSHKeys
*/
@GET
@Consumes("application/vnd.tmrk.cloud.admin.sshKey; type=collection")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
public ListenableFuture<SSHKeys> getSSHKeys(@EndpointParam URI uri);
/**
* @see SSHKeyClient#getSSHKey
*/
@GET
@Consumes("application/vnd.tmrk.cloud.admin.sshKey")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
public ListenableFuture<SSHKey> getSSHKey(@EndpointParam URI uri);
/**
* @see SSHKeyClient#createSSHKey
*/
@POST
@Consumes("application/vnd.tmrk.cloud.admin.sshKey")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
//TODO This would be done better with a template like editSSHKey
@Payload("<CreateSshKey name='{name}'><Default>{defaultKey}</Default></CreateSshKey>")
@Produces(MediaType.APPLICATION_XML)
public ListenableFuture<SSHKey> createSSHKey(@EndpointParam URI uri, @PayloadParam("name")String name, @PayloadParam("defaultKey")boolean defaultKey);
/**
* @see SSHKeyClient#editSSHKey
*/
@PUT
@Consumes("application/vnd.tmrk.cloud.admin.sshKey")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@JAXBResponseParser
@Produces(MediaType.APPLICATION_XML)
public ListenableFuture<SSHKey> editSSHKey(@EndpointParam URI uri, @BinderParam(BindSSHKeyToXmlPayload.class)SSHKey key);
/**
* @see SSHKeyClient#createSSHKey
* TODO Should map the 204 header to a boolean to indicate that it was sucessful
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
public ListenableFuture<Void> deleteSSHKey(@EndpointParam URI uri);
}

View File

@ -0,0 +1,99 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.concurrent.Timeout;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKeys;
import java.net.URI;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to Ssh Key Functions.
* <p/>
*
* @see SSHKeyAsyncClient
* @see <a href=
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
* />
* @author Jason King
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface SSHKeyClient {
/**
* The Get SSH Keys call returns information regarding the SSH keys for an organization
*
* @param uri the uri of the call based upon the organization
* e.g. /cloudapi/ecloud/admin/sshkeys/organizations/{id}
* @return the SSHKeys
*/
public SSHKeys getSSHKeys(URI uri);
/**
* The Get SSH Keys by ID call returns information regarding a specified SSH key for an organization.
*
* @param uri the uri of the call based upon the key
* e.g. /cloudapi/ecloud/admin/sshkeys/{id}
* @return the SSHKey
*/
public SSHKey getSSHKey(URI uri);
/**
* The createSSHKey call creates a new SSH key.
* If successful, the call returns information regarding the SSH key that was created.
* The name is required.
* Note: The name may not be that of another SSH key and may not exceed fifty characters.
* For the first key being created for an organization default should be true.
* To make the key the default, use true
*
* In the returned SSHKey:
* FingerPrint is the SSH key fingerprint, which is a 16 byte hash of the private key.
* PrivateKey is the actual private key, which has been encoded by base64.
* @param uri the uri of the createSshKey action based upon the organisation
* e.g. /cloudapi/ecloud/admin/sshkeys/organizations/{id}/action/createsshkey
* @param name the desired name of the key
* @param defaultKey to make the key the default one
* @return the ssh key
*/
public SSHKey createSSHKey(URI uri, String name, boolean defaultKey);
/**
* The editSSHKey call edits the name of the SSH key.
* If successful, the call returns information regarding the SSH key that was modified.
* The name attribute on the sshKey may be changed.
* Note: The name may not be changed to that of another SSH key and may not exceed fifty characters.
* FingerPrint is optional and ignored if sent.
* Note: The default SSH key may not be modified to false.
* Instead, modify the SSH key desired as the default to true and the existing
* default SSH key will be automatically modified to false.
*/
public void editSSHKey(URI uri, SSHKey key);
/**
* The deleteSSHKey call removes a specified SSH key from an organization.
* //TODO Make this a boolean if sucessful
* @param uri the uri of the ssk key to delete
* e.g. /cloudapi/ecloud/admin/sshkeys/77
*/
public void deleteSSHKey(URI uri);
}

View File

@ -0,0 +1,4 @@
<SshKey name="{name}">
<Default>{isDefault}</Default>
<FingerPrint>{fingerPrint}</FingerPrint>
</SshKey>

View File

@ -0,0 +1,75 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.binders;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
import org.jclouds.http.HttpRequest;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code BindSSHKeyToXmlPayloadTest}
* @author Jason King
*/
@Test(groups = "unit", testName = "BindSSHKeyToXmlPayloadTest")
public class BindSSHKeyToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
}
@SuppressWarnings("unused")
@Singleton
@Provides
@Named("EditSSHKey")
String provideInstantiateVAppTemplateParams() throws IOException {
InputStream is = getClass().getResourceAsStream("/EditSSHKey.xml");
return Strings2.toStringAndClose(is);
}
});
public void testApplyInputStream() throws IOException {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream(
"/EditSSHKey-test.xml"));
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
BindSSHKeyToXmlPayload binder = injector
.getInstance(BindSSHKeyToXmlPayload.class);
SSHKey key = SSHKey.builder().type("application/vnd.tmrk.cloud.admin.sshKey")
.href(URI.create("/cloudapi/ecloud/admin/sshkeys/77"))
.name("newName")
.defaultKey(false).fingerPrint("123").build();
binder.bindToRequest(request, key);
assertEquals(request.getPayload().getRawContent(), expected);
}
}

View File

@ -40,7 +40,7 @@ public class NicsTest {
@BeforeMethod()
public void setUp() throws URISyntaxException {
networkReference = NetworkReference.builder().href(new URI("/netref")).type("a network ref").name("my network ref").build();
networkReference = NetworkReference.builder().href(new URI("/netref")).type("a network ref").name("my network ref").networkType(NetworkReference.NetworkType.INTERNAL).build();
nic = VirtualNic.builder().macAddress("aa:bb").name("my nic").network(networkReference).unitNumber(1).build();
nics = Nics.builder().addVirtualNic(nic).build();
}

View File

@ -0,0 +1,61 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
import org.jclouds.tmrk.enterprisecloud.domain.network.Networks;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.net.URI;
import static org.testng.Assert.assertNotNull;
/**
* Tests behavior of {@code NetworkClient}
*
* @author Jason King
*/
@Test(groups = "live", testName = "NetworkClientLiveTest")
public class NetworkClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTest {
@BeforeGroups(groups = { "live" })
public void setupClient() {
super.setupClient();
client = context.getApi().getNetworkClient();
}
private NetworkClient client;
public void testGetNetworks() throws Exception {
Networks networks = client.getNetworks(URI.create("/cloudapi/ecloud/networks/environments/77"));
assertNotNull(networks);
for(NetworkReference network: networks.getNetworks()) {
testGetNetwork(network.getHref());
}
}
private void testGetNetwork(URI uri) throws Exception {
NetworkReference network = client.getNetwork(uri);
assertNotNull(network);
assertNotNull(network.getAddress());
assertNotNull(network.getNetworkType());
assertNotNull(network.getBroadcastAddress());
assertNotNull(network.getGatewayAddress());
}
}

View File

@ -0,0 +1,133 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import com.google.inject.TypeLiteral;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey;
import org.testng.annotations.Test;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Tests annotation parsing of {@code SSHKeyAsyncClientTest}
*
* @author Jason King
*/
@Test(groups = "unit", testName = "SSHKeyAsyncClientTest")
public class SSHKeyAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<SSHKeyAsyncClient> {
public void testGetSSHKeys() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = SSHKeyAsyncClient.class.getMethod("getSSHKeys", URI.class);
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/admin/sshkeys/organizations/17"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/admin/sshkeys/organizations/17 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.admin.sshKey; type=collection\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetSSHKey() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = SSHKeyAsyncClient.class.getMethod("getSSHKey", URI.class);
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/admin/sshkeys/77"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/admin/sshkeys/77 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.admin.sshKey\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testCreateSSHKey() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = SSHKeyAsyncClient.class.getMethod("createSSHKey", URI.class,String.class,boolean.class);
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/admin/sshkeys/organizations/17/action/createsshkey"),"myKey",true);
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/admin/sshkeys/organizations/17/action/createsshkey HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.admin.sshKey\nx-tmrk-version: 2011-07-01\n");
String xml = "<CreateSshKey name='myKey'><Default>true</Default></CreateSshKey>";
assertPayloadEquals(httpRequest, xml, "application/xml", false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testEditSSHKey() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = SSHKeyAsyncClient.class.getMethod("editSSHKey", URI.class,SSHKey.class);
SSHKey key = SSHKey.builder().type("application/vnd.tmrk.cloud.admin.sshKey")
.href(URI.create("/cloudapi/ecloud/admin/sshkeys/77"))
.name("newName").defaultKey(false).fingerPrint("123").build();
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/admin/sshkeys/77"),key);
assertRequestLineEquals(httpRequest, "PUT https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/admin/sshkeys/77 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.admin.sshKey\nx-tmrk-version: 2011-07-01\n");
String xml = "<SshKey name=\"newName\">\n" +
" <Default>false</Default>\n" +
" <FingerPrint>123</FingerPrint>\n" +
"</SshKey>";
assertPayloadEquals(httpRequest, xml, "application/xml", false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testDeleteSSHKey() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = SSHKeyAsyncClient.class.getMethod("deleteSSHKey", URI.class);
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/admin/sshkeys/77"));
assertRequestLineEquals(httpRequest, "DELETE https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/admin/sshkeys/77 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,"x-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<SSHKeyAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<SSHKeyAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,82 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKeys;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.net.URI;
import static org.testng.Assert.*;
/**
* Tests behavior of {@code SSHKeyClient}
*
* @author Jason King
*/
@Test(groups = "live", testName = "SSHKeyClientLiveTest")
public class SSHKeyClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTest {
@BeforeGroups(groups = { "live" })
public void setupClient() {
super.setupClient();
client = context.getApi().getSSHKeyClient();
}
private SSHKeyClient client;
public void testGetSSHKeys() throws Exception {
//TODO: Remove the hardcoded uri once have access to organization
SSHKeys sshKeys = client.getSSHKeys(URI.create("/cloudapi/ecloud/admin/sshkeys/organizations/17"));
for(SSHKey key: sshKeys.getSSHKeys()) {
testGetSSHKey(key.getHref());
}
}
private void testGetSSHKey(URI uri) {
SSHKey sshKey = client.getSSHKey(uri);
assertNotNull(sshKey);
assertNotNull(sshKey.getFingerPrint());
}
public void testCreateSSHKey() {
SSHKey sshKey = client.createSSHKey(URI.create("/cloudapi/ecloud/admin/sshkeys/organizations/17/action/createsshkey"),"mynewtestkey1",false);
assertNotNull(sshKey);
assertEquals(sshKey.getName(),"mynewtestkey1");
assertFalse(sshKey.isDefaultKey());
assertFalse(sshKey.getFingerPrint().isEmpty());
assertFalse(sshKey.getPrivateKey().isEmpty());
client.deleteSSHKey(sshKey.getHref());
assertNull(client.getSSHKey(sshKey.getHref()));
}
public void testEditSSHKey() {
SSHKey sshKey = client.createSSHKey(URI.create("/cloudapi/ecloud/admin/sshkeys/organizations/17/action/createsshkey"),"mykeytoedit",false);
assertNotNull(sshKey);
SSHKey newKey = sshKey.toBuilder().name("editedname").defaultKey(false).build();
client.editSSHKey(sshKey.getHref(),newKey);
SSHKey result = client.getSSHKey(sshKey.getHref());
assertEquals(result.getName(),"editedname");
client.deleteSSHKey(sshKey.getHref());
assertNull(client.getSSHKey(sshKey.getHref()));
}
}

View File

@ -0,0 +1,156 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.xml;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import org.jclouds.crypto.Crypto;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.BaseRestClientTest;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.network.IpAddress;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
import org.jclouds.tmrk.enterprisecloud.domain.network.Networks;
import org.jclouds.tmrk.enterprisecloud.features.LocationAsyncClient;
import org.jclouds.tmrk.enterprisecloud.features.NetworkAsyncClient;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import javax.inject.Named;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Set;
import static org.jclouds.io.Payloads.newInputStreamPayload;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.testng.Assert.assertNotNull;
/**
* Tests behavior of JAXB parsing for Network(s)
*
* @author Jason King
*/
@Test(groups = "unit", testName = "NetworksJAXBParsingTest")
public class NetworksJAXBParsingTest extends BaseRestClientTest {
@BeforeClass
void setupFactory() {
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
"credentialFoo", String.class, Integer.class,
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
@Override
protected void configure() {}
@SuppressWarnings("unused")
@Provides
@Named("exception")
Set<String> exception() {
throw new AuthorizationException();
}
}));
injector = createContextBuilder(contextSpec).buildInjector();
parserFactory = injector.getInstance(ParseSax.Factory.class);
crypto = injector.getInstance(Crypto.class);
}
@Test
public void testParseNetworksWithJAXB() throws Exception {
Method method = NetworkAsyncClient.class.getMethod("getNetworks",URI.class);
HttpRequest request = factory(NetworkAsyncClient.class).createRequest(method, new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, Networks> parser = (Function<HttpResponse, Networks>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/networks.xml");
Networks networks = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertNotNull(networks);
for(NetworkReference network: networks.getNetworks()) {
assertNetworkFromNetworks(network);
}
}
@Test
public void testParseNetworkWithJAXB() throws Exception {
Method method = NetworkAsyncClient.class.getMethod("getNetwork",URI.class);
HttpRequest request = factory(NetworkAsyncClient.class).createRequest(method, new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, NetworkReference> parser = (Function<HttpResponse, NetworkReference>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/network.xml");
NetworkReference network = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertNotNull(network.getAddress());
assertNotNull(network.getNetworkType());
assertNotNull(network.getBroadcastAddress());
assertNotNull(network.getGatewayAddress());
assertRnatAddress(network.getRnatAddress());
for(IpAddress address:network.getIpAddresses().getIpAddresses()) {
assertIpAddress(address);
}
}
private void assertRnatAddress(NamedResource rnatAddress) {
assertNotNull(rnatAddress);
assertNotNull(rnatAddress.getHref());
assertNotNull(rnatAddress.getName());
assertNotNull(rnatAddress.getType());
}
private void assertIpAddress(IpAddress address) {
assertNotNull(address);
assertNotNull(address.getName());
if( address.getHost() != null) {
assertNamedResource(address.getHost());
}
if( address.getDetectedOn() != null) {
assertNamedResource(address.getDetectedOn());
}
if( address.getRnatAddress() != null) {
assertNamedResource(address.getRnatAddress());
}
}
private void assertNamedResource(NamedResource resource) {
assertNotNull(resource.getName());
}
private void assertNetworkFromNetworks(NetworkReference network) {
assertNotNull(network.getHref());
assertNotNull(network.getType());
assertNotNull(network.getName());
assertNotNull(network.getNetworkType());
}
}

View File

@ -0,0 +1,153 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.xml;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import org.jclouds.crypto.Crypto;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.BaseRestClientTest;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKeys;
import org.jclouds.tmrk.enterprisecloud.features.SSHKeyAsyncClient;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import javax.inject.Named;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Set;
import static org.jclouds.io.Payloads.newInputStreamPayload;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.testng.Assert.*;
/**
* Tests behavior of JAXB parsing for SSHKey(s)
*
* @author Jason King
*/
@Test(groups = "unit", testName = "SSHKeysJAXBParsingTest")
public class SSHKeysJAXBParsingTest extends BaseRestClientTest {
@BeforeClass
void setupFactory() {
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
"credentialFoo", String.class, Integer.class,
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
@Override
protected void configure() {}
@SuppressWarnings("unused")
@Provides
@Named("exception")
Set<String> exception() {
throw new AuthorizationException();
}
}));
injector = createContextBuilder(contextSpec).buildInjector();
parserFactory = injector.getInstance(ParseSax.Factory.class);
crypto = injector.getInstance(Crypto.class);
}
@Test
public void testParseSSHKeysWithJAXB() throws Exception {
Method method = SSHKeyAsyncClient.class.getMethod("getSSHKeys",URI.class);
HttpRequest request = factory(SSHKeyAsyncClient.class).createRequest(method, new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, SSHKeys> parser = (Function<HttpResponse, SSHKeys>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/sshKeys.xml");
SSHKeys sshKeys = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertNotNull(sshKeys);
Link link = Iterables.getOnlyElement(sshKeys.getLinks());
assertEquals(link.getName(),"Cloudsoft Corporation [Beta]");
assertEquals(link.getRelationship(), Link.Relationship.UP);
Action action = Iterables.getOnlyElement(sshKeys.getActions());
assertEquals(action.getName(),"createSshKey");
assertEquals(sshKeys.getSSHKeys().size(), 2);
SSHKey key1 = Iterables.get(sshKeys.getSSHKeys(),0);
assertTrue(key1.isDefaultKey());
assertEquals(key1.getFingerPrint(),"c8:3f:41:d6:28:e2:86:37:a6:a3:e6:df:62:d9:31:e5");
SSHKey key2= Iterables.get(sshKeys.getSSHKeys(),1);
assertFalse(key2.isDefaultKey());
assertEquals(key2.getFingerPrint(),"a1:3f:41:d6:28:e2:86:37:a6:a3:e6:df:62:d9:31:e5");
}
@Test
public void testParseSSHKeyWithJAXB() throws Exception {
Method method = SSHKeyAsyncClient.class.getMethod("getSSHKey",URI.class);
HttpRequest request = factory(SSHKeyAsyncClient.class).createRequest(method, new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, SSHKey> parser = (Function<HttpResponse, SSHKey>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/sshKey.xml");
SSHKey sshKey = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertEquals(sshKey.getHref(),URI.create("/cloudapi/ecloud/admin/sshkeys/77"));
assertEquals(sshKey.getType(),"application/vnd.tmrk.cloud.admin.sshKey");
assertEquals(sshKey.getName(),"test");
assertEquals(sshKey.getLinks().size(),1);
Link link = Iterables.getOnlyElement(sshKey.getLinks());
assertEquals(link.getHref(),URI.create("/cloudapi/ecloud/admin/organizations/17"));
assertEquals(link.getType(),"application/vnd.tmrk.cloud.admin.organization");
assertEquals(link.getName(),"Cloudsoft Corporation [Beta]");
assertEquals(link.getRelationship(), Link.Relationship.UP);
assertEquals(sshKey.getActions().size(), 2);
Action action1 = Iterables.get(sshKey.getActions(), 0);
assertEquals(action1.getHref(),URI.create("/cloudapi/ecloud/admin/sshkeys/77"));
assertEquals(action1.getType(),"application/vnd.tmrk.cloud.admin.sshKey");
assertEquals(action1.getName(),"edit");
Action action2 = Iterables.get(sshKey.getActions(), 1);
assertEquals(action2.getHref(),URI.create("/cloudapi/ecloud/admin/sshkeys/77"));
assertNull(action2.getType());
assertEquals(action2.getName(),"remove");
assertEquals(action2.getActionDisabled(), Action.ActionDisabled.DISABLED);
assertEquals(sshKey.isDefaultKey(),true);
assertEquals(sshKey.getFingerPrint(),"c8:3f:41:d6:28:e2:86:37:a6:a3:e6:df:62:d9:31:e5");
}
}

View File

@ -0,0 +1,4 @@
<SshKey name="newName">
<Default>false</Default>
<FingerPrint>123</FingerPrint>
</SshKey>

View File

@ -0,0 +1,224 @@
<Network href="/cloudapi/ecloud/networks/3936" name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Links>
<Link href="/cloudapi/ecloud/environments/77" name="Beta Environment 01"
type="application/vnd.tmrk.cloud.environment" rel="up"/>
</Links>
<Address>10.146.204.64</Address>
<NetworkType>Internal</NetworkType>
<BroadcastAddress>10.146.204.79</BroadcastAddress>
<GatewayAddress>10.146.204.65</GatewayAddress>
<RnatAddress href="/cloudapi/ecloud/rnats/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.networkRnat"/>
<IpAddresses>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.65"
name="10.146.204.65"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.65/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
<Host href="/cloudapi/ecloud/networkhosts/3930"
name="DAC90012VFW001"
type="application/vnd.tmrk.cloud.networkHost"/>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.66"
name="10.146.204.66"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.66/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
<Host href="/cloudapi/ecloud/networkhosts/3930"
name="DAC90012VFW001"
type="application/vnd.tmrk.cloud.networkHost"/>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.67"
name="10.146.204.67"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.67/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
<Host href="/cloudapi/ecloud/networkhosts/5504" name="helloworld"
type="application/vnd.tmrk.cloud.networkHost"/>
<DetectedOn href="/cloudapi/ecloud/networkhosts/5504"
name="helloworld"
type="application/vnd.tmrk.cloud.networkHost"/>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.68"
name="10.146.204.68"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.68/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.69"
name="10.146.204.69"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.69/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.70"
name="10.146.204.70"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.70/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.71"
name="10.146.204.71"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.71/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.72"
name="10.146.204.72"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.72/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.73"
name="10.146.204.73"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.73/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.74"
name="10.146.204.74"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.74/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.75"
name="10.146.204.75"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.75/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.76"
name="10.146.204.76"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.76/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.77"
name="10.146.204.77"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.77/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
<IpAddress
href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.78"
name="10.146.204.78"
type="application/vnd.tmrk.cloud.ipAddress">
<Links>
<Link href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/ipaddresses/networks/3936/10.146.204.78/action/sync"
name="sync" actionDisabled="disabled"/>
</Actions>
</IpAddress>
</IpAddresses>
</Network>

View File

@ -0,0 +1,16 @@
<Networks href="/cloudapi/ecloud/networks/environments/77"
type="application/vnd.tmrk.cloud.network; type=collection"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Links>
<Link href="/cloudapi/ecloud/environments/77" name="Beta Environment 01"
type="application/vnd.tmrk.cloud.environment" rel="up"/>
</Links>
<Network href="/cloudapi/ecloud/networks/3936" name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network">
<NetworkType>Internal</NetworkType>
</Network>
<Network href="/cloudapi/ecloud/networks/3933" name="10.146.205.128/27"
type="application/vnd.tmrk.cloud.network">
<NetworkType>Dmz</NetworkType>
</Network>
</Networks>

View File

@ -0,0 +1,17 @@
<SshKey href="/cloudapi/ecloud/admin/sshkeys/77" name="test"
type="application/vnd.tmrk.cloud.admin.sshKey"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Links>
<Link href="/cloudapi/ecloud/admin/organizations/17"
name="Cloudsoft Corporation [Beta]"
type="application/vnd.tmrk.cloud.admin.organization" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/admin/sshkeys/77" name="edit"
type="application/vnd.tmrk.cloud.admin.sshKey"/>
<Action href="/cloudapi/ecloud/admin/sshkeys/77" name="remove"
actionDisabled="disabled"/>
</Actions>
<Default>true</Default>
<FingerPrint>c8:3f:41:d6:28:e2:86:37:a6:a3:e6:df:62:d9:31:e5</FingerPrint>
</SshKey>

View File

@ -0,0 +1,48 @@
<SshKeys href="/cloudapi/ecloud/admin/sshkeys/organizations/17"
type="application/vnd.tmrk.cloud.admin.sshKey; type=collection"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Links>
<Link href="/cloudapi/ecloud/admin/organizations/17"
name="Cloudsoft Corporation [Beta]"
type="application/vnd.tmrk.cloud.admin.organization" rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/admin/sshkeys/organizations/17/action/createsshkey"
name="createSshKey"
type="application/vnd.tmrk.cloud.admin.sshKey"/>
</Actions>
<SshKey href="/cloudapi/ecloud/admin/sshkeys/77" name="test"
type="application/vnd.tmrk.cloud.admin.sshKey">
<Links>
<Link href="/cloudapi/ecloud/admin/organizations/17"
name="Cloudsoft Corporation [Beta]"
type="application/vnd.tmrk.cloud.admin.organization"
rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/admin/sshkeys/77" name="edit"
type="application/vnd.tmrk.cloud.admin.sshKey"/>
<Action href="/cloudapi/ecloud/admin/sshkeys/77" name="remove"
actionDisabled="disabled"/>
</Actions>
<Default>true</Default>
<FingerPrint>c8:3f:41:d6:28:e2:86:37:a6:a3:e6:df:62:d9:31:e5</FingerPrint>
</SshKey>
<SshKey href="/cloudapi/ecloud/admin/sshkeys/78" name="added_to_xml"
type="application/vnd.tmrk.cloud.admin.sshKey">
<Links>
<Link href="/cloudapi/ecloud/admin/organizations/17"
name="Cloudsoft Corporation [Beta]"
type="application/vnd.tmrk.cloud.admin.organization"
rel="up"/>
</Links>
<Actions>
<Action href="/cloudapi/ecloud/admin/sshkeys/78" name="edit"
type="application/vnd.tmrk.cloud.admin.sshKey"/>
<Action href="/cloudapi/ecloud/admin/sshkeys/78" name="remove"
actionDisabled="disabled"/>
</Actions>
<Default>false</Default>
<FingerPrint>a1:3f:41:d6:28:e2:86:37:a6:a3:e6:df:62:d9:31:e5</FingerPrint>
</SshKey>
</SshKeys>