Show the details of a floating IP

    .. versionadded:: 2016.3.0

    CLI Examples:

    .. code-block:: bash

        salt-cloud -f show_floating_ip my-digitalocean-config floating_ip='45.55.96.47'
187657
def show_floating_ip(kwargs=None, call=None):
    '''
    
    '''
    if call != 'function':
        log.error(
            'The show_floating_ip function must be called with -f or --function.'
        )
        return False

    if not kwargs:
        kwargs = {}

    if 'floating_ip' not in kwargs:
        log.error('A floating IP is required.')
        return False

    floating_ip = kwargs['floating_ip']
    log.debug('Floating ip is %s', floating_ip)

    details = query(method='floating_ips', command=floating_ip)

    return details
322676
def get_ip_address_from_request(request):
    
    remote_addr = request.META.get('REMOTE_ADDR', '')
    if remote_addr and is_valid_ip(remote_addr):
        return remote_addr.strip()
    return '127.0.0.1'
764706
def get_salt_interface(vm_, opts):
    '''
    
    '''
    salt_host = salt.config.get_cloud_config_value(
        'salt_interface', vm_, opts, default=False,
        search_global=False
    )

    if salt_host is False:
        salt_host = salt.config.get_cloud_config_value(
            'ssh_interface', vm_, opts, default='public_ips',
            search_global=False
        )

    return salt_host
544672
def show_service(kwargs=None, conn=None, call=None):
    '''
    
    '''
    if call != 'function':
        raise SaltCloudSystemExit(
            'The show_service function must be called with -f or --function.'
        )

    if not conn:
        conn = get_conn()

    if kwargs is None:
        kwargs = {}

    if 'name' not in kwargs:
        raise SaltCloudSystemExit('A name must be specified as "name"')

    data = conn.get_hosted_service_properties(
        kwargs['name'],
        kwargs.get('details', False)
    )
    ret = object_to_dict(data)
    return ret
441644
def show(config_file=False):
    '''
    
    '''
    roots = (
        'kern',
        'vm',
        'vfs',
        'net',
        'hw',
        'machdep',
        'user',
        'ddb',
        'proc',
        'emul',
        'security',
        'init'
    )
    cmd = 'sysctl -ae'
    ret = {}
    out = __salt__['cmd.run'](cmd, output_loglevel='trace')
    comps = ['']
    for line in out.splitlines():
        if any([line.startswith('{0}.'.format(root)) for root in roots]):
            comps = re.split('[=:]', line, 1)
            ret[comps[0]] = comps[1]
        elif comps[0]:
            ret[comps[0]] += '{0}\n'.format(line)
        else:
            continue
    return ret
868455
def sync_dns_from_my_ip(self, dns_type='A'):
        
        ip_address = ''
        for finder in self.public_ip_finder:
            try:
                result = requests.get(finder)
            except requests.RequestException:
                continue
            if result.status_code == 200:
                try:
                    socket.inet_aton(result.text)
                    ip_address = result.text
                    break
                except socket.error:
                    try:
                        socket.inet_aton(result.json().get('ip'))
                        ip_address = result.json()['ip']
                        break
                    except socket.error:
                        continue

        if ip_address == '':
            print('None of public ip finder is working. Please try later')
            sys.exit(1)

        try:
            record = self.get_record(dns_type, self.domain) \
                if len(self.domain.split('.')) == 3 \
                else self.get_record(dns_type, self.domain)
        except RecordNotFound:
            if self.proxied:
                self.create_record(dns_type, self.domain, ip_address, proxied=True)
            else:
                self.create_record(dns_type, self.domain, ip_address)
            print('Successfully created new record with IP address {new_ip}'
                  .format(new_ip=ip_address))
        else:
            if record['content'] != ip_address:
                if self.proxied:
                    self.update_record(dns_type, self.domain, ip_address, proxied=True)
                else:
                    self.update_record(dns_type, self.domain, ip_address)
                print('Successfully updated IP address from {old_ip} to {new_ip}'
                      .format(old_ip=record['content'], new_ip=ip_address))
            else:
                print('IP address on CloudFlare is same as your current address')
228217
def cmd_arp_ping(ip, iface, verbose):
    

    if verbose:
        logging.basicConfig(level=logging.INFO, format='%(message)s')

    conf.verb = False

    if iface:
        conf.iface = iface

    res, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip), timeout=2)

    for _, pkt in res:
        if verbose:
            print(pkt.show())
        else:
            print(pkt.summary())
247313
def floating_ip_delete(self, floating_ip):
        '''
        
        '''
        ip = self.floating_ip_show(floating_ip)
        nt_ks = self.compute_conn
        return nt_ks.floating_ips.delete(ip)
333923
def ip(self):
        """"""
        r = ''

        # this was compiled from here:
        # https://github.com/un33k/django-ipware
        # http://www.ietf.org/rfc/rfc3330.txt (IPv4)
        # http://www.ietf.org/rfc/rfc5156.txt (IPv6)
        # https://en.wikipedia.org/wiki/Reserved_IP_addresses
        format_regex = re.compile(r'\s')
        ip_regex = re.compile(r'^(?:{})'.format(r'|'.join([
            r'0\.', # reserved for 'self-identification'
            r'10\.', # class A
            r'169\.254', # link local block
            r'172\.(?:1[6-9]|2[0-9]|3[0-1])\.', # class B
            r'192\.0\.2\.', # documentation/examples
            r'192\.168', # class C
            r'255\.{3}', # broadcast address
            r'2001\:db8', # documentation/examples
            r'fc00\:', # private
            r'fe80\:', # link local unicast
            r'ff00\:', # multicast
            r'127\.', # localhost
            r'\:\:1' # localhost
        ])))

        ips = self.ips
        for ip in ips:
            if not format_regex.search(ip) and not ip_regex.match(ip):
                r = ip
                break

        return r
809421
def linux_interfaces():
    '''
    
    '''
    ifaces = dict()
    ip_path = salt.utils.path.which('ip')
    ifconfig_path = None if ip_path else salt.utils.path.which('ifconfig')
    if ip_path:
        cmd1 = subprocess.Popen(
            '{0} link show'.format(ip_path),
            shell=True,
            close_fds=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT).communicate()[0]
        cmd2 = subprocess.Popen(
            '{0} addr show'.format(ip_path),
            shell=True,
            close_fds=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT).communicate()[0]
        ifaces = _interfaces_ip("{0}\n{1}".format(
            salt.utils.stringutils.to_str(cmd1),
            salt.utils.stringutils.to_str(cmd2)))
    elif ifconfig_path:
        cmd = subprocess.Popen(
            '{0} -a'.format(ifconfig_path),
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT).communicate()[0]
        ifaces = _interfaces_ifconfig(salt.utils.stringutils.to_str(cmd))
    return ifaces
47216
def floating_ip_associate(name, kwargs, call=None):
    '''
    
    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The floating_ip_associate action must be called with -a of --action.'
        )

    if 'floating_ip' not in kwargs:
        log.error('floating_ip is required')
        return False

    conn = get_conn()
    conn.floating_ip_associate(name, kwargs['floating_ip'])
    return list_nodes()[name]
1303433
def floating_ip_pool_list(self):
        '''
        
        '''
        nt_ks = self.compute_conn
        pools = nt_ks.floating_ip_pools.list()
        response = {}
        for pool in pools:
            response[pool.name] = {
                'name': pool.name,
            }
        return response
200429
def fetch(self):
        
        api = self.doapi_manager
        return api._floating_ip(api.request(self.url)["floating_ip"])
139772
def floating_ip_disassociate(self, server_name, floating_ip):
        '''
        
        '''
        nt_ks = self.compute_conn
        server_ = self.server_by_name(server_name)
        server = nt_ks.servers.get(server_.__dict__['id'])
        server.remove_floating_ip(floating_ip)
        return self.floating_ip_list()[floating_ip]
1233026
def is_public_ip(ip):
    '''
    
    '''
    if ':' in ip:
        # ipv6
        if ip.startswith('fe80:'):
            # ipv6 link local
            return False
        return True
    addr = ip_to_int(ip)
    if 167772160 < addr < 184549375:
        # 10.0.0.0/8
        return False
    elif 3232235520 < addr < 3232301055:
        # 192.168.0.0/16
        return False
    elif 2886729728 < addr < 2887778303:
        # 172.16.0.0/12
        return False
    elif 2130706432 < addr < 2147483647:
        # 127.0.0.0/8
        return False
    return True
705026
def show_detailed_monitoring(name=None, instance_id=None, call=None, quiet=False):
    '''
    
    '''
    if call != 'action':
        raise SaltCloudSystemExit(
            'The show_detailed_monitoring action must be called with -a or --action.'
        )
    location = get_location()
    if six.text_type(name).startswith('i-') and (len(name) == 10 or len(name) == 19):
        instance_id = name

    if not name and not instance_id:
        raise SaltCloudSystemExit(
            'The show_detailed_monitoring action must be provided with a name or instance\
 ID'
        )
    matched = _get_node(name=name, instance_id=instance_id, location=location)
    log.log(
        logging.DEBUG if quiet is True else logging.INFO,
        'Detailed Monitoring is %s for %s', matched['monitoring'], name
    )
    return matched['monitoring']
581001
def delete_floating_ip(kwargs=None, call=None):
    '''
    
    '''
    if call != 'function':
        log.error(
            'The delete_floating_ip function must be called with -f or --function.'
        )
        return False

    if not kwargs:
        kwargs = {}

    if 'floating_ip' not in kwargs:
        log.error('A floating IP is required.')
        return False

    floating_ip = kwargs['floating_ip']
    log.debug('Floating ip is %s', kwargs['floating_ip'])

    result = query(method='floating_ips',
                   command=floating_ip,
                   http_method='delete')

    return result