List EC2 name and public and private ip address
341385
def list():
    ""
    for node in env.nodes:
        print "%s (%s, %s)" % (node.tags["Name"], node.ip_address,
            node.private_ip_address)
256393
def ip_address():
    """"""
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # 8.8.8.8 is the google public DNS
    s.connect(("8.8.8.8", 53))
    ip = s.getsockname()[0]
    s.close()
    return ip
952570
def list_nodes(conn=None, call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The list_nodes function must be called with -f or --function.'
        )

    if not conn:
        conn = get_conn()

    ret = {}
    nodes = conn.list_servers()

    for node in nodes:
        public_ips = []
        private_ips = []
        ret = {}

        size = node.get('hardware').get('fixed_instance_size_id', 'Custom size')

        if node.get('private_networks'):
            for private_ip in node['private_networks']:
                private_ips.append(private_ip)

        if node.get('ips'):
            for public_ip in node['ips']:
                public_ips.append(public_ip['ip'])

        server = {
            'id': node['id'],
            'image': node['image']['id'],
            'size': size,
            'state': node['status']['state'],
            'private_ips': private_ips,
            'public_ips': public_ips
        }
        ret[node['name']] = server

    return ret
613683
def ips(self):
        """"""
        r = []
        names = ['X_FORWARDED_FOR', 'CLIENT_IP', 'X_REAL_IP', 'X_FORWARDED', 
               'X_CLUSTER_CLIENT_IP', 'FORWARDED_FOR', 'FORWARDED', 'VIA',
               'REMOTE_ADDR']

        for name in names:
            vs = self.get_header(name, '')
            if vs:
                r.extend(map(lambda v: v.strip(), vs.split(',')))

            vs = self.environ.get(name, '')
            if vs:
                r.extend(map(lambda v: v.strip(), vs.split(',')))

        return r
844898
def read_address(self, ip_address):
        
        '''
            
        '''
        
        title = '%s.read_address' % self.__class__.__name__

    # validate inputs
        input_fields = {
            'ip_address': ip_address
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
    
    # report query
        self.iam.printer('Querying AWS region %s for properties of elastic ip %s.' % (self.iam.region_name, ip_address))
        
    # discover details associated with instance id
        try:
            response = self.connection.describe_addresses(PublicIps=[ ip_address ])
            address_info = response['Addresses'][0]
        except:
            raise AWSConnectionError(title)

    # create dictionary of instance details
        address_details = {
            'instance_id': '',
            'public_ip': '',
            'allocation_id': '',
            'association_id': '',
            'domain': '',
            'network_interface_id': '',
            'network_interface_owner_id': '',
            'private_ip_address': '',
            'tags': [],
            'region': self.iam.region_name
        }
        address_details = self.iam.ingest(address_info, address_details)

        return address_details
1172667
def _get_nics(vm_):
    '''
    
    '''
    nics = []
    if 'public_lan' in vm_:
        firewall_rules = []
        # Set LAN to public if it already exists, otherwise create a new
        # public LAN.
        if 'public_firewall_rules' in vm_:
            firewall_rules = _get_firewall_rules(vm_['public_firewall_rules'])
        nic = NIC(lan=set_public_lan(int(vm_['public_lan'])),
                  name='public',
                  firewall_rules=firewall_rules)
        if 'public_ips' in vm_:
            nic.ips = _get_ip_addresses(vm_['public_ips'])
        nics.append(nic)

    if 'private_lan' in vm_:
        firewall_rules = []
        if 'private_firewall_rules' in vm_:
            firewall_rules = _get_firewall_rules(vm_['private_firewall_rules'])
        nic = NIC(lan=int(vm_['private_lan']),
                  name='private',
                  firewall_rules=firewall_rules)
        if 'private_ips' in vm_:
            nic.ips = _get_ip_addresses(vm_['private_ips'])
        if 'nat' in vm_ and 'private_ips' not in vm_:
            nic.nat = vm_['nat']
        nics.append(nic)
    return nics
1345685
def get_ip_addresses(self, machine, *, boot_only=False, discovered=False):
        
        boot_ips = [
            link.ip_address
            for link in machine.boot_interface.links
            if link.ip_address
        ]
        if boot_only:
            if boot_ips:
                return boot_ips
            elif discovered:
                return [
                    link.ip_address
                    for link in machine.boot_interface.discovered
                    if link.ip_address
                ]
            else:
                return []
        else:
            other_ips = [
                link.ip_address
                for interface in machine.interfaces
                for link in interface.links
                if (interface.id != machine.boot_interface.id and
                    link.ip_address)
            ]
            ips = boot_ips + other_ips
            if ips:
                return ips
            elif discovered:
                return [
                    link.ip_address
                    for link in machine.boot_interface.discovered
                    if link.ip_address
                ] + [
                    link.ip_address
                    for interface in machine.interfaces
                    for link in interface.discovered
                    if (interface.id != machine.boot_interface.id and
                        link.ip_address)
                ]
            else:
                return []
913929
def list_nictags(include_etherstubs=True):
    '''
    
    '''
    ret = {}
    cmd = 'nictagadm list -d "|" -p{0}'.format(
        ' -L' if not include_etherstubs else ''
    )
    res = __salt__['cmd.run_all'](cmd)
    retcode = res['retcode']
    if retcode != 0:
        ret['Error'] = res['stderr'] if 'stderr' in res else 'Failed to get list of nictags.'
    else:
        header = ['name', 'macaddress', 'link', 'type']
        for nictag in res['stdout'].splitlines():
            nictag = nictag.split('|')
            nictag_data = {}
            for field in header:
                nictag_data[field] = nictag[header.index(field)]
            ret[nictag_data['name']] = nictag_data
            del ret[nictag_data['name']]['name']
    return ret
437392
def vm_ip(cls, vm_id):
        """"""
        vm_info = cls.info(vm_id)

        for iface in vm_info['ifaces']:
            if iface['type'] == 'private':
                continue
            for ip in iface['ips']:
                return ip['version'], ip['ip']
566464
def ls(ctx, name, list_formatted):
    """"""
    session = create_session(ctx.obj['AWS_PROFILE_NAME'])
    ec2 = session.resource('ec2')
    if name == '*':
        instances = ec2.instances.filter()
    else:
        condition = {'Name': 'tag:Name', 'Values': [name]}
        instances = ec2.instances.filter(Filters=[condition])
    out = format_output(instances, list_formatted)
    click.echo('\n'.join(out))
661507
def floating_ip_list(self):
        '''
        
        '''
        nt_ks = self.compute_conn
        floating_ips = nt_ks.floating_ips.list()
        response = {}
        for floating_ip in floating_ips:
            response[floating_ip.ip] = {
                '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
799856
def _make_ip_subnet_lookup(vpc_info):
    
    # We create a reverse lookup from the instances private IP addresses to the
    # subnets they are associated with. This is used later on in order to
    # determine whether routes should be set in an RT: Is the RT's subnet
    # associated with ANY of the IP addresses in the route spec? To make this
    # easy, we collect the IPs and subnets of all EC2 instances in the VPC.
    # Once we get a route spec, we create a list of subnets for only the
    # cluster nodes. The assumption is that not all EC2 instances in the VPC
    # necessarily belong to the cluster. We really want to narrow it down to
    # the cluster nodes only. See make_cluster_node_subnet_list().
    vpc_info['ip_subnet_lookup'] = {}
    for instance in vpc_info['instances']:
        for interface in instance.interfaces:
            subnet_id = interface.subnet_id
            for priv_addr in interface.private_ip_addresses:
                vpc_info['ip_subnet_lookup'][priv_addr.private_ip_address] = \
                                                                    subnet_id
523491
def format_private_ip_address(result):
    '''
    
    '''
    from collections import OrderedDict
    # Only display parameters that have content
    order_dict = OrderedDict()
    if result.ip_address is not None:
        order_dict['ipAddress'] = result.ip_address
    if result.subnet_resource_id is not None:
        order_dict['subnetResourceId'] = result.subnet_resource_id

    return order_dict
829209
def get_private_endpoint(id: str, guid: str) -> str:
    """"""
    _username, domain = id.split("@")
    return "https://%s/receive/users/%s" % (domain, guid)
1108997
def is_private_addr(x):
    """"""
    paddrs = ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16']
    found = False
    for ipr in paddrs:
        try:
            if ipaddress.ip_address(x) in ipaddress.ip_network(ipr):
                found = True
                continue
        except:
            break
    return found
1065437
def get_private_and_public(ctx, username, password, private, preset):
    """"""
    session = SRPClientSession(
        SRPContext(username, password, prime=preset[0], generator=preset[1]),
        private=private)

    click.secho('Client private: %s' % session.private_b64)
    click.secho('Client public: %s' % session.public_b64)
823500
def list_nodes(conn=None, call=None):
    '''
    

    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The list_nodes function must be called with -f or --function.'
        )
    ret = {}
    for node, info in list_nodes_full(conn=conn).items():
        for key in ('id', 'name', 'size', 'state', 'private_ips', 'public_ips', 'floating_ips', 'fixed_ips', 'image'):
            ret.setdefault(node, {}).setdefault(key, info.get(key))

    return ret