Fix CloudStack EgressFirewall request parameter name

createEgressFirewall needs networkid instead of ipaddressid:
    http://download.cloud.com/releases/3.0.6/api_3.0.6/root_admin/createEgressFirewallRule.html
This commit is contained in:
Hyeonu Jeong 2013-12-12 15:28:08 +09:00 committed by Andrew Bayer
parent 5ba527ec33
commit 6d9784c4b5
4 changed files with 190 additions and 10 deletions

View File

@ -32,6 +32,7 @@ import org.jclouds.cloudstack.domain.FirewallRule;
import org.jclouds.cloudstack.domain.PortForwardingRule;
import org.jclouds.cloudstack.filters.AuthenticationFilter;
import org.jclouds.cloudstack.options.CreateFirewallRuleOptions;
import org.jclouds.cloudstack.options.ListEgressFirewallRulesOptions;
import org.jclouds.cloudstack.options.ListFirewallRulesOptions;
import org.jclouds.cloudstack.options.ListPortForwardingRulesOptions;
import org.jclouds.rest.annotations.Fallback;
@ -118,7 +119,7 @@ public interface FirewallApi {
@SelectJson("firewallrule")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(EmptySetOnNotFoundOr404.class)
Set<FirewallRule> listEgressFirewallRules(ListFirewallRulesOptions... options);
Set<FirewallRule> listEgressFirewallRules(ListEgressFirewallRulesOptions... options);
/**
* @see FirewallApi#getEgressFirewallRule
@ -133,26 +134,26 @@ public interface FirewallApi {
FirewallRule getEgressFirewallRule(@QueryParam("id") String id);
/**
* @see FirewallApi#createEgressFirewallRuleForIpAndProtocol
* @see FirewallApi#createEgressFirewallRuleForNetworkAndProtocol
*/
@Named("createEgressFirewallRule")
@GET
@QueryParams(keys = "command", values = "createEgressFirewallRule")
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
AsyncCreateResponse createEgressFirewallRuleForIpAndProtocol(@QueryParam("ipaddressid") String ipAddressId,
AsyncCreateResponse createEgressFirewallRuleForNetworkAndProtocol(@QueryParam("networkid") String networkId,
@QueryParam("protocol") FirewallRule.Protocol protocol,
CreateFirewallRuleOptions... options);
/**
* @see FirewallApi#createEgressFirewallRuleForIpProtocolAndPort
* @see FirewallApi#createEgressFirewallRuleForNetworkProtocolAndPort
*/
@Named("createEgressFirewallRule")
@GET
@QueryParams(keys = "command", values = "createEgressFirewallRule")
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
AsyncCreateResponse createEgressFirewallRuleForIpProtocolAndPort(@QueryParam("ipaddressid") String ipAddressId,
AsyncCreateResponse createEgressFirewallRuleForNetworkProtocolAndPort(@QueryParam("networkId") String networkId,
@QueryParam("protocol") FirewallRule.Protocol protocol,
@QueryParam("startPort") int startPort,
@QueryParam("endPort") int endPort);

View File

@ -0,0 +1,179 @@
/*
* 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.cloudstack.options;
import com.google.common.collect.ImmutableSet;
/**
* Options used to control what egress firewall rules are returned
*
* @see <a href=
* "http://download.cloud.com/releases/3.0.6/api_3.0.6/root_admin/listEgressFirewallRules.html"
* />
* @author Hyeonu Jeong
*/
public class ListEgressFirewallRulesOptions extends AccountInDomainOptions {
public static final ListEgressFirewallRulesOptions NONE = new ListEgressFirewallRulesOptions();
/**
* @param id
* firewall rule ID
*/
public ListEgressFirewallRulesOptions id(String id) {
this.queryParameters.replaceValues("id", ImmutableSet.of(id + ""));
return this;
}
/**
* @param networkId
* the id of network of the firewall services
*/
public ListEgressFirewallRulesOptions networkId(String networkId) {
this.queryParameters.replaceValues("networkid", ImmutableSet.of(networkId + ""));
return this;
}
/**
* @param ipAddressId
* the id of IP address of the firewall services
*/
public ListEgressFirewallRulesOptions ipAddressId(String ipAddressId) {
this.queryParameters.replaceValues("ipaddressid", ImmutableSet.of(ipAddressId + ""));
return this;
}
/**
* @param projectId
* List firewall rules in this project.
*/
public ListEgressFirewallRulesOptions projectId(String projectId) {
this.queryParameters.replaceValues("projectid", ImmutableSet.of(projectId + ""));
return this;
}
/**
* @param keyword
* list by keyword
*/
public ListEgressFirewallRulesOptions keyword(String keyword) {
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword));
return this;
}
public ListEgressFirewallRulesOptions page(long page) {
this.queryParameters.replaceValues("page", ImmutableSet.of(page + ""));
return this;
}
public ListEgressFirewallRulesOptions pageSize(long pageSize) {
this.queryParameters.replaceValues("pagesize", ImmutableSet.of(pageSize + ""));
return this;
}
public static class Builder {
/**
* @see ListEgressFirewallRulesOptions#id
*/
public static ListEgressFirewallRulesOptions id(String id) {
ListEgressFirewallRulesOptions options = new ListEgressFirewallRulesOptions();
return options.id(id);
}
/**
* @see ListEgressFirewallRulesOptions#networkId
*/
public static ListEgressFirewallRulesOptions networkId(String networkId) {
ListEgressFirewallRulesOptions options = new ListEgressFirewallRulesOptions();
return options.networkId(networkId);
}
/**
* @see ListEgressFirewallRulesOptions#ipAddressId
*/
public static ListEgressFirewallRulesOptions ipAddressId(String ipAddressId) {
ListEgressFirewallRulesOptions options = new ListEgressFirewallRulesOptions();
return options.ipAddressId(ipAddressId);
}
/**
* @see ListEgressFirewallRulesOptions#projectId(String)
*/
public static ListEgressFirewallRulesOptions projectId(String projectId) {
ListEgressFirewallRulesOptions options = new ListEgressFirewallRulesOptions();
return options.projectId(projectId);
}
/**
* @see ListEgressFirewallRulesOptions#keyword
*/
public static ListEgressFirewallRulesOptions keyword(String keyword) {
ListEgressFirewallRulesOptions options = new ListEgressFirewallRulesOptions();
return options.keyword(keyword);
}
/**
* @see ListEgressFirewallRulesOptions#page
*/
public static ListEgressFirewallRulesOptions page(long page) {
ListEgressFirewallRulesOptions options = new ListEgressFirewallRulesOptions();
return options.page(page);
}
/**
* @see ListEgressFirewallRulesOptions#pageSize
*/
public static ListEgressFirewallRulesOptions pageSize(long pageSize) {
ListEgressFirewallRulesOptions options = new ListEgressFirewallRulesOptions();
return options.pageSize(pageSize);
}
/**
* @see ListEgressFirewallRulesOptions#accountInDomain
*/
public static ListEgressFirewallRulesOptions accountInDomain(String account, String domain) {
ListEgressFirewallRulesOptions options = new ListEgressFirewallRulesOptions();
return options.accountInDomain(account, domain);
}
/**
* @see ListEgressFirewallRulesOptions#domainId
*/
public static ListEgressFirewallRulesOptions domainId(String id) {
ListEgressFirewallRulesOptions options = new ListEgressFirewallRulesOptions();
return options.domainId(id);
}
}
/**
* {@inheritDoc}
*/
@Override
public ListEgressFirewallRulesOptions accountInDomain(String account, String domain) {
return ListEgressFirewallRulesOptions.class.cast(super.accountInDomain(account, domain));
}
/**
* {@inheritDoc}
*/
@Override
public ListEgressFirewallRulesOptions domainId(String domainId) {
return ListEgressFirewallRulesOptions.class.cast(super.domainId(domainId));
}
}

View File

@ -363,13 +363,13 @@ public class FirewallApiExpectTest extends BaseCloudStackExpectTest<FirewallApi>
assertNull(client.getEgressFirewallRule("4"));
}
public void testCreateEgressFirewallRuleForIpAndProtocol() {
public void testCreateEgressFirewallRuleForNetworkAndProtocol() {
FirewallApi client = requestSendsResponse(
HttpRequest.builder()
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&command=createEgressFirewallRule&" +
"ipaddressid=2&protocol=TCP&apiKey=identity&signature=%2BlfEJ5zB7lxqRAn0rY0Rcfg9buw%3D"))
"networkid=2&protocol=TCP&apiKey=identity&signature=I/OJEqiLp8ZHlZskKUiT5uTRE3M%3D"))
.addHeader("Accept", "application/json")
.build(),
HttpResponse.builder()
@ -377,7 +377,7 @@ public class FirewallApiExpectTest extends BaseCloudStackExpectTest<FirewallApi>
.payload(payloadFromResource("/createegressfirewallrulesresponse.json"))
.build());
AsyncCreateResponse response = client.createEgressFirewallRuleForIpAndProtocol("2", FirewallRule.Protocol.TCP);
AsyncCreateResponse response = client.createEgressFirewallRuleForNetworkAndProtocol("2", FirewallRule.Protocol.TCP);
assertEquals(response.getJobId(), "2036");
assertEquals(response.getId(), "2017");
}

View File

@ -157,8 +157,8 @@ public class FirewallApiLiveTest extends BaseCloudStackApiLiveTest {
if (networksDisabled)
return;
AsyncCreateResponse job = client.getFirewallApi().createEgressFirewallRuleForIpAndProtocol(
ip.getId(), FirewallRule.Protocol.TCP, CreateFirewallRuleOptions.Builder.startPort(30).endPort(35));
AsyncCreateResponse job = client.getFirewallApi().createEgressFirewallRuleForNetworkAndProtocol(
network.getId(), FirewallRule.Protocol.TCP, CreateFirewallRuleOptions.Builder.startPort(30).endPort(35));
assertTrue(jobComplete.apply(job.getJobId()));
egressFirewallRule = client.getFirewallApi().getEgressFirewallRule(job.getId());