Search in sources :

Example 1 with SecurityGroupVmRuleSet

use of com.cloud.baremetal.networkservice.schema.SecurityGroupVmRuleSet in project cloudstack by apache.

the class SecurityGroupHttpClient method call.

public SecurityGroupRuleAnswer call(String agentIp, SecurityGroupRulesCmd cmd) {
    PostMethod post = new PostMethod(String.format("http://%s:%s", agentIp, getPort()));
    try {
        SecurityGroupVmRuleSet rset = new SecurityGroupVmRuleSet();
        rset.getEgressRules().addAll(generateRules(cmd.getEgressRuleSet()));
        rset.getIngressRules().addAll(generateRules(cmd.getIngressRuleSet()));
        rset.setVmName(cmd.getVmName());
        rset.setVmIp(cmd.getGuestIp());
        rset.setVmMac(cmd.getGuestMac());
        rset.setVmId(cmd.getVmId());
        rset.setSignature(cmd.getSignature());
        rset.setSequenceNumber(cmd.getSeqNum());
        Marshaller marshaller = context.createMarshaller();
        StringWriter writer = new StringWriter();
        marshaller.marshal(rset, writer);
        String xmlContents = writer.toString();
        logger.debug(xmlContents);
        post.addRequestHeader("command", "set_rules");
        StringRequestEntity entity = new StringRequestEntity(xmlContents);
        post.setRequestEntity(entity);
        if (httpClient.executeMethod(post) != 200) {
            return new SecurityGroupRuleAnswer(cmd, false, post.getResponseBodyAsString());
        } else {
            return new SecurityGroupRuleAnswer(cmd);
        }
    } catch (Exception e) {
        return new SecurityGroupRuleAnswer(cmd, false, e.getMessage());
    } finally {
        if (post != null) {
            post.releaseConnection();
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) StringWriter(java.io.StringWriter) PostMethod(org.apache.commons.httpclient.methods.PostMethod) SecurityGroupVmRuleSet(com.cloud.baremetal.networkservice.schema.SecurityGroupVmRuleSet) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SocketTimeoutException(java.net.SocketTimeoutException)

Aggregations

SecurityGroupRuleAnswer (com.cloud.agent.api.SecurityGroupRuleAnswer)1 SecurityGroupVmRuleSet (com.cloud.baremetal.networkservice.schema.SecurityGroupVmRuleSet)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 StringWriter (java.io.StringWriter)1 SocketTimeoutException (java.net.SocketTimeoutException)1 Marshaller (javax.xml.bind.Marshaller)1 PostMethod (org.apache.commons.httpclient.methods.PostMethod)1 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)1