mirror of https://github.com/apache/jclouds.git
Profitbricks IpBlock API
Conflicts: profitbricks/src/main/java/org/jclouds/profitbricks/ProfitBricksApi.java
This commit is contained in:
parent
36d499b47f
commit
af93f3b68f
|
@ -20,6 +20,7 @@ import java.io.Closeable;
|
|||
import org.jclouds.profitbricks.features.DataCenterApi;
|
||||
import org.jclouds.profitbricks.features.FirewallApi;
|
||||
import org.jclouds.profitbricks.features.ImageApi;
|
||||
import org.jclouds.profitbricks.features.IpBlockApi;
|
||||
import org.jclouds.profitbricks.features.NicApi;
|
||||
import org.jclouds.profitbricks.features.ServerApi;
|
||||
import org.jclouds.profitbricks.features.SnapshotApi;
|
||||
|
@ -48,4 +49,8 @@ public interface ProfitBricksApi extends Closeable {
|
|||
|
||||
@Delegate
|
||||
SnapshotApi snapshotApi();
|
||||
|
||||
@Delegate
|
||||
IpBlockApi ipBlockApi();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* 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;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
@AutoValue
|
||||
public abstract class IpBlock {
|
||||
|
||||
public abstract String id();
|
||||
|
||||
public abstract Location location();
|
||||
|
||||
public abstract List<PublicIp> publicIps();
|
||||
|
||||
public abstract List<String> ips();
|
||||
|
||||
public static IpBlock create(String id, Location location, List<PublicIp> publicIps, List<String> ips) {
|
||||
return new AutoValue_IpBlock(id, location, publicIps, ips != null ? ImmutableList.copyOf(ips) : ImmutableList.<String>of());
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
private String id;
|
||||
private Location location;
|
||||
private List<PublicIp> publicIps;
|
||||
private List<String> ips;
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder location(Location location) {
|
||||
this.location = location;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder publicIps(List<PublicIp> publicIps) {
|
||||
this.publicIps = publicIps;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ips(List<String> ips) {
|
||||
this.ips = ips;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IpBlock build() {
|
||||
return IpBlock.create(id, location, publicIps, ips);
|
||||
}
|
||||
|
||||
public Builder fromIpBlock(IpBlock in) {
|
||||
return this.id(in.id()).location(in.location()).publicIps(in.publicIps()).ips(in.ips());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
public abstract static class PublicIp {
|
||||
|
||||
public abstract String ip();
|
||||
|
||||
@Nullable
|
||||
public abstract String nicId();
|
||||
|
||||
public static PublicIp create(String ip, String nicId) {
|
||||
return new AutoValue_IpBlock_PublicIp(ip, nicId);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return builder().fromPublicIp(this);
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
private String ip;
|
||||
private String nicId;
|
||||
|
||||
public Builder ip(String ip) {
|
||||
this.ip = ip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder nicId(String nicId) {
|
||||
this.nicId = nicId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublicIp build() {
|
||||
return PublicIp.create(ip, nicId);
|
||||
}
|
||||
|
||||
public Builder fromPublicIp(PublicIp in) {
|
||||
return this.ip(in.ip()).nicId(in.nicId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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.IpBlock;
|
||||
import org.jclouds.profitbricks.http.filters.ProfitBricksSoapMessageEnvelope;
|
||||
import org.jclouds.profitbricks.http.parser.RequestIdOnlyResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.ipblock.IpBlockListResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.ipblock.IpBlockResponseHandler;
|
||||
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 IpBlockApi {
|
||||
|
||||
@POST
|
||||
@Named("publicipblock:get")
|
||||
@Payload("<ws:getPublicIpBlock><blockId>{id}</blockId></ws:getPublicIpBlock>")
|
||||
@XMLResponseParser(IpBlockResponseHandler.class)
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
IpBlock getIpBlock(@PayloadParam("id") String identifier);
|
||||
|
||||
@POST
|
||||
@Named("publicipblock:getall")
|
||||
@Payload("<ws:getAllPublicIpBlocks />")
|
||||
@XMLResponseParser(IpBlockListResponseHandler.class)
|
||||
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
|
||||
List<IpBlock> getAllIpBlock();
|
||||
|
||||
@POST
|
||||
@Named("publicipblock:reserve")
|
||||
@Payload("<ws:reservePublicIpBlock><request><blockSize>{blockSize}</blockSize><location>{location}</location></request></ws:reservePublicIpBlock>")
|
||||
@XMLResponseParser(IpBlockResponseHandler.class)
|
||||
IpBlock reservePublicIpBlock(@PayloadParam("blockSize") String blockSize, @PayloadParam("location") String location);
|
||||
|
||||
@POST
|
||||
@Named("publicipblock:addip")
|
||||
@Payload("<ws:addPublicIpToNic><ip>{ip}</ip><nicId>{nicid}</nicId></ws:addPublicIpToNic>")
|
||||
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||
String addPublicIpToNic(@PayloadParam("ip") String ip, @PayloadParam("nicid") String nicid);
|
||||
|
||||
@POST
|
||||
@Named("publicipblock:removeip")
|
||||
@Payload("<ws:removePublicIpFromNic><ip>{ip}</ip><nicId>{nicid}</nicId></ws:removePublicIpFromNic>")
|
||||
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||
String removePublicIpFromNic(@PayloadParam("ip") String ip, @PayloadParam("nicid") String nicid);
|
||||
|
||||
@POST
|
||||
@Named("publicipblock:releaseblock")
|
||||
@Payload("<ws:releasePublicIpBlock><blockId>{blockid}</blockId></ws:releasePublicIpBlock>")
|
||||
@XMLResponseParser(RequestIdOnlyResponseHandler.class)
|
||||
String releasePublicIpBlock(@PayloadParam("blockid") String blockid);
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.ipblock;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import org.jclouds.profitbricks.domain.IpBlock;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||
import org.jclouds.profitbricks.http.parser.publicip.PublicIpListResponseHandler;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public abstract class BaseIpBlockResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||
|
||||
protected final PublicIpListResponseHandler publicIpListResponseHandler;
|
||||
protected final List<IpBlock.PublicIp> publicIps = Lists.newArrayList();
|
||||
protected List<String> ips;
|
||||
|
||||
protected IpBlock.Builder builder;
|
||||
protected boolean usePublicIpListParser = false;
|
||||
|
||||
BaseIpBlockResponseHandler(PublicIpListResponseHandler publicIpListResponseHandler) {
|
||||
this.builder = IpBlock.builder();
|
||||
this.publicIpListResponseHandler = publicIpListResponseHandler;
|
||||
ips = Lists.newArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
if ("publicIps".equals(qName))
|
||||
usePublicIpListParser = true;
|
||||
if (usePublicIpListParser)
|
||||
publicIpListResponseHandler.startElement(uri, localName, qName, attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
if (usePublicIpListParser)
|
||||
publicIpListResponseHandler.characters(ch, start, length);
|
||||
else
|
||||
super.characters(ch, start, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
if ("blockId".equals(qName))
|
||||
builder.id(textToStringValue());
|
||||
else if ("location".equals(qName))
|
||||
builder.location(Location.fromId(textToStringValue()));
|
||||
else if ("ips".equals(qName))
|
||||
ips.add(textToStringValue());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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.ipblock;
|
||||
|
||||
import autovalue.shaded.com.google.common.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import org.jclouds.profitbricks.domain.IpBlock;
|
||||
import org.jclouds.profitbricks.http.parser.publicip.PublicIpListResponseHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class IpBlockListResponseHandler extends BaseIpBlockResponseHandler<List<IpBlock>> {
|
||||
|
||||
private final List<IpBlock> ipBlocks;
|
||||
|
||||
@Inject
|
||||
IpBlockListResponseHandler(PublicIpListResponseHandler publicIpListResponseHandler) {
|
||||
super(publicIpListResponseHandler);
|
||||
ipBlocks = Lists.newArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (usePublicIpListParser)
|
||||
publicIpListResponseHandler.endElement(uri, localName, qName);
|
||||
else {
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName)) {
|
||||
ipBlocks.add(builder
|
||||
.publicIps(publicIpListResponseHandler.getResult())
|
||||
.build());
|
||||
publicIpListResponseHandler.reset();
|
||||
builder = IpBlock.builder();
|
||||
}
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
if ("publicIps".equals(qName))
|
||||
usePublicIpListParser = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IpBlock> getResult() {
|
||||
return ipBlocks;
|
||||
}
|
||||
|
||||
}
|
|
@ -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.http.parser.ipblock;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.profitbricks.domain.IpBlock;
|
||||
import org.jclouds.profitbricks.http.parser.publicip.PublicIpListResponseHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class IpBlockResponseHandler extends BaseIpBlockResponseHandler<IpBlock> {
|
||||
|
||||
private boolean done = false;
|
||||
|
||||
@Inject
|
||||
IpBlockResponseHandler(PublicIpListResponseHandler publicIpListResponseHandler) {
|
||||
super(publicIpListResponseHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (done)
|
||||
return;
|
||||
|
||||
if (usePublicIpListParser)
|
||||
publicIpListResponseHandler.endElement(uri, localName, qName);
|
||||
else {
|
||||
setPropertyOnEndTag(qName);
|
||||
if ("return".equals(qName)) {
|
||||
done = true;
|
||||
builder.publicIps(publicIpListResponseHandler.getResult());
|
||||
builder.ips(ips);
|
||||
}
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
if ("publicIps".equals(qName))
|
||||
usePublicIpListParser = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.builder = IpBlock.builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IpBlock getResult() {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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.publicip;
|
||||
|
||||
import org.jclouds.profitbricks.domain.IpBlock;
|
||||
import org.jclouds.profitbricks.http.parser.BaseProfitBricksResponseHandler;
|
||||
|
||||
public abstract class BasePublicIpResponseHandler<T> extends BaseProfitBricksResponseHandler<T> {
|
||||
|
||||
protected IpBlock.PublicIp.Builder builder;
|
||||
|
||||
BasePublicIpResponseHandler() {
|
||||
this.builder = IpBlock.PublicIp.builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPropertyOnEndTag(String qName) {
|
||||
if ("ip".equals(qName))
|
||||
builder.ip(textToStringValue());
|
||||
else if ("nicId".equals(qName))
|
||||
builder.nicId(textToStringValue());
|
||||
|
||||
}
|
||||
}
|
|
@ -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.publicip;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import org.jclouds.profitbricks.domain.IpBlock.PublicIp;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class PublicIpListResponseHandler extends BasePublicIpResponseHandler<List<PublicIp>> {
|
||||
|
||||
private List<PublicIp> publicIps;
|
||||
|
||||
PublicIpListResponseHandler() {
|
||||
this.publicIps = Lists.newArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
setPropertyOnEndTag(qName);
|
||||
|
||||
if ("publicIps".equals(qName))
|
||||
publicIps.add(builder.build());
|
||||
clearTextBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.publicIps = Lists.newArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PublicIp> getResult() {
|
||||
return publicIps;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* 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.IpBlock;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.domain.Nic;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test(groups = "live", testName = "IpBlockApiLiveTest", singleThreaded = true)
|
||||
public class IpBlockApiLiveTest extends BaseProfitBricksLiveTest {
|
||||
|
||||
private String nicid;
|
||||
private IpBlock newIpBlock;
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
||||
List<Nic> nics = api.nicApi().getAllNics();
|
||||
|
||||
assertFalse(nics.isEmpty(), "At least one NIC is requred to test IpBlocks");
|
||||
|
||||
Nic nic = Iterables.getFirst(nics, null);
|
||||
|
||||
nicid = nic.id();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReservePublicIpBlock() {
|
||||
newIpBlock = api.ipBlockApi().reservePublicIpBlock("2", Location.US_LAS.value());
|
||||
|
||||
assertNotNull(newIpBlock);
|
||||
assertNotNull(newIpBlock.ips());
|
||||
assertFalse(newIpBlock.ips().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllIpBlocks() {
|
||||
List<IpBlock> ipBlocks = api.ipBlockApi().getAllIpBlock();
|
||||
|
||||
assertNotNull(ipBlocks);
|
||||
assertFalse(ipBlocks.isEmpty());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testReservePublicIpBlock")
|
||||
public void testGetOneIpBlock() {
|
||||
IpBlock ipBlock = api.ipBlockApi().getIpBlock(newIpBlock.id());
|
||||
|
||||
assertNotNull(ipBlock);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testReservePublicIpBlock")
|
||||
public void testAddPublicIpToNic() {
|
||||
String requestId = api.ipBlockApi().addPublicIpToNic(newIpBlock.ips().get(0), nicid);
|
||||
|
||||
assertNotNull(requestId);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAddPublicIpToNic")
|
||||
public void testRemovePublicIpFromNic() {
|
||||
String requestId = api.ipBlockApi().removePublicIpFromNic(newIpBlock.ips().get(0), nicid);
|
||||
|
||||
assertNotNull(requestId);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testRemovePublicIpFromNic")
|
||||
public void testReleasePublicIpBlock() {
|
||||
String requestId = api.ipBlockApi().releasePublicIpBlock(newIpBlock.id());
|
||||
|
||||
assertNotNull(requestId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* 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.IpBlock;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest;
|
||||
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;
|
||||
|
||||
@Test(groups = "unit", testName = "IpBlockApiMockTest")
|
||||
public class IpBlockApiMockTest extends BaseProfitBricksMockTest {
|
||||
|
||||
@Test
|
||||
public void testGetOneIpBlock() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
IpBlockApi api = pbApi.ipBlockApi();
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
String content = "<ws:getPublicIpBlock><blockId>" + id + "</blockId></ws:getPublicIpBlock>";
|
||||
|
||||
try {
|
||||
IpBlock ipBlock = api.getIpBlock(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(ipBlock);
|
||||
assertEquals(ipBlock.id(), id);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNonExisingIpBlock() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
IpBlockApi api = pbApi.ipBlockApi();
|
||||
|
||||
String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop";
|
||||
|
||||
try {
|
||||
IpBlock ipBlock = api.getIpBlock(id);
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertNull(ipBlock);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllIpBlock() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblocks.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
IpBlockApi api = pbApi.ipBlockApi();
|
||||
|
||||
try {
|
||||
List<IpBlock> ipBlocks = api.getAllIpBlock();
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertNotNull(ipBlocks);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllIpBlockReturning404() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(404));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
IpBlockApi api = pbApi.ipBlockApi();
|
||||
|
||||
try {
|
||||
List<IpBlock> ipBlocks = api.getAllIpBlock();
|
||||
assertRequestHasCommonProperties(server.takeRequest());
|
||||
assertTrue(ipBlocks.isEmpty());
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReservePublicIpBlock() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-reserve.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
IpBlockApi api = pbApi.ipBlockApi();
|
||||
|
||||
String blockSize = "2";
|
||||
Location location = Location.US_LAS;
|
||||
|
||||
String content = "<ws:reservePublicIpBlock><request><blockSize>" + blockSize + "</blockSize><location>" + location.value() + "</location></request></ws:reservePublicIpBlock>";
|
||||
try {
|
||||
IpBlock ipBlock = api.reservePublicIpBlock(blockSize, location.value());
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(ipBlock);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddPublicIpToNic() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-addtonic.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
IpBlockApi api = pbApi.ipBlockApi();
|
||||
|
||||
String ip = "2";
|
||||
String nicid = "nicid";
|
||||
|
||||
String content = "<ws:addPublicIpToNic><ip>" + ip + "</ip><nicId>" + nicid + "</nicId></ws:addPublicIpToNic>";
|
||||
try {
|
||||
String requestId = api.addPublicIpToNic(ip, nicid);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(requestId);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemovePublicIpFromNic() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-removefromnic.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
IpBlockApi api = pbApi.ipBlockApi();
|
||||
|
||||
String ip = "2";
|
||||
String nicid = "nicid";
|
||||
|
||||
String content = "<ws:removePublicIpFromNic><ip>" + ip + "</ip><nicId>" + nicid + "</nicId></ws:removePublicIpFromNic>";
|
||||
try {
|
||||
String requestId = api.removePublicIpFromNic(ip, nicid);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(requestId);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReleasePublicIpBlock() throws Exception {
|
||||
MockWebServer server = mockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-release.xml")));
|
||||
|
||||
ProfitBricksApi pbApi = api(server.getUrl(rootUrl));
|
||||
IpBlockApi api = pbApi.ipBlockApi();
|
||||
|
||||
String blockid = "2";
|
||||
|
||||
String content = "<ws:releasePublicIpBlock><blockId>" + blockid + "</blockId></ws:releasePublicIpBlock>";
|
||||
try {
|
||||
String requestId = api.releasePublicIpBlock(blockid);
|
||||
assertRequestHasCommonProperties(server.takeRequest(), content);
|
||||
assertNotNull(requestId);
|
||||
} finally {
|
||||
pbApi.close();
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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.ipblock;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.domain.IpBlock;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.domain.IpBlock.PublicIp;
|
||||
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 = "IpBlockListResponseHandlerTest")
|
||||
public class IpBlockListResponseHandlerTest extends BaseResponseHandlerTest<List<IpBlock>> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<List<IpBlock>> createParser() {
|
||||
return factory.create(injector.getInstance(IpBlockListResponseHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetAllIpBlock() {
|
||||
ParseSax<List<IpBlock>> parser = createParser();
|
||||
|
||||
List<IpBlock> actual = parser.parse(payloadFromResource("/ipblock/ipblocks.xml"));
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
|
||||
List<IpBlock> expected = ImmutableList.<IpBlock>of(
|
||||
IpBlock.builder()
|
||||
.id("block-id")
|
||||
.location(Location.US_LAS)
|
||||
.publicIps(ImmutableList.<PublicIp>of(
|
||||
PublicIp.builder()
|
||||
.ip("1.1")
|
||||
.nicId("nic-id")
|
||||
.build(),
|
||||
PublicIp.builder()
|
||||
.ip("1.2")
|
||||
.nicId("nic-id")
|
||||
.build()))
|
||||
.build(),
|
||||
IpBlock.builder()
|
||||
.id("block-id")
|
||||
.location(Location.US_LAS)
|
||||
.publicIps(ImmutableList.<PublicIp>of(
|
||||
PublicIp.builder()
|
||||
.ip("2.1")
|
||||
.nicId("nic-id")
|
||||
.build(),
|
||||
PublicIp.builder()
|
||||
.ip("2.2")
|
||||
.nicId("nic-id")
|
||||
.build()))
|
||||
.build()
|
||||
);
|
||||
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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.ipblock;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.profitbricks.domain.IpBlock;
|
||||
import org.jclouds.profitbricks.domain.Location;
|
||||
import org.jclouds.profitbricks.domain.IpBlock.PublicIp;
|
||||
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 = "IpBlockResponseHandlerTest")
|
||||
public class IpBlockResponseHandlerTest extends BaseResponseHandlerTest<IpBlock> {
|
||||
|
||||
@Override
|
||||
protected ParseSax<IpBlock> createParser() {
|
||||
return factory.create(injector.getInstance(IpBlockResponseHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseResponseFromGetIpBlock() {
|
||||
ParseSax<IpBlock> parser = createParser();
|
||||
|
||||
IpBlock actual = parser.parse(payloadFromResource("/ipblock/ipblock.xml"));
|
||||
assertNotNull(actual, "Parsed content returned null");
|
||||
List<String> emptyIpList = Lists.newArrayList();
|
||||
|
||||
IpBlock expected = IpBlock.builder()
|
||||
.id("qwertyui-qwer-qwer-qwer-qwertyyuiiop")
|
||||
.location(Location.US_LAS)
|
||||
.publicIps(ImmutableList.<PublicIp>of(
|
||||
PublicIp.builder()
|
||||
.ip("ip")
|
||||
.nicId("nic-id")
|
||||
.build(),
|
||||
PublicIp.builder()
|
||||
.ip("ip")
|
||||
.nicId("nic-id")
|
||||
.build()))
|
||||
.ips(emptyIpList)
|
||||
.build();
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:addPublicIpToNicResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<requestId>request-id</requestId>
|
||||
<dataCenterId>datacenter-id</dataCenterId>
|
||||
<dataCenterVersion>datacenter-version</dataCenterVersion>
|
||||
</return>
|
||||
</ns2:addPublicIpToNicResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:releasePublicIpBlockResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<requestId>request-id</requestId>
|
||||
</return>
|
||||
</ns2:releasePublicIpBlockResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:addPublicIpToNicResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<requestId>request-id</requestId>
|
||||
<dataCenterId>datacenter-id</dataCenterId>
|
||||
<dataCenterVersion>datacenter-version</dataCenterVersion>
|
||||
</return>
|
||||
</ns2:addPublicIpToNicResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:reservePublicIpBlockResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<requestId>request-id</requestId>
|
||||
<blockId>block-id</blockId>
|
||||
<location>us/las</location>
|
||||
<ips>ip</ips>
|
||||
</return>
|
||||
</ns2:reservePublicIpBlockResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:getAllPublicIpBlocksResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<blockId>qwertyui-qwer-qwer-qwer-qwertyyuiiop</blockId>
|
||||
<location>us/las</location>
|
||||
<publicIps>
|
||||
<ip>ip</ip>
|
||||
<nicId>nic-id</nicId>
|
||||
</publicIps>
|
||||
<publicIps>
|
||||
<ip>ip</ip>
|
||||
</publicIps>
|
||||
</return>
|
||||
</ns2:getAllPublicIpBlocksResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<S:Body>
|
||||
<ns2:getAllPublicIpBlocksResponse xmlns:ns2="http://ws.api.profitbricks.com/">
|
||||
<return>
|
||||
<blockId>block-id</blockId>
|
||||
<location>us/las</location>
|
||||
<publicIps>
|
||||
<ip>1.1</ip>
|
||||
<nicId>nic-id</nicId>
|
||||
</publicIps>
|
||||
<publicIps>
|
||||
<ip>1.2</ip>
|
||||
<nicId>nic-id</nicId>
|
||||
</publicIps>
|
||||
</return>
|
||||
<return>
|
||||
<blockId>block-id</blockId>
|
||||
<location>us/las</location>
|
||||
<publicIps>
|
||||
<ip>2.1</ip>
|
||||
</publicIps>
|
||||
<publicIps>
|
||||
<ip>2.2</ip>
|
||||
<nicId>nic-id</nicId>
|
||||
</publicIps>
|
||||
</return>
|
||||
</ns2:getAllPublicIpBlocksResponse>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
Loading…
Reference in New Issue