Clear DCNM out partition information.

        Clear the DCNM OUT partition service node IP address and update
        the result
969388
def clear_dcnm_out_part(self, tenant_id, fw_dict, is_fw_virt=False):
        
        res = fw_const.DCNM_OUT_PART_UPDDEL_SUCCESS
        self.update_fw_db_result(tenant_id, dcnm_status=res)
        LOG.info("Out partition cleared -noop- with service ip addr")
        return True
863837
def remove_nio(self, port_number):
        

        if port_number not in self._nios:
            raise NodeError("Port {} is not allocated".format(port_number))

        nio = self._nios[port_number]
        if isinstance(nio, NIOUDP):
            self.manager.port_manager.release_udp_port(nio.lport, self._project)

        log.info('Cloud "{name}" [{id}]: NIO {nio} removed from port {port}'.format(name=self._name,
                                                                                    id=self._id,
                                                                                    nio=nio,
                                                                                    port=port_number))

        del self._nios[port_number]
        if self._ubridge_hypervisor and self._ubridge_hypervisor.is_running():
            yield from self._delete_ubridge_connection(port_number)
        yield from self.start()
        return nio
490874
def delete_host_from_segment(ipaddress, networkaddress, auth, url):
    '''

    '''
    host_id = get_host_id(ipaddress, networkaddress, auth, url)
    remove_scope_ip(host_id, auth.creds, auth.url)
185499
def fill_dcnm_net_info(self, tenant_id, direc, vlan_id=0,
                           segmentation_id=0):
        
        serv_obj = self.get_service_obj(tenant_id)
        fw_dict = serv_obj.get_fw_dict()
        fw_id = fw_dict.get('fw_id')
        net_dict = {'status': 'ACTIVE', 'admin_state_up': True,
                    'tenant_id': tenant_id, 'provider:network_type': 'local',
                    'vlan_id': vlan_id, 'segmentation_id': segmentation_id}
        if vlan_id == 0:
            net_dict.update({'mob_domain': False, 'mob_domain_name': None})
        else:
            net_dict.update({'mob_domain': True})
        # TODO(padkrish) NWK ID are not filled.
        if direc == 'in':
            name = fw_id[0:4] + fw_const.IN_SERVICE_NWK + (
                fw_id[len(fw_id) - 4:])
            net_dict.update({'name': name, 'part_name': None,
                             'config_profile': self.serv_host_prof,
                             'fwd_mode': self.serv_host_mode})
        else:
            name = fw_id[0:4] + fw_const.OUT_SERVICE_NWK + (
                fw_id[len(fw_id) - 4:])
            net_dict.update({'name': name,
                             'part_name': fw_const.SERV_PART_NAME,
                             'config_profile': self.serv_ext_prof,
                             'fwd_mode': self.serv_ext_mode})
        return net_dict
1020110
def clear_cache(ip=None):
    """"""
    if ip:
        with ignored(Exception):
            client = CLIENT_CACHE[ip]
            del CLIENT_CACHE[ip]
            client.close()
    else:
        for client in CLIENT_CACHE.values():
            with ignored(Exception):
                client.close()
        CLIENT_CACHE.clear()
629236
def remove_nio(self, port_number):
        

        if port_number not in self._nios:
            raise DynamipsError("Port {} is not allocated".format(port_number))

        nio = self._nios[port_number]
        if isinstance(nio, NIOUDP):
            self.manager.port_manager.release_udp_port(nio.lport, self._project)
        if self._hypervisor:
            yield from self._hypervisor.send('ethsw remove_nio "{name}" {nio}'.format(name=self._name, nio=nio))

        log.info('Ethernet switch "{name}" [{id}]: NIO {nio} removed from port {port}'.format(name=self._name,
                                                                                              id=self._id,
                                                                                              nio=nio,
                                                                                              port=port_number))

        del self._nios[port_number]
        if port_number in self._mappings:
            del self._mappings[port_number]

        return nio
947941
def _delete_service_nwk(self, tenant_id, tenant_name, direc):
        
        net_dict = {}
        if direc == 'in':
            seg, vlan = self.get_in_seg_vlan(tenant_id)
            net_dict['part_name'] = None
        else:
            seg, vlan = self.get_out_seg_vlan(tenant_id)
            net_dict['part_name'] = fw_const.SERV_PART_NAME
        net_dict['segmentation_id'] = seg
        net_dict['vlan'] = vlan
        net = utils.Dict2Obj(net_dict)
        ret = True
        try:
            self.dcnm_obj.delete_service_network(tenant_name, net)
        except dexc.DfaClientRequestFailed:
            LOG.error("Failed to delete network in DCNM %s", direc)
            ret = False
        return ret
94150
def reset(self):
        """"""
        self.domain = \
            dns.name.Name(dns.name.from_text(socket.gethostname())[1:])
        if len(self.domain) == 0:
            self.domain = dns.name.root
        self.nameservers = []
        self.localhosts = set([
          'localhost',
          'loopback',
          '127.0.0.1',
          '0.0.0.0',
          '::1',
          'ip6-localhost',
          'ip6-loopback',
        ])
        # connected and active network interfaces
        self.interfaces = set()
        self.search = set()
        self.search_patterns = ['www.%s.com', 'www.%s.org', 'www.%s.net', ]
        self.port = 53
        self.timeout = 2.0
        self.lifetime = 30.0
        self.keyring = None
        self.keyname = None
        self.keyalgorithm = dns.tsig.default_algorithm
        self.edns = -1
        self.ednsflags = 0
        self.payload = 0
        self.cache = None
419536
def update_dcnm_partition_static_route(self, tenant_id, arg_dict):
        
        ip_list = self.os_helper.get_subnet_nwk_excl(tenant_id,
                                                     arg_dict.get('excl_list'))
        srvc_node_ip = self.get_out_srvc_node_ip_addr(tenant_id)
        ret = self.dcnm_obj.update_partition_static_route(
            arg_dict.get('tenant_name'), fw_const.SERV_PART_NAME, ip_list,
            vrf_prof=self.cfg.firewall.fw_service_part_vrf_profile,
            service_node_ip=srvc_node_ip)
        if not ret:
            LOG.error("Unable to update DCNM ext profile with static "
                      "route %s", arg_dict.get('router_id'))
            self.delete_intf_router(tenant_id, arg_dict.get('tenant_name'),
                                    arg_dict.get('router_id'))
            return False
        return True
815658
def delete_host(zone, name, nameserver='127.0.0.1', timeout=5, port=53,
                **kwargs):
    '''
    
    '''
    fqdn = '{0}.{1}'.format(name, zone)
    request = dns.message.make_query(fqdn, 'A')
    answer = dns.query.udp(request, nameserver, timeout, port)
    try:
        ips = [i.address for i in answer.answer[0].items]
    except IndexError:
        ips = []

    res = delete(zone, name, nameserver=nameserver, timeout=timeout, port=port,
                 **kwargs)

    fqdn = fqdn + '.'
    for ip in ips:
        parts = ip.split('.')[::-1]
        popped = []

        # Iterate over possible reverse zones
        while len(parts) > 1:
            p = parts.pop(0)
            popped.append(p)
            zone = '{0}.{1}'.format('.'.join(parts), 'in-addr.arpa.')
            name = '.'.join(popped)
            ptr = delete(zone, name, 'PTR', fqdn, nameserver=nameserver,
                         timeout=timeout, port=port, **kwargs)
        if ptr:
            res = True
    return res
998193
def clear_node(name):
    '''
    
    '''
    ret = {'name': name,
           'changes': {},
           'result': None,
           'comment': ''}

    if __opts__['test']:
        ret['comment'] = 'Clearing local node statistics'
        return ret

    __salt__['trafficserver.clear_node']()

    ret['result'] = True
    ret['comment'] = 'Cleared local node statistics'
    return ret
755038
def clear_data(self):
        
        # Removes the item from filesystem and resets URL to ''
        url = self.get_url()
        # try to clear from payload first, in case that fails we won't mess with AWS
        self._payload.clear_url()
        os.remove(url)
957695
def destroy_dns_records(fqdn):
    '''
    
    '''
    domain = '.'.join(fqdn.split('.')[-2:])
    hostname = '.'.join(fqdn.split('.')[:-2])
    # TODO: remove this when the todo on 754 is available
    try:
        response = query(method='domains', droplet_id=domain, command='records')
    except SaltCloudSystemExit:
        log.debug('Failed to find domains.')
        return False
    log.debug("found DNS records: %s", pprint.pformat(response))
    records = response['domain_records']

    if records:
        record_ids = [r['id'] for r in records if r['name'].decode() == hostname]
        log.debug("deleting DNS record IDs: %s", record_ids)
        for id_ in record_ids:
            try:
                log.info('deleting DNS record %s', id_)
                ret = query(
                    method='domains',
                    droplet_id=domain,
                    command='records/{0}'.format(id_),
                    http_method='delete'
                )
            except SaltCloudSystemExit:
                log.error('failed to delete DNS domain %s record ID %s.', domain, hostname)
            log.debug('DNS deletion REST call returned: %s', pprint.pformat(ret))

    return False
304339
def resolve_network_cidr(ip_address):
    '''
    
    '''
    netmask = get_netmask_for_address(ip_address)
    return str(netaddr.IPNetwork("%s/%s" % (ip_address, netmask)).cidr)
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
407792
def clear_data(self):
        
        # cjshaw@mit.edu, Jan 9, 2015
        # Removes the item from AWS S3 and resets URL to ''
        odl_repo, url = get_aws_s3_handle(self._config_map)
        existing_url = self._payload.get_url_metadata().get_existing_string_values()[0]
        # try to clear from payload first, in case that fails we won't mess with AWS
        self._payload.clear_url()
        key_path = existing_url.replace(url, '')

        # for boto3, remove leading /
        if key_path[0] == '/':
            key_path = key_path[1::]
        odl_repo.delete_object(
            Bucket=self._config_map['s3_bucket'],
            Key=key_path
        )
577974
def update_subnet_db_info(self, tenant_id, direc, net_id, subnet_id):
        
        subnet_dict = self.retrieve_dcnm_subnet_info(tenant_id, direc)
        if not subnet_dict:
            LOG.error("Subnet dict not found for tenant %s", tenant_id)
            return
        subnet = subnet_dict['cidr'].split('/')[0]
        if direc == 'in':
            self.service_in_ip.update_subnet(subnet, net_id, subnet_id)
        else:
            self.service_out_ip.update_subnet(subnet, net_id, subnet_id)