added static ip and vlan collections to cloudsigma

This commit is contained in:
Adrian Cole 2011-02-02 00:17:47 -08:00
parent 359a0feeaa
commit 37d5533028
21 changed files with 1526 additions and 18 deletions

View File

@ -31,6 +31,7 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.cloudsigma.binders.BindCloneDriveOptionsToPlainTextString;
import org.jclouds.cloudsigma.binders.BindDriveDataToPlainTextString;
import org.jclouds.cloudsigma.binders.BindDriveToPlainTextString;
import org.jclouds.cloudsigma.binders.BindNameToPayload;
import org.jclouds.cloudsigma.binders.BindServerToPlainTextString;
import org.jclouds.cloudsigma.domain.Drive;
import org.jclouds.cloudsigma.domain.DriveData;
@ -38,12 +39,19 @@ import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.cloudsigma.domain.ProfileInfo;
import org.jclouds.cloudsigma.domain.Server;
import org.jclouds.cloudsigma.domain.ServerInfo;
import org.jclouds.cloudsigma.domain.StaticIPInfo;
import org.jclouds.cloudsigma.domain.VLANInfo;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToProfileInfo;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerInfo;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToStaticIPInfo;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToVLANInfo;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet;
import org.jclouds.cloudsigma.functions.SplitNewlines;
import org.jclouds.cloudsigma.functions.SplitNewlinesAndReturnSecondField;
import org.jclouds.cloudsigma.options.CloneDriveOptions;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.BinderParam;
@ -242,4 +250,98 @@ public interface CloudSigmaAsyncClient {
@Path("/drives/{uuid}/destroy")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> destroyDrive(@PathParam("uuid") String uuid);
/**
* @see CloudSigmaClient#createVLAN
*/
@POST
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToVLANInfo.class)
@Path("/resources/vlan/create")
ListenableFuture<VLANInfo> createVLAN(@BinderParam(BindNameToPayload.class) String name);
/**
* @see CloudSigmaClient#listVLANInfo
*/
@GET
@Path("/resources/vlan/info")
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet.class)
ListenableFuture<Set<VLANInfo>> listVLANInfo();
/**
* @see CloudSigmaClient#getVLANInfo
*/
@GET
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToVLANInfo.class)
@Path("/resources/vlan/{uuid}/info")
ListenableFuture<VLANInfo> getVLANInfo(@PathParam("uuid") String uuid);
/**
* @see CloudSigmaClient#setVLANConfiguration
*/
@POST
@ResponseParser(KeyValuesDelimitedByBlankLinesToVLANInfo.class)
@Path("/resources/vlan/{uuid}/set")
ListenableFuture<VLANInfo> renameVLAN(@PathParam("uuid") String uuid,
@BinderParam(BindNameToPayload.class) String name);
/**
* @see CloudSigmaClient#listVLANs
*/
@GET
@Path("/resources/vlan/list")
@ResponseParser(SplitNewlinesAndReturnSecondField.class)
ListenableFuture<Set<String>> listVLANs();
/**
* @see CloudSigmaClient#destroyVLAN
*/
@POST
@Path("/resources/vlan/{uuid}/destroy")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> destroyVLAN(@PathParam("uuid") String uuid);
/**
* @see CloudSigmaClient#createStaticIP
*/
@POST
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToStaticIPInfo.class)
@Path("/resources/ip/create")
ListenableFuture<StaticIPInfo> createStaticIP();
/**
* @see CloudSigmaClient#listStaticIPInfo
*/
@GET
@Path("/resources/ip/info")
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet.class)
ListenableFuture<Set<StaticIPInfo>> listStaticIPInfo();
/**
* @see CloudSigmaClient#getStaticIPInfo
*/
@GET
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToStaticIPInfo.class)
@Path("/resources/ip/{uuid}/info")
ListenableFuture<StaticIPInfo> getStaticIPInfo(@PathParam("uuid") String uuid);
/**
* @see CloudSigmaClient#listStaticIPs
*/
@GET
@Path("/resources/ip/list")
@ResponseParser(SplitNewlinesAndReturnSecondField.class)
ListenableFuture<Set<String>> listStaticIPs();
/**
* @see CloudSigmaClient#destroyStaticIP
*/
@POST
@Path("/resources/ip/{uuid}/destroy")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> destroyStaticIP(@PathParam("uuid") String uuid);
}

View File

@ -28,6 +28,8 @@ import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.cloudsigma.domain.ProfileInfo;
import org.jclouds.cloudsigma.domain.Server;
import org.jclouds.cloudsigma.domain.ServerInfo;
import org.jclouds.cloudsigma.domain.StaticIPInfo;
import org.jclouds.cloudsigma.domain.VLANInfo;
import org.jclouds.cloudsigma.options.CloneDriveOptions;
import org.jclouds.concurrent.Timeout;
@ -40,7 +42,7 @@ import org.jclouds.concurrent.Timeout;
* @author Adrian Cole
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface CloudSigmaClient {
public interface CloudSigmaClient {
/**
* Get profile info
@ -48,14 +50,14 @@ public interface CloudSigmaClient {
* @return info or null, if not found
*/
ProfileInfo getProfileInfo();
/**
* list of server uuids in your account
*
* @return or empty set if no servers are found
*/
Set<String> listServers();
/**
* Get all servers info
*
@ -220,5 +222,88 @@ public interface CloudSigmaClient {
*/
DriveInfo cloneDrive(String sourceUuid, String newName, CloneDriveOptions... options);
/**
* list of vlan uuids in your account
*
* @return or empty set if no vlans are found
*/
Set<String> listVLANs();
/**
* Get all vlans info
*
* @return or empty set if no vlans are found
*/
Set<? extends VLANInfo> listVLANInfo();
/**
* @param uuid
* what to get
* @return null, if not found
*/
VLANInfo getVLANInfo(String uuid);
/**
* create a new vlan
*
* @param vlan
* @return newly created vlan
*/
VLANInfo createVLAN(String name);
/**
* set vlan configuration
*
* @param uuid
* what vlan to change
* @param newName
* what the new name is
* @return new data
*/
VLANInfo renameVLAN(String uuid, String newName);
/**
* Destroy a vlan
*
* @param uuid
* what to destroy
*/
void destroyVLAN(String uuid);
/**
* list of ip uuids in your account
*
* @return or empty set if no ips are found
*/
Set<String> listStaticIPs();
/**
* Get all ips info
*
* @return or empty set if no ips are found
*/
Set<? extends StaticIPInfo> listStaticIPInfo();
/**
* @param uuid
* what to get
* @return null, if not found
*/
StaticIPInfo getStaticIPInfo(String uuid);
/**
* create a new ip
*
* @return newly created ip
*/
StaticIPInfo createStaticIP();
/**
* Destroy a ip
*
* @param uuid
* what to destroy
*/
void destroyStaticIP(String uuid);
}

View File

@ -0,0 +1,44 @@
/**
*
* 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.cloudsigma.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class BindNameToPayload implements Binder {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
request.setPayload("name " + checkNotNull(payload, "name") + "\n");
request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
return request;
}
}

View File

@ -0,0 +1,231 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not user this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.cloudsigma.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class StaticIPInfo {
public static class Builder {
protected String ip;
protected String user;
protected String netmask;
protected Set<String> nameservers = ImmutableSet.of();
protected String gateway;
public Builder ip(String ip) {
this.ip = ip;
return this;
}
public Builder user(String user) {
this.user = user;
return this;
}
public Builder nameservers(Iterable<String> nameservers) {
this.nameservers = ImmutableSet.copyOf(checkNotNull(nameservers, "nameservers"));
return this;
}
public Builder gateway(String gateway) {
this.gateway = gateway;
return this;
}
public Builder netmask(String netmask) {
this.netmask = netmask;
return this;
}
public StaticIPInfo build() {
return new StaticIPInfo(ip, user, netmask, nameservers, gateway);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
result = prime * result + ((nameservers == null) ? 0 : nameservers.hashCode());
result = prime * result + ((netmask == null) ? 0 : netmask.hashCode());
result = prime * result + ((user == null) ? 0 : user.hashCode());
result = prime * result + ((ip == null) ? 0 : ip.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;
Builder other = (Builder) obj;
if (gateway == null) {
if (other.gateway != null)
return false;
} else if (!gateway.equals(other.gateway))
return false;
if (nameservers == null) {
if (other.nameservers != null)
return false;
} else if (!nameservers.equals(other.nameservers))
return false;
if (netmask == null) {
if (other.netmask != null)
return false;
} else if (!netmask.equals(other.netmask))
return false;
if (user == null) {
if (other.user != null)
return false;
} else if (!user.equals(other.user))
return false;
if (ip == null) {
if (other.ip != null)
return false;
} else if (!ip.equals(other.ip))
return false;
return true;
}
}
protected final String ip;
protected final String user;
protected final String netmask;
protected final Set<String> nameservers;
protected final String gateway;
public StaticIPInfo(String ip, String user, String netmask, Iterable<String> nameservers, String gateway) {
this.ip = checkNotNull(ip, "ip");
this.user = checkNotNull(user, "user");
this.netmask = checkNotNull(netmask, "netmask");
this.nameservers = ImmutableSet.copyOf(checkNotNull(nameservers, "nameservers"));
this.gateway = checkNotNull(gateway, "gateway");
}
/**
*
* @return ip of the ip.
*/
@Nullable
public String getAddress() {
return ip;
}
/**
*
* @return user owning the ip
*/
public String getUser() {
return user;
}
/**
*
* @return netmask of the ip
*/
public String getNetmask() {
return netmask;
}
/**
*
* @return nameservers of the ip
*/
public Set<String> getNameservers() {
return nameservers;
}
/**
*
* @return gateway of the ip
*/
public String getGateway() {
return gateway;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
result = prime * result + ((nameservers == null) ? 0 : nameservers.hashCode());
result = prime * result + ((netmask == null) ? 0 : netmask.hashCode());
result = prime * result + ((user == null) ? 0 : user.hashCode());
result = prime * result + ((ip == null) ? 0 : ip.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;
StaticIPInfo other = (StaticIPInfo) obj;
if (gateway == null) {
if (other.gateway != null)
return false;
} else if (!gateway.equals(other.gateway))
return false;
if (nameservers == null) {
if (other.nameservers != null)
return false;
} else if (!nameservers.equals(other.nameservers))
return false;
if (netmask == null) {
if (other.netmask != null)
return false;
} else if (!netmask.equals(other.netmask))
return false;
if (user == null) {
if (other.user != null)
return false;
} else if (!user.equals(other.user))
return false;
if (ip == null) {
if (other.ip != null)
return false;
} else if (!ip.equals(other.ip))
return false;
return true;
}
@Override
public String toString() {
return "[ip=" + ip + ", user=" + user + ", netmask=" + netmask + ", nameservers="
+ nameservers + ", gateway=" + gateway + "]";
}
}

View File

@ -0,0 +1,166 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not user this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.cloudsigma.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
*
* @author Adrian Cole
*/
public class VLANInfo {
public static class Builder {
protected String uuid;
protected String name;
protected String user;
public Builder uuid(String uuid) {
this.uuid = uuid;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder user(String user) {
this.user = user;
return this;
}
public VLANInfo build() {
return new VLANInfo(uuid, name, user);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((user == null) ? 0 : user.hashCode());
result = prime * result + ((uuid == null) ? 0 : uuid.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;
Builder other = (Builder) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (user == null) {
if (other.user != null)
return false;
} else if (!user.equals(other.user))
return false;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
return true;
}
}
@Nullable
protected final String uuid;
protected final String name;
protected final String user;
public VLANInfo(String uuid, String name, String user) {
this.uuid = checkNotNull(uuid, "uuid");
this.name = checkNotNull(name, "name");
this.user = checkNotNull(user, "user");
}
/**
*
* @return uuid of the vlan.
*/
@Nullable
public String getUuid() {
return uuid;
}
/**
*
* @return name of the vlan
*/
public String getName() {
return name;
}
/**
*
* @return user owning the vlan
*/
public String getUser() {
return user;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((user == null) ? 0 : user.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;
VLANInfo other = (VLANInfo) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (user == null) {
if (other.user != null)
return false;
} else if (!user.equals(other.user))
return false;
return true;
}
@Override
public String toString() {
return "[uuid=" + uuid + ", name=" + name + ", user=" + user + "]";
}
}

View File

@ -0,0 +1,53 @@
/**
*
* 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.cloudsigma.functions;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.cloudsigma.domain.StaticIPInfo;
import org.jclouds.http.HttpResponse;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class KeyValuesDelimitedByBlankLinesToStaticIPInfo implements Function<HttpResponse, StaticIPInfo> {
private final ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet setParser;
@Inject
public KeyValuesDelimitedByBlankLinesToStaticIPInfo(ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet setParser) {
this.setParser = setParser;
}
@Override
public StaticIPInfo apply(HttpResponse response) {
Set<StaticIPInfo> drives = setParser.apply(response);
if (drives.size() == 0)
return null;
return Iterables.get(drives, 0);
}
}

View File

@ -0,0 +1,53 @@
/**
*
* 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.cloudsigma.functions;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.cloudsigma.domain.VLANInfo;
import org.jclouds.http.HttpResponse;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class KeyValuesDelimitedByBlankLinesToVLANInfo implements Function<HttpResponse, VLANInfo> {
private final ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet setParser;
@Inject
public KeyValuesDelimitedByBlankLinesToVLANInfo(ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet setParser) {
this.setParser = setParser;
}
@Override
public VLANInfo apply(HttpResponse response) {
Set<VLANInfo> drives = setParser.apply(response);
if (drives.size() == 0)
return null;
return Iterables.get(drives, 0);
}
}

View File

@ -0,0 +1,60 @@
/**
*
* 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.cloudsigma.functions;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.cloudsigma.domain.StaticIPInfo;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ReturnStringIf2xx;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet implements Function<HttpResponse, Set<StaticIPInfo>> {
private final ReturnStringIf2xx returnStringIf200;
private final ListOfKeyValuesDelimitedByBlankLinesToListOfMaps mapConverter;
private final MapToStaticIPInfo mapToProfile;
@Inject
ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet(ReturnStringIf2xx returnStringIf200,
ListOfKeyValuesDelimitedByBlankLinesToListOfMaps mapConverter, MapToStaticIPInfo mapToProfile) {
this.returnStringIf200 = returnStringIf200;
this.mapConverter = mapConverter;
this.mapToProfile = mapToProfile;
}
@Override
public Set<StaticIPInfo> apply(HttpResponse response) {
String text = returnStringIf200.apply(response);
if (text == null || text.trim().equals(""))
return ImmutableSet.<StaticIPInfo> of();
return ImmutableSet.copyOf(Iterables.transform(mapConverter.apply(text), mapToProfile));
}
}

View File

@ -0,0 +1,60 @@
/**
*
* 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.cloudsigma.functions;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.cloudsigma.domain.VLANInfo;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ReturnStringIf2xx;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet implements Function<HttpResponse, Set<VLANInfo>> {
private final ReturnStringIf2xx returnStringIf200;
private final ListOfKeyValuesDelimitedByBlankLinesToListOfMaps mapConverter;
private final MapToVLANInfo mapToProfile;
@Inject
ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet(ReturnStringIf2xx returnStringIf200,
ListOfKeyValuesDelimitedByBlankLinesToListOfMaps mapConverter, MapToVLANInfo mapToProfile) {
this.returnStringIf200 = returnStringIf200;
this.mapConverter = mapConverter;
this.mapToProfile = mapToProfile;
}
@Override
public Set<VLANInfo> apply(HttpResponse response) {
String text = returnStringIf200.apply(response);
if (text == null || text.trim().equals(""))
return ImmutableSet.<VLANInfo> of();
return ImmutableSet.copyOf(Iterables.transform(mapConverter.apply(text), mapToProfile));
}
}

View File

@ -0,0 +1,63 @@
/**
*
* 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.cloudsigma.functions;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.cloudsigma.domain.StaticIPInfo;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
/**
*
* @author Adrian Cole
*/
@Singleton
public class MapToStaticIPInfo implements Function<Map<String, String>, StaticIPInfo> {
@Resource
protected Logger logger = Logger.NULL;
@Override
public StaticIPInfo apply(Map<String, String> from) {
if (from.size() == 0)
return null;
if (from.size() == 0)
return null;
StaticIPInfo.Builder builder = new StaticIPInfo.Builder();
builder.ip(from.get("resource"));
builder.user(from.get("user"));
builder.netmask(from.get("netmask"));
builder.nameservers(Splitter.on(' ').split(from.get("nameserver")));
builder.gateway(from.get("gateway"));
try {
return builder.build();
} catch (NullPointerException e) {
logger.trace("entry missing data: %s; %s", e.getMessage(), from);
return null;
}
}
}

View File

@ -0,0 +1,59 @@
/**
*
* 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.cloudsigma.functions;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.cloudsigma.domain.VLANInfo;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class MapToVLANInfo implements Function<Map<String, String>, VLANInfo> {
@Resource
protected Logger logger = Logger.NULL;
@Override
public VLANInfo apply(Map<String, String> from) {
if (from.size() == 0)
return null;
if (from.size() == 0)
return null;
VLANInfo.Builder builder = new VLANInfo.Builder();
builder.uuid(from.get("resource"));
builder.name(from.get("name"));
builder.user(from.get("user"));
try {
return builder.build();
} catch (NullPointerException e) {
logger.trace("entry missing data: %s; %s", e.getMessage(), from);
return null;
}
}
}

View File

@ -44,7 +44,7 @@ public class SplitNewlines implements Function<HttpResponse, Set<String>> {
private final ReturnStringIf2xx returnStringIf200;
@Inject
SplitNewlines(ReturnStringIf2xx returnStringIf200) {
protected SplitNewlines(ReturnStringIf2xx returnStringIf200) {
this.returnStringIf200 = returnStringIf200;
}

View File

@ -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.cloudsigma.functions;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ReturnStringIf2xx;
import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SplitNewlinesAndReturnSecondField extends SplitNewlines {
@Inject
SplitNewlinesAndReturnSecondField(ReturnStringIf2xx returnStringIf200) {
super(returnStringIf200);
}
@Override
public Set<String> apply(HttpResponse response) {
return ImmutableSet.copyOf(Iterables.filter(
Iterables.transform(super.apply(response), new Function<String, String>() {
@Override
public String apply(String arg0) {
if (arg0 == null)
return null;
Iterable<String> parts = Splitter.on(' ').split(arg0);
if (Iterables.size(parts) == 2)
return Iterables.get(parts, 1);
else if (Iterables.size(parts) == 1)
return Iterables.get(parts, 0);
return null;
}
}), Predicates.notNull()));
}
}

View File

@ -64,6 +64,8 @@ public class CloudSigmaErrorHandler implements HttpErrorHandler {
if ((command.getCurrentRequest().getEndpoint().getPath().endsWith("/info"))
|| (message != null && message.indexOf("could not be found") != -1))
exception = new ResourceNotFoundException(message, exception);
else if (message != null && message.indexOf("currently in use") != -1)
exception = new IllegalStateException(message, exception);
else
exception = new IllegalArgumentException(message, exception);
break;

View File

@ -45,10 +45,28 @@ public class Servers {
* @return a builder for a persistent 1Ghz 512m server with DHCP enabled network.
*/
public static Server.Builder small(String name, String driveUuuid, String vncPassword) {
return smallWithStaticIP(name, driveUuuid, vncPassword, "auto");
}
/**
* Helper to create a small persistent server
*
* @param name
* what to name the server
* @param driveUuuid
* id of the boot drive
* @param vncPassword
* password for vnc
* @param ip
* static IP
* @return a builder for a persistent 1Ghz 512m server with DHCP enabled network.
*/
public static Server.Builder smallWithStaticIP(String name, String driveUuuid, String vncPassword, String ip) {
return new Server.Builder().name(name).cpu(1000).mem(512).persistent(true)
.devices(ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(driveUuuid).build()))
.bootDeviceIds(ImmutableSet.of("ide:0:0"))
.nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).dhcp("auto").build()))
.nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).dhcp(ip).build()))
.vnc(new VNC(null, vncPassword, false));
}
}

View File

@ -33,9 +33,14 @@ import org.jclouds.cloudsigma.domain.Server;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToProfileInfo;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerInfo;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToStaticIPInfo;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToVLANInfo;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet;
import org.jclouds.cloudsigma.functions.SplitNewlines;
import org.jclouds.cloudsigma.functions.SplitNewlinesAndReturnSecondField;
import org.jclouds.cloudsigma.options.CloneDriveOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication;
@ -77,6 +82,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
checkFilters(httpRequest);
}
public void testListStandardDrives() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("listStandardDrives");
HttpRequest httpRequest = processor.createRequest(method);
@ -208,8 +214,8 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
public void testSetDriveData() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("setDriveData", String.class, DriveData.class);
HttpRequest httpRequest = processor.createRequest(method, "100",
new DriveData.Builder().name("foo").size(10000l).use(ImmutableList.of("production", "candy")).build());
HttpRequest httpRequest = processor.createRequest(method, "100", new DriveData.Builder().name("foo").size(10000l)
.use(ImmutableList.of("production", "candy")).build());
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/100/set HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
@ -283,8 +289,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
public void testCreateServer() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("createServer", Server.class);
HttpRequest httpRequest = processor.createRequest(method,
BindServerToPlainTextStringTest.SERVER);
HttpRequest httpRequest = processor.createRequest(method, BindServerToPlainTextStringTest.SERVER);
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/create HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
@ -300,8 +305,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
public void testSetServerConfiguration() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("setServerConfiguration", String.class, Server.class);
HttpRequest httpRequest = processor.createRequest(method, "100",
BindServerToPlainTextStringTest.SERVER);
HttpRequest httpRequest = processor.createRequest(method, "100", BindServerToPlainTextStringTest.SERVER);
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/100/set HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
@ -438,6 +442,202 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
}
public void testListVLANs() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("listVLANs");
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/vlan/list HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\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 https://api.cloudsigma.com/resources/vlan/list HTTP/1.1");
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic Zm9vOmJhcg==\n");
assertPayloadEquals(httpRequest, null, null, false);
// TODO: insert expected response class, which probably extends ParseJson
assertResponseParserClassEquals(method, httpRequest, SplitNewlinesAndReturnSecondField.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testListVLANInfo() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("listVLANInfo");
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/vlan/info HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testGetVLANInfo() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("getVLANInfo", String.class);
HttpRequest httpRequest = processor.createRequest(method, "uuid");
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/vlan/uuid/info HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToVLANInfo.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testCreateVLAN() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("createVLAN", String.class);
HttpRequest httpRequest = processor.createRequest(method, "poohbear");
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/resources/vlan/create HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, "name poohbear\n", "text/plain", false);
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToVLANInfo.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testRenameVLAN() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("renameVLAN", String.class, String.class);
HttpRequest httpRequest = processor.createRequest(method, "100", "poohbear");
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/resources/vlan/100/set HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, "name poohbear\n", "text/plain", false);
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToVLANInfo.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testDestroyVLAN() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("destroyVLAN", String.class);
HttpRequest httpRequest = processor.createRequest(method, "uuid");
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/resources/vlan/uuid/destroy HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testListStaticIPs() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("listStaticIPs");
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/ip/list HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\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 https://api.cloudsigma.com/resources/ip/list HTTP/1.1");
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic Zm9vOmJhcg==\n");
assertPayloadEquals(httpRequest, null, null, false);
// TODO: insert expected response class, which probably extends ParseJson
assertResponseParserClassEquals(method, httpRequest, SplitNewlinesAndReturnSecondField.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testListStaticIPInfo() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("listStaticIPInfo");
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/ip/info HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testGetStaticIPInfo() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("getStaticIPInfo", String.class);
HttpRequest httpRequest = processor.createRequest(method, "uuid");
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/ip/uuid/info HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToStaticIPInfo.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testCreateStaticIP() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("createStaticIP");
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/resources/ip/create HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToStaticIPInfo.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testDestroyStaticIP() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("destroyStaticIP", String.class);
HttpRequest httpRequest = processor.createRequest(method, "uuid");
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/resources/ip/uuid/destroy HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);

View File

@ -42,6 +42,8 @@ import org.jclouds.cloudsigma.domain.ProfileInfo;
import org.jclouds.cloudsigma.domain.Server;
import org.jclouds.cloudsigma.domain.ServerInfo;
import org.jclouds.cloudsigma.domain.ServerStatus;
import org.jclouds.cloudsigma.domain.StaticIPInfo;
import org.jclouds.cloudsigma.domain.VLANInfo;
import org.jclouds.cloudsigma.options.CloneDriveOptions;
import org.jclouds.cloudsigma.predicates.DriveClaimed;
import org.jclouds.cloudsigma.util.Servers;
@ -72,7 +74,7 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
@Test(groups = "live")
@Test(groups = "live", sequential = true)
public class CloudSigmaClientLiveTest {
protected long driveSize = 8 * 1024 * 1024 * 1024l;
protected int maxDriveImageTime = 300;
@ -123,18 +125,58 @@ public class CloudSigmaClientLiveTest {
TimeUnit.SECONDS);
}
@Test
public void testListServers() throws Exception {
Set<String> servers = client.listServers();
assertNotNull(servers);
}
@Test
public void testGetProfileInfo() throws Exception {
ProfileInfo profile = client.getProfileInfo();
assertNotNull(profile);
}
@Test
public void testListVLANs() throws Exception {
Set<String> vlans = client.listVLANs();
assertNotNull(vlans);
}
@Test
public void testListVLANInfo() throws Exception {
Set<? extends VLANInfo> vlans = client.listVLANInfo();
assertNotNull(vlans);
}
@Test
public void testGetVLAN() throws Exception {
for (String vlanUUID : client.listVLANs()) {
assert !"".equals(vlanUUID);
assertNotNull(client.getVLANInfo(vlanUUID));
}
}
@Test
public void testListStaticIPs() throws Exception {
Set<String> ips = client.listStaticIPs();
assertNotNull(ips);
}
@Test
public void testListStaticIPInfo() throws Exception {
Set<? extends StaticIPInfo> ips = client.listStaticIPInfo();
assertNotNull(ips);
}
@Test
public void testGetStaticIP() throws Exception {
for (String ipUUID : client.listStaticIPs()) {
assert !"".equals(ipUUID);
assertNotNull(client.getStaticIPInfo(ipUUID));
}
}
@Test
public void testListServers() throws Exception {
Set<String> servers = client.listServers();
assertNotNull(servers);
}
@Test
public void testListServerInfo() throws Exception {
Set<? extends ServerInfo> servers = client.listServerInfo();
@ -223,6 +265,47 @@ public class CloudSigmaClientLiveTest {
drive = drive2;
}
@Test
public void testCreateAndDestroyVLAN() throws Exception {
VLANInfo vlan = client.createVLAN(prefix);
String id = vlan.getUuid();
try {
vlan = client.getVLANInfo(vlan.getUuid());
assertEquals(vlan.getName(), prefix);
vlan = client.renameVLAN(vlan.getUuid(), prefix + "2");
// test that rename didn't work :)
assertEquals(vlan.getName(), prefix);
vlan = client.getVLANInfo(vlan.getUuid());
assertEquals(vlan.getName(), prefix);
} finally {
client.destroyVLAN(id);
}
}
@Test
public void testCreateAndDestroyStaticIP() throws Exception {
StaticIPInfo ip = client.createStaticIP();
String id = ip.getAddress();
try {
ip = client.getStaticIPInfo(ip.getAddress());
assertNotNull(ip);
Logger.getAnonymousLogger().info("preparing drive");
prepareDrive();
Server serverRequest = Servers.smallWithStaticIP(prefix, drive.getUuid(), vncPassword, ip.getAddress())
.build();
Logger.getAnonymousLogger().info("starting server");
server = client.createServer(serverRequest);
assertEquals(server.getNics().get(0).getDhcp(), ip.getAddress());
} finally {
client.destroyServer(server.getUuid());
client.destroyDrive(drive.getUuid());
client.destroyStaticIP(id);
}
}
protected ServerInfo server;
@Test(dependsOnMethods = "testSetDriveData")

View File

@ -0,0 +1,50 @@
/**
*
* 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.cloudsigma.functions;
import static org.testng.Assert.assertEquals;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
import com.google.inject.Guice;
/**
*
* @author Adrian Cole
*/
@Test(groups = { "unit" })
public class KeyValuesDelimitedByBlankLinesToVLANInfoTest {
private static final KeyValuesDelimitedByBlankLinesToVLANInfo FN = Guice.createInjector().getInstance(
KeyValuesDelimitedByBlankLinesToVLANInfo.class);
public void testNone() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload(""))), null);
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload("\n\n"))), null);
assertEquals(FN.apply(new HttpResponse(200, "", null)), null);
}
public void testOne() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToVLANInfoTest.class
.getResourceAsStream("/vlan.txt")))), MapToVLANInfoTest.ONE);
}
}

View File

@ -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.cloudsigma.functions;
import static org.testng.Assert.assertEquals;
import org.jclouds.cloudsigma.domain.VLANInfo;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
/**
*
* @author Adrian Cole
*/
@Test(groups = { "unit" })
public class ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSetTest {
private static final ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet FN = Guice.createInjector().getInstance(
ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet.class);
public void testNone() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload(""))), ImmutableSet.<VLANInfo> of());
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload("\n\n"))), ImmutableSet.<VLANInfo> of());
assertEquals(FN.apply(new HttpResponse(200, "", null)), ImmutableSet.<VLANInfo> of());
}
public void testOne() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToVLANInfoTest.class
.getResourceAsStream("/vlan.txt")))), ImmutableSet.<VLANInfo> of(MapToVLANInfoTest.ONE));
}
}

View File

@ -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.cloudsigma.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Map;
import org.jclouds.cloudsigma.domain.VLANInfo;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
*
* @author Adrian Cole
*/
@Test(groups = { "unit" })
public class MapToVLANInfoTest {
public static VLANInfo ONE = new VLANInfo.Builder()//
.uuid("6e2d1f6a-03c8-422b-bc8e-d744612cf46a")//
.name("My VLAN1").user("f2e19d5c-eaa1-44e5-94aa-dc194594bd7b").build();
private static final MapToVLANInfo MAP_TO_VLAN = new MapToVLANInfo();
public void testEmptyMapReturnsNull() {
assertEquals(MAP_TO_VLAN.apply(ImmutableMap.<String, String> of()), null);
}
public void test() throws IOException {
Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply(
Strings2.toStringAndClose(MapToVLANInfoTest.class.getResourceAsStream("/vlan.txt"))).get(0);
assertEquals(MAP_TO_VLAN.apply(input), ONE);
}
}

View File

@ -0,0 +1,4 @@
resource 6e2d1f6a-03c8-422b-bc8e-d744612cf46a
type vlan
user f2e19d5c-eaa1-44e5-94aa-dc194594bd7b
name My VLAN1