Return public IP, private IP, or hostname for the libcloud 'node' object
557784
def __get_host(node, vm_):
    '''
    
    '''
    if __get_ssh_interface(vm_) == 'private_ips' or vm_['external_ip'] is None:
        ip_address = node.private_ips[0]
        log.info('Salt node data. Private_ip: %s', ip_address)
    else:
        ip_address = node.public_ips[0]
        log.info('Salt node data. Public_ip: %s', ip_address)

    if ip_address:
        return ip_address

    return node.name
128324
def reformat_node(item=None, full=False):
    '''
    
    '''
    desired_keys = [
        'id', 'name', 'state', 'public_ips', 'private_ips', 'size', 'image',
        'location'
    ]
    item['private_ips'] = []
    item['public_ips'] = []
    if 'ips' in item:
        for ip in item['ips']:
            if salt.utils.cloud.is_public_ip(ip):
                item['public_ips'].append(ip)
            else:
                item['private_ips'].append(ip)

    # add any undefined desired keys
    for key in desired_keys:
        if key not in item:
            item[key] = None

    # remove all the extra key value pairs to provide a brief listing
    to_del = []
    if not full:
        for key in six.iterkeys(item):  # iterate over a copy of the keys
            if key not in desired_keys:
                to_del.append(key)

    for key in to_del:
        del item[key]

    if 'state' in item:
        item['state'] = joyent_node_state(item['state'])

    return item
889179
def active_network_addresses(hypervisor):
    """"""
    active = []

    for network in hypervisor.listNetworks():
        try:
            xml = hypervisor.networkLookupByName(network).XMLDesc(0)
        except libvirt.libvirtError:  # network has been destroyed meanwhile
            continue
        else:
            ip_element = etree.fromstring(xml).find('.//ip')
            address = ip_element.get('address')
            netmask = ip_element.get('netmask')

            active.append(ipaddress.IPv4Network(u'/'.join((address, netmask)),
                                                strict=False))

    return active
937097
def get_ips(self, instance_id):
        
        self._init_az_api()
        cluster_name, node_name = instance_id
        # XXX: keep in sync with contents of `vm_deployment_template`
        ip_name = ('{node_name}-public-ip'.format(node_name=node_name))
        ip = self._network_client.public_ip_addresses.get(cluster_name, ip_name)
        if (ip.provisioning_state == 'Succeeded' and ip.ip_address):
            return [ip.ip_address]
        else:
            return []
968407
def list_nodes_full(conn=None, call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The list_nodes_full function must be called with -f or '
            '--function.'
        )

    if not conn:
        conn = get_conn()   # pylint: disable=E0602

    ret = {}
    datacenter_id = get_datacenter_id()
    nodes = conn.list_servers(datacenter_id=datacenter_id, depth=3)

    for item in nodes['items']:
        node = {'id': item['id']}
        node.update(item['properties'])
        node['state'] = node.pop('vmState')
        node['public_ips'] = []
        node['private_ips'] = []
        if item['entities']['nics']['items'] > 0:
            for nic in item['entities']['nics']['items']:
                if nic['properties']['ips']:
                    pass
                ip_address = nic['properties']['ips'][0]
                if salt.utils.cloud.is_public_ip(ip_address):
                    node['public_ips'].append(ip_address)
                else:
                    node['private_ips'].append(ip_address)

        ret[node['name']] = node

    __utils__['cloud.cache_node_list'](
        ret,
        __active_provider_name__.split(':')[0],
        __opts__
    )

    return ret
200438
def get_node_ip_address(address="8.8.8.8:53"):
    
    ip_address, port = address.split(":")
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        # This command will raise an exception if there is no internet
        # connection.
        s.connect((ip_address, int(port)))
        node_ip_address = s.getsockname()[0]
    except Exception as e:
        node_ip_address = "127.0.0.1"
        # [Errno 101] Network is unreachable
        if e.errno == 101:
            try:
                # try get node ip address from host name
                host_name = socket.getfqdn(socket.gethostname())
                node_ip_address = socket.gethostbyname(host_name)
            except Exception:
                pass
    finally:
        s.close()

    return node_ip_address
1198177
private static function getNodeId()
    {
        if (self::$hostIp !== null) {
            return ip2long(self::$hostIp);
        }

        self::$hostIp = '127.0.0.1';

        if (self::$hostName !== null) {
            self::$hostIp = crc32(self::$hostName);
        }

        if (true === function_exists('php_uname')) {
            self::$hostName = php_uname('n');
            self::$hostIp = gethostbyname(self::$hostName);
        }

        if (true === function_exists('gethostname')) {
            self::$hostName = gethostname();
            self::$hostIp = gethostbyname(self::$hostName);
        }

        return ip2long(self::$hostIp);
    }
475862
def peer_ips(peer_relation='cluster', addr_key='private-address'):
    ''''''
    peers = {}
    for r_id in relation_ids(peer_relation):
        for unit in relation_list(r_id):
            peers[unit] = relation_get(addr_key, rid=r_id, unit=unit)
    return peers
1020390
def get_host_uuid(self):
        
        xml = self._request_host()
        root = etree.fromstring(xml)
        data = self._elementtree_to_dict(root)
        return data['HSI']['SPN']['text'], data['HSI']['cUUID']['text']
628178
def get_head_node_ip(config_file, override_cluster_name):
    """"""

    config = yaml.load(open(config_file).read())
    if override_cluster_name is not None:
        config["cluster_name"] = override_cluster_name

    provider = get_node_provider(config["provider"], config["cluster_name"])
    try:
        head_node = _get_head_node(config, config_file, override_cluster_name)
        if config.get("provider", {}).get("use_internal_ips", False) is True:
            head_node_ip = provider.internal_ip(head_node)
        else:
            head_node_ip = provider.external_ip(head_node)
    finally:
        provider.cleanup()

    return head_node_ip
1096980
function() {
            var result = [];
            var hostname = spec.env.allPublicNodeIds.publicHostname ||
                    $._.__ca_getAppFullName__();
            var start = spec.env.allPublicNodeIds.publicRangeStart;
            var end = spec.env.allPublicNodeIds.publicRangeEnd;
            for (var i = start; i<= end; i++) {
                result.push(hostname + ':' + i);
            }
            return result;
        }
1104386
def PublicIPs(self):
		
		if not self.public_ips:  self.public_ips = clc.v2.PublicIPs(server=self,public_ips_lst=self.ip_addresses,session=self.session)

		return(self.public_ips)
191355
def _get_ipaddress(node):
    
    if "ipaddress" not in node:
        with settings(hide('stdout'), warn_only=True):
            output = sudo('ohai -l warn ipaddress')
        if output.succeeded:
            try:
                node['ipaddress'] = json.loads(output)[0]
            except ValueError:
                abort("Could not parse ohai's output for ipaddress"
                      ":\n  {0}".format(output))
            return True
    return False
370057
def list_nodes(search="unsigned"):
    
    nodes = nago.core.get_nodes()
    if search == "all":
        return map(lambda x: {x[0]: x[1].data}, nodes.items())
    elif search == 'unsigned':
        result = {}
        for token, node in nodes.items():
            if node.get('access') is None:
                result[token] = node.data
        return result
    else:
        result = {}
        for token, node in nodes.items():
            host_name = node.get('host_name')
            if search in (token, host_name):
                result[token] = node.data
        return result
441085
def _get_public_ip(name, resource_group):
    '''
    
    '''
    netconn = get_conn(client_type='network')
    try:
        pubip_query = netconn.public_ip_addresses.get(
            resource_group_name=resource_group,
            public_ip_address_name=name
        )
        pubip = pubip_query.as_dict()
    except CloudError as exc:
        __utils__['azurearm.log_cloud_error']('network', exc.message)
        pubip = {'error': exc.message}

    return pubip
41899
def nodes_aws(c_obj):
    """"""
    aws_nodes = []
    try:
        aws_nodes = c_obj.list_nodes()
    except BaseHTTPError as e:
        abort_err("\r HTTP Error with AWS: {}".format(e))
    aws_nodes = adj_nodes_aws(aws_nodes)
    return aws_nodes
1369587
def list_nodes_full(**kwargs):
    '''
    
    '''
    nodes = _query('server/list')
    ret = {}

    for node in nodes:
        name = nodes[node]['label']
        ret[name] = nodes[node].copy()
        ret[name]['id'] = node
        ret[name]['image'] = nodes[node]['os']
        ret[name]['size'] = nodes[node]['VPSPLANID']
        ret[name]['state'] = nodes[node]['status']
        ret[name]['private_ips'] = nodes[node]['internal_ip']
        ret[name]['public_ips'] = nodes[node]['main_ip']

    return ret