• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java VnSubnetsType类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中net.juniper.contrail.api.types.VnSubnetsType的典型用法代码示例。如果您正苦于以下问题:Java VnSubnetsType类的具体用法?Java VnSubnetsType怎么用?Java VnSubnetsType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

VnSubnetsType类属于net.juniper.contrail.api.types包,在下文中一共展示了VnSubnetsType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: readIpAm

点赞 3

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
private void readIpAm() {
    List<ObjectReference<VnSubnetsType>> objList = apiVn.getNetworkIpam();
    if (objList != null) {
        for (ObjectReference<VnSubnetsType> objRef: Utils.safe(objList)) {
            if (objRef == null) {
                continue;
            }
            VnSubnetsType subnetsType = objRef.getAttr();
            List<IpamSubnetType> ipamsubList = subnetsType.getIpamSubnets();
            if (ipamsubList == null) {
                continue;
            }
            for (IpamSubnetType sub: ipamsubList) {
                if (sub == null) {
                    continue;
                }
                subnetAddress = sub.getSubnet().getIpPrefix();
                int len = sub.getSubnet().getIpPrefixLen();
                int mask = 0xFFFFFFFF << (32 - len);
                subnetMask = InetAddresses.fromInteger(mask).getHostAddress();
                gatewayAddress = sub.getDefaultGateway();
            }
        }
    }
}
 

开发者ID:Juniper,
项目名称:contrail-vcenter-plugin,
代码行数:26,
代码来源:VirtualNetworkInfo.java

示例2: subnetExists

点赞 3

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
private boolean subnetExists(List<ObjectReference<VnSubnetsType>> ipamRefs, NeutronSubnet subnet) {
    if (ipamRefs != null) {
        for (ObjectReference<VnSubnetsType> ref : ipamRefs) {
            VnSubnetsType vnSubnetsType = ref.getAttr();
            if (vnSubnetsType != null) {
                List<VnSubnetsType.IpamSubnetType> subnets = vnSubnetsType.getIpamSubnets();
                if (subnets != null) {
                    for (VnSubnetsType.IpamSubnetType subnetValue : subnets) {
                        String[] ipPrefix = getIpPrefix(subnet);
                        Boolean doesSubnetExist = subnetValue.getSubnet().getIpPrefix().matches(ipPrefix[0]);
                        if (doesSubnetExist) {
                            return doesSubnetExist;
                        }
                    }
                }
            }
        }
    }
    return false;
}
 

开发者ID:opendaylight,
项目名称:archived-plugin2oc,
代码行数:21,
代码来源:SubnetHandler.java

示例3: subnetExists

点赞 3

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
/**
 * Invoked to check if subnet exists from the Neutron Subnet object.
 *
 * @param ipamRefs
 *            An list of new ObjectReference<VnSubnetsType> objects.
 *
 * @param subnet
 *            An instance of new Neutron Subnet object.
 *
 * @return boolean
 */
private boolean subnetExists(List<ObjectReference<VnSubnetsType>> ipamRefs, NeutronSubnet subnet) {
    if (ipamRefs != null) {
        for (ObjectReference<VnSubnetsType> ref : ipamRefs) {
            VnSubnetsType vnSubnetsType = ref.getAttr();
            if (vnSubnetsType != null) {
                List<VnSubnetsType.IpamSubnetType> subnets = vnSubnetsType.getIpamSubnets();
                if (subnets != null) {
                    for (VnSubnetsType.IpamSubnetType subnetValue : subnets) {
                        String[] ipPrefix = getIpPrefix(subnet);
                        Boolean doesSubnetExist = subnetValue.getSubnet().getIpPrefix().matches(ipPrefix[0]);
                        if (doesSubnetExist) {
                            return doesSubnetExist;
                        }
                    }
                }
            }
        }
    }
    return false;
}
 

开发者ID:opendaylight,
项目名称:archived-plugin2oc,
代码行数:32,
代码来源:LoadBalancerHandler.java

示例4: testCanCreateSubnetExists

点赞 3

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
@Test
public void testCanCreateSubnetExists() throws IOException {
    Activator.apiConnector = mockedApiConnector;
    NeutronSubnet neutronSubnet = defaultSubnetObject();
    when(mockedApiConnector.findById(VirtualNetwork.class, neutronSubnet.getNetworkUUID())).thenReturn(mockedVirtualNetwork);
    VnSubnetsType vnSubnetType = new VnSubnetsType();
    ObjectReference<VnSubnetsType> ref = new ObjectReference<>();
    List<ObjectReference<VnSubnetsType>> ipamRefs = new ArrayList<ObjectReference<VnSubnetsType>>();
    List<VnSubnetsType.IpamSubnetType> subnets = new ArrayList<VnSubnetsType.IpamSubnetType>();
    VnSubnetsType.IpamSubnetType subnetType = new VnSubnetsType.IpamSubnetType();
    SubnetType type = new SubnetType();
    List<String> temp = new ArrayList<String>();
    for (int i = 0; i < 1; i++) {
        subnetType.setSubnet(type);
        subnetType.getSubnet().setIpPrefix("10.0.0.0");
        subnetType.getSubnet().setIpPrefixLen(24);
        subnets.add(subnetType);
        vnSubnetType.addIpamSubnets(subnetType);
        ref.setReference(temp, vnSubnetType, "", "");
        ipamRefs.add(ref);
    }
    when(mockedVirtualNetwork.getNetworkIpam()).thenReturn(ipamRefs);
    assertEquals(HttpURLConnection.HTTP_FORBIDDEN, subnetHandler.canCreateSubnet(neutronSubnet));
}
 

开发者ID:opendaylight,
项目名称:archived-plugin2oc,
代码行数:25,
代码来源:SubnetHandlerTest.java

示例5: testcanUpdateSubnetNotFound

点赞 3

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
@Test
public void testcanUpdateSubnetNotFound() throws IOException {
    Activator.apiConnector = mockedApiConnector;
    NeutronSubnet neutronSubnet = defaultSubnetObject();
    NeutronSubnet deltaSubnet = defaultDeltaSubnet();
    when(mockedApiConnector.findById(VirtualNetwork.class, neutronSubnet.getNetworkUUID())).thenReturn(mockedVirtualNetwork);
    VnSubnetsType vnSubnetType = new VnSubnetsType();
    ObjectReference<VnSubnetsType> ref = new ObjectReference<>();
    List<ObjectReference<VnSubnetsType>> ipamRefs = new ArrayList<ObjectReference<VnSubnetsType>>();
    List<VnSubnetsType.IpamSubnetType> subnets = new ArrayList<VnSubnetsType.IpamSubnetType>();
    VnSubnetsType.IpamSubnetType subnetType = new VnSubnetsType.IpamSubnetType();
    SubnetType type = new SubnetType();
    List<String> temp = new ArrayList<String>();
    for (int i = 0; i < 1; i++) {
        subnetType.setSubnet(type);
        subnetType.setSubnetUuid("9b9570f2-17b1-4fc3-99ec-1b7f7778a29b");
        subnetType.getSubnet().setIpPrefix("10.0.0.0");
        subnetType.getSubnet().setIpPrefixLen(24);
        subnets.add(subnetType);
        vnSubnetType.addIpamSubnets(subnetType);
        ref.setReference(temp, vnSubnetType, "", "");
        ipamRefs.add(ref);
    }
    when(mockedVirtualNetwork.getNetworkIpam()).thenReturn(ipamRefs);
    assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, subnetHandler.canUpdateSubnet(deltaSubnet, neutronSubnet));
}
 

开发者ID:opendaylight,
项目名称:archived-plugin2oc,
代码行数:27,
代码来源:SubnetHandlerTest.java

示例6: testcanUpdateSubnetOK

点赞 3

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
@Test
public void testcanUpdateSubnetOK() throws IOException {
    Activator.apiConnector = mockedApiConnector;
    NeutronSubnet neutronSubnet = defaultSubnetObject();
    NeutronSubnet deltaSubnet = defaultDeltaSubnet();
    when(mockedApiConnector.findById(VirtualNetwork.class, neutronSubnet.getNetworkUUID())).thenReturn(mockedVirtualNetwork);
    VnSubnetsType vnSubnetType = new VnSubnetsType();
    ObjectReference<VnSubnetsType> ref = new ObjectReference<>();
    List<ObjectReference<VnSubnetsType>> ipamRefs = new ArrayList<ObjectReference<VnSubnetsType>>();
    List<VnSubnetsType.IpamSubnetType> subnets = new ArrayList<VnSubnetsType.IpamSubnetType>();
    VnSubnetsType.IpamSubnetType subnetType = new VnSubnetsType.IpamSubnetType();
    SubnetType type = new SubnetType();
    List<String> temp = new ArrayList<String>();
    for (int i = 0; i < 1; i++) {
        subnetType.setSubnet(type);
        subnetType.setSubnetUuid("7b9570f2-17b1-4fc3-99ec-1b7f7778a29b");
        subnetType.getSubnet().setIpPrefix("10.0.0.0");
        subnetType.getSubnet().setIpPrefixLen(24);
        subnets.add(subnetType);
        vnSubnetType.addIpamSubnets(subnetType);
        ref.setReference(temp, vnSubnetType, "", "");
        ipamRefs.add(ref);
    }
    when(mockedVirtualNetwork.getNetworkIpam()).thenReturn(ipamRefs);
    assertEquals(HttpURLConnection.HTTP_OK, subnetHandler.canUpdateSubnet(deltaSubnet, neutronSubnet));
}
 

开发者ID:opendaylight,
项目名称:archived-plugin2oc,
代码行数:27,
代码来源:SubnetHandlerTest.java

示例7: testCanDeleteSubnetOK

点赞 3

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
@Test
public void testCanDeleteSubnetOK() throws IOException {
    Activator.apiConnector = mockedApiConnector;
    NeutronSubnet neutronSubnet = defaultSubnetObject();
    when(mockedApiConnector.findById(VirtualNetwork.class, neutronSubnet.getNetworkUUID())).thenReturn(mockedVirtualNetwork);
    VnSubnetsType vnSubnetType = new VnSubnetsType();
    ObjectReference<VnSubnetsType> ref = new ObjectReference<>();
    List<ObjectReference<VnSubnetsType>> ipamRefs = new ArrayList<ObjectReference<VnSubnetsType>>();
    List<VnSubnetsType.IpamSubnetType> subnets = new ArrayList<VnSubnetsType.IpamSubnetType>();
    VnSubnetsType.IpamSubnetType subnetType = new VnSubnetsType.IpamSubnetType();
    SubnetType type = new SubnetType();
    List<String> temp = new ArrayList<String>();
    for (int i = 0; i < 1; i++) {
        subnetType.setSubnet(type);
        subnetType.setSubnetUuid("7b9570f2-17b1-4fc3-99ec-1b7f7778a29b");
        subnetType.getSubnet().setIpPrefix("10.0.0.0");
        subnetType.getSubnet().setIpPrefixLen(24);
        subnets.add(subnetType);
        vnSubnetType.addIpamSubnets(subnetType);
        ref.setReference(temp, vnSubnetType, "", "");
        ipamRefs.add(ref);
    }
    when(mockedVirtualNetwork.getNetworkIpam()).thenReturn(ipamRefs);
    when(mockedVirtualNetwork.getFloatingIpPools()).thenReturn(null);
    assertEquals(HttpURLConnection.HTTP_OK, subnetHandler.canDeleteSubnet(neutronSubnet));
}
 

开发者ID:opendaylight,
项目名称:archived-plugin2oc,
代码行数:27,
代码来源:SubnetHandlerTest.java

示例8: testAttr

点赞 3

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
@Test
public void testAttr() {
    VirtualNetwork vn = new VirtualNetwork();
    vn.setName("testnet");
    NetworkIpam ipam = new NetworkIpam();
    ipam.setName("testipam");
    VnSubnetsType subnets = new VnSubnetsType();
    subnets.addIpamSubnets(new IpamSubnetType(new SubnetType("192.168.0.0", 24), "192.168.0.254", null, UUID.randomUUID().toString(), false, null, null, false, null, null, vn.getName() + "-subnet", 1));
    vn.setNetworkIpam(ipam, subnets);
    String jsdata = ApiSerializer.serializeObject("virtual-network", vn);
    assertNotSame(jsdata, -1, jsdata.indexOf("192.168.0.0"));

    final JsonParser parser = new JsonParser();
    final JsonObject js_obj = parser.parse(jsdata).getAsJsonObject();
    final JsonElement element = js_obj.get("virtual-network");
    VirtualNetwork result = (VirtualNetwork) ApiSerializer.deserialize(element.toString(), VirtualNetwork.class);
    List<IpamSubnetType> iplist = result.getNetworkIpam().get(0).getAttr().getIpamSubnets();
    assertSame(1, iplist.size());
    assertEquals("192.168.0.0", iplist.get(0).getSubnet().getIpPrefix());
}
 

开发者ID:Juniper,
项目名称:contrail-java-api,
代码行数:21,
代码来源:ObjectReferenceTest.java

示例9: subnetExists

点赞 3

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
private int subnetExists(List<ObjectReference<VnSubnetsType>> ipamRefs, NeutronSubnet subnet) {
    for (ObjectReference<VnSubnetsType> ref : ipamRefs) {
        VnSubnetsType vnSubnetsType = ref.getAttr();
        if (vnSubnetsType != null) {
            List<VnSubnetsType.IpamSubnetType> subnets = vnSubnetsType.getIpamSubnets();
            if (subnets != null) {
                if (subnet.getCidr() == null) {
                    LOGGER.error("CIDR can't be null");
                    return HttpURLConnection.HTTP_BAD_REQUEST;
                }
                for (VnSubnetsType.IpamSubnetType subnetValue : subnets) {
                    String[] ipPrefix = getIpPrefix(subnet);
                    Boolean doesSubnetExist = subnetValue.getSubnet().getIpPrefix().matches(ipPrefix[0]);
                    if (doesSubnetExist) {
                        LOGGER.error("The subnet already exists..");
                        return HttpURLConnection.HTTP_FORBIDDEN;
                    }
                }
            }
        }
    }
    return 0;
}
 

开发者ID:Juniper,
项目名称:odl-opencontrail-plugin,
代码行数:24,
代码来源:SubnetHandler.java

示例10: testCanCreateSubnetExists

点赞 3

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
@Test
public void testCanCreateSubnetExists() throws IOException {
    Activator.apiConnector = mockedApiConnector;
    NeutronSubnet neutronSubnet = defaultSubnetObject();
    when(mockedApiConnector.findById(VirtualNetwork.class, neutronSubnet.getNetworkUUID())).thenReturn(mockedVirtualNetwork);
    VnSubnetsType vnSubnetType = new VnSubnetsType();
    ObjectReference<VnSubnetsType> ref = new ObjectReference<>();
    List<ObjectReference<VnSubnetsType>> ipamRefs = new ArrayList<ObjectReference<VnSubnetsType>>();
    List<VnSubnetsType.IpamSubnetType> subnets = new ArrayList<VnSubnetsType.IpamSubnetType>();
    VnSubnetsType.IpamSubnetType subnetType = new VnSubnetsType.IpamSubnetType();
    SubnetType type = new SubnetType();
    List<String> temp = new ArrayList<String>();
    for (int i = 0; i < 1; i++) {
        subnetType.setSubnet(type);
        subnetType.getSubnet().setIpPrefix("10.0.0.1");
        subnetType.getSubnet().setIpPrefixLen(24);
        subnets.add(subnetType);
        vnSubnetType.addIpamSubnets(subnetType);
        ref.setReference(temp, vnSubnetType, "", "");
        ipamRefs.add(ref);
    }
    when(mockedVirtualNetwork.getNetworkIpam()).thenReturn(ipamRefs);
    assertTrue(subnetType.getSubnet().getIpPrefix().matches("10.0.0.1"));
    assertEquals(HttpURLConnection.HTTP_FORBIDDEN, subnetHandler.canCreateSubnet(neutronSubnet));
}
 

开发者ID:Juniper,
项目名称:odl-opencontrail-plugin,
代码行数:26,
代码来源:SubnetHandlerTest.java

示例11: testcanUpdatePortFixedIPsNotNull

点赞 2

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
@Test
public void testcanUpdatePortFixedIPsNotNull() throws IOException {
    Activator.apiConnector = mockedApiConnector;
    NeutronPort neutronPort = defaultNeutronPortObject();
    NeutronPort dummyNeutronPort = detaNeutronPort();
    when(mockedApiConnector.findById(Project.class, neutronPort.getTenantID())).thenReturn(mockedProject);
    when(mockedApiConnector.findById(VirtualMachineInterface.class, neutronPort.getPortUUID())).thenReturn(mockedVirtualMachineInterface);
    when(mockedApiConnector.findByName(VirtualMachineInterface.class, mockedProject, dummyNeutronPort.getName())).thenReturn(null);
    List<Neutron_IPs> ips = new ArrayList<Neutron_IPs>();
    Neutron_IPs fixedIP = new Neutron_IPs();
    fixedIP.setSubnetUUID("9b9570f2-17b1-4fc3-99ec-1b7f7778a29b");
    ips.add(fixedIP);
    dummyNeutronPort.setFixedIPs(ips);
    when(mockedApiConnector.findById(VirtualNetwork.class, neutronPort.getNetworkUUID())).thenReturn(mockedVirtualNetwork);
    VnSubnetsType vnSubnetType = new VnSubnetsType();
    ObjectReference<VnSubnetsType> ref = new ObjectReference<>();
    List<ObjectReference<VnSubnetsType>> ipamRefs = new ArrayList<ObjectReference<VnSubnetsType>>();
    List<VnSubnetsType.IpamSubnetType> subnets = new ArrayList<VnSubnetsType.IpamSubnetType>();
    VnSubnetsType.IpamSubnetType subnetType = new VnSubnetsType.IpamSubnetType();
    SubnetType type = new SubnetType();
    List<String> temp = new ArrayList<String>();
    for (int i = 0; i < 1; i++) {
        subnetType.setSubnet(type);
        subnetType.setSubnetUuid("0b9570f2-17b1-4fc3-99ec-1b7f7778a29b");
        subnetType.getSubnet().setIpPrefix("10.0.0.0");
        subnetType.getSubnet().setIpPrefixLen(24);
        subnets.add(subnetType);
        vnSubnetType.addIpamSubnets(subnetType);
        ref.setReference(temp, vnSubnetType, "", "");
        ipamRefs.add(ref);
    }
    when(mockedVirtualNetwork.getNetworkIpam()).thenReturn(ipamRefs);
    assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, porthandler.canUpdatePort(dummyNeutronPort, neutronPort));
}
 

开发者ID:opendaylight,
项目名称:archived-plugin2oc,
代码行数:35,
代码来源:PortHandlerTest.java

示例12: testCanDeleteSubnetFPinUse

点赞 2

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
@Test
public void testCanDeleteSubnetFPinUse() throws IOException {
    Activator.apiConnector = mockedApiConnector;
    NeutronSubnet neutronSubnet = defaultSubnetObject();
    when(mockedApiConnector.findById(VirtualNetwork.class, neutronSubnet.getNetworkUUID())).thenReturn(mockedVirtualNetwork);
    VnSubnetsType vnSubnetType = new VnSubnetsType();
    ObjectReference<VnSubnetsType> ref = new ObjectReference<>();
    List<ObjectReference<VnSubnetsType>> ipamRefs = new ArrayList<ObjectReference<VnSubnetsType>>();
    List<VnSubnetsType.IpamSubnetType> subnets = new ArrayList<VnSubnetsType.IpamSubnetType>();
    VnSubnetsType.IpamSubnetType subnetType = new VnSubnetsType.IpamSubnetType();
    SubnetType type = new SubnetType();
    List<String> temp = new ArrayList<String>();
    for (int i = 0; i < 1; i++) {
        subnetType.setSubnet(type);
        subnetType.setSubnetUuid("7b9570f2-17b1-4fc3-99ec-1b7f7778a29b");
        subnetType.getSubnet().setIpPrefix("10.0.0.0");
        subnetType.getSubnet().setIpPrefixLen(24);
        subnets.add(subnetType);
        vnSubnetType.addIpamSubnets(subnetType);
        ref.setReference(temp, vnSubnetType, "", "");
        ipamRefs.add(ref);
    }
    when(mockedVirtualNetwork.getNetworkIpam()).thenReturn(ipamRefs);
    List<ObjectReference<ApiPropertyBase>> fpPoolList = new ArrayList<ObjectReference<ApiPropertyBase>>();
    when(mockedVirtualNetwork.getFloatingIpPools()).thenReturn(fpPoolList);
    assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, subnetHandler.canDeleteSubnet(neutronSubnet));
}
 

开发者ID:opendaylight,
项目名称:archived-plugin2oc,
代码行数:28,
代码来源:SubnetHandlerTest.java

示例13: testCanCreateSubnetExistsWithCIDRNull

点赞 2

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
@Test
public void testCanCreateSubnetExistsWithCIDRNull() throws IOException {
    Activator.apiConnector = mockedApiConnector;
    NeutronSubnet neutronSubnet = new NeutronSubnet();
    neutronSubnet.setNetworkUUID("6b9570f2-17b1-4fc399ec-1b7f7778a29b");
    neutronSubnet.setSubnetUUID("7b9570f2-17b1-4fc399ec-1b7f7778a29b");
    when(mockedApiConnector.findById(VirtualNetwork.class, neutronSubnet.getNetworkUUID())).thenReturn(mockedVirtualNetwork);
    VnSubnetsType vnSubnetType = new VnSubnetsType();
    ObjectReference<VnSubnetsType> ref = new ObjectReference<>();
    List<ObjectReference<VnSubnetsType>> ipamRefs = new ArrayList<ObjectReference<VnSubnetsType>>();
    List<VnSubnetsType.IpamSubnetType> subnets = new ArrayList<VnSubnetsType.IpamSubnetType>();
    VnSubnetsType.IpamSubnetType subnetType = new VnSubnetsType.IpamSubnetType();
    SubnetType type = new SubnetType();
    List<String> temp = new ArrayList<String>();
    for (int i = 0; i < 1; i++) {
        subnetType.setSubnet(type);
        subnetType.getSubnet().setIpPrefix("10.0.0.1");
        subnetType.getSubnet().setIpPrefixLen(24);
        subnets.add(subnetType);
        vnSubnetType.addIpamSubnets(subnetType);
        ref.setReference(temp, vnSubnetType, "", "");
        ipamRefs.add(ref);
    }
    when(mockedVirtualNetwork.getNetworkIpam()).thenReturn(ipamRefs);
    assertTrue(subnetType.getSubnet().getIpPrefix().matches("10.0.0.1"));
    assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, subnetHandler.canCreateSubnet(neutronSubnet));
}
 

开发者ID:Juniper,
项目名称:odl-opencontrail-plugin,
代码行数:28,
代码来源:SubnetHandlerTest.java

示例14: getSubnet

点赞 2

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
private VnSubnetsType getSubnet(VirtualNetworkInfo vnInfo) {
    if (vnInfo.getSubnetAddress() == null || vnInfo.getSubnetMask() == null) {
        return null;
    }
    SubnetUtils subnetUtils = new SubnetUtils(vnInfo.getSubnetAddress(), vnInfo.getSubnetMask());
    String cidr = subnetUtils.getInfo().getCidrSignature();
    String[] addr_pair = cidr.split("\\/");

    List<AllocationPoolType> allocation_pools = null;
    if (vnInfo.getIpPoolEnabled() == true && !vnInfo.getRange().isEmpty()) {
        String[] pools = vnInfo.getRange().split("\\#");
        if (pools.length == 2) {
            allocation_pools = new ArrayList<AllocationPoolType>();
            String start = (pools[0]).replace(" ","");
            String num   = (pools[1]).replace(" ","");
            int start_ip = InetAddresses.coerceToInteger(InetAddresses.forString(start));
            int end_ip = start_ip + Integer.parseInt(num) - 1;
            String end = InetAddresses.toAddrString(InetAddresses.fromInteger(end_ip));
            s_logger.debug("Subnet IP Range :  Start:"  + start + " End:" + end);
            AllocationPoolType pool1 = new
                    AllocationPoolType(start, end);
            allocation_pools.add(pool1);
        }
    }

    // if gateway address is empty string, don't pass empty string to
    // api-server. INstead set it to null so that java binding will
    // drop gateway address from json content for virtual-network create
    if (vnInfo.getGatewayAddress() != null) {
        if (vnInfo.getGatewayAddress().trim().isEmpty())
          vnInfo.setGatewayAddress(null);
    }

    VnSubnetsType subnet = new VnSubnetsType();
    subnet.addIpamSubnets(new IpamSubnetType(
                               new SubnetType(addr_pair[0],
                                   Integer.parseInt(addr_pair[1])),
                                   vnInfo.getGatewayAddress(),
                                   null,                          // dns_server_address
                                   UUID.randomUUID().toString(),  // subnet_uuid
                                   true,                          // enable_dhcp
                                   null,                          // dns_nameservers
                                   allocation_pools,
                                   true,                          // addr_from_start
                                   null,                          // dhcp_options_list
                                   null,                          // host_routes
                                   vnInfo.getName() + "-subnet", 1));
    return subnet;
}
 

开发者ID:Juniper,
项目名称:contrail-vcenter-plugin,
代码行数:50,
代码来源:VncDB.java

示例15: deleteSubnet

点赞 2

import net.juniper.contrail.api.types.VnSubnetsType; //导入依赖的package包/类
/**
 * Invoked to delete a specified subnet.
 *
 * @param subnet
 *            An instance of the Neutron Subnet object to be deleted.
 *
 * @param virtualNetwork
 *            An instance of the Virtual network object.
 *
 * @return A HTTP status code to the deletion request.
 */
private boolean deleteSubnet(NeutronSubnet subnet, VirtualNetwork virtualNetwork) {
    try {
        VnSubnetsType.IpamSubnetType subnetVmType = null;
        VnSubnetsType vnSubnetsType = null;
        List<VnSubnetsType.IpamSubnetType> subnets = null;
        List<ObjectReference<VnSubnetsType>> ipamRefs = virtualNetwork.getNetworkIpam();
        if (ipamRefs != null) {
            for (ObjectReference<VnSubnetsType> ref : ipamRefs) {
                vnSubnetsType = ref.getAttr();
                if (vnSubnetsType != null) {
                    subnets = vnSubnetsType.getIpamSubnets();
                    for (VnSubnetsType.IpamSubnetType subnetValue : subnets) {
                        String[] ipPrefix = getIpPrefix(subnet);
                        boolean doesSubnetExist = subnetValue.getSubnet().getIpPrefix().matches(ipPrefix[0]);
                        if (doesSubnetExist) {
                            subnetVmType = subnetValue;
                        }
                    }
                }
            }
            vnSubnetsType.clearIpamSubnets();
            for (VnSubnetsType.IpamSubnetType subnetVal : subnets) {
                if (!subnetVal.getSubnet().getIpPrefix().matches(subnetVmType.getSubnet().getIpPrefix())) {
                    vnSubnetsType.addIpamSubnets(subnetVal);
                }
            }
            if (vnSubnetsType.getIpamSubnets() != null) {
                virtualNetwork.clearNetworkIpam();
                String ipamId = apiConnector.findByName(NetworkIpam.class, null, "default-network-ipam");
                NetworkIpam ipam = (NetworkIpam) apiConnector.findById(NetworkIpam.class, ipamId);
                virtualNetwork.addNetworkIpam(ipam, vnSubnetsType);
            } else {
                virtualNetwork.clearNetworkIpam();
            }
            return apiConnector.update(virtualNetwork);
        } else {
            LOGGER.error("Subnet deletion failed...");
            return false;
        }
    } catch (IOException ioEx) {
        LOGGER.error("Exception     : " + ioEx);
        return false;
    } catch (Exception ex) {
        LOGGER.error("Exception     : " + ex);
        return false;
    }
}
 

开发者ID:opendaylight,
项目名称:archived-plugin2oc,
代码行数:59,
代码来源:SubnetHandler.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)