Examples of DhcpSubnet


Examples of org.midonet.client.resource.DhcpSubnet

        Bridge netBridge = getOrCreateNetworkBridge(network);

        // On bridge, get DHCP subnet (ensure it exists)
        ResourceCollection res = netBridge.getDhcpSubnets();

        DhcpSubnet sub = null;

        if(!res.isEmpty()){
            sub = (DhcpSubnet) res.get(0);
        } else {
            Pair<String,Integer> cidrInfo = NetUtils.getCidr(network.getCidr());
            sub = netBridge.addDhcpSubnet();

            sub.subnetLength(cidrInfo.second());
            sub.subnetPrefix(cidrInfo.first());
            sub.defaultGateway(network.getGateway());
            List<String> dcs = new ArrayList<String>();
            dcs.add(dest.getDataCenter().getDns1());
            sub.dnsServerAddrs(dcs);

            sub.create();
        }

        // On DHCP subnet, add host using host details
        if(sub == null){
            s_logger.error("Failed to create DHCP subnet on Midonet bridge");
            return false;
        } else {
            // Check if the host already exists - we may just be restarting an existing VM
            boolean isNewDhcpHost = true;

            for (DhcpHost dhcpHost : sub.getDhcpHosts()) {
                if(dhcpHost.getIpAddr().equals(nic.getIp4Address())){
                    isNewDhcpHost = false;
                    break;
                }
            }

            if(isNewDhcpHost){
                DhcpHost host = sub.addDhcpHost();
                host.ipAddr(nic.getIp4Address());
                host.macAddr(nic.getMacAddress());
                // This only sets the cloudstack internal name
                host.name(vm.getHostName());
View Full Code Here

Examples of org.midonet.client.resource.DhcpSubnet

            cleanBridge(netBridge);

            // Delete DHCP subnets
            for(Object dhcpSubnet : netBridge.getDhcpSubnets()){
                DhcpSubnet sub = (DhcpSubnet) dhcpSubnet;
                sub.delete();
            }

            netBridge.delete();
        }
    }
View Full Code Here

Examples of org.midonet.client.resource.DhcpSubnet

        //mockHostCollection
        ResourceCollection<DhcpHost> hosts = new ResourceCollection<DhcpHost>(new ArrayList<DhcpHost>());

        //mockDhcpSubnet
        DhcpSubnet mockSub = mock(DhcpSubnet.class);
        when(mockSub.addDhcpHost()).thenReturn(mockDhcpHost);
        when(mockSub.getDhcpHosts()).thenReturn(hosts);

        //mockSubnetCollection
        ResourceCollection mockSubnetCollection = mock(ResourceCollection.class);
        when(mockSubnetCollection.get(anyInt())).thenReturn(mockSub);
View Full Code Here

Examples of org.midonet.client.resource.DhcpSubnet

        Bridge netBridge = getOrCreateNetworkBridge(network);

        // On bridge, get DHCP subnet (ensure it exists)
        ResourceCollection res = netBridge.getDhcpSubnets();

        DhcpSubnet sub = null;

        if (!res.isEmpty()) {
            sub = (DhcpSubnet)res.get(0);
        } else {
            Pair<String, Integer> cidrInfo = NetUtils.getCidr(network.getCidr());
            sub = netBridge.addDhcpSubnet();

            sub.subnetLength(cidrInfo.second());
            sub.subnetPrefix(cidrInfo.first());
            sub.defaultGateway(network.getGateway());
            List<String> dcs = new ArrayList<String>();
            dcs.add(dest.getDataCenter().getDns1());
            sub.dnsServerAddrs(dcs);

            sub.create();
        }

        // On DHCP subnet, add host using host details
        if (sub == null) {
            s_logger.error("Failed to create DHCP subnet on Midonet bridge");
            return false;
        } else {
            // Check if the host already exists - we may just be restarting an existing VM
            boolean isNewDhcpHost = true;

            for (DhcpHost dhcpHost : sub.getDhcpHosts()) {
                if (dhcpHost.getIpAddr().equals(nic.getIp4Address())) {
                    isNewDhcpHost = false;
                    break;
                }
            }

            if (isNewDhcpHost) {
                DhcpHost host = sub.addDhcpHost();
                host.ipAddr(nic.getIp4Address());
                host.macAddr(nic.getMacAddress());
                // This only sets the cloudstack internal name
                host.name(vm.getHostName());
View Full Code Here

Examples of org.midonet.client.resource.DhcpSubnet

            cleanBridge(netBridge);

            // Delete DHCP subnets
            for (Object dhcpSubnet : netBridge.getDhcpSubnets()) {
                DhcpSubnet sub = (DhcpSubnet)dhcpSubnet;
                sub.delete();
            }

            netBridge.delete();
        }
    }
View Full Code Here

Examples of org.midonet.client.resource.DhcpSubnet

        Bridge netBridge = getOrCreateNetworkBridge(network);

        // On bridge, get DHCP subnet (ensure it exists)
        ResourceCollection res = netBridge.getDhcpSubnets();

        DhcpSubnet sub = null;

        if(!res.isEmpty()){
            sub = (DhcpSubnet) res.get(0);
        } else {
            Pair<String,Integer> cidrInfo = NetUtils.getCidr(network.getCidr());
            sub = netBridge.addDhcpSubnet();

            sub.subnetLength(cidrInfo.second());
            sub.subnetPrefix(cidrInfo.first());
            sub.defaultGateway(network.getGateway());
            List<String> dcs = new ArrayList<String>();
            dcs.add(dest.getDataCenter().getDns1());
            sub.dnsServerAddrs(dcs);

            sub.create();
        }

        // On DHCP subnet, add host using host details
        if(sub == null){
            s_logger.error("Failed to create DHCP subnet on Midonet bridge");
            return false;
        } else {
            // Check if the host already exists - we may just be restarting an existing VM
            boolean isNewDhcpHost = true;

            for (DhcpHost dhcpHost : sub.getDhcpHosts()) {
                if(dhcpHost.getIpAddr().equals(nic.getIp4Address())){
                    isNewDhcpHost = false;
                    break;
                }
            }

            if(isNewDhcpHost){
                DhcpHost host = sub.addDhcpHost();
                host.ipAddr(nic.getIp4Address());
                host.macAddr(nic.getMacAddress());
                // This only sets the cloudstack internal name
                host.name(vm.getHostName());
View Full Code Here

Examples of org.midonet.client.resource.DhcpSubnet

            cleanBridge(netBridge);

            // Delete DHCP subnets
            for(Object dhcpSubnet : netBridge.getDhcpSubnets()){
                DhcpSubnet sub = (DhcpSubnet) dhcpSubnet;
                sub.delete();
            }

            netBridge.delete();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.