mirror of https://github.com/apache/jclouds.git
added FirewallService and FirewallRule implementation for Savvis
This commit is contained in:
parent
5ae1ba44d2
commit
8cd0036475
|
@ -0,0 +1,348 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.savvis.vpdc.domain;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* API returns a firewall rule in a firewall service
|
||||
*
|
||||
* @author Kedar Dave
|
||||
*/
|
||||
public class FirewallRule extends Resource {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder extends Resource.Builder {
|
||||
|
||||
private String firewallType;
|
||||
private boolean isEnabled;
|
||||
private String source;
|
||||
private String destination;
|
||||
private String port;
|
||||
private String policy;
|
||||
private String description;
|
||||
private boolean isLogged;
|
||||
private String protocol;
|
||||
|
||||
@Override
|
||||
public FirewallRule build() {
|
||||
return new FirewallRule(id, name, type, href, firewallType, isEnabled, source, destination, port,
|
||||
policy, description, isLogged, protocol);
|
||||
}
|
||||
|
||||
public Builder firewallType(String firewallType) {
|
||||
this.firewallType = firewallType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isEnabled(boolean isEnabled) {
|
||||
this.isEnabled = isEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder source(String source) {
|
||||
this.source = source;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder destination(String destination) {
|
||||
this.destination = destination;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder port(String port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder policy(String policy) {
|
||||
this.policy = policy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isLogged(boolean isLogged) {
|
||||
this.isLogged = isLogged;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder protocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean isEnabled) {
|
||||
this.isEnabled = isEnabled;
|
||||
}
|
||||
|
||||
public String getFirewallType() {
|
||||
return firewallType;
|
||||
}
|
||||
|
||||
public void setFirewallType(String firewallType) {
|
||||
this.firewallType = firewallType;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public String getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(String destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
public void setPolicy(String policy) {
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isLogged() {
|
||||
return isLogged;
|
||||
}
|
||||
|
||||
public void setLogged(boolean isLogged) {
|
||||
this.isLogged = isLogged;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public static Builder fromFirewallRule(FirewallRule in) {
|
||||
return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref())
|
||||
.firewallType(in.getFirewallType()).isEnabled(in.isEnabled()).source(in.getSource())
|
||||
.destination(in.getDestination()).port(in.getPort()).policy(in.getPolicy()).description(in.getDescription())
|
||||
.isLogged(in.isLogged()).protocol(in.getProtocol());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder id(String id) {
|
||||
return Builder.class.cast(super.id(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder name(String name) {
|
||||
return Builder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder type(String type) {
|
||||
return Builder.class.cast(super.type(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder href(URI href) {
|
||||
return Builder.class.cast(super.href(href));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String firewallType;
|
||||
private boolean isEnabled;
|
||||
private String source;
|
||||
private String destination;
|
||||
private String port;
|
||||
private String policy;
|
||||
private String description;
|
||||
private boolean isLogged;
|
||||
private String protocol;
|
||||
|
||||
public FirewallRule(String id, String name, String type, URI href, String firewallType, boolean isEnabled,
|
||||
String source, String destination, String port, String policy, String description, boolean isLogged, String protocol) {
|
||||
super(id, name, type, href);
|
||||
this.firewallType = firewallType;
|
||||
this.isEnabled = isEnabled;
|
||||
this.source = source;
|
||||
this.destination = destination;
|
||||
this.port = port;
|
||||
this.policy = policy;
|
||||
this.description = description;
|
||||
this.isLogged = isLogged;
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder toBuilder() {
|
||||
return Builder.fromFirewallRule(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
FirewallRule other = (FirewallRule) obj;
|
||||
if (firewallType == null) {
|
||||
if (other.firewallType != null)
|
||||
return false;
|
||||
} else if (!firewallType.equals(other.firewallType))
|
||||
return false;
|
||||
if (source == null) {
|
||||
if (other.source != null)
|
||||
return false;
|
||||
} else if (!source.equals(other.source))
|
||||
return false;
|
||||
if (destination == null) {
|
||||
if (other.destination != null)
|
||||
return false;
|
||||
} else if (!destination.equals(other.destination))
|
||||
return false;
|
||||
if (port == null) {
|
||||
if (other.port != null)
|
||||
return false;
|
||||
} else if (!port.equals(other.port))
|
||||
return false;
|
||||
if (policy == null) {
|
||||
if (other.policy != null)
|
||||
return false;
|
||||
} else if (!policy.equals(other.policy))
|
||||
return false;
|
||||
if (protocol == null) {
|
||||
if (other.protocol != null)
|
||||
return false;
|
||||
} else if (!protocol.equals(other.protocol))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean isEnabled) {
|
||||
this.isEnabled = isEnabled;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public String getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(String destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public String getFirewallType() {
|
||||
return firewallType;
|
||||
}
|
||||
|
||||
public void setFirewallType(String firewallType) {
|
||||
this.firewallType = firewallType;
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
public void setPolicy(String policy) {
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isLogged() {
|
||||
return isLogged;
|
||||
}
|
||||
|
||||
public void setLogged(boolean isLogged) {
|
||||
this.isLogged = isLogged;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[firewallType=" + firewallType + ", description=" + description + ", source=" + source + ", destination=" + destination
|
||||
+ ", port=" + port + ", protocol=" + protocol + ", policy=" + policy + ", isLogged=" + isLogged;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.savvis.vpdc.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* API returns the firewall service containing firewall rules for a given VDC
|
||||
*
|
||||
* @author Kedar Dave
|
||||
*/
|
||||
public class FirewallService extends Resource {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder extends Resource.Builder {
|
||||
private boolean isEnabled;
|
||||
private Set<FirewallRule> firewallRules = Sets.newLinkedHashSet();
|
||||
|
||||
@Override
|
||||
public FirewallService build() {
|
||||
return new FirewallService(id, name, type, href, isEnabled, firewallRules);
|
||||
}
|
||||
|
||||
public Builder isEnabled(boolean isEnabled) {
|
||||
this.isEnabled = isEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder firewallRule(FirewallRule in) {
|
||||
this.firewallRules.add(checkNotNull(in, "firewallRule"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder firewallRules(Set<FirewallRule> firewallRules) {
|
||||
this.firewallRules.addAll(checkNotNull(firewallRules, "firewallRules"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Builder fromFirewallService(FirewallService in) {
|
||||
return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref())
|
||||
.isEnabled(in.isEnabled()).firewallRules(in.getFirewallRules());
|
||||
}
|
||||
|
||||
public Set<FirewallRule> getFirewallRules() {
|
||||
return firewallRules;
|
||||
}
|
||||
|
||||
public void setFirewallRules(Set<FirewallRule> firewallRules) {
|
||||
this.firewallRules = firewallRules;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean isEnabled) {
|
||||
this.isEnabled = isEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder id(String id) {
|
||||
return Builder.class.cast(super.id(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder name(String name) {
|
||||
return Builder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder type(String type) {
|
||||
return Builder.class.cast(super.type(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder href(URI href) {
|
||||
return Builder.class.cast(super.href(href));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isEnabled;
|
||||
private Set<FirewallRule> firewallRules;
|
||||
|
||||
public FirewallService(String id, String name, String type, URI href, boolean isEnabled, Set<FirewallRule> firewallRules) {
|
||||
super(id, name, type, href);
|
||||
this.isEnabled = isEnabled;
|
||||
this.firewallRules = ImmutableSet.copyOf(checkNotNull(firewallRules, "firewallRules"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder toBuilder() {
|
||||
return Builder.fromFirewallService(this);
|
||||
}
|
||||
|
||||
public Set<FirewallRule> getFirewallRules() {
|
||||
return firewallRules;
|
||||
}
|
||||
|
||||
public void setFirewallRules(Set<FirewallRule> firewallRules) {
|
||||
this.firewallRules = firewallRules;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean isEnabled) {
|
||||
this.isEnabled = isEnabled;
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,7 @@ import org.jclouds.rest.annotations.ParamParser;
|
|||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.savvis.vpdc.domain.FirewallService;
|
||||
import org.jclouds.savvis.vpdc.domain.Network;
|
||||
import org.jclouds.savvis.vpdc.domain.Org;
|
||||
import org.jclouds.savvis.vpdc.domain.Task;
|
||||
|
@ -39,6 +40,7 @@ import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie;
|
|||
import org.jclouds.savvis.vpdc.functions.DefaultOrgIfNull;
|
||||
import org.jclouds.savvis.vpdc.options.BindGetVAppOptions;
|
||||
import org.jclouds.savvis.vpdc.options.GetVAppOptions;
|
||||
import org.jclouds.savvis.vpdc.xml.FirewallServiceHandler;
|
||||
import org.jclouds.savvis.vpdc.xml.NetworkHandler;
|
||||
import org.jclouds.savvis.vpdc.xml.OrgHandler;
|
||||
import org.jclouds.savvis.vpdc.xml.TaskHandler;
|
||||
|
@ -111,4 +113,14 @@ public interface BrowsingAsyncClient {
|
|||
@Path("task/{taskId}")
|
||||
ListenableFuture<Task> getTask(@PathParam("taskId") String taskId);
|
||||
|
||||
/**
|
||||
* @see BrowsingClient#getFirewallRules
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(FirewallServiceHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("org/{billingSiteId}/vdc/{vpdcId}/FirewallService")
|
||||
ListenableFuture<FirewallService> getFirewallRules(@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
|
||||
@PathParam("vpdcId") String vpdcId);
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.savvis.vpdc.domain.FirewallService;
|
||||
import org.jclouds.savvis.vpdc.domain.Network;
|
||||
import org.jclouds.savvis.vpdc.domain.Org;
|
||||
import org.jclouds.savvis.vpdc.domain.Task;
|
||||
|
@ -105,4 +106,18 @@ public interface BrowsingClient {
|
|||
*/
|
||||
Task getTask(String taskId);
|
||||
|
||||
/**
|
||||
* Gets Firewall Rules
|
||||
*
|
||||
* @param billingSiteId
|
||||
* billing site Id, or null for default
|
||||
* @param vpdcId
|
||||
* vpdc Id
|
||||
*
|
||||
* @return If the request is successful, caller could get the firewall rules as specified in the
|
||||
* result element and if the request is not successful, caller would get empty
|
||||
* rules list and respective validation (error) message.
|
||||
*/
|
||||
FirewallService getFirewallRules(String billingSiteId, String vpdcId);
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.savvis.vpdc.xml;
|
||||
|
||||
import static org.jclouds.util.SaxUtils.currentOrNull;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.savvis.vpdc.domain.FirewallRule;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author Kedar Dave
|
||||
*/
|
||||
public class FirewallRuleHandler extends ParseSax.HandlerWithResult<FirewallRule> {
|
||||
protected StringBuilder currentText = new StringBuilder();
|
||||
private FirewallRule.Builder builder = FirewallRule.builder();
|
||||
|
||||
public FirewallRule getResult() {
|
||||
try {
|
||||
return builder.build();
|
||||
} finally {
|
||||
builder = FirewallRule.builder();
|
||||
}
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
String current = currentOrNull(currentText);
|
||||
if(current != null){
|
||||
if (qName.endsWith("Type")) {
|
||||
builder.firewallType(current);
|
||||
} else if (qName.endsWith("IsEnabled")) {
|
||||
builder.isEnabled(Boolean.parseBoolean(current));
|
||||
} else if (qName.endsWith("Source")) {
|
||||
builder.source(current);
|
||||
} else if (qName.endsWith("Destination")) {
|
||||
builder.destination(current);
|
||||
} else if (qName.endsWith("Port")) {
|
||||
builder.port(current);
|
||||
} else if (qName.endsWith("Policy")) {
|
||||
builder.policy(current);
|
||||
} else if (qName.endsWith("Description")) {
|
||||
builder.description(current);
|
||||
} else if (qName.endsWith("Log")) {
|
||||
builder.isLogged(Boolean.parseBoolean(current));
|
||||
} else if (qName.endsWith("Tcp")) {
|
||||
builder.protocol("Tcp");
|
||||
} else if (qName.contains("Udp") || qName.contains("udp")) {
|
||||
builder.protocol("Udp");
|
||||
} else if (qName.contains("Icmp") || qName.contains("icmp") ||
|
||||
qName.contains("Ping") || qName.contains("ping")) {
|
||||
builder.protocol("Icmp-ping");
|
||||
}
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.savvis.vpdc.xml;
|
||||
|
||||
import static org.jclouds.util.SaxUtils.currentOrNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.savvis.vpdc.domain.FirewallService;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author Kedar Dave
|
||||
*/
|
||||
public class FirewallServiceHandler extends ParseSax.HandlerWithResult<FirewallService> {
|
||||
protected StringBuilder currentText = new StringBuilder();
|
||||
private FirewallRuleHandler firewallRuleHandler;
|
||||
private FirewallService.Builder builder = FirewallService.builder();
|
||||
boolean inFirewallService;
|
||||
boolean inFirewallRule;
|
||||
|
||||
@Inject
|
||||
public FirewallServiceHandler(FirewallRuleHandler firewallRuleHandler) {
|
||||
this.firewallRuleHandler = firewallRuleHandler;
|
||||
}
|
||||
|
||||
public FirewallService getResult() {
|
||||
try {
|
||||
return builder.build();
|
||||
} finally {
|
||||
builder = FirewallService.builder();
|
||||
}
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||
if (qName.endsWith("FirewallService")) {
|
||||
inFirewallService = true;
|
||||
} else if (qName.endsWith("FirewallRule")) {
|
||||
inFirewallRule = true;
|
||||
firewallRuleHandler.startElement(uri, localName, qName, attrs);
|
||||
}
|
||||
else{
|
||||
// firewallRuleHandler.startElement(uri, localName, qName, attrs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if (qName.endsWith("FirewallService")) {
|
||||
inFirewallService = false;
|
||||
} else if(qName.endsWith("FirewallRule")) {
|
||||
builder.firewallRule(firewallRuleHandler.getResult());
|
||||
inFirewallRule = false;
|
||||
} else if (qName.endsWith("isEnabled")) {
|
||||
if(inFirewallService){
|
||||
String current = currentOrNull(currentText);
|
||||
if(current != null){
|
||||
builder.isEnabled(Boolean.parseBoolean(current));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inFirewallRule) {
|
||||
firewallRuleHandler.endElement(uri, localName, qName);
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
firewallRuleHandler.characters(ch, start, length);
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,11 @@ import static org.jclouds.savvis.vpdc.options.GetVAppOptions.Builder.withPowerSt
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.savvis.vpdc.domain.FirewallRule;
|
||||
import org.jclouds.savvis.vpdc.domain.FirewallService;
|
||||
import org.jclouds.savvis.vpdc.domain.Network;
|
||||
import org.jclouds.savvis.vpdc.domain.Org;
|
||||
import org.jclouds.savvis.vpdc.domain.Resource;
|
||||
|
@ -107,7 +112,7 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testVApp() throws Exception {
|
||||
for (Resource org1 : context.getApi().listOrgs()) {
|
||||
|
@ -143,4 +148,29 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFirewallRules() throws Exception {
|
||||
for (Resource org1 : context.getApi().listOrgs()) {
|
||||
Org org = client.getOrg(org1.getId());
|
||||
for (Resource vdc : org.getVDCs()) {
|
||||
FirewallService response = client.getFirewallRules(org.getId(), vdc.getId());
|
||||
Set<FirewallRule> firewallRules = response.getFirewallRules();
|
||||
if(firewallRules != null){
|
||||
Iterator<FirewallRule> iter = firewallRules.iterator();
|
||||
while(iter.hasNext()){
|
||||
FirewallRule firewallRule = iter.next();
|
||||
assertNotNull(firewallRule);
|
||||
// these are null for firewall rules
|
||||
assertEquals(response.getHref(), null);
|
||||
assertEquals(response.getType(), null);
|
||||
assertNotNull(firewallRule.getFirewallType());
|
||||
assertNotNull(firewallRule.getProtocol());
|
||||
assertNotNull(firewallRule.getSource());
|
||||
assertNotNull(firewallRule.getDestination());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.savvis.vpdc.xml;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.Factory;
|
||||
import org.jclouds.http.functions.config.SaxParserModule;
|
||||
import org.jclouds.savvis.vpdc.domain.FirewallRule;
|
||||
import org.jclouds.savvis.vpdc.domain.FirewallService;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code FirewallServiceHandler and @code FirewallRuleHandler}
|
||||
*
|
||||
* @author Kedar Dave
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class FirewallServiceHandlerTest {
|
||||
|
||||
public void test() {
|
||||
InputStream is = getClass().getResourceAsStream("/firewallService.xml");
|
||||
Injector injector = Guice.createInjector(new SaxParserModule());
|
||||
Factory factory = injector.getInstance(ParseSax.Factory.class);
|
||||
FirewallService result = factory.create(injector.getInstance(FirewallServiceHandler.class)).parse(is);
|
||||
assertEquals(result.isEnabled(), false);
|
||||
assertEquals(
|
||||
result.getFirewallRules(),
|
||||
ImmutableSet.<FirewallRule> of(
|
||||
new FirewallRule(null, null, null, null, "SERVER_TIER_FIREWALL", true, "internet" , "VM Tier01" ,
|
||||
"22", "allow", "Server Tier Firewall Rule", false, "Tcp"),
|
||||
new FirewallRule(null, null, null, null, "SERVER_TIER_FIREWALL", true, "VM Tier03" , "VM Tier03" ,
|
||||
null, "allow", "Server Tier Firewall Rule", false, "Icmp-ping")));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<svvs:FirewallService xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common"
|
||||
xmlns:vApp="http://www.vmware.com/vcloud/v0.8"
|
||||
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
|
||||
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
|
||||
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
xmlns:svvs="http://schemas.api.sandbox.symphonyVPDC.savvis.net/vpdci">
|
||||
<svvs:IsEnabled>false</svvs:IsEnabled>
|
||||
<svvs:FirewallRule>
|
||||
<svvs:IsEnabled>true</svvs:IsEnabled>
|
||||
<svvs:Description>Server Tier Firewall Rule</svvs:Description>
|
||||
<svvs:Type>SERVER_TIER_FIREWALL</svvs:Type>
|
||||
<svvs:Log>no</svvs:Log>
|
||||
<svvs:Policy>allow</svvs:Policy>
|
||||
<svvs:Protocols>
|
||||
<svvs:Tcp>true</svvs:Tcp>
|
||||
</svvs:Protocols>
|
||||
<svvs:Port>22</svvs:Port>
|
||||
<svvs:Destination>VM Tier01</svvs:Destination>
|
||||
<svvs:Source>internet</svvs:Source>
|
||||
</svvs:FirewallRule>
|
||||
<svvs:FirewallRule>
|
||||
<svvs:IsEnabled>true</svvs:IsEnabled>
|
||||
<svvs:Description>Server Tier Firewall Rule</svvs:Description>
|
||||
<svvs:Type>SERVER_TIER_FIREWALL</svvs:Type>
|
||||
<svvs:Log>no</svvs:Log>
|
||||
<svvs:Policy>allow</svvs:Policy>
|
||||
<svvs:Protocols>
|
||||
<svvs:Icmp-ping>true</svvs:Icmp-ping>
|
||||
</svvs:Protocols>
|
||||
<svvs:Port></svvs:Port>
|
||||
<svvs:Destination>VM Tier03</svvs:Destination>
|
||||
<svvs:Source>VM Tier03</svvs:Source>
|
||||
</svvs:FirewallRule>
|
||||
</svvs:FirewallService>
|
Loading…
Reference in New Issue