Fill DCNM network parameters.

        Function that fills the network parameters for a tenant required by
        DCNM.
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
207339
def add_snmp(data, interfaces):
    
    snmp_interface = []
    if interfaces: # Not providing interfaces will enable SNMP on all NDIs
        interfaces = map(str, interfaces)
        for interface in data:
            interface_id = str(interface.get('interface_id'))
            for if_def in interface.get('interfaces', []):
                _interface_id = None
                if 'vlan_id' in if_def:
                    _interface_id = '{}.{}'.format(
                        interface_id, if_def['vlan_id'])
                else:
                    _interface_id = interface_id
                if _interface_id in interfaces and 'type' not in interface:
                    for node in if_def.get('nodes', []):
                        snmp_interface.append(
                            {'address': node.get('address'),
                             'nicid': _interface_id})
    return snmp_interface
1357427
def expand_parameters(self, para):
        '''
        
        '''
        if len(para) == 1:
            for key, values in para.items():
                return list(map(lambda v: {key: v}, values))

        key = list(para)[0]
        values = para.pop(key)
        rest_para = self.expand_parameters(para)
        ret_para = list()
        for val in values:
            for config in rest_para:
                config[key] = val
                ret_para.append(copy.deepcopy(config))
        return ret_para
1169857
def network_create(self, name, **kwargs):
        '''
        
        '''
        nt_ks = self.compute_conn
        kwargs['label'] = name
        kwargs = self._sanatize_network_params(kwargs)
        net = nt_ks.networks.create(**kwargs)
        return net.__dict__
14483
def retrieve_network_info(self, tenant_id, direc):
        
        serv_obj = self.get_service_obj(tenant_id)
        net_dict = self.retrieve_dcnm_net_info(tenant_id, direc)
        if net_dict:
            return net_dict
        net_dict = self.fill_dcnm_net_info(tenant_id, direc)
        serv_obj.store_dcnm_net_dict(net_dict, direc)
        return net_dict
821779
public static void fill(Mapping src, Mapping dst) {
        for (Node off : src.getOfflineNodes()) {
            dst.addOfflineNode(off);
        }
        for (VM r : src.getReadyVMs()) {
            dst.addReadyVM(r);
        }
        for (Node on : src.getOnlineNodes()) {
            dst.addOnlineNode(on);
            for (VM r : src.getRunningVMs(on)) {
                dst.addRunningVM(r, on);
            }
            for (VM s : src.getSleepingVMs(on)) {
                dst.addSleepingVM(s, on);
            }

        }
    }
1085181
function updateConnectionParameters() {
      if (self.connectionWait < MAX_CONNECTION_ATTEMPT_WAIT) {
        self.connectionWait += UNSUCCESSFUL_CONNECTION_ATTEMPT_ADDITIONAL_WAIT;
      }

      if (self.openTimeout < MAX_OPEN_ATTEMPT_TIMEOUT) {
        self.openTimeout += UNSUCCESSFUL_OPEN_ATTEMPT_ADDITIONAL_TIMEOUT;
      }

      if (self.connectedTimeout < MAX_CONNECTED_ATTEMPT_TIMEOUT) {
        self.connectedTimeout += UNSUCCESSFUL_CONNECTED_ATTEMPT_ADDITIONAL_TIMEOUT;
      }

      if (self.compulsorySecure !== true) {
        self.connectionSecure = !self.connectionSecure;
      }

      self.connectionAttempts++;
    }
88221
def __init_config_params(self, config):
        """"""
        if self.version >= (2, 4):
            params = config.get('setParameter', {})
            # Set enableTestCommands by default but allow enableTestCommands:0.
            params.setdefault('enableTestCommands', 1)
            # Reduce transactionLifetimeLimitSeconds for faster driver testing.
            if self.version >= (4, 1) and not self.is_mongos:
                params.setdefault('transactionLifetimeLimitSeconds', 3)
            # Increase transaction lock timeout to reduce the chance that tests
            # fail with LockTimeout: "Unable to acquire lock {...} within 5ms".
            if self.version >= (4, 0) and not self.is_mongos:
                params.setdefault('maxTransactionLockRequestTimeoutMillis', 25)
            config['setParameter'] = params

        compressors = config.get('networkMessageCompressors')
        if compressors is None:
            if self.version >= (4, 1, 7):
                # SERVER-38168 added zstd support in 4.1.7.
                config['networkMessageCompressors'] = 'zstd,zlib,snappy,noop'
            elif self.version >= (3, 5, 9):
                # SERVER-27310 added zlib support in 3.5.9.
                config['networkMessageCompressors'] = 'zlib,snappy,noop'
            elif self.version >= (3, 4):
                config['networkMessageCompressors'] = 'snappy,noop'
1219717
def new_with_params(self, param_groups:Collection[Collection[nn.Parameter]]):
        ""
        opt_func = getattr(self, 'opt_func', self.opt.__class__)
        opt = opt_func([{'params': p, 'lr':0} for p in param_groups])
        opt = self.__class__(opt, wd=self.wd, true_wd=self.true_wd, bn_wd=self.bn_wd)
        opt.lr,opt.opt_func,opt.mom,opt.beta = self.lr,opt_func,self.mom,self.beta
        return opt
688453
def network_create(request, **kwargs):
    
    LOG.debug("network_create(): kwargs = %s", kwargs)
    if 'tenant_id' not in kwargs:
        kwargs['tenant_id'] = request.user.project_id
    body = {'network': kwargs}
    network = neutronclient(request).create_network(body=body).get('network')
    return Network(network)
962299
def create(self, dcid, ip_type, params=None):
        ''' 
        '''
        params = update_params(params, {
            'DCID': dcid,
            'ip_type': ip_type
        })
        return self.request('/v1/reservedip/create', params, 'POST')
318521
def create_dcnm_in_nwk(self, tenant_id, fw_dict, is_fw_virt=False):
        
        tenant_name = fw_dict.get('tenant_name')
        ret = self._create_service_nwk(tenant_id, tenant_name, 'in')
        if ret:
            res = fw_const.DCNM_IN_NETWORK_CREATE_SUCCESS
            LOG.info("In Service network created for tenant %s",
                     tenant_id)
        else:
            res = fw_const.DCNM_IN_NETWORK_CREATE_FAIL
            LOG.info("In Service network create failed for tenant %s",
                     tenant_id)
        self.update_fw_db_result(tenant_id, dcnm_status=res)
        return ret
1300887
def _register_function(func, con):
    
    nargs = number_of_arguments(func)
    con.connection.connection.create_function(func.__name__, nargs, func)
292154
def populate_local_cache_tenant(self, fw_id, fw_data):
        
        tenant_id = fw_data.get('tenant_id')
        self.create_serv_obj(tenant_id)
        serv_obj = self.get_service_obj(tenant_id)
        serv_obj.create_fw_db(fw_id, fw_data.get('name'), tenant_id)
        self.pop_fw_local(tenant_id, fw_data.get('in_network_id'), "in",
                          fw_data.get('in_service_node_ip'))
        self.pop_fw_local(tenant_id, fw_data.get('out_network_id'), "out",
                          fw_data.get('out_service_node_ip'))
        serv_obj.update_fw_local_result_str(fw_data.get('os_status'),
                                            fw_data.get('dcnm_status'),
                                            fw_data.get('device_status'))
        compl_res = fw_data.get('result')
        result = compl_res.split('(')[0]
        serv_obj.store_local_final_result(result)
        state = self.pop_fw_state(compl_res, fw_data.get('os_status'),
                                  fw_data.get('dcnm_status'))
        if state is None:
            LOG.error("Unable to get state complete result %(res)s"
                      " OS status %(os)s, dcnm status %(dcnm)s",
                      {'res': compl_res, 'os': fw_data.get('os_status'),
                       'dcnm': fw_data.get('dcnm_status')})
        serv_obj.store_state(state, popl_db=False)
        if state == fw_const.FABRIC_PREPARE_DONE_STATE:
            serv_obj.set_fabric_create(True)
        router_id = fw_data.get('router_id')
        rout_net_id = fw_data.get('router_net_id')
        rout_subnet_id = fw_data.get('router_subnet_id')
        # Result is already populated above, so pass None below.
        # And, the result passed should be a string
        serv_obj.update_fw_local_router(rout_net_id, rout_subnet_id, router_id,
                                        None)
1205779
def _program_dcnm_static_route(self, tenant_id, tenant_name):
        
        in_ip_dict = self.get_in_ip_addr(tenant_id)
        in_gw = in_ip_dict.get('gateway')
        in_ip = in_ip_dict.get('subnet')
        if in_gw is None:
            LOG.error("No FW service GW present")
            return False
        out_ip_dict = self.get_out_ip_addr(tenant_id)
        out_ip = out_ip_dict.get('subnet')

        # Program DCNM to update profile's static IP address on OUT part
        excl_list = []
        excl_list.append(in_ip)
        excl_list.append(out_ip)
        subnet_lst = self.os_helper.get_subnet_nwk_excl(tenant_id, excl_list,
                                                        excl_part=True)
        # This count is for telling DCNM to insert the static route in a
        # particular position. Total networks created - exclusive list as
        # above - the network that just got created.
        srvc_node_ip = self.get_out_srvc_node_ip_addr(tenant_id)
        ret = self.dcnm_obj.update_partition_static_route(
            tenant_name, fw_const.SERV_PART_NAME, subnet_lst,
            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")
            return False
        return True
1309387
def connect_params_async(self):
        
        kwargs = self.connect_params.copy()
        kwargs.update({
            'minsize': self.min_connections,
            'maxsize': self.max_connections,
            'autocommit': True,
        })
        return kwargs
767176
def add_connections(self, conns):
        
        rets = []
        for addr, kwargs in conns:
            r = self.add_connection(addr, **kwargs)
            rets.append(r)
        return rets