Search in sources :

Example 1 with ApplyAclRuleVspCommand

use of com.cloud.agent.api.element.ApplyAclRuleVspCommand in project cloudstack by apache.

the class NuageVspElement method applyACLRules.

protected boolean applyACLRules(final Network network, List<? extends InternalIdentity> rules, boolean isNetworkAcl, boolean networkReset) throws ResourceUnavailableException {
    VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
    List<VspAclRule> vspAclRules = Lists.transform(rules, new Function<InternalIdentity, VspAclRule>() {

        @Nullable
        @Override
        public VspAclRule apply(@Nullable InternalIdentity input) {
            if (input instanceof FirewallRule) {
                return _nuageVspEntityBuilder.buildVspAclRule((FirewallRule) input, network);
            }
            return _nuageVspEntityBuilder.buildVspAclRule((NetworkACLItem) input);
        }
    });
    HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
    VspAclRule.ACLType vspAclType = isNetworkAcl ? VspAclRule.ACLType.NetworkACL : VspAclRule.ACLType.Firewall;
    ApplyAclRuleVspCommand cmd = new ApplyAclRuleVspCommand(vspAclType, vspNetwork, vspAclRules, networkReset);
    Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("ApplyAclRuleNuageVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
        if ((null != answer) && (null != answer.getDetails())) {
            throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
        }
    }
    return true;
}
Also used : HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) NetworkACLItem(com.cloud.network.vpc.NetworkACLItem) ApplyAclRuleVspCommand(com.cloud.agent.api.element.ApplyAclRuleVspCommand) VspAclRule(net.nuage.vsp.acs.client.api.model.VspAclRule) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) InternalIdentity(org.apache.cloudstack.api.InternalIdentity) FirewallRule(com.cloud.network.rules.FirewallRule) Nullable(javax.annotation.Nullable)

Example 2 with ApplyAclRuleVspCommand

use of com.cloud.agent.api.element.ApplyAclRuleVspCommand in project cloudstack by apache.

the class CommandsTest method testApplyAclRuleVspCommandGsonEquals.

@Test
public void testApplyAclRuleVspCommandGsonEquals() throws IllegalAccessException, InvocationTargetException, InstantiationException {
    VspNetwork vspNetwork = new VspNetwork.Builder().id(1).uuid("uuid").name("name").cidr("192.168.1.0/24").gateway("192.168.1.1").build();
    VspAclRule aclRule = new VspAclRule.Builder().action(VspAclRule.ACLAction.Allow).uuid("uuid").trafficType(VspAclRule.ACLTrafficType.Egress).protocol(Protocol.TCP).startPort(80).endPort(80).priority(1).state(VspAclRule.ACLState.Active).build();
    ApplyAclRuleVspCommand before = new ApplyAclRuleVspCommand(VspAclRule.ACLType.NetworkACL, vspNetwork, Arrays.asList(aclRule), false);
    ApplyAclRuleVspCommand after = serializeAndDeserialize(before);
    Assert.assertThat(after.getAclRules().get(0).getProtocol().hasPort(), is(Protocol.TCP.hasPort()));
}
Also used : ApplyAclRuleVspCommand(com.cloud.agent.api.element.ApplyAclRuleVspCommand) VspAclRule(net.nuage.vsp.acs.client.api.model.VspAclRule) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) Test(org.junit.Test)

Example 3 with ApplyAclRuleVspCommand

use of com.cloud.agent.api.element.ApplyAclRuleVspCommand in project cloudstack by apache.

the class NuageVspResourceTest method testApplyAclRuleVspCommand.

@Test
public void testApplyAclRuleVspCommand() throws Exception {
    _resource.configure("NuageVspResource", _hostDetails);
    VspNetwork vspNetwork = buildVspNetwork();
    List<VspAclRule> vspAclRules = Lists.newArrayList(buildVspAclRule());
    ApplyAclRuleVspCommand cmd = new ApplyAclRuleVspCommand(VspAclRule.ACLType.NetworkACL, vspNetwork, vspAclRules, false);
    Answer applyAclAns = _resource.executeRequest(cmd);
    assertTrue(applyAclAns.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) ApplyAclRuleVspCommand(com.cloud.agent.api.element.ApplyAclRuleVspCommand) VspAclRule(net.nuage.vsp.acs.client.api.model.VspAclRule) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Aggregations

ApplyAclRuleVspCommand (com.cloud.agent.api.element.ApplyAclRuleVspCommand)3 VspAclRule (net.nuage.vsp.acs.client.api.model.VspAclRule)3 VspNetwork (net.nuage.vsp.acs.client.api.model.VspNetwork)3 Answer (com.cloud.agent.api.Answer)2 Test (org.junit.Test)2 NuageTest (com.cloud.NuageTest)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 HostVO (com.cloud.host.HostVO)1 FirewallRule (com.cloud.network.rules.FirewallRule)1 NetworkACLItem (com.cloud.network.vpc.NetworkACLItem)1 Nullable (javax.annotation.Nullable)1 InternalIdentity (org.apache.cloudstack.api.InternalIdentity)1