sort available networks pool in ascending order based on the network's
 IP address to allocate the network for the new subnet to be added in the
 existing virtual network
439770
def sort_available_networks(available_networks)
      available_networks.sort_by { |nwrk| nwrk.network.address.split(".").map(&:to_i) }
    end
1275931
def nth_subnet(prefix_len,index)
			count = self.subnet_count(prefix_len)
			if (count == 0 || index >= count)
				return nil
			end
			sub0 = IPv4Net.new(self.network, Mask32.new(prefix_len))
			return sub0.nth_next_sib(index)
		end
68881
def _add(self, hostport):
        """"""
        peer = self.peer_class(
            tchannel=self.tchannel,
            hostport=hostport,
            on_conn_change=self._update_heap,
        )
        peer.rank = self.rank_calculator.get_rank(peer)
        self._peers[peer.hostport] = peer

        self.peer_heap.add_and_shuffle(peer)
374369
def create(cls, name, datacenter, subnet=None, gateway=None,
               background=False):
        """"""
        if not background and not cls.intty():
            background = True

        datacenter_id_ = int(Datacenter.usable_id(datacenter))

        vlan_params = {
            'name': name,
            'datacenter_id': datacenter_id_,
        }

        if subnet:
            vlan_params['subnet'] = subnet
        if gateway:
            vlan_params['gateway'] = gateway

        result = cls.call('hosting.vlan.create', vlan_params)

        if not background:
            # interactive mode, run a progress bar
            cls.echo('Creating your vlan.')
            cls.display_progress(result)
            cls.echo('Your vlan %s has been created.' % name)

        return result
487337
def create_network(self, name, tenant_id, subnet, gw=None):
        

        try:
            body = {'network': {'name': name, 'tenant_id': tenant_id,
                                'admin_state_up': True}}
            netw = self.neutronclient.create_network(body=body)
            net_dict = netw.get('network')
            net_id = net_dict.get('id')
        except Exception as exc:
            LOG.error("Failed to create network %(name)s, Exc %(exc)s",
                      {'name': name, 'exc': str(exc)})
            return None, None

        try:
            if gw is None:
                body = {'subnet': {'cidr': subnet,
                                   'ip_version': 4,
                                   'network_id': net_id,
                                   'tenant_id': tenant_id,
                                   'enable_dhcp': False}}
            else:
                body = {'subnet': {'cidr': subnet,
                                   'ip_version': 4,
                                   'network_id': net_id,
                                   'tenant_id': tenant_id,
                                   'enable_dhcp': False,
                                   'gateway_ip': gw}}
            subnet_ret = self.neutronclient.create_subnet(body=body)
            subnet_dict = subnet_ret.get('subnet')
            subnet_id = subnet_dict.get('id')
        except Exception as exc:
            LOG.error("Failed to create subnet %(sub)s, exc %(exc)s",
                      {'sub': subnet, 'exc': str(exc)})
            try:
                self.neutronclient.delete_network(net_id)
            except Exception as exc:
                LOG.error("Failed to delete network %(net)s, exc %(exc)s",
                          {'net': net_id, 'exc': str(exc)})
            return None, None
        return net_id, subnet_id
27340
def sort_used_networks_by_hosts_size(used_network)
      used_network.sort_by.with_index { |nwrk, i| [-nwrk.hosts.size, i] }
    end
90514
def floating_ip_create(self, pool=None):
        '''
        
        '''
        nt_ks = self.compute_conn
        floating_ip = nt_ks.floating_ips.create(pool)
        response = {
            'ip': floating_ip.ip,
            'fixed_ip': floating_ip.fixed_ip,
            'id': floating_ip.id,
            'instance_id': floating_ip.instance_id,
            'pool': floating_ip.pool
        }
        return response
1195019
def add_ip_to_net(networks, host):
    
    for network in networks:
        if host['ipaddr'] in network['network']:
            network['hosts'].append(host)
            return
487504
def virtual_interface_create(self, name, net_name):
        '''
        
        '''
        nt_ks = self.compute_conn
        serverid = self._server_uuid_from_name(name)
        networkid = self.network_show(net_name).get('id', None)
        if networkid is None:
            return {net_name: False}
        nets = nt_ks.virtual_interfaces.create(networkid, serverid)
        return nets
835939
def add_global_ip(self, version=4, test_order=False):
        
        # This method is here to improve the public interface from a user's
        # perspective since ordering a single global IP through the subnet
        # interface is not intuitive.
        return self.add_subnet('global', version=version,
                               test_order=test_order)
789424
def partition_master(incoming=True, outgoing=True):
    

    echo('Partitioning master. Incoming:{} | Outgoing:{}'.format(incoming, outgoing))

    network.save_iptables(shakedown.master_ip())
    network.flush_all_rules(shakedown.master_ip())
    network.allow_all_traffic(shakedown.master_ip())

    if incoming and outgoing:
        network.run_iptables(shakedown.master_ip(), DISABLE_MASTER_INCOMING)
        network.run_iptables(shakedown.master_ip(), DISABLE_MASTER_OUTGOING)
    elif incoming:
        network.run_iptables(shakedown.master_ip(), DISABLE_MASTER_INCOMING)
    elif outgoing:
        network.run_iptables(shakedown.master_ip(), DISABLE_MASTER_OUTGOING)
    else:
        pass
486501
def nth_subnet(prefix_len,index)
			count = self.subnet_count(prefix_len)
			if (count == 0 || index >= count)
				return nil
			end
			sub0 = IPv6Net.new(self.network, Mask128.new(prefix_len))
			return sub0.nth_next_sib(index)
		end
404937
def _configure_subnet(config):
    """"""

    # Rationale: avoid subnet lookup if the network is already
    # completely manually configured
    if ("networkInterfaces" in config["head_node"]
            and "networkInterfaces" in config["worker_nodes"]):
        return config

    subnets = _list_subnets(config)

    if not subnets:
        raise NotImplementedError("Should be able to create subnet.")

    # TODO: make sure that we have usable subnet. Maybe call
    # compute.subnetworks().listUsable? For some reason it didn't
    # work out-of-the-box
    default_subnet = subnets[0]

    if "networkInterfaces" not in config["head_node"]:
        config["head_node"]["networkInterfaces"] = [{
            "subnetwork": default_subnet["selfLink"],
            "accessConfigs": [{
                "name": "External NAT",
                "type": "ONE_TO_ONE_NAT",
            }],
        }]

    if "networkInterfaces" not in config["worker_nodes"]:
        config["worker_nodes"]["networkInterfaces"] = [{
            "subnetwork": default_subnet["selfLink"],
            "accessConfigs": [{
                "name": "External NAT",
                "type": "ONE_TO_ONE_NAT",
            }],
        }]

    return config
1367574
def create_network(self, network):
        """"""
        n_res = MechResource(network['id'], a_const.NETWORK_RESOURCE,
                             a_const.CREATE)
        self.provision_queue.put(n_res)
933608
@SuppressWarnings("unchecked")
    private void addPool(Node<K, V> n, boolean updateMinimum) {
        decreasePool[decreasePoolSize] = n;
        n.poolIndex = decreasePoolSize;
        decreasePoolSize++;

        if (updateMinimum && decreasePoolSize > 1) {
            Node<K, V> poolMin = decreasePool[decreasePoolMinPos];
            int c;
            if (comparator == null) {
                c = ((Comparable<? super K>) n.key).compareTo(poolMin.key);
            } else {
                c = comparator.compare(n.key, poolMin.key);
            }
            if (c < 0) {
                decreasePoolMinPos = n.poolIndex;
            }
        }
    }
1298935
def show_subnetpool(self, subnetpool, **_params):
        """"""
        return self.get(self.subnetpool_path % (subnetpool), params=_params)
392774
public IPv6AddressPool allocate()
    {
        if (!isExhausted())
        {
            // get the first range of free subnets, and take the first subnet of that range
            final IPv6AddressRange firstFreeRange = freeRanges.first();
            final IPv6Network allocated = IPv6Network.fromAddressAndMask(firstFreeRange.getFirst(), allocationSubnetSize);

            return doAllocate(allocated, firstFreeRange);
        }
        else
        {
            // exhausted
            return null;
        }
    }