mirror of
https://github.com/apache/jclouds.git
synced 2025-02-09 11:35:41 +00:00
JCLOUDS-702: JCloud ProfitBricks provider - Server & Image API
This commit is contained in:
parent
8206d19a81
commit
ee24ddb2b4
@ -57,13 +57,13 @@
|
||||
<version>${jclouds.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.auto.value</groupId>
|
||||
<artifactId>auto-value</artifactId>
|
||||
<groupId>com.google.auto.service</groupId>
|
||||
<artifactId>auto-service</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.auto.service</groupId>
|
||||
<artifactId>auto-service</artifactId>
|
||||
<groupId>com.google.auto.value</groupId>
|
||||
<artifactId>auto-value</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test dependencies -->
|
||||
|
@ -19,10 +19,18 @@ package org.jclouds.profitbricks;
|
||||
import java.io.Closeable;
|
||||
|
||||
import org.jclouds.profitbricks.features.DataCenterApi;
|
||||
import org.jclouds.profitbricks.features.ImageApi;
|
||||
import org.jclouds.profitbricks.features.ServerApi;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
public interface ProfitBricksApi extends Closeable {
|
||||
|
||||
@Delegate
|
||||
DataCenterApi dataCenterApi();
|
||||
|
||||
@Delegate
|
||||
ImageApi imageApi();
|
||||
|
||||
@Delegate
|
||||
ServerApi serverApi();
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public abstract class BaseProfitBricksRequestBinder<T> implements MapBinder {
|
||||
protected abstract String createPayload(T payload);
|
||||
|
||||
protected String formatIfNotEmpty(String pattern, Object param) {
|
||||
return Strings.isNullOrEmpty(param.toString()) ? "" : String.format(pattern, param);
|
||||
return Strings.isNullOrEmpty(nullableToString( param )) ? "" : String.format(pattern, param);
|
||||
}
|
||||
|
||||
protected String nullableToString(Object object) {
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.binder.server;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
|
||||
public class CreateServerRequestBinder extends BaseProfitBricksRequestBinder<Server.Request.CreatePayload> {
|
||||
|
||||
protected final StringBuilder requestBuilder;
|
||||
|
||||
CreateServerRequestBinder() {
|
||||
super( "server" );
|
||||
this.requestBuilder = new StringBuilder( 128 * 4 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createPayload( Server.Request.CreatePayload payload ) {
|
||||
requestBuilder.append( "<ws:createServer>" )
|
||||
.append( "<request>" )
|
||||
.append( format( "<dataCenterId>%s</dataCenterId>", payload.dataCenterId() ) )
|
||||
.append( format( "<cores>%s</cores>", payload.cores() ) )
|
||||
.append( format( "<ram>%s</ram>", payload.ram() ) )
|
||||
.append( formatIfNotEmpty( "<serverName>%s</serverName>", payload.name() ) )
|
||||
.append( formatIfNotEmpty( "<bootFromStorageId>%s</bootFromStorageId>", payload.bootFromStorageId() ) )
|
||||
.append( formatIfNotEmpty( "<bootFromImageId>%s</bootFromImageId>", payload.bootFromImageId() ) )
|
||||
.append( formatIfNotEmpty( "<internetAccess>%s</internetAccess>", payload.hasInternetAccess() ) )
|
||||
.append( formatIfNotEmpty( "<lanId>%s</lanId>", payload.lanId() ) )
|
||||
.append( formatIfNotEmpty( "<osType>%s</osType>", payload.osType() ) )
|
||||
.append( formatIfNotEmpty( "<availabilityZone>%s</availabilityZone>", payload.availabilityZone() ) )
|
||||
.append( formatIfNotEmpty( "<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<nicHotPlug>%s</nicHotPlug>", payload.isNicHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<nicHotUnPlug>%s</nicHotUnPlug>", payload.isNicHotUnPlug() ) )
|
||||
.append( formatIfNotEmpty( "<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.isDiscVirtioHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.isDiscVirtioHotUnPlug() ) )
|
||||
.append( "</request>" )
|
||||
.append( "</ws:createServer>" );
|
||||
return requestBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.binder.server;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import org.jclouds.profitbricks.binder.BaseProfitBricksRequestBinder;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
|
||||
public class UpdateServerRequestBinder extends BaseProfitBricksRequestBinder<Server.Request.UpdatePayload> {
|
||||
|
||||
protected final StringBuilder requestBuilder;
|
||||
|
||||
UpdateServerRequestBinder() {
|
||||
super( "server" );
|
||||
this.requestBuilder = new StringBuilder( 128 * 4 );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createPayload( Server.Request.UpdatePayload payload ) {
|
||||
requestBuilder.append( "<ws:updateServer>" )
|
||||
.append( "<request>" )
|
||||
.append( format( "<serverId>%s</serverId>", payload.id() ) )
|
||||
.append( format( "<cores>%s</cores>", payload.cores() ) )
|
||||
.append( format( "<ram>%s</ram>", payload.ram() ) )
|
||||
.append( formatIfNotEmpty( "<serverName>%s</serverName>", payload.name() ) )
|
||||
.append( formatIfNotEmpty( "<bootFromStorageId>%s</bootFromStorageId>", payload.bootFromStorageId() ) )
|
||||
.append( formatIfNotEmpty( "<bootFromImageId>%s</bootFromImageId>", payload.bootFromImageId() ) )
|
||||
.append( formatIfNotEmpty( "<osType>%s</osType>", payload.osType() ) )
|
||||
.append( formatIfNotEmpty( "<availabilityZone>%s</availabilityZone>", payload.availabilityZone() ) )
|
||||
.append( formatIfNotEmpty( "<cpuHotPlug>%s</cpuHotPlug>", payload.isCpuHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<ramHotPlug>%s</ramHotPlug>", payload.isRamHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<nicHotPlug>%s</nicHotPlug>", payload.isNicHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<nicHotUnPlug>%s</nicHotUnPlug>", payload.isNicHotUnPlug() ) )
|
||||
.append( formatIfNotEmpty( "<discVirtioHotPlug>%s</discVirtioHotPlug>", payload.isDiscVirtioHotPlug() ) )
|
||||
.append( formatIfNotEmpty( "<discVirtioHotUnPlug>%s</discVirtioHotUnPlug>", payload.isDiscVirtioHotUnPlug() ) )
|
||||
.append( "</request>" )
|
||||
.append( "</ws:updateServer>" );
|
||||
return requestBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
@ -23,5 +23,5 @@ package org.jclouds.profitbricks.compute.internal;
|
||||
*/
|
||||
public enum ProvisioningStatusAware {
|
||||
|
||||
DATACENTER;
|
||||
DATACENTER, SERVER;
|
||||
}
|
||||
|
@ -48,6 +48,8 @@ public class ProvisioningStatusPollingPredicate implements Predicate<String> {
|
||||
switch (domain) {
|
||||
case DATACENTER:
|
||||
return expect == api.dataCenterApi().getDataCenterState(input);
|
||||
case SERVER:
|
||||
return expect == api.serverApi().getServer( input ).state();
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown domain '" + domain + "'");
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.domain;
|
||||
|
||||
public enum AvailabilityZone {
|
||||
|
||||
AUTO, ZONE_1, ZONE_2, UNRECOGNIZED;
|
||||
|
||||
public String value() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public static AvailabilityZone fromValue( String v ) {
|
||||
try {
|
||||
return valueOf( v );
|
||||
} catch ( Exception ex ) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.domain;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
|
||||
@AutoValue
|
||||
public abstract class Image {
|
||||
|
||||
public enum Type {
|
||||
|
||||
HDD, CDROM, UNRECOGNIZED;
|
||||
|
||||
public static Type fromValue(String v) {
|
||||
try {
|
||||
return valueOf(v);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String id();
|
||||
|
||||
public abstract String name();
|
||||
|
||||
public abstract float size(); // MB
|
||||
|
||||
public abstract Type type();
|
||||
|
||||
public abstract Location location();
|
||||
|
||||
public abstract OsType osType();
|
||||
|
||||
public abstract boolean isPublic();
|
||||
|
||||
public abstract boolean isWriteable();
|
||||
|
||||
public abstract boolean isBootable();
|
||||
|
||||
public abstract boolean isCpuHotPlug();
|
||||
|
||||
public abstract boolean isCpuHotUnPlug();
|
||||
|
||||
public abstract boolean isRamHotPlug();
|
||||
|
||||
public abstract boolean isRamHotUnPlug();
|
||||
|
||||
public abstract boolean isNicHotPlug();
|
||||
|
||||
public abstract boolean isNicHotUnPlug();
|
||||
|
||||
public abstract boolean isDiscVirtioHotPlug();
|
||||
|
||||
public abstract boolean isDiscVirtioHotUnPlug();
|
||||
|
||||
public static Image create(String id, String name, float size, Type type, Location location, OsType osType,
|
||||
boolean isPublic, boolean isWriteable, boolean isBootable, boolean cpuHotPlug, boolean cpuHotUnPlug,
|
||||
boolean ramHotPlug, boolean ramHotUnPlug, boolean nicHotPlug, boolean nicHotUnPlug,
|
||||
boolean discVirtioHotPlug, boolean discVirtioHotUnPlug) {
|
||||
return new AutoValue_Image(id, name, size, type, location, osType, isPublic, isWriteable,
|
||||
isBootable, cpuHotPlug, cpuHotUnPlug, ramHotPlug, ramHotUnPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return builder().fromImage(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private float size;
|
||||
private Type type;
|
||||
private Location location;
|
||||
private OsType osType;
|
||||
private boolean isPublic;
|
||||
private boolean isWriteable;
|
||||
private boolean isBootable;
|
||||
private boolean cpuHotPlug;
|
||||
private boolean cpuHotUnPlug;
|
||||
private boolean ramHotPlug;
|
||||
private boolean ramHotUnPlug;
|
||||
private boolean nicHotPlug;
|
||||
private boolean nicHotUnPlug;
|
||||
private boolean discVirtioHotPlug;
|
||||
private boolean discVirtioHotUnPlug;
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder size(float size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(Type type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder osType(OsType osType) {
|
||||
this.osType = osType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder location(Location location) {
|
||||
this.location = location;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isPublic(boolean isPublic) {
|
||||
this.isPublic = isPublic;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isWriteable(boolean isWriteable) {
|
||||
this.isWriteable = isWriteable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isBootable(boolean isBootable) {
|
||||
this.isBootable = isBootable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isCpuHotPlug(boolean cpuHotPlug) {
|
||||
this.cpuHotPlug = cpuHotPlug;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isCpuHotUnPlug(boolean cpuHotUnPlug) {
|
||||
this.cpuHotUnPlug = cpuHotUnPlug;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isRamHotPlug(boolean ramHotPlug) {
|
||||
this.ramHotPlug = ramHotPlug;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isRamHotUnPlug(boolean ramHotUnPlug) {
|
||||
this.ramHotUnPlug = ramHotUnPlug;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isNicHotPlug(boolean nicHotPlug) {
|
||||
this.nicHotPlug = nicHotPlug;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isNicHotUnPlug(boolean nicHotUnPlug) {
|
||||
this.nicHotUnPlug = nicHotUnPlug;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isDiscVirtioHotPlug(boolean discVirtioHotPlug) {
|
||||
this.discVirtioHotPlug = discVirtioHotPlug;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isDiscVirtioHotUnPlug(boolean discVirtioHotUnPlug) {
|
||||
this.discVirtioHotUnPlug = discVirtioHotUnPlug;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Image build() {
|
||||
return Image.create(id, name, size, type, location, osType, isPublic, isWriteable, isBootable, cpuHotPlug, cpuHotUnPlug,
|
||||
ramHotPlug, ramHotUnPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug);
|
||||
}
|
||||
|
||||
public Builder fromImage(Image in) {
|
||||
return this.id(in.id()).isBootable(in.isBootable()).isCpuHotPlug(in.isCpuHotPlug()).isCpuHotUnPlug(in.isCpuHotUnPlug())
|
||||
.isDiscVirtioHotPlug(in.isDiscVirtioHotPlug()).isDiscVirtioHotUnPlug(in.isDiscVirtioHotUnPlug())
|
||||
.isNicHotPlug(in.isNicHotPlug()).isNicHotUnPlug(in.isNicHotUnPlug()).isPublic(in.isPublic())
|
||||
.isRamHotPlug(in.isRamHotPlug()).isRamHotUnPlug(in.isRamHotUnPlug()).isWriteable(in.isWriteable())
|
||||
.location(in.location()).name(in.name()).osType(in.osType()).size(in.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.domain;
|
||||
|
||||
public enum OsType {
|
||||
|
||||
WINDOWS, LINUX, OTHER, UNRECOGNIZED;
|
||||
|
||||
public static OsType fromValue(String v) {
|
||||
try {
|
||||
return valueOf(v);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,424 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.domain;
|
||||
|
||||
import org.jclouds.profitbricks.domain.internal.ServerCommonProperties;
|
||||
import com.google.auto.value.AutoValue;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.Date;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
@AutoValue
|
||||
public abstract class Server implements ServerCommonProperties {
|
||||
|
||||
public enum Status {
|
||||
|
||||
NOSTATE, RUNNING, BLOCKED, PAUSED, SHUTDOWN, SHUTOFF, CRASHED, UNRECOGNIZED;
|
||||
|
||||
public String value() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public static Status fromValue( String v ) {
|
||||
try {
|
||||
return valueOf( v );
|
||||
} catch ( IllegalArgumentException ex ) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract String id();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public abstract String name();
|
||||
|
||||
@Nullable
|
||||
public abstract Boolean hasInternetAccess();
|
||||
|
||||
public abstract ProvisioningState state();
|
||||
|
||||
@Nullable
|
||||
public abstract Status status();
|
||||
|
||||
@Nullable
|
||||
public abstract OsType osType();
|
||||
|
||||
@Nullable
|
||||
public abstract AvailabilityZone availabilityZone();
|
||||
|
||||
@Nullable
|
||||
public abstract Date creationTime();
|
||||
|
||||
@Nullable
|
||||
public abstract Date lastModificationTime();
|
||||
|
||||
// public abstract List<Storage> storages();
|
||||
// public abstract List<Nic> storages();
|
||||
public static Server create( String id, String name, int cores, int ram, Boolean hasInternetAccess, ProvisioningState state,
|
||||
Status status, OsType osType, AvailabilityZone availabilityZone, Date creationTime, Date lastModificationTime, Boolean isCpuHotPlug,
|
||||
Boolean isRamHotPlug, Boolean isNicHotPlug, Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug ) {
|
||||
return new AutoValue_Server( isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug, isDiscVirtioHotUnPlug,
|
||||
cores, ram, id, name, hasInternetAccess, state, status, osType, availabilityZone, creationTime, lastModificationTime );
|
||||
|
||||
}
|
||||
|
||||
public static DescribingBuilder builder() {
|
||||
return new DescribingBuilder();
|
||||
}
|
||||
|
||||
public DescribingBuilder toBuilder() {
|
||||
return builder().fromServer( this );
|
||||
}
|
||||
|
||||
public abstract static class Builder<B extends Builder, D extends ServerCommonProperties> {
|
||||
|
||||
protected String name;
|
||||
protected int cores;
|
||||
protected int ram;
|
||||
protected Boolean cpuHotPlug;
|
||||
protected Boolean ramHotPlug;
|
||||
protected Boolean nicHotPlug;
|
||||
protected Boolean nicHotUnPlug;
|
||||
protected Boolean discVirtioHotPlug;
|
||||
protected Boolean discVirtioHotUnPlug;
|
||||
|
||||
public B name( String name ) {
|
||||
this.name = name;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B cores( int cores ) {
|
||||
this.cores = cores;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B ram( int ram ) {
|
||||
this.ram = ram;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B isCpuHotPlug( Boolean cpuHotPlug ) {
|
||||
this.cpuHotPlug = cpuHotPlug;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B isRamHotPlug( Boolean ramHotPlug ) {
|
||||
this.ramHotPlug = ramHotPlug;
|
||||
return self();
|
||||
|
||||
}
|
||||
|
||||
public B isNicHotPlug( Boolean nicHotPlug ) {
|
||||
this.nicHotPlug = nicHotPlug;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B isNicHotUnPlug( Boolean nicHotUnPlug ) {
|
||||
this.nicHotUnPlug = nicHotUnPlug;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B isDiscVirtioHotPlug( Boolean discVirtioHotPlug ) {
|
||||
this.discVirtioHotPlug = discVirtioHotPlug;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B isDiscVirtioHotUnPlug( Boolean discVirtioHotUnPlug ) {
|
||||
this.discVirtioHotUnPlug = discVirtioHotUnPlug;
|
||||
return self();
|
||||
}
|
||||
|
||||
public abstract B self();
|
||||
|
||||
public abstract D build();
|
||||
}
|
||||
|
||||
public static class DescribingBuilder extends Builder<DescribingBuilder, Server> {
|
||||
|
||||
private String id;
|
||||
private ProvisioningState state;
|
||||
private Status status;
|
||||
private OsType osType;
|
||||
private AvailabilityZone zone;
|
||||
private Date creationTime;
|
||||
private Date lastModificationTime;
|
||||
private Boolean hasInternetAccess;
|
||||
|
||||
public DescribingBuilder id( String id ) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder state( ProvisioningState state ) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder status( Status status ) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder osType( OsType osType ) {
|
||||
this.osType = osType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder availabilityZone( AvailabilityZone zone ) {
|
||||
this.zone = zone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder creationTime( Date creationTime ) {
|
||||
this.creationTime = creationTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder lastModificationTime( Date lastModificationTime ) {
|
||||
this.lastModificationTime = lastModificationTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescribingBuilder hasInternetAccess( Boolean hasInternetAccess ) {
|
||||
this.hasInternetAccess = hasInternetAccess;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server build() {
|
||||
return Server.create( id, name, cores, ram, hasInternetAccess, state, status, osType, zone, creationTime,
|
||||
lastModificationTime, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug );
|
||||
}
|
||||
|
||||
private DescribingBuilder fromServer( Server in ) {
|
||||
return this.id( in.id() ).cores( in.cores() ).creationTime( in.creationTime() ).hasInternetAccess( in.hasInternetAccess() )
|
||||
.isCpuHotPlug( in.isCpuHotPlug() ).isDiscVirtioHotPlug( in.isDiscVirtioHotPlug() ).isDiscVirtioHotUnPlug( in.isDiscVirtioHotUnPlug() )
|
||||
.isNicHotPlug( in.isNicHotPlug() ).isNicHotUnPlug( in.isNicHotUnPlug() ).isRamHotPlug( in.isRamHotPlug() )
|
||||
.lastModificationTime( in.lastModificationTime() ).name( in.name() ).osType( in.osType() ).ram( in.ram() ).state( in.state() )
|
||||
.status( in.status() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DescribingBuilder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class Request {
|
||||
|
||||
public static CreatePayload.Builder creatingBuilder() {
|
||||
return new CreatePayload.Builder();
|
||||
}
|
||||
|
||||
public static UpdatePayload.Builder updatingBuilder() {
|
||||
return new UpdatePayload.Builder();
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
public abstract static class CreatePayload implements ServerCommonProperties {
|
||||
|
||||
public abstract String dataCenterId();
|
||||
|
||||
@Nullable
|
||||
public abstract String bootFromStorageId();
|
||||
|
||||
@Nullable
|
||||
public abstract String bootFromImageId();
|
||||
|
||||
@Nullable
|
||||
public abstract Integer lanId();
|
||||
|
||||
@Nullable
|
||||
public abstract Boolean hasInternetAccess();
|
||||
|
||||
@Nullable
|
||||
public abstract AvailabilityZone availabilityZone();
|
||||
|
||||
@Nullable
|
||||
public abstract OsType osType();
|
||||
|
||||
public static CreatePayload create( String dataCenterId, String name, int core, int ram ) {
|
||||
return create( dataCenterId, name, core, ram, "", "", null, false, null, null, null, null, null, null, null, null );
|
||||
}
|
||||
|
||||
public static CreatePayload create( String dataCenterId, String name, int cores, int ram, String bootFromStorageId, String bootFromImageId,
|
||||
Integer lanId, Boolean hasInternetAccess, AvailabilityZone availabilityZone, OsType osType, Boolean isCpuHotPlug, Boolean isRamHotPlug,
|
||||
Boolean isNicHotPlug, Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug ) {
|
||||
validateCores( cores );
|
||||
validateRam( ram, isRamHotPlug );
|
||||
return new AutoValue_Server_Request_CreatePayload( isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug,
|
||||
isDiscVirtioHotUnPlug, name, cores, ram, dataCenterId, bootFromStorageId, bootFromImageId, lanId, hasInternetAccess,
|
||||
availabilityZone, osType );
|
||||
}
|
||||
|
||||
public static class Builder extends Server.Builder<Builder, CreatePayload> {
|
||||
|
||||
private String dataCenterId;
|
||||
private String bootFromStorageId;
|
||||
private String bootFromImageId;
|
||||
private Integer lanId;
|
||||
private Boolean hasInternetAccess;
|
||||
private AvailabilityZone availabilityZone;
|
||||
private OsType osType;
|
||||
|
||||
public Builder dataCenterId( String dataCenterId ) {
|
||||
this.dataCenterId = dataCenterId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder dataCenterId( DataCenter dataCenter ) {
|
||||
this.dataCenterId = checkNotNull( dataCenter, "Cannot pass null datacenter" ).id();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bootFromStorageId( String storageId ) {
|
||||
this.bootFromStorageId = storageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bootFromImageId( String image ) {
|
||||
this.bootFromImageId = image;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lanId( Integer lanId ) {
|
||||
this.lanId = lanId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder availabilityZone( AvailabilityZone zone ) {
|
||||
this.availabilityZone = zone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder osType( OsType osType ) {
|
||||
this.osType = osType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hasInternetAccess( Boolean hasInternetAccess ) {
|
||||
this.hasInternetAccess = hasInternetAccess;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreatePayload build() {
|
||||
return CreatePayload.create( dataCenterId, name, cores, ram, bootFromStorageId, bootFromImageId, lanId, hasInternetAccess,
|
||||
availabilityZone, osType, cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
public abstract static class UpdatePayload implements ServerCommonProperties {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public abstract String name();
|
||||
|
||||
public abstract String id();
|
||||
|
||||
@Nullable
|
||||
public abstract String bootFromStorageId();
|
||||
|
||||
@Nullable
|
||||
public abstract String bootFromImageId();
|
||||
|
||||
@Nullable
|
||||
public abstract AvailabilityZone availabilityZone();
|
||||
|
||||
@Nullable
|
||||
public abstract OsType osType();
|
||||
|
||||
public static UpdatePayload create( String id, String name, int cores, int ram, String bootFromStorageId, String bootFromImageId,
|
||||
AvailabilityZone availabilityZone, OsType osType, Boolean isCpuHotPlug, Boolean isRamHotPlug, Boolean isNicHotPlug,
|
||||
Boolean isNicHotUnPlug, Boolean isDiscVirtioHotPlug, Boolean isDiscVirtioHotUnPlug ) {
|
||||
return new AutoValue_Server_Request_UpdatePayload( isCpuHotPlug, isRamHotPlug, isNicHotPlug, isNicHotUnPlug, isDiscVirtioHotPlug,
|
||||
isDiscVirtioHotUnPlug, cores, ram, name, id, bootFromStorageId, bootFromImageId, availabilityZone, osType );
|
||||
}
|
||||
|
||||
public static class Builder extends Server.Builder<Builder, UpdatePayload> {
|
||||
|
||||
private String id;
|
||||
private String bootFromStorageId;
|
||||
private String bootFromImageId;
|
||||
private AvailabilityZone availabilityZone;
|
||||
private OsType osType;
|
||||
|
||||
public Builder id( String id ) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bootFromStorageId( String storageId ) {
|
||||
this.bootFromStorageId = storageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bootFromImageId( String image ) {
|
||||
this.bootFromImageId = image;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder availabilityZone( AvailabilityZone zone ) {
|
||||
this.availabilityZone = zone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder osType( OsType osType ) {
|
||||
this.osType = osType;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdatePayload build() {
|
||||
return UpdatePayload.create( id, name, cores, ram, bootFromStorageId, bootFromImageId, availabilityZone, osType,
|
||||
cpuHotPlug, ramHotPlug, nicHotPlug, nicHotUnPlug, discVirtioHotPlug, discVirtioHotUnPlug );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void validateCores( int cores ) {
|
||||
checkArgument( cores > 0, "Core must be atleast 1." );
|
||||
}
|
||||
|
||||
private static void validateRam( int ram, Boolean isRamHotPlug ) {
|
||||
int minRam = ( isRamHotPlug == null || !isRamHotPlug ) ? 256 : 1024;
|
||||
checkArgument( ram >= minRam && ram % 256 == 0, "RAM must be multiples of 256 with minimum of 256 MB (1024 MB if ramHotPlug is enabled)" );
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.domain.internal;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* An interface used as common data type for {@link org.jclouds.profitbricks.domain.Server.Builder}
|
||||
*/
|
||||
public interface ServerCommonProperties {
|
||||
|
||||
@Nullable
|
||||
Boolean isCpuHotPlug();
|
||||
|
||||
@Nullable
|
||||
Boolean isRamHotPlug();
|
||||
|
||||
@Nullable
|
||||
Boolean isNicHotPlug();
|
||||
|
||||
@Nullable
|
||||
Boolean isNicHotUnPlug();
|
||||
|
||||
@Nullable
|
||||
Boolean isDiscVirtioHotPlug();
|
||||
|
||||
@Nullable
|
||||
Boolean isDiscVirtioHotUnPlug();
|
||||
|
||||
String name();
|
||||
|
||||
int cores();
|
||||
|
||||
int ram(); // in MB
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.features;
|
||||
|
||||
import java.util.List;
|
||||
import javax.inject.Named;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.jclouds.Fallbacks;
|
||||
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||
import org.jclouds.profitbricks.http.parser.image.ImageInfoResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.image.ImageListResponseHandler;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.Payload;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
|
||||
@RequestFilters({BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class})
|
||||
@Consumes(MediaType.TEXT_XML)
|
||||
@Produces(MediaType.TEXT_XML)
|
||||
public interface ImageApi {
|
||||
|
||||
/**
|
||||
* @return Outputs a list of all HDD and/or CD-ROM/DVD images existing on or uploaded to the ProfitBricks FTP server.
|
||||
*/
|
||||
@POST
|
||||
@Named("image:getall")
|
||||
@Payload("<ws:getAllImages/>")
|
||||
@XMLResponseParser(ImageListResponseHandler.class)
|
||||
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||
List<Image> getAllImages();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param identifier Image Id
|
||||
* @return Returns information about a HDD or CD-ROM/DVD (ISO) image.
|
||||
*/
|
||||
@POST
|
||||
@Named("image:get")
|
||||
@Payload("<ws:getImage><imageId>{id}</imageId></ws:getImage>")
|
||||
@XMLResponseParser(ImageInfoResponseHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
Image getImage(@PayloadParam("id") String identifier);
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.features;
|
||||
|
||||
import java.util.List;
|
||||
import javax.inject.Named;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.jclouds.Fallbacks;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.profitbricks.binder.server.CreateServerRequestBinder;
|
||||
import org.jclouds.profitbricks.binder.server.UpdateServerRequestBinder;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||
import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.server.ServerIdOnlyResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.server.ServerInfoResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.server.ServerListResponseHandler;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.Payload;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
|
||||
@RequestFilters( { BasicAuthentication.class, ProfitBricksSoapMessageEnvelope.class } )
|
||||
@Consumes( MediaType.TEXT_XML )
|
||||
@Produces( MediaType.TEXT_XML )
|
||||
public interface ServerApi {
|
||||
|
||||
/**
|
||||
* @return Returns information about all virtual server, such as configuration, provisioning status, power status, etc.
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:getall" )
|
||||
@Payload( "<ws:getAllServers/>" )
|
||||
@XMLResponseParser( ServerListResponseHandler.class )
|
||||
@Fallback( Fallbacks.EmptyListOnNotFoundOr404.class )
|
||||
List<Server> getAllServers();
|
||||
|
||||
/**
|
||||
* @param identifier Identifier of the virtual server
|
||||
* @return Returns information about a virtual server, such as configuration, provisioning status, power status, etc.
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:get" )
|
||||
@Payload( "<ws:getServer><serverId>{id}</serverId></ws:getServer>" )
|
||||
@XMLResponseParser( ServerInfoResponseHandler.class )
|
||||
@Fallback( Fallbacks.NullOnNotFoundOr404.class )
|
||||
Server getServer( @PayloadParam( "id" ) String identifier );
|
||||
|
||||
/**
|
||||
* Starts an existing virtual server
|
||||
* <ul>
|
||||
* <li>Server may receive new public IP addresses if necessary </li>
|
||||
* <li>Billing will continue</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* @param id Identifier of the target virtual server
|
||||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:start" )
|
||||
@Payload( "<ws:startServer><serverId>{id}</serverId></ws:startServer>" )
|
||||
@XMLResponseParser( RequestIdOnlyResponseHandler.class )
|
||||
String startServer( @PayloadParam( "id" ) String id );
|
||||
|
||||
/**
|
||||
*
|
||||
* Stops an existing virtual server forcefully (HARD stop)
|
||||
* <ul>
|
||||
* <li>Server will be forcefully powered off. Any unsaved data may be lost! </li>
|
||||
* <li>Billing for this server will be stopped </li>
|
||||
* <li>When restarting the server a new public IP gets assigned, alternatively, you can reserve IP addresses, see reservation of public
|
||||
* IP blocks</li>
|
||||
* </ul>
|
||||
*
|
||||
* A graceful stop of a server is not possible through the ProfitBricks API. We recommend to access and execute the command on the
|
||||
* virtual server directly. Once the server was shutdown you still can use the "stopServer" method that will stop billing.
|
||||
*
|
||||
* @param id Identifier of the target virtual server
|
||||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:stop" )
|
||||
@Payload( "<ws:stopServer><serverId>{id}</serverId></ws:stopServer>" )
|
||||
@XMLResponseParser( RequestIdOnlyResponseHandler.class )
|
||||
String stopServer( @PayloadParam( "id" ) String id );
|
||||
|
||||
/**
|
||||
* Resets an existing virtual server (POWER CYCLE).
|
||||
* <ul>
|
||||
* <li>Server will be forcefully powered off and restarted immediately. Any unsaved data may be lost!</li>
|
||||
* <li> Billing will continue</li>
|
||||
* </ul>
|
||||
* <b>Graceful REBOOT</b>
|
||||
*
|
||||
* A graceful reboot of a server is not possible through the ProfitBricks API. We recommend to access and execute the command on the
|
||||
* virtual server directly.
|
||||
*
|
||||
* @param id Identifier of the target virtual server
|
||||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:reset" )
|
||||
@Payload( "<ws:resetServer><serverId>{id}</serverId></ws:resetServer>" )
|
||||
@XMLResponseParser( RequestIdOnlyResponseHandler.class )
|
||||
String resetServer( @PayloadParam( "id" ) String id );
|
||||
|
||||
/**
|
||||
* Creates a Virtual Server within an existing data center. Parameters can be specified to set up a boot device and connect the server to
|
||||
* an existing LAN or the Internet.
|
||||
*
|
||||
* @param payload Payload
|
||||
* @return serverId of the created server
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:create" )
|
||||
@MapBinder( CreateServerRequestBinder.class )
|
||||
@XMLResponseParser( ServerIdOnlyResponseHandler.class )
|
||||
String createServer( @PayloadParam( "server" ) Server.Request.CreatePayload payload );
|
||||
|
||||
/**
|
||||
* Updates parameters of an existing virtual server device.
|
||||
*
|
||||
* @param payload Paylaod
|
||||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:update" )
|
||||
@MapBinder( UpdateServerRequestBinder.class )
|
||||
@XMLResponseParser( RequestIdOnlyResponseHandler.class )
|
||||
String updateServer( @PayloadParam( "server" ) Server.Request.UpdatePayload payload );
|
||||
|
||||
/**
|
||||
* Deletes an existing Virtual Server.
|
||||
*
|
||||
* @param id Identifier of the target virtual server
|
||||
* @return Identifier of current request
|
||||
*/
|
||||
@POST
|
||||
@Named( "server:delete" )
|
||||
@Payload( "<ws:deleteServer><serverId>{id}</serverId></ws:deleteServer>" )
|
||||
@Fallback( Fallbacks.FalseOnNotFoundOr404.class )
|
||||
boolean deleteServer( @PayloadParam( "id" ) String id );
|
||||
|
||||
}
|
@ -49,6 +49,14 @@ public abstract class BaseProfitBricksResponseHandler<T> extends ParseSax.Handle
|
||||
return strBuilder.toString().trim();
|
||||
}
|
||||
|
||||
protected Float textToFloatValue() {
|
||||
return Float.valueOf(textToStringValue());
|
||||
}
|
||||
|
||||
protected Double textToDoubleValue(){
|
||||
return Double.valueOf( textToStringValue());
|
||||
}
|
||||
|
||||
protected int textToIntValue() {
|
||||
return Integer.parseInt(textToStringValue());
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class RequestIdOnlyResponseHandler extends BaseProfitBricksResponseHandler<String> {
|
||||
|
||||
private String requestId;
|
||||
|
||||
@Inject
|
||||
RequestIdOnlyResponseHandler( DateCodecFactory dateCodec ) {
|
||||
super( dateCodec );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement( String uri, String localName, String qName ) throws SAXException {
|
||||
setPropertyOnEndTag( qName );
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag( String qName ) {
|
||||
if ( "requestId".equals( qName ) )
|
||||
requestId = textToStringValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResult() {
|
||||
return requestId;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.image;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import org.jclouds.profitbricks.domain.Image.Type;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.domain.OsType;
|
||||
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||
|
||||
public abstract class BaseImageResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||
|
||||
protected Image.Builder builder;
|
||||
|
||||
@Inject
|
||||
BaseImageResponseHandler(DateCodecFactory dateCodecFactory) {
|
||||
super(dateCodecFactory);
|
||||
this.builder = Image.builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
if ("imageId".equals(qName))
|
||||
builder.id(textToStringValue());
|
||||
else if ("imageName".equals(qName))
|
||||
builder.name(textToStringValue());
|
||||
else if ("imageSize".equals(qName))
|
||||
builder.size(textToFloatValue());
|
||||
else if ("imageType".equals(qName))
|
||||
builder.type(Type.fromValue(textToStringValue()));
|
||||
else if ("location".equals(qName))
|
||||
builder.location(Location.fromId(textToStringValue()));
|
||||
else if ("osType".equals(qName))
|
||||
builder.osType(OsType.fromValue(textToStringValue()));
|
||||
else if ("public".equals(qName))
|
||||
builder.isPublic(textToBooleanValue());
|
||||
else if ("writeable".equals(qName))
|
||||
builder.isWriteable(textToBooleanValue());
|
||||
else if ("bootable".equals(qName))
|
||||
builder.isBootable(textToBooleanValue());
|
||||
else if ("cpuHotPlug".equals(qName))
|
||||
builder.isCpuHotPlug(textToBooleanValue());
|
||||
else if ("cpuHotUnPlug".equals(qName))
|
||||
builder.isCpuHotUnPlug(textToBooleanValue());
|
||||
else if ("ramHotPlug".equals(qName))
|
||||
builder.isRamHotPlug(textToBooleanValue());
|
||||
else if ("ramHotUnPlug".equals(qName))
|
||||
builder.isRamHotUnPlug(textToBooleanValue());
|
||||
else if ("nicHotPlug".equals(qName))
|
||||
builder.isNicHotPlug(textToBooleanValue());
|
||||
else if ("nicHotUnPlug".equals(qName))
|
||||
builder.isNicHotUnPlug(textToBooleanValue());
|
||||
else if ("discVirtioHotPlug".equals(qName))
|
||||
builder.isDiscVirtioHotPlug(textToBooleanValue());
|
||||
else if ("discVirtioHotUnPlug".equals(qName))
|
||||
builder.isDiscVirtioHotUnPlug(textToBooleanValue());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.image;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class ImageInfoResponseHandler extends BaseImageResponseHandler<Image> {
|
||||
|
||||
private boolean done = false;
|
||||
|
||||
@Inject
|
||||
ImageInfoResponseHandler(DateCodecFactory dateCodecFactory) {
|
||||
super(dateCodecFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (done)
|
||||
return;
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName))
|
||||
done = true;
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getResult() {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.image;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class ImageListResponseHandler extends BaseImageResponseHandler<List<Image>> {
|
||||
|
||||
private final List<Image> images;
|
||||
|
||||
@Inject
|
||||
ImageListResponseHandler(DateCodecFactory dateCodecFactory) {
|
||||
super(dateCodecFactory);
|
||||
this.images = Lists.newArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName)) {
|
||||
images.add(builder.build());
|
||||
builder = Image.builder();
|
||||
}
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Image> getResult() {
|
||||
return images;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.server;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.AvailabilityZone;
|
||||
import org.jclouds.profitbricks.domain.OsType;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||
|
||||
public abstract class BaseServerResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||
|
||||
protected Server.DescribingBuilder builder;
|
||||
|
||||
@Inject
|
||||
BaseServerResponseHandler( DateCodecFactory dateCodec ) {
|
||||
super( dateCodec );
|
||||
this.builder = Server.builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag( String qName ) {
|
||||
if ( "serverId".equals( qName ) )
|
||||
builder.id( textToStringValue() );
|
||||
else if ( "serverName".equals( qName ) )
|
||||
builder.name( textToStringValue() );
|
||||
else if ( "cores".equals( qName ) )
|
||||
builder.cores( textToIntValue() );
|
||||
else if ( "ram".equals( qName ) )
|
||||
builder.ram( textToIntValue() );
|
||||
else if ( "provisioningState".equals( qName ) )
|
||||
builder.state( ProvisioningState.fromValue( textToStringValue() ) );
|
||||
else if ( "virtualMachineState".equals( qName ) )
|
||||
builder.status( Server.Status.fromValue( textToStringValue() ) );
|
||||
else if ( "osType".equals( qName ) )
|
||||
builder.osType( OsType.fromValue( textToStringValue() ) );
|
||||
else if ( "availabilityZone".equals( qName ) )
|
||||
builder.availabilityZone( AvailabilityZone.fromValue( textToStringValue() ) );
|
||||
else if ( "creationTime".equals( qName ) )
|
||||
builder.creationTime( textToIso8601Date() );
|
||||
else if ( "lastModificationTime".equals( qName ) )
|
||||
builder.lastModificationTime( textToIso8601Date() );
|
||||
else if ( "internetAccess".equals( qName ) )
|
||||
builder.hasInternetAccess( textToBooleanValue() );
|
||||
else if ( "cpuHotPlug".equals( qName ) )
|
||||
builder.isCpuHotPlug( textToBooleanValue() );
|
||||
else if ( "ramHotPlug".equals( qName ) )
|
||||
builder.isRamHotPlug( textToBooleanValue() );
|
||||
else if ( "nicHotPlug".equals( qName ) )
|
||||
builder.isNicHotPlug( textToBooleanValue() );
|
||||
else if ( "nicHotUnPlug".equals( qName ) )
|
||||
builder.isNicHotUnPlug( textToBooleanValue() );
|
||||
else if ( "discVirtioHotPlug".equals( qName ) )
|
||||
builder.isDiscVirtioHotPlug( textToBooleanValue() );
|
||||
else if ( "discVirtioHotUnPlug".equals( qName ) )
|
||||
builder.isDiscVirtioHotUnPlug( textToBooleanValue() );
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.server;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Handler for parsing SOAP response where <i>serverId</i> is the only <i>usable</i> value.
|
||||
*
|
||||
* Other properties available (which are ignored): requestId, dataCenterId, dataCenterVersion
|
||||
*/
|
||||
public class ServerIdOnlyResponseHandler extends BaseProfitBricksResponseHandler<String> {
|
||||
|
||||
private String serverId;
|
||||
|
||||
@Inject
|
||||
ServerIdOnlyResponseHandler( DateCodecFactory dateCodec ) {
|
||||
super( dateCodec );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement( String uri, String localName, String qName ) throws SAXException {
|
||||
setPropertyOnEndTag( qName );
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag( String qName ) {
|
||||
if ( "serverId".equals( qName ) )
|
||||
serverId = textToStringValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResult() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.server;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class ServerInfoResponseHandler extends BaseServerResponseHandler<Server> {
|
||||
|
||||
private boolean done = false;
|
||||
|
||||
@Inject
|
||||
ServerInfoResponseHandler( DateCodecFactory dateCodec ) {
|
||||
super( dateCodec );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement( String uri, String localName, String qName ) throws SAXException {
|
||||
if ( done )
|
||||
return;
|
||||
setPropertyOnEndTag( qName );
|
||||
if ( "return".equals( qName ) )
|
||||
done = true;
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getResult() {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.server;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class ServerListResponseHandler extends BaseServerResponseHandler<List<Server>> {
|
||||
|
||||
private final List<Server> servers;
|
||||
|
||||
@Inject
|
||||
ServerListResponseHandler( DateCodecFactory dateCodec ) {
|
||||
super( dateCodec );
|
||||
this.servers = Lists.newArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement( String uri, String localName, String qName ) throws SAXException {
|
||||
setPropertyOnEndTag( qName );
|
||||
if ( "return".equals( qName ) ) {
|
||||
servers.add( builder.build() );
|
||||
builder = Server.builder();
|
||||
}
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Server> getResult() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.binder.server;
|
||||
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "CreateServerRequestBinderTest" )
|
||||
public class CreateServerRequestBinderTest {
|
||||
|
||||
@Test
|
||||
public void testCreatePayload() {
|
||||
CreateServerRequestBinder binder = new CreateServerRequestBinder();
|
||||
|
||||
Server.Request.CreatePayload payload = Server.Request.creatingBuilder()
|
||||
.name( "jclouds-node" )
|
||||
.cores( 4 )
|
||||
.ram( 4 * 1024 )
|
||||
.dataCenterId( "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" )
|
||||
.build();
|
||||
|
||||
String actual = binder.createPayload( payload );
|
||||
assertNotNull( actual, "Binder returned null payload" );
|
||||
assertEquals( actual, expectedPayload );
|
||||
}
|
||||
|
||||
private final String expectedPayload
|
||||
= ( " <ws:createServer>\n"
|
||||
+ " <request>\n"
|
||||
+ " <dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>\n"
|
||||
+ " <cores>4</cores>\n"
|
||||
+ " <ram>4096</ram>\n"
|
||||
+ " <serverName>jclouds-node</serverName>\n"
|
||||
// + " <bootFromStorageId>?</bootFromStorageId>\n"
|
||||
// + " <bootFromImageId>?</bootFromImageId>\n"
|
||||
// + " <internetAccess>false</internetAccess>\n"
|
||||
// + " <lanId>?</lanId>\n"
|
||||
// + " <osType>?</osType>\n"
|
||||
// + " <availabilityZone>AUTO</availabilityZone>\n"
|
||||
// + " <cpuHotPlug>false</cpuHotPlug>\n"
|
||||
// + " <ramHotPlug>false</ramHotPlug>\n"
|
||||
// + " <nicHotPlug>false</nicHotPlug>\n"
|
||||
// + " <nicHotUnPlug>false</nicHotUnPlug>\n"
|
||||
// + " <discVirtioHotPlug>false</discVirtioHotPlug>\n"
|
||||
// + " <discVirtioHotUnPlug>false</discVirtioHotUnPlug>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:createServer>" )
|
||||
.replaceAll( "\\s+", "" );
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.binder.server;
|
||||
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "UpdateServerRequestBinderTest" )
|
||||
public class UpdateServerRequestBinderTest {
|
||||
|
||||
@Test
|
||||
public void testCreatePayload() {
|
||||
UpdateServerRequestBinder binder = new UpdateServerRequestBinder();
|
||||
|
||||
Server.Request.UpdatePayload payload = Server.Request.updatingBuilder()
|
||||
.id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" )
|
||||
.cores( 8 )
|
||||
.ram( 8 * 1024 )
|
||||
.name( "apache-node")
|
||||
.build();
|
||||
|
||||
String actual = binder.createPayload( payload );
|
||||
assertNotNull(actual, "Binder returned null payload");
|
||||
assertEquals(actual, expectedPayload);
|
||||
}
|
||||
|
||||
private final String expectedPayload
|
||||
= ( " <ws:updateServer>\n"
|
||||
+ " <request>\n"
|
||||
+ " <serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId>\n"
|
||||
+ " <cores>8</cores>\n"
|
||||
+ " <ram>8192</ram>\n"
|
||||
+ " <serverName>apache-node</serverName>\n"
|
||||
// + " <bootFromStorageId>?</bootFromStorageId>\n"
|
||||
// + " <bootFromImageId>?</bootFromImageId>\n"
|
||||
// + " <osType>?</osType>\n"
|
||||
// + " <availabilityZone>?</availabilityZone>\n"
|
||||
// + " <cpuHotPlug>?</cpuHotPlug>\n"
|
||||
// + " <ramHotPlug>?</ramHotPlug>\n"
|
||||
// + " <nicHotPlug>?</nicHotPlug>\n"
|
||||
// + " <nicHotUnPlug>?</nicHotUnPlug>\n"
|
||||
// + " <discVirtioHotPlug>?</discVirtioHotPlug>\n"
|
||||
// + " <discVirtioHotUnPlug>?</discVirtioHotUnPlug>\n"
|
||||
+ " </request>\n"
|
||||
+ " </ws:updateServer>" )
|
||||
.replaceAll( "\\s+", "" );
|
||||
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ServerBuilderTest" )
|
||||
public class ServerBuilderTest {
|
||||
|
||||
private final Boolean _isCpuHotPlug = true;
|
||||
private final Boolean _isRamHotPlug = false;
|
||||
private final Boolean _isNicHotPlug = true;
|
||||
private final Boolean _isNicHotUnPlug = false;
|
||||
private final Boolean _isDiscVirtioHotPlug = true;
|
||||
private final Boolean _isDiscVirtioHotUnPlug = false;
|
||||
private final int _cores = 8;
|
||||
private final int _ram = 8 * 1024;
|
||||
private final String _id = "some-random-server-id";
|
||||
private final String _name = "jclouds-node";
|
||||
private final Boolean _hasInternetAccess = true;
|
||||
private final ProvisioningState _state = ProvisioningState.INACTIVE;
|
||||
private final Server.Status _status = Server.Status.SHUTOFF;
|
||||
private final OsType _osType = OsType.LINUX;
|
||||
private final AvailabilityZone _availabilityZone = AvailabilityZone.ZONE_1;
|
||||
private final Date _creationTime = new Date();
|
||||
private final Date _lastModificationTime = new Date();
|
||||
|
||||
private final Integer _lanId = 5;
|
||||
private final String _dataCenterId = "some-random-datacenter-id";
|
||||
private final String _bootFromStorageId = "some-random-storage-id";
|
||||
private final String _bootFromImageId = "some-random-image-id";
|
||||
|
||||
private final String _serverId = "some-random-server-id";
|
||||
|
||||
@Test
|
||||
public void testAutoValueServerPropertiesSettingCorrectly() {
|
||||
Server actual = Server.builder()
|
||||
.availabilityZone( _availabilityZone )
|
||||
.creationTime( _creationTime )
|
||||
.cores( _cores )
|
||||
.hasInternetAccess( _hasInternetAccess )
|
||||
.id( _id )
|
||||
.name( _name )
|
||||
.isCpuHotPlug( _isCpuHotPlug )
|
||||
.isDiscVirtioHotPlug( _isDiscVirtioHotPlug )
|
||||
.isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug )
|
||||
.isNicHotPlug( _isNicHotPlug )
|
||||
.isNicHotUnPlug( _isNicHotUnPlug )
|
||||
.isRamHotPlug( _isRamHotPlug )
|
||||
.lastModificationTime( _lastModificationTime )
|
||||
.ram( _ram )
|
||||
.osType( _osType )
|
||||
.state( _state )
|
||||
.status( _status )
|
||||
.build();
|
||||
|
||||
assertEquals( actual.availabilityZone(), _availabilityZone );
|
||||
assertEquals( actual.cores(), _cores );
|
||||
assertEquals( actual.creationTime(), _creationTime );
|
||||
assertEquals( actual.hasInternetAccess(), _hasInternetAccess );
|
||||
assertEquals( actual.id(), _id );
|
||||
assertEquals( actual.name(), _name );
|
||||
assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug );
|
||||
assertEquals( actual.isNicHotPlug(), _isNicHotPlug );
|
||||
assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug );
|
||||
assertEquals( actual.isRamHotPlug(), _isRamHotPlug );
|
||||
assertEquals( actual.lastModificationTime(), _lastModificationTime );
|
||||
assertEquals( actual.ram(), _ram );
|
||||
assertEquals( actual.osType(), _osType );
|
||||
assertEquals( actual.state(), _state );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoValueServerRequestCreatePayloadPropertiesSettingCorrectly() {
|
||||
Server.Request.CreatePayload actual = Server.Request.creatingBuilder()
|
||||
.availabilityZone( _availabilityZone )
|
||||
.bootFromImageId( _bootFromImageId )
|
||||
.bootFromStorageId( _bootFromStorageId )
|
||||
.cores( _cores )
|
||||
.dataCenterId( _dataCenterId )
|
||||
.hasInternetAccess( _hasInternetAccess )
|
||||
.name( _name )
|
||||
.isCpuHotPlug( _isCpuHotPlug )
|
||||
.isDiscVirtioHotPlug( _isDiscVirtioHotPlug )
|
||||
.isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug )
|
||||
.isNicHotPlug( _isNicHotPlug )
|
||||
.isNicHotUnPlug( _isNicHotUnPlug )
|
||||
.isRamHotPlug( _isRamHotPlug )
|
||||
.lanId( _lanId )
|
||||
.ram( _ram )
|
||||
.osType( _osType )
|
||||
.build();
|
||||
|
||||
assertEquals( actual.availabilityZone(), _availabilityZone );
|
||||
assertEquals( actual.bootFromImageId(), _bootFromImageId );
|
||||
assertEquals( actual.bootFromStorageId(), _bootFromStorageId );
|
||||
assertEquals( actual.cores(), _cores );
|
||||
assertEquals( actual.dataCenterId(), _dataCenterId );
|
||||
assertEquals( actual.hasInternetAccess(), _hasInternetAccess );
|
||||
assertEquals( actual.name(), _name );
|
||||
assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug );
|
||||
assertEquals( actual.isNicHotPlug(), _isNicHotPlug );
|
||||
assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug );
|
||||
assertEquals( actual.isRamHotPlug(), _isRamHotPlug );
|
||||
assertEquals( actual.lanId(), _lanId );
|
||||
assertEquals( actual.ram(), _ram );
|
||||
assertEquals( actual.osType(), _osType );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoValueServerRequestUpdatePayloadPropertiesSettingCorrectly() {
|
||||
Server.Request.UpdatePayload actual = Server.Request.updatingBuilder()
|
||||
.availabilityZone( _availabilityZone )
|
||||
.bootFromImageId( _bootFromImageId )
|
||||
.bootFromStorageId( _bootFromStorageId )
|
||||
.cores( _cores )
|
||||
.name( _name )
|
||||
.id( _id )
|
||||
.isCpuHotPlug( _isCpuHotPlug )
|
||||
.isDiscVirtioHotPlug( _isDiscVirtioHotPlug )
|
||||
.isDiscVirtioHotUnPlug( _isDiscVirtioHotUnPlug )
|
||||
.isNicHotPlug( _isNicHotPlug )
|
||||
.isNicHotUnPlug( _isNicHotUnPlug )
|
||||
.isRamHotPlug( _isRamHotPlug )
|
||||
.ram( _ram )
|
||||
.osType( _osType )
|
||||
.build();
|
||||
|
||||
assertEquals( actual.availabilityZone(), _availabilityZone );
|
||||
assertEquals( actual.bootFromImageId(), _bootFromImageId );
|
||||
assertEquals( actual.bootFromStorageId(), _bootFromStorageId );
|
||||
assertEquals( actual.cores(), _cores );
|
||||
assertEquals( actual.name(), _name );
|
||||
assertEquals( actual.id(), _id );
|
||||
assertEquals( actual.isCpuHotPlug(), _isCpuHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug );
|
||||
assertEquals( actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug );
|
||||
assertEquals( actual.isNicHotPlug(), _isNicHotPlug );
|
||||
assertEquals( actual.isNicHotUnPlug(), _isNicHotUnPlug );
|
||||
assertEquals( actual.isRamHotPlug(), _isRamHotPlug );
|
||||
assertEquals( actual.ram(), _ram );
|
||||
assertEquals( actual.osType(), _osType );
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
||||
|
||||
try {
|
||||
List<DataCenter> dataCenters = api.getAllDataCenters();
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllDataCenters/>");
|
||||
assertNotNull(dataCenters);
|
||||
assertEquals(dataCenters.size(), 2);
|
||||
} finally {
|
||||
@ -87,9 +87,10 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
||||
String id = "12345678-abcd-efgh-ijkl-987654321000";
|
||||
String content = "<ws:getDataCenter><dataCenterId>" + id + "</dataCenterId></ws:getDataCenter>";
|
||||
try {
|
||||
DataCenter dataCenter = api.getDataCenter(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content );
|
||||
assertNotNull(dataCenter);
|
||||
assertEquals(dataCenter.id(), id);
|
||||
} finally {
|
||||
@ -101,7 +102,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
||||
@Test
|
||||
public void testGetNonExistingDataCenter() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml")));
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
@ -126,9 +127,10 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
||||
String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
String content = "<ws:getDataCenterState><dataCenterId>" + id + "</dataCenterId></ws:getDataCenterState>";
|
||||
try {
|
||||
ProvisioningState state = api.getDataCenterState(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content );
|
||||
assertNotNull(state);
|
||||
assertEquals(state, ProvisioningState.AVAILABLE);
|
||||
} finally {
|
||||
@ -145,11 +147,15 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
||||
String content = "<ws:createDataCenter><request>"
|
||||
+ "<dataCenterName>JClouds-DC</dataCenterName>"
|
||||
+ "<location>de/fra</location>"
|
||||
+ "</request></ws:createDataCenter>";
|
||||
try {
|
||||
DataCenter dataCenter = api.createDataCenter(
|
||||
DataCenter.Request.CreatePayload.create("JClouds-DC", Location.DE_FRA)
|
||||
);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content );
|
||||
assertNotNull(dataCenter);
|
||||
assertEquals(dataCenter.id(), "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
|
||||
assertEquals(dataCenter.version(), 1);
|
||||
@ -179,13 +185,19 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
||||
|
||||
String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
String newName = "Apache";
|
||||
|
||||
String content = "<ws:updateDataCenter><request>"
|
||||
+ "<dataCenterId>" + id + "</dataCenterId>"
|
||||
+ "<dataCenterName>" + newName + "</dataCenterName>"
|
||||
+ "</request></ws:updateDataCenter>";
|
||||
try {
|
||||
DataCenter dataCenter = api.updateDataCenter(
|
||||
DataCenter.Request.UpdatePayload.create(id, "Apache")
|
||||
DataCenter.Request.UpdatePayload.create(id, newName)
|
||||
);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(dataCenter);
|
||||
assertEquals(dataCenter.id(), id);
|
||||
assertEquals(dataCenter.version(), 2);
|
||||
@ -204,10 +216,12 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
||||
String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
|
||||
String content = "<ws:clearDataCenter><dataCenterId>" + id + "</dataCenterId></ws:clearDataCenter>";
|
||||
try {
|
||||
DataCenter dataCenter = api.clearDataCenter(id);
|
||||
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(dataCenter);
|
||||
assertEquals(dataCenter.id(), id);
|
||||
assertEquals(dataCenter.version(), 3);
|
||||
@ -225,9 +239,12 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
||||
String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
|
||||
String content = "<ws:deleteDataCenter><dataCenterId>" + id + "</dataCenterId></ws:deleteDataCenter>";
|
||||
try {
|
||||
boolean result = api.deleteDataCenter("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
boolean result = api.deleteDataCenter(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertTrue(result);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
@ -238,7 +255,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest {
|
||||
@Test
|
||||
public void testDeleteNonExistingDataCenter() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml")));
|
||||
server.enqueue(new MockResponse().setResponseCode( 404 ));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
DataCenterApi api = pbApi.dataCenterApi();
|
||||
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.features;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.util.List;
|
||||
import org.jclouds.profitbricks.BaseProfitBricksLiveTest;
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test(groups = "live", testName = "ImageApiLiveTest", singleThreaded = true)
|
||||
public class ImageApiLiveTest extends BaseProfitBricksLiveTest {
|
||||
|
||||
private String imageId;
|
||||
|
||||
@Test
|
||||
public void testGetAllImages() {
|
||||
List<Image> images = api.imageApi().getAllImages();
|
||||
|
||||
assertNotNull(images);
|
||||
assertFalse(images.isEmpty(), "No images found.");
|
||||
imageId = Iterables.getFirst(images, null).id();
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testGetAllImages")
|
||||
public void testGetImage() {
|
||||
Image image = api.imageApi().getImage(imageId);
|
||||
|
||||
assertNotNull(image);
|
||||
assertEquals(image.id(), imageId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNonExistingImage() {
|
||||
String id = "random-non-existing-id";
|
||||
Image image = api.imageApi().getImage(id);
|
||||
|
||||
assertNull(image, "Should've just returned null");
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.features;
|
||||
|
||||
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||
import java.util.List;
|
||||
import org.jclouds.profitbricks.ProfitBricksApi;
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
|
||||
import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Mock tests for the {@link org.jclouds.profitbricks.features.ImageApi} class
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ImageApiMockTest")
|
||||
public class ImageApiMockTest extends BaseProfitBricksMockTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllImages() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/image/images.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ImageApi api = pbApi.imageApi();
|
||||
|
||||
try {
|
||||
List<Image> images = api.getAllImages();
|
||||
assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllImages/>");
|
||||
assertNotNull(images);
|
||||
assertTrue(images.size() == 7);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllImagesReturning404() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ImageApi api = pbApi.imageApi();
|
||||
|
||||
try {
|
||||
List<Image> images = api.getAllImages();
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertTrue(images.isEmpty());
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetImage() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/image/image.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ImageApi api = pbApi.imageApi();
|
||||
|
||||
String id = "5ad99c9e-9166-11e4-9d74-52540066fee9";
|
||||
|
||||
String content = "<ws:getImage><imageId>" + id + "</imageId></ws:getImage>";
|
||||
try {
|
||||
Image image = api.getImage(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(image);
|
||||
assertEquals(image.id(), id);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNonExistingImage() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
ImageApi api = pbApi.imageApi();
|
||||
|
||||
String id = "random-non-existing-id";
|
||||
try {
|
||||
Image image = api.getImage(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertNull(image);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.features;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.jclouds.profitbricks.BaseProfitBricksLiveTest;
|
||||
import org.jclouds.profitbricks.compute.internal.ProvisioningStatusAware;
|
||||
import org.jclouds.profitbricks.compute.internal.ProvisioningStatusPollingPredicate;
|
||||
import org.jclouds.profitbricks.domain.DataCenter;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.util.Predicates2;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "live", testName = "ServerApiLiveTest", singleThreaded = true )
|
||||
public class ServerApiLiveTest extends BaseProfitBricksLiveTest {
|
||||
|
||||
private Predicate<String> waitUntilAvailable;
|
||||
private DataCenter dataCenter;
|
||||
private String createdServerId;
|
||||
|
||||
@Override
|
||||
protected void initialize() {
|
||||
super.initialize();
|
||||
List<DataCenter> dataCenters = api.dataCenterApi().getAllDataCenters();
|
||||
assertFalse( dataCenters.isEmpty(), "Must atleast have 1 datacenter available for server testing." );
|
||||
|
||||
this.dataCenter = Iterables.getFirst( dataCenters, null );
|
||||
|
||||
this.waitUntilAvailable = Predicates2.retry(
|
||||
new ProvisioningStatusPollingPredicate( api, ProvisioningStatusAware.SERVER, ProvisioningState.AVAILABLE ),
|
||||
2l * 60l, 2l, TimeUnit.SECONDS );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateServer() {
|
||||
String serverId = api.serverApi().createServer(
|
||||
Server.Request.CreatePayload.create( dataCenter.id(), "jclouds-node", 1, 1024 ) );
|
||||
|
||||
assertNotNull( serverId );
|
||||
this.createdServerId = serverId;
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testCreateServer" )
|
||||
public void testGetServer() {
|
||||
Server server = api.serverApi().getServer( createdServerId );
|
||||
|
||||
assertNotNull( server );
|
||||
assertEquals( server.id(), createdServerId );
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testCreateServer" )
|
||||
public void testGetAllServers() {
|
||||
List<Server> servers = api.serverApi().getAllServers();
|
||||
|
||||
assertNotNull( servers );
|
||||
assertFalse( servers.isEmpty() );
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testCreateServer" )
|
||||
public void testWaitUntilAvailable() {
|
||||
boolean available = waitUntilAvailable.apply( createdServerId );
|
||||
|
||||
assertTrue( available );
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testWaitUntilAvailable" )
|
||||
public void testUpdateServer() {
|
||||
String requestId = api.serverApi().updateServer(
|
||||
Server.Request.updatingBuilder()
|
||||
.id( createdServerId )
|
||||
.name( "apache-node" )
|
||||
.cores( 2 )
|
||||
.ram( 2 * 1024 )
|
||||
.build() );
|
||||
|
||||
assertNotNull( requestId );
|
||||
waitUntilAvailable.apply( createdServerId );
|
||||
|
||||
Server server = api.serverApi().getServer( createdServerId );
|
||||
assertEquals( server.state(), ProvisioningState.AVAILABLE );
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testUpdateServer" )
|
||||
public void testStopServer() {
|
||||
String requestId = api.serverApi().stopServer( createdServerId );
|
||||
assertNotNull( requestId );
|
||||
|
||||
Predicate<String> waitUntilInactive = Predicates2.retry( new ProvisioningStatusPollingPredicate(
|
||||
api, ProvisioningStatusAware.SERVER, ProvisioningState.INACTIVE ), 2l * 60l, 2l, TimeUnit.SECONDS );
|
||||
|
||||
waitUntilInactive.apply( createdServerId );
|
||||
Server server = api.serverApi().getServer( createdServerId );
|
||||
assertEquals( server.status(), Server.Status.SHUTOFF );
|
||||
}
|
||||
|
||||
@Test( dependsOnMethods = "testStopServer" )
|
||||
public void testStartServer() {
|
||||
String requestId = api.serverApi().startServer( createdServerId );
|
||||
assertNotNull( requestId );
|
||||
|
||||
waitUntilAvailable.apply( createdServerId );
|
||||
|
||||
Server server = api.serverApi().getServer( createdServerId );
|
||||
assertEquals( server.status(), Server.Status.RUNNING );
|
||||
}
|
||||
|
||||
@AfterClass( alwaysRun = true )
|
||||
public void testDeleteServer() {
|
||||
if ( createdServerId != null ) {
|
||||
boolean result = api.serverApi().deleteServer( createdServerId );
|
||||
|
||||
assertTrue( result, "Created test server was not deleted." );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,338 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.features;
|
||||
|
||||
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||
import java.util.List;
|
||||
import org.jclouds.profitbricks.ProfitBricksApi;
|
||||
import org.jclouds.profitbricks.domain.AvailabilityZone;
|
||||
import org.jclouds.profitbricks.domain.OsType;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
|
||||
import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ServerApiMockTest" )
|
||||
public class ServerApiMockTest extends BaseProfitBricksMockTest {
|
||||
|
||||
@Test
|
||||
public void testGetAllServers() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/servers.xml" ) ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
try {
|
||||
List<Server> servers = api.getAllServers();
|
||||
assertRequestHasCommonProperties( server.takeRequest(), "<ws:getAllServers/>" );
|
||||
assertNotNull( servers );
|
||||
assertTrue( servers.size() == 2 );
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllServersReturning404() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setResponseCode( 404 ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
try {
|
||||
List<Server> servers = api.getAllServers();
|
||||
assertRequestHasCommonProperties( server.takeRequest() );
|
||||
assertTrue( servers.isEmpty() );
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server.xml" ) ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:getServer><serverId>" + id + "</serverId></ws:getServer>";
|
||||
try {
|
||||
Server svr = api.getServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertNotNull( svr );
|
||||
assertEquals( svr.id(), id );
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNonExistingServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setResponseCode( 404 ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "random-non-existing-id";
|
||||
try {
|
||||
Server srvr = api.getServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest() );
|
||||
assertNull( srvr );
|
||||
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-start.xml" ) ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:startServer><serverId>" + id + "</serverId></ws:startServer>";
|
||||
try {
|
||||
String requestId = api.startServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertEquals( requestId, "123456" );
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartNonExistingServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setResponseCode( 500 ).setBody( payloadFromResource( "/fault-404.xml" ) ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "random-non-existing-id";
|
||||
try {
|
||||
String requestId = api.startServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest() );
|
||||
fail( "Should've failed." );
|
||||
} catch ( ResourceNotFoundException ex ) {
|
||||
// expected exception
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-stop.xml" ) ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:stopServer><serverId>" + id + "</serverId></ws:stopServer>";
|
||||
try {
|
||||
String requestId = api.stopServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertEquals( requestId, "123456" );
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResetServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-reset.xml" ) ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:resetServer><serverId>" + id + "</serverId></ws:resetServer>";
|
||||
try {
|
||||
String requestId = api.resetServer( id );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertEquals( requestId, "123456" );
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-create.xml" ) ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String dataCenterId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||
String name = "jclouds-node";
|
||||
String imageId = "some-random-image-id";
|
||||
|
||||
String content = "<ws:createServer>"
|
||||
+ "<request>"
|
||||
+ "<dataCenterId>" + dataCenterId + "</dataCenterId>"
|
||||
+ "<cores>4</cores>"
|
||||
+ "<ram>4096</ram>"
|
||||
+ "<serverName>" + name + "</serverName>"
|
||||
// + "<bootFromStorageId></bootFromStorageId>"
|
||||
+ "<bootFromImageId>" + imageId + "</bootFromImageId>"
|
||||
+ "<internetAccess>true</internetAccess>"
|
||||
+ "<lanId>2</lanId>"
|
||||
+ "<osType>LINUX</osType>"
|
||||
+ "<availabilityZone>ZONE_1</availabilityZone>"
|
||||
+ "<cpuHotPlug>true</cpuHotPlug>"
|
||||
+ "<ramHotPlug>false</ramHotPlug>"
|
||||
+ "<nicHotPlug>true</nicHotPlug>"
|
||||
+ "<nicHotUnPlug>false</nicHotUnPlug>"
|
||||
+ "<discVirtioHotPlug>true</discVirtioHotPlug>"
|
||||
+ "<discVirtioHotUnPlug>false</discVirtioHotUnPlug>"
|
||||
+ "</request>"
|
||||
+ "</ws:createServer>";
|
||||
|
||||
try {
|
||||
String serverId = api.createServer( Server.Request.creatingBuilder()
|
||||
.dataCenterId( dataCenterId )
|
||||
.name( name )
|
||||
.cores( 4 )
|
||||
.ram( 4 * 1024 )
|
||||
.bootFromImageId( imageId )
|
||||
.hasInternetAccess( Boolean.TRUE )
|
||||
.lanId( 2 )
|
||||
.osType( OsType.LINUX )
|
||||
.availabilityZone( AvailabilityZone.ZONE_1 )
|
||||
.isCpuHotPlug( Boolean.TRUE )
|
||||
.isRamHotPlug( Boolean.FALSE )
|
||||
.isNicHotPlug( Boolean.TRUE )
|
||||
.isNicHotUnPlug( Boolean.FALSE )
|
||||
.isDiscVirtioHotPlug( Boolean.TRUE )
|
||||
.isDiscVirtioHotUnPlug( Boolean.FALSE )
|
||||
.build() );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertNotNull( serverId );
|
||||
assertEquals( serverId, "qwertyui-qwer-qwer-qwer-qwertyyuiiop" );
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-update.xml" ) ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
String newName = "apache-node";
|
||||
String storageId = "some-random-storage-id";
|
||||
|
||||
String content = "<ws:updateServer>"
|
||||
+ "<request>"
|
||||
+ "<serverId>" + serverId + "</serverId>"
|
||||
+ "<cores>8</cores>"
|
||||
+ "<ram>8192</ram>"
|
||||
+ "<serverName>" + newName + "</serverName>"
|
||||
+ "<bootFromStorageId>" + storageId + "</bootFromStorageId>"
|
||||
// + "<bootFromImageId>?</bootFromImageId>"
|
||||
+ "<osType>OTHER</osType>"
|
||||
+ "<availabilityZone>AUTO</availabilityZone>"
|
||||
+ "<cpuHotPlug>false</cpuHotPlug>"
|
||||
+ "<ramHotPlug>true</ramHotPlug>"
|
||||
+ "<nicHotPlug>false</nicHotPlug>"
|
||||
+ "<nicHotUnPlug>true</nicHotUnPlug>"
|
||||
+ "<discVirtioHotPlug>false</discVirtioHotPlug>"
|
||||
+ "<discVirtioHotUnPlug>true</discVirtioHotUnPlug>"
|
||||
+ "</request>"
|
||||
+ "</ws:updateServer>";
|
||||
try {
|
||||
String requestId = api.updateServer( Server.Request.updatingBuilder()
|
||||
.id( serverId )
|
||||
.name( newName )
|
||||
.cores( 8 )
|
||||
.ram( 8 * 1024 )
|
||||
.bootFromStorageId( storageId )
|
||||
.osType( OsType.OTHER )
|
||||
.availabilityZone( AvailabilityZone.AUTO )
|
||||
.isCpuHotPlug( false )
|
||||
.isRamHotPlug( true )
|
||||
.isNicHotPlug( false )
|
||||
.isNicHotUnPlug( true )
|
||||
.isDiscVirtioHotPlug( false )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.build() );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertNotNull( requestId );
|
||||
assertEquals( requestId, "102458" );
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteServer() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue( new MockResponse().setBody( payloadFromResource( "/server/server-delete.xml" ) ) );
|
||||
|
||||
ProfitBricksApi pbApi = api( server.getUrl( rootUrl ) );
|
||||
ServerApi api = pbApi.serverApi();
|
||||
|
||||
String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:deleteServer><serverId>" + serverId + "</serverId></ws:deleteServer>";
|
||||
try {
|
||||
boolean result = api.deleteServer( serverId );
|
||||
assertRequestHasCommonProperties( server.takeRequest(), content );
|
||||
assertTrue( result );
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "RequestIdOnlyResponseHandlerTest" )
|
||||
public class RequestIdOnlyResponseHandlerTest extends BaseResponseHandlerTest<String> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<String> createParser() {
|
||||
return factory.create( injector.getInstance( RequestIdOnlyResponseHandler.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromStartServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String requestId = parser.parse( payloadFromResource( "/server/server-start.xml" ) );
|
||||
|
||||
assertEquals( requestId, "123456" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromStopServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String requestId = parser.parse( payloadFromResource( "/server/server-stop.xml" ) );
|
||||
|
||||
assertEquals( requestId, "123456" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromResetServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String requestId = parser.parse( payloadFromResource( "/server/server-reset.xml" ) );
|
||||
|
||||
assertEquals( requestId, "123456" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromUpdateServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String requestId = parser.parse( payloadFromResource( "/server/server-update.xml" ) );
|
||||
|
||||
assertEquals( requestId, "102458" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromDeleteServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String requestId = parser.parse( payloadFromResource( "/server/server-delete.xml" ) );
|
||||
|
||||
assertEquals( requestId, "102459" );
|
||||
}
|
||||
|
||||
}
|
@ -40,8 +40,8 @@ public class ServiceFaultResponseHandlerTest extends BaseResponseHandlerTest<Ser
|
||||
ServiceFault expected = ServiceFault.builder()
|
||||
.faultCode(ServiceFault.FaultCode.RESOURCE_NOT_FOUND)
|
||||
.httpCode(404)
|
||||
.message("The requested resource could not be found. Please refer to Request Id : 11122416. [VDC-6-404] The requested data center does not exist or already deleted by the users. ResourceId random-non-existing-id")
|
||||
.requestId(11122416)
|
||||
.message("The requested resource could not be found. Please refer to Request Id : 16370720. [VDC-6-404] The requested resource does not exist or already deleted by the users. ResourceId random-non-existing-id")
|
||||
.requestId(16370720)
|
||||
.build();
|
||||
|
||||
assertEquals(expected, actual);
|
||||
|
@ -19,7 +19,6 @@ package org.jclouds.profitbricks.http.parser.datacenter;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.domain.DataCenter;
|
||||
@ -37,7 +36,7 @@ public class DataCenterInfoResponseHandlerTest extends BaseResponseHandlerTest<D
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetDataCenter() throws ParserConfigurationException {
|
||||
public void testParseResponseFromGetDataCenter() {
|
||||
ParseSax<DataCenter> parser = createParser();
|
||||
DataCenter actual = parser.parse(payloadFromResource("/datacenter/datacenter.xml"));
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.image;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.domain.OsType;
|
||||
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ImageInfoResponseHandlerTest" )
|
||||
public class ImageInfoResponseHandlerTest extends BaseResponseHandlerTest<Image> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<Image> createParser() {
|
||||
return factory.create( injector.getInstance( ImageInfoResponseHandler.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetImage() {
|
||||
ParseSax<Image> parser = createParser();
|
||||
Image actual = parser.parse( payloadFromResource( "/image/image.xml" ) );
|
||||
assertNotNull( actual, "Parsed content returned null" );
|
||||
|
||||
Image expected = Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "5ad99c9e-9166-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-14.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.US_LAS )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.build();
|
||||
|
||||
assertEquals( expected, actual );
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.image;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.domain.Image;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.domain.OsType;
|
||||
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ImageListResponseHandlerTest" )
|
||||
public class ImageListResponseHandlerTest extends BaseResponseHandlerTest<List<Image>> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<List<Image>> createParser() {
|
||||
return factory.create( injector.getInstance( ImageListResponseHandler.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetAllImages() {
|
||||
ParseSax<List<Image>> parser = createParser();
|
||||
|
||||
List<Image> actual = parser.parse( payloadFromResource( "/image/images.xml" ) );
|
||||
assertNotNull( actual, "Parsed content returned null" );
|
||||
|
||||
List<Image> expected = ImmutableList.<Image>of(
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "e4f73936-9161-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-12.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.DE_FRA )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "a984a5d3-9163-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-14.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.DE_FRA )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "5f3cac96-915f-11e4-9d74-52540066fee9" )
|
||||
.name( "Debian-jessie-prerelease-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.UNRECOGNIZED )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "f4742db0-9160-11e4-9d74-52540066fee9" )
|
||||
.name( "Fedora-19-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.UNRECOGNIZED )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "86902c18-9164-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-12.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.UNRECOGNIZED )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "3b48e3ff-9163-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-14.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.DE_FKB )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.build(),
|
||||
Image.builder()
|
||||
.isBootable( true )
|
||||
.isCpuHotPlug( true )
|
||||
.isCpuHotUnPlug( false )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.id( "6ce17716-9164-11e4-9d74-52540066fee9" )
|
||||
.name( "Ubuntu-12.04-LTS-server-2015-01-01" )
|
||||
.size( 2048f )
|
||||
.type( Image.Type.HDD )
|
||||
.location( Location.US_LAS )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.osType( OsType.LINUX )
|
||||
.isPublic( true )
|
||||
.isRamHotPlug( true )
|
||||
.isRamHotUnPlug( false )
|
||||
.isWriteable( true )
|
||||
.build()
|
||||
);
|
||||
|
||||
assertEquals( expected, actual );
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.server;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ServerIdOnlyResponseHandlerTest" )
|
||||
public class ServerIdOnlyResponseHandlerTest extends BaseResponseHandlerTest<String> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<String> createParser() {
|
||||
return factory.create( injector.getInstance( ServerIdOnlyResponseHandler.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromCreateServer() {
|
||||
ParseSax<String> parser = createParser();
|
||||
|
||||
String serverId = parser.parse( payloadFromResource( "/server/server-create.xml" ) );
|
||||
|
||||
assertEquals( "qwertyui-qwer-qwer-qwer-qwertyyuiiop", serverId );
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.server;
|
||||
|
||||
import java.text.ParseException;
|
||||
import org.jclouds.date.DateCodec;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.domain.AvailabilityZone;
|
||||
import org.jclouds.profitbricks.domain.OsType;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ServerInfoResponseHandlerTest" )
|
||||
public class ServerInfoResponseHandlerTest extends BaseResponseHandlerTest<Server> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<Server> createParser() {
|
||||
return factory.create( injector.getInstance( ServerInfoResponseHandler.class ) );
|
||||
}
|
||||
|
||||
protected DateCodecFactory createDateParser() {
|
||||
return injector.getInstance( DateCodecFactory.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetServer() throws ParseException {
|
||||
ParseSax<Server> parser = createParser();
|
||||
|
||||
Server actual = parser.parse( payloadFromResource( "/server/server.xml" ) );
|
||||
assertNotNull( actual, "Parsed content returned null" );
|
||||
|
||||
DateCodec dateParser = createDateParser().iso8601();
|
||||
|
||||
Server expected = Server.builder()
|
||||
.id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" )
|
||||
.name( "facebook-node" )
|
||||
.cores( 4 )
|
||||
.ram( 4096 )
|
||||
.hasInternetAccess( true )
|
||||
.state( ProvisioningState.AVAILABLE )
|
||||
.status( Server.Status.RUNNING )
|
||||
.creationTime( dateParser.toDate( "2014-12-04T07:09:23.138Z" ) )
|
||||
.lastModificationTime( dateParser.toDate( "2014-12-12T03:08:35.629Z" ) )
|
||||
.osType( OsType.LINUX )
|
||||
.availabilityZone( AvailabilityZone.AUTO )
|
||||
.isCpuHotPlug( true )
|
||||
.isRamHotPlug( true )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.build();
|
||||
|
||||
assertEquals( actual, expected );
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.profitbricks.http.parser.server;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import org.jclouds.date.DateCodec;
|
||||
import org.jclouds.date.DateCodecFactory;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.domain.AvailabilityZone;
|
||||
import org.jclouds.profitbricks.domain.OsType;
|
||||
import org.jclouds.profitbricks.domain.ProvisioningState;
|
||||
import org.jclouds.profitbricks.domain.Server;
|
||||
import org.jclouds.profitbricks.http.parser.BaseResponseHandlerTest;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test( groups = "unit", testName = "ServerListResponseHandlerTest" )
|
||||
public class ServerListResponseHandlerTest extends BaseResponseHandlerTest<List<Server>> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<List<Server>> createParser() {
|
||||
return factory.create( injector.getInstance( ServerListResponseHandler.class ) );
|
||||
}
|
||||
|
||||
protected DateCodecFactory createDateParser() {
|
||||
return injector.getInstance( DateCodecFactory.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetAllServers() {
|
||||
ParseSax<List<Server>> parser = createParser();
|
||||
|
||||
List<Server> actual = parser.parse( payloadFromResource( "/server/servers.xml" ) );
|
||||
assertNotNull( actual, "Parsed content returned null" );
|
||||
|
||||
DateCodec dateParser = createDateParser().iso8601();
|
||||
|
||||
List<Server> expected = ImmutableList.<Server>of(
|
||||
Server.builder()
|
||||
.id( "qwertyui-qwer-qwer-qwer-qwertyyuiiop" )
|
||||
.name( "facebook-node" )
|
||||
.cores( 4 )
|
||||
.ram( 4096 )
|
||||
.hasInternetAccess( true )
|
||||
.state( ProvisioningState.AVAILABLE )
|
||||
.status( Server.Status.RUNNING )
|
||||
.creationTime( dateParser.toDate( "2014-12-04T07:09:23.138Z" ) )
|
||||
.lastModificationTime( dateParser.toDate( "2014-12-12T03:08:35.629Z" ) )
|
||||
.osType( OsType.LINUX )
|
||||
.availabilityZone( AvailabilityZone.AUTO )
|
||||
.isCpuHotPlug( true )
|
||||
.isRamHotPlug( true )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.build(),
|
||||
Server.builder()
|
||||
.id( "asdfghjk-asdf-asdf-asdf-asdfghjklkjl" )
|
||||
.name( "google-node" )
|
||||
.cores( 1 )
|
||||
.ram( 1024 )
|
||||
.hasInternetAccess( false )
|
||||
.state( ProvisioningState.AVAILABLE )
|
||||
.status( Server.Status.RUNNING )
|
||||
.creationTime( dateParser.toDate( "2014-11-12T07:01:00.441Z" ) )
|
||||
.lastModificationTime( dateParser.toDate( "2014-11-12T07:01:00.441Z" ) )
|
||||
.osType( OsType.LINUX )
|
||||
.availabilityZone( AvailabilityZone.AUTO )
|
||||
.isCpuHotPlug( true )
|
||||
.isRamHotPlug( true )
|
||||
.isNicHotPlug( true )
|
||||
.isNicHotUnPlug( true )
|
||||
.isDiscVirtioHotPlug( true )
|
||||
.isDiscVirtioHotUnPlug( true )
|
||||
.build()
|
||||
);
|
||||
|
||||
assertEquals( actual, expected );
|
||||
}
|
||||
}
|
@ -46,6 +46,13 @@ public class BaseProfitBricksMockTest {
|
||||
protected static final String authHeader = BasicAuthentication.basic("username", "password");
|
||||
protected static final String provider = "profitbricks";
|
||||
protected static final String rootUrl = "/1.3";
|
||||
|
||||
private static final String SOAP_PREFIX
|
||||
= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.profitbricks.com/\">"
|
||||
+ "<soapenv:Header/>"
|
||||
+ "<soapenv:Body>";
|
||||
|
||||
private static final String SOAP_SUFFIX = "</soapenv:Body></soapenv:Envelope>";
|
||||
|
||||
private final Set<Module> modules = ImmutableSet.<Module>of();
|
||||
|
||||
@ -70,7 +77,7 @@ public class BaseProfitBricksMockTest {
|
||||
server.play();
|
||||
return server;
|
||||
}
|
||||
|
||||
|
||||
public byte[] payloadFromResource(String resource) {
|
||||
try {
|
||||
return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8);
|
||||
@ -78,6 +85,10 @@ public class BaseProfitBricksMockTest {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected static String payloadSoapWithBody(String body){
|
||||
return SOAP_PREFIX.concat( body ).concat( SOAP_SUFFIX );
|
||||
}
|
||||
|
||||
protected static void assertRequestHasCommonProperties(final RecordedRequest request) {
|
||||
assertEquals(request.getMethod(), "POST");
|
||||
@ -85,4 +96,9 @@ public class BaseProfitBricksMockTest {
|
||||
assertEquals(request.getHeader(HttpHeaders.AUTHORIZATION), authHeader);
|
||||
assertEquals(request.getHeader(HttpHeaders.ACCEPT), MediaType.TEXT_XML);
|
||||
}
|
||||
|
||||
protected static void assertRequestHasCommonProperties(final RecordedRequest request, String content ){
|
||||
assertEquals( new String( request.getBody() ), payloadSoapWithBody( content ) );
|
||||
assertRequestHasCommonProperties( request );
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
|
||||
<faultcode>S:Server</faultcode>
|
||||
<faultstring>The requested resource could not be found. Please refer to Request Id : 11122416. [VDC-6-404] The requested data center does not exist or already deleted by the users. ResourceId random-non-existing-id</faultstring>
|
||||
<detail>
|
||||
<ns2:ProfitbricksServiceFault xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<faultCode>RESOURCE_NOT_FOUND</faultCode>
|
||||
<httpCode>404</httpCode>
|
||||
<message>The requested resource could not be found. Please refer to Request Id : 11122416. [VDC-6-404] The requested data center does not exist or already deleted by the users. ResourceId random-non-existing-id</message>
|
||||
<requestId>11122416</requestId>
|
||||
</ns2:ProfitbricksServiceFault>
|
||||
</detail>
|
||||
</S:Fault>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
|
||||
<faultcode>S:Server</faultcode>
|
||||
<faultstring>The requested resource could not be found. Please refer to Request Id : 11122416. [VDC-6-404] The requested data center does not exist or already deleted by the users. ResourceId random-non-existing-id</faultstring>
|
||||
<detail>
|
||||
<ns2:ProfitbricksServiceFault xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<faultCode>RESOURCE_NOT_FOUND</faultCode>
|
||||
<httpCode>404</httpCode>
|
||||
<message>The requested resource could not be found. Please refer to Request Id : 11122416. [VDC-6-404] The requested data center does not exist or already deleted by the users. ResourceId random-non-existing-id</message>
|
||||
<requestId>11122416</requestId>
|
||||
</ns2:ProfitbricksServiceFault>
|
||||
</detail>
|
||||
</S:Fault>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
||||
<S:Body>
|
||||
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
|
||||
<faultcode>S:Server</faultcode>
|
||||
<faultstring>The requested resource could not be found. Please refer to Request Id : 16370720. [VDC-6-404] The requested resource does not exist or already deleted by the users. ResourceId random-non-existing-id</faultstring>
|
||||
<detail>
|
||||
<ns2:ProfitbricksServiceFault xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<faultCode>RESOURCE_NOT_FOUND</faultCode>
|
||||
<httpCode>404</httpCode>
|
||||
<message>The requested resource could not be found. Please refer to Request Id : 16370720. [VDC-6-404] The requested resource does not exist or already deleted by the users. ResourceId random-non-existing-id</message>
|
||||
<requestId>16370720</requestId>
|
||||
</ns2:ProfitbricksServiceFault>
|
||||
</detail>
|
||||
</S:Fault>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
||||
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
|
||||
<faultcode>S:Server</faultcode>
|
||||
<faultstring>The requested resource could not be found. Please refer to Request Id : 16361390. [VDC-6-404] The requested image does not exist or already deleted by the users. ResourceId random-non-existing-id</faultstring>
|
||||
<detail>
|
||||
<ns2:ProfitbricksServiceFault xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<faultCode>RESOURCE_NOT_FOUND</faultCode>
|
||||
<httpCode>404</httpCode>
|
||||
<message>The requested resource could not be found. Please refer to Request Id : 16361390. [VDC-6-404] The requested image does not exist or already deleted by the users. ResourceId random-non-existing-id</message>
|
||||
<requestId>16361390</requestId>
|
||||
</ns2:ProfitbricksServiceFault>
|
||||
</detail>
|
||||
</S:Fault>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
26
providers/profitbricks/src/test/resources/image/image.xml
Normal file
26
providers/profitbricks/src/test/resources/image/image.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:getImageResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<bootable>true</bootable>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<cpuHotUnPlug>false</cpuHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
<imageId>5ad99c9e-9166-11e4-9d74-52540066fee9</imageId>
|
||||
<imageName>Ubuntu-14.04-LTS-server-2015-01-01</imageName>
|
||||
<imageSize>2048</imageSize>
|
||||
<imageType>HDD</imageType>
|
||||
<location>us/las</location>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<osType>LINUX</osType>
|
||||
<public>true</public>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<ramHotUnPlug>false</ramHotUnPlug>
|
||||
<writeable>true</writeable>
|
||||
</return>
|
||||
</ns2:getImageResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
140
providers/profitbricks/src/test/resources/image/images.xml
Normal file
140
providers/profitbricks/src/test/resources/image/images.xml
Normal file
@ -0,0 +1,140 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:getAllImagesResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<bootable>true</bootable>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<cpuHotUnPlug>false</cpuHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
<imageId>e4f73936-9161-11e4-9d74-52540066fee9</imageId>
|
||||
<imageName>Ubuntu-12.04-LTS-server-2015-01-01</imageName>
|
||||
<imageSize>2048</imageSize>
|
||||
<imageType>HDD</imageType>
|
||||
<location>de/fra</location>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<osType>LINUX</osType>
|
||||
<public>true</public>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<ramHotUnPlug>false</ramHotUnPlug>
|
||||
<writeable>true</writeable>
|
||||
</return>
|
||||
<return>
|
||||
<bootable>true</bootable>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<cpuHotUnPlug>false</cpuHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
<imageId>a984a5d3-9163-11e4-9d74-52540066fee9</imageId>
|
||||
<imageName>Ubuntu-14.04-LTS-server-2015-01-01</imageName>
|
||||
<imageSize>2048</imageSize>
|
||||
<imageType>HDD</imageType>
|
||||
<location>de/fra</location>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<osType>LINUX</osType>
|
||||
<public>true</public>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<ramHotUnPlug>false</ramHotUnPlug>
|
||||
<writeable>true</writeable>
|
||||
</return>
|
||||
<return>
|
||||
<bootable>true</bootable>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<cpuHotUnPlug>false</cpuHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
<imageId>5f3cac96-915f-11e4-9d74-52540066fee9</imageId>
|
||||
<imageName>Debian-jessie-prerelease-server-2015-01-01</imageName>
|
||||
<imageSize>2048</imageSize>
|
||||
<imageType>HDD</imageType>
|
||||
<location>us/lasdev</location>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<osType>LINUX</osType>
|
||||
<public>true</public>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<ramHotUnPlug>false</ramHotUnPlug>
|
||||
<writeable>true</writeable>
|
||||
</return>
|
||||
<return>
|
||||
<bootable>true</bootable>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<cpuHotUnPlug>false</cpuHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
<imageId>f4742db0-9160-11e4-9d74-52540066fee9</imageId>
|
||||
<imageName>Fedora-19-server-2015-01-01</imageName>
|
||||
<imageSize>2048</imageSize>
|
||||
<imageType>HDD</imageType>
|
||||
<location>us/lasdev</location>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<osType>LINUX</osType>
|
||||
<public>true</public>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<ramHotUnPlug>false</ramHotUnPlug>
|
||||
<writeable>true</writeable>
|
||||
</return>
|
||||
<return>
|
||||
<bootable>true</bootable>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<cpuHotUnPlug>false</cpuHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
<imageId>86902c18-9164-11e4-9d74-52540066fee9</imageId>
|
||||
<imageName>Ubuntu-12.04-LTS-server-2015-01-01</imageName>
|
||||
<imageSize>2048</imageSize>
|
||||
<imageType>HDD</imageType>
|
||||
<location>us/lasdev</location>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<osType>LINUX</osType>
|
||||
<public>true</public>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<ramHotUnPlug>false</ramHotUnPlug>
|
||||
<writeable>true</writeable>
|
||||
</return>
|
||||
<return>
|
||||
<bootable>true</bootable>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<cpuHotUnPlug>false</cpuHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
<imageId>3b48e3ff-9163-11e4-9d74-52540066fee9</imageId>
|
||||
<imageName>Ubuntu-14.04-LTS-server-2015-01-01</imageName>
|
||||
<imageSize>2048</imageSize>
|
||||
<imageType>HDD</imageType>
|
||||
<location>de/fkb</location>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<osType>LINUX</osType>
|
||||
<public>true</public>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<ramHotUnPlug>false</ramHotUnPlug>
|
||||
<writeable>true</writeable>
|
||||
</return>
|
||||
<return>
|
||||
<bootable>true</bootable>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<cpuHotUnPlug>false</cpuHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
<imageId>6ce17716-9164-11e4-9d74-52540066fee9</imageId>
|
||||
<imageName>Ubuntu-12.04-LTS-server-2015-01-01</imageName>
|
||||
<imageSize>2048</imageSize>
|
||||
<imageType>HDD</imageType>
|
||||
<location>us/las</location>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<osType>LINUX</osType>
|
||||
<public>true</public>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<ramHotUnPlug>false</ramHotUnPlug>
|
||||
<writeable>true</writeable>
|
||||
</return>
|
||||
</ns2:getAllImagesResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
@ -0,0 +1,13 @@
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:createServerReturn>
|
||||
<return>
|
||||
<requestId>102457</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>2</dataCenterVersion>
|
||||
<serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId>
|
||||
</return>
|
||||
</ws:createServerReturn>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:deleteServerResponse>
|
||||
<return>
|
||||
<requestId>102459</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>4</dataCenterVersion>
|
||||
</return>
|
||||
</ws:deleteServerResponse>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:resetServerResponse>
|
||||
<return>
|
||||
<requestId>123456</requestId>
|
||||
</return>
|
||||
</ws:resetServerResponse>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:startServerResponse>
|
||||
<return>
|
||||
<requestId>123456</requestId>
|
||||
</return>
|
||||
</ws:startServerResponse>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:stopServerResponse>
|
||||
<return>
|
||||
<requestId>123456</requestId>
|
||||
</return>
|
||||
</ws:stopServerResponse>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.api.profitbricks.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ws:updateServerResponse>
|
||||
<return>
|
||||
<requestId>102458</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>3</dataCenterVersion>
|
||||
</return>
|
||||
</ws:updateServerResponse>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>
|
57
providers/profitbricks/src/test/resources/server/server.xml
Normal file
57
providers/profitbricks/src/test/resources/server/server.xml
Normal file
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:getServerResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<requestId>16366014</requestId>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>10</dataCenterVersion>
|
||||
<serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId>
|
||||
<serverName>facebook-node</serverName>
|
||||
<cores>4</cores>
|
||||
<ram>4096</ram>
|
||||
<internetAccess>true</internetAccess>
|
||||
<ips>173.252.120.6</ips>
|
||||
<connectedStorages>
|
||||
<bootDevice>true</bootDevice>
|
||||
<busType>VIRTIO</busType>
|
||||
<deviceNumber>1</deviceNumber>
|
||||
<size>40</size>
|
||||
<storageId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</storageId>
|
||||
<storageName>facebook-storage</storageName>
|
||||
</connectedStorages>
|
||||
<nics>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>10</dataCenterVersion>
|
||||
<nicId>qwqwqwqw-wewe-erer-rtrt-tytytytytyty</nicId>
|
||||
<lanId>1</lanId>
|
||||
<internetAccess>true</internetAccess>
|
||||
<serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId>
|
||||
<ips>173.252.120.6</ips>
|
||||
<macAddress>02:01:09:cd:f0:b0</macAddress>
|
||||
<firewall>
|
||||
<active>false</active>
|
||||
<firewallId>wqwqwqwq-ewew-rere-trtr-ytytytytytyt</firewallId>
|
||||
<nicId>qwqwqwqw-wewe-erer-rtrt-tytytytytyty</nicId>
|
||||
<provisioningState>AVAILABLE</provisioningState>
|
||||
</firewall>
|
||||
<dhcpActive>true</dhcpActive>
|
||||
<gatewayIp>173.252.120.1</gatewayIp>
|
||||
<provisioningState>AVAILABLE</provisioningState>
|
||||
</nics>
|
||||
<provisioningState>AVAILABLE</provisioningState>
|
||||
<virtualMachineState>RUNNING</virtualMachineState>
|
||||
<creationTime>2014-12-04T07:09:23.138Z</creationTime>
|
||||
<lastModificationTime>2014-12-12T03:08:35.629Z</lastModificationTime>
|
||||
<osType>LINUX</osType>
|
||||
<availabilityZone>AUTO</availabilityZone>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
</return>
|
||||
</ns2:getServerResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
104
providers/profitbricks/src/test/resources/server/servers.xml
Normal file
104
providers/profitbricks/src/test/resources/server/servers.xml
Normal file
@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:getAllServersResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>10</dataCenterVersion>
|
||||
<serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId>
|
||||
<serverName>facebook-node</serverName>
|
||||
<cores>4</cores>
|
||||
<ram>4096</ram>
|
||||
<internetAccess>true</internetAccess>
|
||||
<ips>173.252.120.6</ips>
|
||||
<connectedStorages>
|
||||
<bootDevice>true</bootDevice>
|
||||
<busType>VIRTIO</busType>
|
||||
<deviceNumber>1</deviceNumber>
|
||||
<size>40</size>
|
||||
<storageId>qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh</storageId>
|
||||
<storageName>facebook-storage</storageName>
|
||||
</connectedStorages>
|
||||
<nics>
|
||||
<dataCenterId>aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</dataCenterId>
|
||||
<dataCenterVersion>10</dataCenterVersion>
|
||||
<nicId>qwqwqwqw-wewe-erer-rtrt-tytytytytyty</nicId>
|
||||
<lanId>1</lanId>
|
||||
<internetAccess>true</internetAccess>
|
||||
<serverId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</serverId>
|
||||
<ips>173.252.120.6</ips>
|
||||
<macAddress>02:01:09:cd:f0:b0</macAddress>
|
||||
<firewall>
|
||||
<active>false</active>
|
||||
<firewallId>wqwqwqwq-ewew-rere-trtr-ytytytytytyt</firewallId>
|
||||
<nicId>qwqwqwqw-wewe-erer-rtrt-tytytytytyty</nicId>
|
||||
<provisioningState>AVAILABLE</provisioningState>
|
||||
</firewall>
|
||||
<dhcpActive>true</dhcpActive>
|
||||
<gatewayIp>173.252.120.1</gatewayIp>
|
||||
<provisioningState>AVAILABLE</provisioningState>
|
||||
</nics>
|
||||
<provisioningState>AVAILABLE</provisioningState>
|
||||
<virtualMachineState>RUNNING</virtualMachineState>
|
||||
<creationTime>2014-12-04T07:09:23.138Z</creationTime>
|
||||
<lastModificationTime>2014-12-12T03:08:35.629Z</lastModificationTime>
|
||||
<osType>LINUX</osType>
|
||||
<availabilityZone>AUTO</availabilityZone>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
</return>
|
||||
<return>
|
||||
<dataCenterId>qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy</dataCenterId>
|
||||
<dataCenterVersion>238</dataCenterVersion>
|
||||
<serverId>asdfghjk-asdf-asdf-asdf-asdfghjklkjl</serverId>
|
||||
<serverName>google-node</serverName>
|
||||
<cores>1</cores>
|
||||
<ram>1024</ram>
|
||||
<internetAccess>false</internetAccess>
|
||||
<ips>202.69.181.241</ips>
|
||||
<connectedStorages>
|
||||
<bootDevice>true</bootDevice>
|
||||
<busType>VIRTIO</busType>
|
||||
<deviceNumber>1</deviceNumber>
|
||||
<size>5</size>
|
||||
<storageId>asfasfle-f23n-cu89-klfr-njkdsvwllkfa</storageId>
|
||||
<storageName>google-disk</storageName>
|
||||
</connectedStorages>
|
||||
<nics>
|
||||
<dataCenterId>qqqqqqqq-wwww-rrrr-tttt-yyyyyyyyyyyy</dataCenterId>
|
||||
<dataCenterVersion>238</dataCenterVersion>
|
||||
<nicId>mkl45h5e-sdgb-h6rh-235r-rfweshdfhreh</nicId>
|
||||
<lanId>3</lanId>
|
||||
<internetAccess>false</internetAccess>
|
||||
<serverId>asdfghjk-asdf-asdf-asdf-asdfghjklkjl</serverId>
|
||||
<ips>202.69.181.241</ips>
|
||||
<macAddress>02:01:9e:5e:35:1e</macAddress>
|
||||
<firewall>
|
||||
<active>false</active>
|
||||
<firewallId>cvvdsgbd-sdgj-eger-h56j-wet43gvsgeg4</firewallId>
|
||||
<nicId>mkl45h5e-sdgb-h6rh-235r-rfweshdfhreh</nicId>
|
||||
<provisioningState>INPROCESS</provisioningState>
|
||||
</firewall>
|
||||
<dhcpActive>false</dhcpActive>
|
||||
<provisioningState>AVAILABLE</provisioningState>
|
||||
</nics>
|
||||
<provisioningState>AVAILABLE</provisioningState>
|
||||
<virtualMachineState>RUNNING</virtualMachineState>
|
||||
<creationTime>2014-11-12T07:01:00.441Z</creationTime>
|
||||
<lastModificationTime>2014-11-12T07:01:00.441Z</lastModificationTime>
|
||||
<osType>LINUX</osType>
|
||||
<availabilityZone>AUTO</availabilityZone>
|
||||
<cpuHotPlug>true</cpuHotPlug>
|
||||
<ramHotPlug>true</ramHotPlug>
|
||||
<nicHotPlug>true</nicHotPlug>
|
||||
<nicHotUnPlug>true</nicHotUnPlug>
|
||||
<discVirtioHotPlug>true</discVirtioHotPlug>
|
||||
<discVirtioHotUnPlug>true</discVirtioHotUnPlug>
|
||||
</return>
|
||||
</ns2:getAllServersResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
Loading…
x
Reference in New Issue
Block a user