idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
37,900 | def l3_tenant_id ( cls ) : if cls . _l3_tenant_uuid is None : if hasattr ( cfg . CONF . keystone_authtoken , 'project_domain_id' ) : cls . _l3_tenant_uuid = cls . _get_tenant_id_using_keystone_v3 ( ) else : cls . _l3_tenant_uuid = cls . _get_tenant_id_using_keystone_v2 ( ) return cls . _l3_tenant_uuid | Returns id of tenant owning hosting device resources . |
37,901 | def mgmt_nw_id ( cls ) : if cls . _mgmt_nw_uuid is None : tenant_id = cls . l3_tenant_id ( ) if not tenant_id : return net = bc . get_plugin ( ) . get_networks ( bc . context . get_admin_context ( ) , { 'tenant_id' : [ tenant_id ] , 'name' : [ cfg . CONF . general . management_network ] } , [ 'id' , 'subnets' ] ) if len ( net ) == 1 : num_subnets = len ( net [ 0 ] [ 'subnets' ] ) if num_subnets == 0 : LOG . error ( 'The management network has no subnet. ' 'Please assign one.' ) return elif num_subnets > 1 : LOG . info ( 'The management network has %d subnets. The ' 'first one will be used.' , num_subnets ) cls . _mgmt_nw_uuid = net [ 0 ] . get ( 'id' ) cls . _mgmt_subnet_uuid = net [ 0 ] [ 'subnets' ] [ 0 ] elif len ( net ) > 1 : LOG . error ( 'The management network for does not have ' 'unique name. Please ensure that it is.' ) else : LOG . error ( 'There is no virtual management network. Please ' 'create one.' ) return cls . _mgmt_nw_uuid | Returns id of the management network . |
37,902 | def mgmt_sec_grp_id ( cls ) : if not extensions . is_extension_supported ( bc . get_plugin ( ) , "security-group" ) : return if cls . _mgmt_sec_grp_id is None : tenant_id = cls . l3_tenant_id ( ) res = bc . get_plugin ( ) . get_security_groups ( bc . context . get_admin_context ( ) , { 'tenant_id' : [ tenant_id ] , 'name' : [ cfg . CONF . general . default_security_group ] } , [ 'id' ] ) if len ( res ) == 1 : sec_grp_id = res [ 0 ] . get ( 'id' , None ) cls . _mgmt_sec_grp_id = sec_grp_id elif len ( res ) > 1 : LOG . error ( 'The security group for the management network ' 'does not have unique name. Please ensure that ' 'it is.' ) else : LOG . error ( 'There is no security group for the management ' 'network. Please create one.' ) return cls . _mgmt_sec_grp_id | Returns id of security group used by the management network . |
37,903 | def delete_all_hosting_devices ( self , context , force_delete = False ) : for item in self . _get_collection_query ( context , hd_models . HostingDeviceTemplate ) : self . delete_all_hosting_devices_by_template ( context , template = item , force_delete = force_delete ) | Deletes all hosting devices . |
37,904 | def _process_non_responsive_hosting_device ( self , context , hosting_device ) : if ( hosting_device [ 'template' ] [ 'host_category' ] == VM_CATEGORY and hosting_device [ 'auto_delete' ] ) : self . _delete_dead_service_vm_hosting_device ( context , hosting_device ) return True return False | Host type specific processing of non responsive hosting devices . |
37,905 | def _create_hosting_device_templates_from_config ( self ) : hdt_dict = config . get_specific_config ( 'cisco_hosting_device_template' ) attr_info = ciscohostingdevicemanager . RESOURCE_ATTRIBUTE_MAP [ ciscohostingdevicemanager . DEVICE_TEMPLATES ] adm_context = bc . context . get_admin_context ( ) for hdt_uuid , kv_dict in hdt_dict . items ( ) : hdt_uuid = config . uuidify ( hdt_uuid ) try : self . get_hosting_device_template ( adm_context , hdt_uuid ) is_create = False except ciscohostingdevicemanager . HostingDeviceTemplateNotFound : is_create = True kv_dict [ 'id' ] = hdt_uuid kv_dict [ 'tenant_id' ] = self . l3_tenant_id ( ) config . verify_resource_dict ( kv_dict , True , attr_info ) hdt = { ciscohostingdevicemanager . DEVICE_TEMPLATE : kv_dict } try : if is_create : self . create_hosting_device_template ( adm_context , hdt ) else : self . update_hosting_device_template ( adm_context , kv_dict [ 'id' ] , hdt ) except n_exc . NeutronException : with excutils . save_and_reraise_exception ( ) : LOG . error ( 'Invalid hosting device template definition ' 'in configuration file for template = %s' , hdt_uuid ) | To be called late during plugin initialization so that any hosting device templates defined in the config file is properly inserted in the DB . |
37,906 | def _create_hosting_devices_from_config ( self ) : hd_dict = config . get_specific_config ( 'cisco_hosting_device' ) attr_info = ciscohostingdevicemanager . RESOURCE_ATTRIBUTE_MAP [ ciscohostingdevicemanager . DEVICES ] adm_context = bc . context . get_admin_context ( ) for hd_uuid , kv_dict in hd_dict . items ( ) : hd_uuid = config . uuidify ( hd_uuid ) try : old_hd = self . get_hosting_device ( adm_context , hd_uuid ) is_create = False except ciscohostingdevicemanager . HostingDeviceNotFound : old_hd = { } is_create = True kv_dict [ 'id' ] = hd_uuid kv_dict [ 'tenant_id' ] = self . l3_tenant_id ( ) kv_dict [ 'cfg_agent_id' ] = old_hd . get ( 'cfg_agent_id' ) kv_dict [ 'management_port_id' ] = old_hd . get ( 'management_port_id' ) config . verify_resource_dict ( kv_dict , True , attr_info ) hd = { ciscohostingdevicemanager . DEVICE : kv_dict } try : if is_create : self . create_hosting_device ( adm_context , hd ) else : self . update_hosting_device ( adm_context , kv_dict [ 'id' ] , hd ) except n_exc . NeutronException : with excutils . save_and_reraise_exception ( ) : LOG . error ( 'Invalid hosting device specification in ' 'configuration file for device = %s' , hd_uuid ) | To be called late during plugin initialization so that any hosting device specified in the config file is properly inserted in the DB . |
37,907 | def add_router_to_hosting_device ( self , client , hosting_device_id , body ) : res_path = hostingdevice . HostingDevice . resource_path return client . post ( ( res_path + DEVICE_L3_ROUTERS ) % hosting_device_id , body = body ) | Adds a router to hosting device . |
37,908 | def remove_router_from_hosting_device ( self , client , hosting_device_id , router_id ) : res_path = hostingdevice . HostingDevice . resource_path return client . delete ( ( res_path + DEVICE_L3_ROUTERS + "/%s" ) % ( hosting_device_id , router_id ) ) | Remove a router from hosting_device . |
37,909 | def list_routers_on_hosting_device ( self , client , hosting_device_id , ** _params ) : res_path = hostingdevice . HostingDevice . resource_path return client . get ( ( res_path + DEVICE_L3_ROUTERS ) % hosting_device_id , params = _params ) | Fetches a list of routers hosted on a hosting device . |
37,910 | def list_hosting_devices_hosting_routers ( self , client , router_id , ** _params ) : return client . get ( ( client . router_path + L3_ROUTER_DEVICES ) % router_id , params = _params ) | Fetches a list of hosting devices hosting a router . |
37,911 | def setup_client_rpc ( self ) : self . clnt = rpc . DfaRpcClient ( self . _url , constants . DFA_SERVER_QUEUE , exchange = constants . DFA_EXCHANGE ) | Setup RPC client for dfa agent . |
37,912 | def setup_rpc ( self ) : endpoints = RpcCallBacks ( self . _vdpm , self . _iptd ) self . server = rpc . DfaRpcServer ( self . _qn , self . _my_host , self . _url , endpoints , exchange = constants . DFA_EXCHANGE ) | Setup RPC server for dfa agent . |
37,913 | def _add_rid_to_vrf_list ( self , ri ) : if ri . ex_gw_port or ri . router . get ( 'gw_port' ) : driver = self . driver_manager . get_driver ( ri . id ) vrf_name = driver . _get_vrf_name ( ri ) if not vrf_name : return if not self . _router_ids_by_vrf . get ( vrf_name ) : LOG . debug ( "++ CREATING VRF %s" % vrf_name ) driver . _do_create_vrf ( vrf_name ) self . _router_ids_by_vrf . setdefault ( vrf_name , set ( ) ) . add ( ri . router [ 'id' ] ) | Add router ID to a VRF list . |
37,914 | def _remove_rid_from_vrf_list ( self , ri ) : if ri . ex_gw_port or ri . router . get ( 'gw_port' ) : driver = self . driver_manager . get_driver ( ri . id ) vrf_name = driver . _get_vrf_name ( ri ) if self . _router_ids_by_vrf . get ( vrf_name ) and ( ri . router [ 'id' ] in self . _router_ids_by_vrf [ vrf_name ] ) : self . _router_ids_by_vrf [ vrf_name ] . remove ( ri . router [ 'id' ] ) if not self . _router_ids_by_vrf . get ( vrf_name ) : LOG . debug ( "++ REMOVING VRF %s" % vrf_name ) driver . _remove_vrf ( ri ) del self . _router_ids_by_vrf [ vrf_name ] | Remove router ID from a VRF list . |
37,915 | def _internal_network_removed ( self , ri , port , ex_gw_port ) : itfc_deleted = False driver = self . driver_manager . get_driver ( ri . id ) vrf_name = driver . _get_vrf_name ( ri ) network_name = ex_gw_port [ 'hosting_info' ] . get ( 'network_name' ) if self . _router_ids_by_vrf_and_ext_net . get ( vrf_name , { } ) . get ( network_name ) and ( ri . router [ 'id' ] in self . _router_ids_by_vrf_and_ext_net [ vrf_name ] [ network_name ] ) : if len ( ri . internal_ports ) == 1 and port in ri . internal_ports : self . _router_ids_by_vrf_and_ext_net [ vrf_name ] [ network_name ] . remove ( ri . router [ 'id' ] ) if not self . _router_ids_by_vrf_and_ext_net [ vrf_name ] . get ( network_name ) : LOG . debug ( "++ REMOVING NETWORK %s" % network_name ) itfc_deleted = True del self . _router_ids_by_vrf_and_ext_net [ vrf_name ] [ network_name ] if not self . _router_ids_by_vrf_and_ext_net . get ( vrf_name ) : del self . _router_ids_by_vrf_and_ext_net [ vrf_name ] driver . internal_network_removed ( ri , port , itfc_deleted = itfc_deleted ) if ri . snat_enabled and ex_gw_port : driver . disable_internal_network_NAT ( ri , port , ex_gw_port , itfc_deleted = itfc_deleted ) | Remove an internal router port |
37,916 | def do_list_organizations ( self , line ) : org_list = self . dcnm_client . list_organizations ( ) if not org_list : print ( 'No organization found.' ) return org_table = PrettyTable ( [ 'Organization Name' ] ) for org in org_list : org_table . add_row ( [ org [ 'organizationName' ] ] ) print ( org_table ) | Get list of organization on DCNM . |
37,917 | def create_routertype ( self , context , routertype ) : LOG . debug ( "create_routertype() called. Contents %s" , routertype ) rt = routertype [ 'routertype' ] with context . session . begin ( subtransactions = True ) : routertype_db = l3_models . RouterType ( id = self . _get_id ( rt ) , tenant_id = rt [ 'tenant_id' ] , name = rt [ 'name' ] , description = rt [ 'description' ] , template_id = rt [ 'template_id' ] , ha_enabled_by_default = rt [ 'ha_enabled_by_default' ] , shared = rt [ 'shared' ] , slot_need = rt [ 'slot_need' ] , scheduler = rt [ 'scheduler' ] , driver = rt [ 'driver' ] , cfg_agent_service_helper = rt [ 'cfg_agent_service_helper' ] , cfg_agent_driver = rt [ 'cfg_agent_driver' ] ) context . session . add ( routertype_db ) return self . _make_routertype_dict ( routertype_db ) | Creates a router type . |
37,918 | def associate_hosting_device_with_config_agent ( self , client , config_agent_id , body ) : return client . post ( ( ConfigAgentHandlingHostingDevice . resource_path + CFG_AGENT_HOSTING_DEVICES ) % config_agent_id , body = body ) | Associates a hosting_device with a config agent . |
37,919 | def disassociate_hosting_device_with_config_agent ( self , client , config_agent_id , hosting_device_id ) : return client . delete ( ( ConfigAgentHandlingHostingDevice . resource_path + CFG_AGENT_HOSTING_DEVICES + "/%s" ) % ( config_agent_id , hosting_device_id ) ) | Disassociates a hosting_device with a config agent . |
37,920 | def list_hosting_device_handled_by_config_agent ( self , client , cfg_agent_id , ** _params ) : return client . get ( ( ConfigAgentHandlingHostingDevice . resource_path + CFG_AGENT_HOSTING_DEVICES ) % cfg_agent_id , params = _params ) | Fetches a list of hosting devices handled by a config agent . |
37,921 | def list_config_agents_handling_hosting_device ( self , client , hosting_device_id , ** _params ) : resource_path = '/dev_mgr/hosting_devices/%s' return client . get ( ( resource_path + HOSTING_DEVICE_CFG_AGENTS ) % hosting_device_id , params = _params ) | Fetches a list of config agents handling a hosting device . |
37,922 | def _parse_nexus_vni_range ( self , tunnel_range ) : for ident in tunnel_range : if not self . _is_valid_nexus_vni ( ident ) : raise exc . NetworkTunnelRangeError ( tunnel_range = tunnel_range , error = _ ( "%(id)s is not a valid Nexus VNI value." ) % { 'id' : ident } ) if tunnel_range [ 1 ] < tunnel_range [ 0 ] : raise exc . NetworkTunnelRangeError ( tunnel_range = tunnel_range , error = _ ( "End of tunnel range is less than start of " "tunnel range." ) ) | Raise an exception for invalid tunnel range or malformed range . |
37,923 | def sync_allocations ( self ) : vxlan_vnis = set ( ) for tun_min , tun_max in self . tunnel_ranges : vxlan_vnis |= set ( six . moves . range ( tun_min , tun_max + 1 ) ) session = bc . get_writer_session ( ) with session . begin ( subtransactions = True ) : allocs = ( session . query ( nexus_models_v2 . NexusVxlanAllocation ) . with_lockmode ( "update" ) . all ( ) ) existing_vnis = set ( alloc . vxlan_vni for alloc in allocs ) vnis_to_remove = [ alloc . vxlan_vni for alloc in allocs if ( alloc . vxlan_vni not in vxlan_vnis and not alloc . allocated ) ] bulk_size = 100 chunked_vnis = ( vnis_to_remove [ i : i + bulk_size ] for i in range ( 0 , len ( vnis_to_remove ) , bulk_size ) ) for vni_list in chunked_vnis : session . query ( nexus_models_v2 . NexusVxlanAllocation ) . filter ( nexus_models_v2 . NexusVxlanAllocation . vxlan_vni . in_ ( vni_list ) ) . delete ( synchronize_session = False ) vnis = list ( vxlan_vnis - existing_vnis ) chunked_vnis = ( vnis [ i : i + bulk_size ] for i in range ( 0 , len ( vnis ) , bulk_size ) ) for vni_list in chunked_vnis : bulk = [ { 'vxlan_vni' : vni , 'allocated' : False } for vni in vni_list ] session . execute ( nexus_models_v2 . NexusVxlanAllocation . __table__ . insert ( ) , bulk ) | Synchronize vxlan_allocations table with configured tunnel ranges . |
37,924 | def _setup_notification_listener ( self , topic_name , url ) : self . notify_listener = rpc . DfaNotifcationListener ( topic_name , url , rpc . DfaNotificationEndpoints ( self ) ) | Setup notification listener for a service . |
37,925 | def callback ( self , timestamp , event_type , payload ) : try : data = ( event_type , payload ) LOG . debug ( 'RX NOTIFICATION ==>\nevent_type: %(event)s, ' 'payload: %(payload)s\n' , ( { 'event' : event_type , 'payload' : payload } ) ) if 'create' in event_type : pri = self . _create_pri elif 'delete' in event_type : pri = self . _delete_pri elif 'update' in event_type : pri = self . _update_pri else : pri = self . _delete_pri self . _pq . put ( ( pri , timestamp , data ) ) except Exception as exc : LOG . exception ( 'Error: %(err)s for event %(event)s' , { 'err' : str ( exc ) , 'event' : event_type } ) | Callback method for processing events in notification queue . |
37,926 | def event_handler ( self ) : if not self . _notify_queue : LOG . error ( 'event_handler: no notification queue for %s' , self . _service_name ) return LOG . debug ( 'calling event handler for %s' , self ) self . start ( ) self . wait ( ) | Wait on queue for listening to the events . |
37,927 | def set_driver ( self , resource ) : try : resource_id = resource [ 'id' ] hosting_device = resource [ 'hosting_device' ] hd_id = hosting_device [ 'id' ] if hd_id in self . _hosting_device_routing_drivers_binding : driver = self . _hosting_device_routing_drivers_binding [ hd_id ] self . _drivers [ resource_id ] = driver else : driver_class = resource [ 'router_type' ] [ 'cfg_agent_driver' ] obfusc_creds = dict ( hosting_device . get ( 'credentials' ) ) if obfusc_creds : real_pw = self . _cfg_agent . get_hosting_device_password ( obfusc_creds . get ( 'credentials_id' ) ) hosting_device [ 'credentials' ] [ 'password' ] = real_pw driver = importutils . import_object ( driver_class , ** hosting_device ) self . _hosting_device_routing_drivers_binding [ hd_id ] = driver if obfusc_creds : hosting_device [ 'credentials' ] = obfusc_creds self . _drivers [ resource_id ] = driver return driver except ImportError : with excutils . save_and_reraise_exception ( reraise = False ) : LOG . exception ( "Error loading cfg agent driver %(driver)s " "for hosting device template %(t_name)s" "(%(t_id)s)" , { 'driver' : driver_class , 't_id' : hd_id , 't_name' : resource [ 'name' ] } ) raise cfg_exceptions . DriverNotExist ( driver = driver_class ) except KeyError as e : with excutils . save_and_reraise_exception ( reraise = False ) : raise cfg_exceptions . DriverNotSetForMissingParameter ( e ) | Set the driver for a neutron resource . |
37,928 | def _import_ucsmsdk ( self ) : if not CONF . ml2_cisco_ucsm . ucsm_https_verify : LOG . warning ( const . SSL_WARNING ) from networking_cisco . ml2_drivers . ucsm import ucs_ssl ucs_driver = importutils . import_module ( 'ucsmsdk.ucsdriver' ) ucs_driver . ssl = ucs_ssl class ucsmsdk ( object ) : handle = importutils . import_class ( 'ucsmsdk.ucshandle.UcsHandle' ) fabricVlan = importutils . import_class ( 'ucsmsdk.mometa.fabric.FabricVlan.FabricVlan' ) vnicProfile = importutils . import_class ( 'ucsmsdk.mometa.vnic.VnicProfile.VnicProfile' ) vnicEtherIf = importutils . import_class ( 'ucsmsdk.mometa.vnic.VnicEtherIf.VnicEtherIf' ) vmVnicProfCl = importutils . import_class ( 'ucsmsdk.mometa.vm.VmVnicProfCl.VmVnicProfCl' ) return ucsmsdk | Imports the ucsmsdk module . |
37,929 | def ucs_manager_connect ( self , ucsm_ip ) : if not self . ucsmsdk : self . ucsmsdk = self . _import_ucsmsdk ( ) ucsm = CONF . ml2_cisco_ucsm . ucsms . get ( ucsm_ip ) if not ucsm or not ucsm . ucsm_username or not ucsm . ucsm_password : LOG . error ( 'UCS Manager network driver failed to get login ' 'credentials for UCSM %s' , ucsm_ip ) return None handle = self . ucsmsdk . handle ( ucsm_ip , ucsm . ucsm_username , ucsm . ucsm_password ) try : handle . login ( ) except Exception as e : raise cexc . UcsmConnectFailed ( ucsm_ip = ucsm_ip , exc = e ) return handle | Connects to a UCS Manager . |
37,930 | def _create_vlanprofile ( self , handle , vlan_id , ucsm_ip ) : vlan_name = self . make_vlan_name ( vlan_id ) vlan_profile_dest = ( const . VLAN_PATH + const . VLAN_PROFILE_PATH_PREFIX + vlan_name ) try : vp1 = handle . query_dn ( const . VLAN_PATH ) if not vp1 : LOG . warning ( 'UCS Manager network driver Vlan Profile ' 'path at %s missing' , const . VLAN_PATH ) return False vp2 = self . ucsmsdk . fabricVlan ( parent_mo_or_dn = vp1 , name = vlan_name , compression_type = const . VLAN_COMPRESSION_TYPE , sharing = const . NONE , pub_nw_name = "" , id = str ( vlan_id ) , mcast_policy_name = "" , default_net = "no" ) handle . add_mo ( vp2 ) handle . commit ( ) if vp2 : LOG . debug ( 'UCS Manager network driver Created Vlan ' 'Profile %s at %s' , vlan_name , vlan_profile_dest ) return True except Exception as e : return self . _handle_ucsm_exception ( e , 'Vlan Profile' , vlan_name , ucsm_ip ) | Creates VLAN profile to able associated with the Port Profile . |
37,931 | def nova_services_up ( self ) : required = set ( [ 'nova-conductor' , 'nova-cert' , 'nova-scheduler' , 'nova-compute' ] ) try : services = self . _nclient . services . list ( ) except Exception as e : LOG . error ( 'Failure determining running Nova services: %s' , e ) return False return not bool ( required . difference ( [ service . binary for service in services if service . status == 'enabled' and service . state == 'up' ] ) ) | Checks if required Nova services are up and running . |
37,932 | def _get_unscheduled_routers ( self , plugin , context ) : if NEUTRON_VERSION . version [ 0 ] <= NEUTRON_NEWTON_VERSION . version [ 0 ] : context , plugin = plugin , context no_agent_binding = ~ sql . exists ( ) . where ( bc . Router . id == bc . rb_model . RouterL3AgentBinding . router_id ) ns_routertype_id = plugin . get_namespace_router_type_id ( context ) query = context . session . query ( bc . Router . id ) query = query . join ( l3_models . RouterHostingDeviceBinding ) query = query . filter ( l3_models . RouterHostingDeviceBinding . router_type_id == ns_routertype_id , no_agent_binding ) unscheduled_router_ids = [ router_id_ [ 0 ] for router_id_ in query ] if unscheduled_router_ids : return plugin . get_routers ( context , filters = { 'id' : unscheduled_router_ids } ) return [ ] | Get routers with no agent binding . |
37,933 | def _filter_unscheduled_routers ( self , plugin , context , routers ) : if NEUTRON_VERSION . version [ 0 ] <= NEUTRON_NEWTON_VERSION . version [ 0 ] : context , plugin = plugin , context unscheduled_routers = [ ] for router in routers : if ( router [ routertype . TYPE_ATTR ] != plugin . get_namespace_router_type_id ( context ) ) : continue l3_agents = plugin . get_l3_agents_hosting_routers ( context , [ router [ 'id' ] ] ) if l3_agents : LOG . debug ( 'Router %(router_id)s has already been ' 'hosted by L3 agent %(agent_id)s' , { 'router_id' : router [ 'id' ] , 'agent_id' : l3_agents [ 0 ] [ 'id' ] } ) else : unscheduled_routers . append ( router ) return unscheduled_routers | Filter from list of routers the ones that are not scheduled . |
37,934 | def _get_underscheduled_routers ( self , plugin , context ) : underscheduled_routers = [ ] max_agents_for_ha = plugin . get_number_of_agents_for_scheduling ( context ) for router , count in plugin . get_routers_l3_agents_count ( context ) : if ( router [ routertype . TYPE_ATTR ] != plugin . get_namespace_router_type_id ( context ) ) : continue if ( count < 1 or router . get ( 'ha' , False ) and count < max_agents_for_ha ) : underscheduled_routers . append ( router ) return underscheduled_routers | For release > = pike . |
37,935 | def auto_schedule_hosting_devices ( self , plugin , context , agent_host ) : query = context . session . query ( bc . Agent ) query = query . filter_by ( agent_type = c_constants . AGENT_TYPE_CFG , host = agent_host , admin_state_up = True ) try : cfg_agent_db = query . one ( ) except ( exc . MultipleResultsFound , exc . NoResultFound ) : LOG . debug ( 'No enabled Cisco cfg agent on host %s' , agent_host ) return if cfg_agentschedulers_db . CfgAgentSchedulerDbMixin . is_agent_down ( cfg_agent_db . heartbeat_timestamp ) : LOG . warning ( 'Cisco cfg agent %s is not alive' , cfg_agent_db . id ) return cfg_agent_db | Schedules unassociated hosting devices to Cisco cfg agent . |
37,936 | def _get_external_network_dict ( self , context , port_db ) : if port_db . device_owner == DEVICE_OWNER_ROUTER_GW : network = self . _core_plugin . get_network ( context , port_db . network_id ) else : router = self . l3_plugin . get_router ( context , port_db . device_id ) ext_gw_info = router . get ( EXTERNAL_GW_INFO ) if not ext_gw_info : return { } , None network = self . _core_plugin . get_network ( context , ext_gw_info [ 'network_id' ] ) external_network = self . get_ext_net_name ( network [ 'name' ] ) transit_net = self . transit_nets_cfg . get ( external_network ) or self . _default_ext_dict transit_net [ 'network_name' ] = external_network return transit_net , network | Get external network information |
37,937 | def apic_driver ( self ) : if not self . _apic_driver : try : self . _apic_driver = ( bc . get_plugin ( 'GROUP_POLICY' ) . policy_driver_manager . policy_drivers [ 'apic' ] . obj ) self . _get_ext_net_name = self . _get_ext_net_name_gbp self . _get_vrf_context = self . _get_vrf_context_gbp except AttributeError : LOG . info ( "GBP service plugin not present -- will " "try APIC ML2 plugin." ) if not self . _apic_driver : try : self . _apic_driver = ( self . _core_plugin . mechanism_manager . mech_drivers [ 'cisco_apic_ml2' ] . obj ) self . _get_ext_net_name = self . _get_ext_net_name_neutron self . _get_vrf_context = self . _get_vrf_context_neutron except KeyError : LOG . error ( "APIC ML2 plugin not present: " "no APIC ML2 driver could be found." ) raise AciDriverNoAciDriverInstalledOrConfigured ( ) return self . _apic_driver | Get APIC driver |
37,938 | def _snat_subnet_for_ext_net ( self , context , subnet , net ) : if subnet [ 'network_id' ] == net [ 'id' ] : return True network = self . _core_plugin . get_network ( context . elevated ( ) , subnet [ 'network_id' ] ) ext_net_name = network [ 'name' ] if ( APIC_SNAT_NET + '-' ) in ext_net_name : ext_net_name = ext_net_name [ len ( APIC_SNAT_NET + '-' ) : ] if net [ 'id' ] == ext_net_name : return True return False | Determine if an SNAT subnet is for this external network . |
37,939 | def extend_hosting_port_info ( self , context , port_db , hosting_device , hosting_info ) : if hosting_info . get ( 'segmentation_id' ) is None : LOG . debug ( 'No segmentation ID in hosting_info -- assigning' ) hosting_info [ 'segmentation_id' ] = ( port_db . hosting_info . get ( 'segmentation_id' ) ) is_external = ( port_db . device_owner == DEVICE_OWNER_ROUTER_GW ) hosting_info [ 'physical_interface' ] = self . _get_interface_info ( hosting_device [ 'id' ] , port_db . network_id , is_external ) ext_dict , net = self . _get_external_network_dict ( context , port_db ) if is_external and ext_dict : hosting_info [ 'network_name' ] = ext_dict [ 'network_name' ] hosting_info [ 'cidr_exposed' ] = ext_dict [ 'cidr_exposed' ] hosting_info [ 'gateway_ip' ] = ext_dict [ 'gateway_ip' ] details = self . get_vrf_context ( context , port_db [ 'device_id' ] , port_db ) router_id = port_db . device_id router = self . l3_plugin . get_router ( context , router_id ) if router . get ( ROUTER_ROLE_ATTR ) : return hosting_info [ 'vrf_id' ] = details [ 'vrf_id' ] if ext_dict . get ( 'global_config' ) : hosting_info [ 'global_config' ] = ( ext_dict [ 'global_config' ] ) self . _add_snat_info ( context , router , net , hosting_info ) else : if ext_dict . get ( 'interface_config' ) : hosting_info [ 'interface_config' ] = ext_dict [ 'interface_config' ] | Get the segmenetation ID and interface |
37,940 | def allocate_hosting_port ( self , context , router_id , port_db , network_type , hosting_device_id ) : if port_db . get ( 'device_owner' ) == DEVICE_OWNER_ROUTER_GW : ext_dict , net = self . _get_external_network_dict ( context , port_db ) if net and net . get ( 'provider:network_type' ) == 'opflex' : if ext_dict . get ( 'segmentation_id' ) : return { 'allocated_port_id' : port_db . id , 'allocated_vlan' : ext_dict [ 'segmentation_id' ] } else : raise AciDriverConfigMissingSegmentationId ( ext_net = net ) return super ( AciVLANTrunkingPlugDriver , self ) . allocate_hosting_port ( context , router_id , port_db , network_type , hosting_device_id ) if port_db . get ( 'device_owner' ) != DEVICE_OWNER_ROUTER_INTF : return router = self . l3_plugin . get_router ( context , router_id ) gw_info = router [ EXTERNAL_GW_INFO ] if not gw_info : return network_id = gw_info . get ( 'network_id' ) networks = self . _core_plugin . get_networks ( context . elevated ( ) , { 'id' : [ network_id ] } ) l3out_network = networks [ 0 ] l3out_name = self . get_ext_net_name ( l3out_network [ 'name' ] ) details = self . get_vrf_context ( context , router_id , port_db ) if details is None : LOG . debug ( 'aci_vlan_trunking_driver: No vrf_details' ) return vrf_name = details . get ( 'vrf_name' ) vrf_tenant = details . get ( 'vrf_tenant' ) allocated_vlan = self . apic_driver . l3out_vlan_alloc . get_vlan_allocated ( l3out_name , vrf_name , vrf_tenant = vrf_tenant ) if allocated_vlan is None : if not vrf_tenant : return super ( AciVLANTrunkingPlugDriver , self ) . allocate_hosting_port ( context , router_id , port_db , network_type , hosting_device_id ) return return { 'allocated_port_id' : port_db . id , 'allocated_vlan' : allocated_vlan } | Get the VLAN and port for this hosting device |
37,941 | def _get_ext_net_name_gbp ( self , network_name ) : prefix = network_name [ : re . search ( UUID_REGEX , network_name ) . start ( ) - 1 ] return prefix . strip ( APIC_OWNED ) | Get the external network name |
37,942 | def is_valid_mac ( addr ) : addrs = addr . split ( ':' ) if len ( addrs ) != 6 : return False for m in addrs : try : if int ( m , 16 ) > 255 : return False except ValueError : return False return True | Check the syntax of a given mac address . |
37,943 | def make_cidr ( gw , mask ) : try : int_mask = ( 0xFFFFFFFF << ( 32 - int ( mask ) ) ) & 0xFFFFFFFF gw_addr_int = struct . unpack ( '>L' , socket . inet_aton ( gw ) ) [ 0 ] & int_mask return ( socket . inet_ntoa ( struct . pack ( "!I" , gw_addr_int ) ) + '/' + str ( mask ) ) except ( socket . error , struct . error , ValueError , TypeError ) : return | Create network address in CIDR format . |
37,944 | def find_agent_host_id ( this_host ) : host_id = this_host try : for root , dirs , files in os . walk ( '/run/resource-agents' ) : for fi in files : if 'neutron-scale-' in fi : host_id = 'neutron-n-' + fi . split ( '-' ) [ 2 ] break return host_id except IndexError : return host_id | Returns the neutron agent host id for RHEL - OSP6 HA setup . |
37,945 | def _build_credentials ( self , nexus_switches ) : credentials = { } for switch_ip , attrs in nexus_switches . items ( ) : credentials [ switch_ip ] = ( attrs [ const . USERNAME ] , attrs [ const . PASSWORD ] , attrs [ const . HTTPS_VERIFY ] , attrs [ const . HTTPS_CERT ] , None ) if not attrs [ const . HTTPS_VERIFY ] : LOG . warning ( "HTTPS Certificate verification is " "disabled. Your connection to Nexus " "Switch %(ip)s is insecure." , { 'ip' : switch_ip } ) return credentials | Build credential table for Rest API Client . |
37,946 | def capture_and_print_timeshot ( self , start_time , which , other = 99 , switch = "x.x.x.x" ) : curr_timeout = time . time ( ) - start_time if which in self . time_stats : self . time_stats [ which ] [ "total_time" ] += curr_timeout self . time_stats [ which ] [ "total_count" ] += 1 if ( curr_timeout < self . time_stats [ which ] [ "min" ] ) : self . time_stats [ which ] [ "min" ] = curr_timeout if ( curr_timeout > self . time_stats [ which ] [ "max" ] ) : self . time_stats [ which ] [ "max" ] = curr_timeout else : self . time_stats [ which ] = { "total_time" : curr_timeout , "total_count" : 1 , "min" : curr_timeout , "max" : curr_timeout } LOG . debug ( "NEXUS_TIME_STATS %(switch)s, pid %(pid)d, tid %(tid)d: " "%(which)s_timeout %(curr)f count %(count)d " "average %(ave)f other %(other)d min %(min)f max %(max)f" , { 'switch' : switch , 'pid' : os . getpid ( ) , 'tid' : threading . current_thread ( ) . ident , 'which' : which , 'curr' : curr_timeout , 'count' : self . time_stats [ which ] [ "total_count" ] , 'ave' : ( self . time_stats [ which ] [ "total_time" ] / self . time_stats [ which ] [ "total_count" ] ) , 'other' : other , 'min' : self . time_stats [ which ] [ "min" ] , 'max' : self . time_stats [ which ] [ "max" ] } ) | Determine delta keep track and print results . |
37,947 | def get_interface_switch ( self , nexus_host , intf_type , interface ) : if intf_type == "ethernet" : path_interface = "phys-[eth" + interface + "]" else : path_interface = "aggr-[po" + interface + "]" action = snipp . PATH_IF % path_interface starttime = time . time ( ) response = self . client . rest_get ( action , nexus_host ) self . capture_and_print_timeshot ( starttime , "getif" , switch = nexus_host ) LOG . debug ( "GET call returned interface %(if_type)s %(interface)s " "config" , { 'if_type' : intf_type , 'interface' : interface } ) return response | Get the interface data from host . |
37,948 | def _get_interface_switch_trunk_present ( self , nexus_host , intf_type , interface ) : result = self . get_interface_switch ( nexus_host , intf_type , interface ) if_type = 'l1PhysIf' if intf_type == "ethernet" else 'pcAggrIf' if_info = result [ 'imdata' ] [ 0 ] [ if_type ] try : mode_cfg = if_info [ 'attributes' ] [ 'mode' ] except Exception : mode_cfg = None mode_found = ( mode_cfg == "trunk" ) try : vlan_list = if_info [ 'attributes' ] [ 'trunkVlans' ] except Exception : vlan_list = None vlan_configured = ( vlan_list != const . UNCONFIGURED_VLAN ) return mode_found , vlan_configured | Check if switchport trunk configs present . |
37,949 | def add_ch_grp_to_interface ( self , nexus_host , if_type , port , ch_grp ) : if if_type != "ethernet" : LOG . error ( "Unexpected interface type %(iftype)s when " "adding change group" , { 'iftype' : if_type } ) return starttime = time . time ( ) path_snip = snipp . PATH_ALL path_interface = "phys-[eth" + port + "]" body_snip = snipp . BODY_ADD_CH_GRP % ( ch_grp , ch_grp , path_interface ) self . send_edit_string ( nexus_host , path_snip , body_snip ) self . capture_and_print_timeshot ( starttime , "add_ch_group" , switch = nexus_host ) | Applies channel - group n to ethernet interface . |
37,950 | def _apply_user_port_channel_config ( self , nexus_host , vpc_nbr ) : cli_cmds = self . _get_user_port_channel_config ( nexus_host , vpc_nbr ) if cli_cmds : self . _send_cli_conf_string ( nexus_host , cli_cmds ) else : vpc_str = str ( vpc_nbr ) path_snip = snipp . PATH_ALL body_snip = snipp . BODY_ADD_PORT_CH_P2 % ( vpc_str , vpc_str ) self . send_edit_string ( nexus_host , path_snip , body_snip ) | Adds STP and no lacp suspend config to port channel . |
37,951 | def create_port_channel ( self , nexus_host , vpc_nbr ) : starttime = time . time ( ) vpc_str = str ( vpc_nbr ) path_snip = snipp . PATH_ALL body_snip = snipp . BODY_ADD_PORT_CH % ( vpc_str , vpc_str , vpc_str ) self . send_edit_string ( nexus_host , path_snip , body_snip ) self . _apply_user_port_channel_config ( nexus_host , vpc_nbr ) self . capture_and_print_timeshot ( starttime , "create_port_channel" , switch = nexus_host ) | Creates port channel n on Nexus switch . |
37,952 | def delete_port_channel ( self , nexus_host , vpc_nbr ) : starttime = time . time ( ) path_snip = snipp . PATH_ALL body_snip = snipp . BODY_DEL_PORT_CH % ( vpc_nbr ) self . send_edit_string ( nexus_host , path_snip , body_snip ) self . capture_and_print_timeshot ( starttime , "delete_port_channel" , switch = nexus_host ) | Deletes delete port channel on Nexus switch . |
37,953 | def _get_port_channel_group ( self , nexus_host , intf_type , interface ) : ch_grp = 0 if intf_type != 'ethernet' : return ch_grp match_key = "eth" + interface action = snipp . PATH_GET_PC_MEMBERS starttime = time . time ( ) result = self . client . rest_get ( action , nexus_host ) self . capture_and_print_timeshot ( starttime , "getpc" , switch = nexus_host ) try : for pcmbr in result [ 'imdata' ] : mbr_data = pcmbr [ 'pcRsMbrIfs' ] [ 'attributes' ] if mbr_data [ 'tSKey' ] == match_key : _ , nbr = mbr_data [ 'parentSKey' ] . split ( "po" ) ch_grp = int ( nbr ) break except Exception : ch_grp = 0 LOG . debug ( "GET interface %(key)s port channel is %(pc)d" , { 'key' : match_key , 'pc' : ch_grp } ) return ch_grp | Look for channel - group x config and return x . |
37,954 | def initialize_baremetal_switch_interfaces ( self , interfaces ) : if not interfaces : return max_ifs = len ( interfaces ) starttime = time . time ( ) learned , nexus_ip_list = self . _build_host_list_and_verify_chgrp ( interfaces ) if not nexus_ip_list : return if max_ifs > 1 : if learned : ch_grp = interfaces [ 0 ] [ - 1 ] self . _configure_learned_port_channel ( nexus_ip_list , ch_grp ) else : ch_grp = self . _get_new_baremetal_portchannel_id ( nexus_ip_list ) else : ch_grp = 0 for i , ( nexus_host , intf_type , nexus_port , is_native , ch_grp_saved ) in enumerate ( interfaces ) : if max_ifs > 1 : if learned : ch_grp = ch_grp_saved else : self . _config_new_baremetal_portchannel ( ch_grp , nexus_host , intf_type , nexus_port ) self . _replace_interface_ch_grp ( interfaces , i , ch_grp ) intf_type = 'port-channel' nexus_port = str ( ch_grp ) else : self . _replace_interface_ch_grp ( interfaces , i , ch_grp ) trunk_mode_present , vlan_present = ( self . _get_interface_switch_trunk_present ( nexus_host , intf_type , nexus_port ) ) if not vlan_present : self . send_enable_vlan_on_trunk_int ( nexus_host , "" , intf_type , nexus_port , False , not trunk_mode_present ) elif not trunk_mode_present : LOG . warning ( TRUNK_MODE_NOT_FOUND , nexus_host , nexus_help . format_interface_name ( intf_type , nexus_port ) ) self . capture_and_print_timeshot ( starttime , "init_bmif" , switch = nexus_host ) | Initialize Nexus interfaces and for initial baremetal event . |
37,955 | def initialize_all_switch_interfaces ( self , interfaces , switch_ip = None , replay = True ) : if not interfaces : return starttime = time . time ( ) if replay : try : vpcs = nxos_db . get_active_switch_vpc_allocs ( switch_ip ) except cexc . NexusVPCAllocNotFound : vpcs = [ ] for vpc in vpcs : if not vpc . learned : self . create_port_channel ( switch_ip , vpc . vpc_id ) for i , ( nexus_host , intf_type , nexus_port , is_native , ch_grp ) in enumerate ( interfaces ) : if replay and ch_grp != 0 : try : vpc = nxos_db . get_switch_vpc_alloc ( switch_ip , ch_grp ) self . add_ch_grp_to_interface ( nexus_host , intf_type , nexus_port , ch_grp ) except cexc . NexusVPCAllocNotFound : pass intf_type = 'port-channel' nexus_port = str ( ch_grp ) no_chgrp_len = len ( interfaces [ i ] ) - 1 interfaces [ i ] = interfaces [ i ] [ : no_chgrp_len ] + ( ch_grp , ) trunk_mode_present , vlan_present = ( self . _get_interface_switch_trunk_present ( nexus_host , intf_type , nexus_port ) ) if not vlan_present : self . send_enable_vlan_on_trunk_int ( nexus_host , "" , intf_type , nexus_port , False , not trunk_mode_present ) elif not trunk_mode_present : LOG . warning ( TRUNK_MODE_NOT_FOUND , nexus_host , nexus_help . format_interface_name ( intf_type , nexus_port ) ) self . capture_and_print_timeshot ( starttime , "get_allif" , switch = nexus_host ) | Configure Nexus interface and get port channel number . |
37,956 | def get_nexus_type ( self , nexus_host ) : starttime = time . time ( ) response = self . client . rest_get ( snipp . PATH_GET_NEXUS_TYPE , nexus_host ) self . capture_and_print_timeshot ( starttime , "gettype" , switch = nexus_host ) if response : try : result = response [ 'imdata' ] [ 0 ] [ "eqptCh" ] [ 'attributes' ] [ 'descr' ] except Exception : result = '' nexus_type = re . findall ( "Nexus\s*(\d)\d+\s*[0-9A-Z]+\s*" "[cC]hassis" , result ) if len ( nexus_type ) > 0 : LOG . debug ( "GET call returned Nexus type %d" , int ( nexus_type [ 0 ] ) ) return int ( nexus_type [ 0 ] ) else : result = '' LOG . debug ( "GET call failed to return Nexus type. Received %s." , result ) return - 1 | Given the nexus host get the type of Nexus switch . |
37,957 | def get_create_vlan ( self , nexus_host , vlanid , vni , conf_str ) : starttime = time . time ( ) if vni : body_snip = snipp . BODY_VXLAN_ALL_INCR % ( vlanid , vni ) else : body_snip = snipp . BODY_VLAN_ALL_INCR % vlanid conf_str += body_snip + snipp . BODY_VLAN_ALL_CONT self . capture_and_print_timeshot ( starttime , "get_create_vlan" , switch = nexus_host ) return conf_str | Returns an XML snippet for create VLAN on a Nexus Switch . |
37,958 | def set_all_vlan_states ( self , nexus_host , vlanid_range ) : starttime = time . time ( ) if not vlanid_range : LOG . warning ( "Exiting set_all_vlan_states: " "No vlans to configure" ) return vlan_id_list = re . sub ( r'\s' , '' , vlanid_range ) . split ( ',' ) if not vlan_id_list or not vlan_id_list [ 0 ] : LOG . warning ( "Exiting set_all_vlan_states: " "No vlans to configure" ) return path_str , body_vlan_all = self . start_create_vlan ( ) while vlan_id_list : rangev = vlan_id_list . pop ( 0 ) if '-' in rangev : fr , to = rangev . split ( '-' ) max = int ( to ) + 1 for vlan_id in range ( int ( fr ) , max ) : body_vlan_all = self . get_create_vlan ( nexus_host , vlan_id , 0 , body_vlan_all ) else : body_vlan_all = self . get_create_vlan ( nexus_host , rangev , 0 , body_vlan_all ) body_vlan_all = self . end_create_vlan ( body_vlan_all ) self . send_edit_string ( nexus_host , path_str , body_vlan_all ) self . capture_and_print_timeshot ( starttime , "set_all_vlan_states" , switch = nexus_host ) | Set the VLAN states to active . |
37,959 | def create_vlan ( self , nexus_host , vlanid , vni ) : starttime = time . time ( ) path_snip , body_snip = self . start_create_vlan ( ) body_snip = self . get_create_vlan ( nexus_host , vlanid , vni , body_snip ) body_snip = self . end_create_vlan ( body_snip ) self . send_edit_string ( nexus_host , path_snip , body_snip ) self . capture_and_print_timeshot ( starttime , "create_vlan_seg" , switch = nexus_host ) | Given switch vlanid vni Create a VLAN on Switch . |
37,960 | def delete_vlan ( self , nexus_host , vlanid ) : starttime = time . time ( ) path_snip = snipp . PATH_VLAN % vlanid self . client . rest_delete ( path_snip , nexus_host ) self . capture_and_print_timeshot ( starttime , "del_vlan" , switch = nexus_host ) | Delete a VLAN on Nexus Switch given the VLAN ID . |
37,961 | def _get_vlan_body_on_trunk_int ( self , nexus_host , vlanid , intf_type , interface , is_native , is_delete , add_mode ) : starttime = time . time ( ) LOG . debug ( "NexusDriver get if body config for host %s: " "if_type %s port %s" , nexus_host , intf_type , interface ) if intf_type == "ethernet" : body_if_type = "l1PhysIf" path_interface = "phys-[eth" + interface + "]" else : body_if_type = "pcAggrIf" path_interface = "aggr-[po" + interface + "]" path_snip = ( snipp . PATH_IF % ( path_interface ) ) mode = snipp . BODY_PORT_CH_MODE if add_mode else '' if is_delete : increment_it = "-" debug_desc = "delif" native_vlan = "" else : native_vlan = 'vlan-' + str ( vlanid ) debug_desc = "createif" if vlanid is "" : increment_it = "" else : increment_it = "+" if is_native : body_snip = ( snipp . BODY_NATIVE_TRUNKVLAN % ( body_if_type , mode , increment_it + str ( vlanid ) , str ( native_vlan ) ) ) else : body_snip = ( snipp . BODY_TRUNKVLAN % ( body_if_type , mode , increment_it + str ( vlanid ) ) ) self . capture_and_print_timeshot ( starttime , debug_desc , switch = nexus_host ) return path_snip , body_snip | Prepares an XML snippet for VLAN on a trunk interface . |
37,962 | def disable_vlan_on_trunk_int ( self , nexus_host , vlanid , intf_type , interface , is_native ) : starttime = time . time ( ) path_snip , body_snip = self . _get_vlan_body_on_trunk_int ( nexus_host , vlanid , intf_type , interface , is_native , True , False ) self . send_edit_string ( nexus_host , path_snip , body_snip ) self . capture_and_print_timeshot ( starttime , "delif" , switch = nexus_host ) | Disable a VLAN on a trunk interface . |
37,963 | def send_edit_string ( self , nexus_host , path_snip , body_snip , check_to_close_session = True ) : starttime = time . time ( ) LOG . debug ( "NexusDriver edit config for host %s: path: %s body: %s" , nexus_host , path_snip , body_snip ) self . client . rest_post ( path_snip , nexus_host , body_snip ) self . capture_and_print_timeshot ( starttime , "send_edit" , switch = nexus_host ) | Sends rest Post request to Nexus switch . |
37,964 | def _send_cli_conf_string ( self , nexus_host , cli_str ) : starttime = time . time ( ) path_snip = snipp . PATH_USER_CMDS body_snip = snipp . BODY_USER_CONF_CMDS % ( '1' , cli_str ) LOG . debug ( "NexusDriver CLI config for host %s: path: %s body: %s" , nexus_host , path_snip , body_snip ) self . nxapi_client . rest_post ( path_snip , nexus_host , body_snip ) self . capture_and_print_timeshot ( starttime , "send_cliconf" , switch = nexus_host ) | Sends CLI Config commands to Nexus switch using NXAPI . |
37,965 | def send_enable_vlan_on_trunk_int ( self , nexus_host , vlanid , intf_type , interface , is_native , add_mode = False ) : path_snip , body_snip = self . _get_vlan_body_on_trunk_int ( nexus_host , vlanid , intf_type , interface , is_native , False , add_mode ) self . send_edit_string ( nexus_host , path_snip , body_snip ) | Gathers and sends an interface trunk XML snippet . |
37,966 | def create_and_trunk_vlan ( self , nexus_host , vlan_id , intf_type , nexus_port , vni , is_native ) : starttime = time . time ( ) self . create_vlan ( nexus_host , vlan_id , vni ) LOG . debug ( "NexusDriver created VLAN: %s" , vlan_id ) if nexus_port : self . send_enable_vlan_on_trunk_int ( nexus_host , vlan_id , intf_type , nexus_port , is_native ) self . capture_and_print_timeshot ( starttime , "create_all" , switch = nexus_host ) | Create VLAN and trunk it on the specified ports . |
37,967 | def enable_vxlan_feature ( self , nexus_host , nve_int_num , src_intf ) : starttime = time . time ( ) self . send_edit_string ( nexus_host , snipp . PATH_VXLAN_STATE , ( snipp . BODY_VXLAN_STATE % "enabled" ) ) self . send_edit_string ( nexus_host , snipp . PATH_VNSEG_STATE , ( snipp . BODY_VNSEG_STATE % "enabled" ) ) self . send_edit_string ( nexus_host , ( snipp . PATH_NVE_CREATE % nve_int_num ) , ( snipp . BODY_NVE_CREATE % nve_int_num ) ) self . send_edit_string ( nexus_host , ( snipp . PATH_NVE_CREATE % nve_int_num ) , ( snipp . BODY_NVE_ADD_LOOPBACK % ( "enabled" , src_intf ) ) ) self . capture_and_print_timeshot ( starttime , "enable_vxlan" , switch = nexus_host ) | Enable VXLAN on the switch . |
37,968 | def disable_vxlan_feature ( self , nexus_host ) : starttime = time . time ( ) self . send_edit_string ( nexus_host , snipp . PATH_VXLAN_STATE , ( snipp . BODY_VXLAN_STATE % "disabled" ) ) self . send_edit_string ( nexus_host , snipp . PATH_VNSEG_STATE , ( snipp . BODY_VNSEG_STATE % "disabled" ) ) self . capture_and_print_timeshot ( starttime , "disable_vxlan" , switch = nexus_host ) | Disable VXLAN on the switch . |
37,969 | def create_nve_member ( self , nexus_host , nve_int_num , vni , mcast_group ) : starttime = time . time ( ) path = snipp . PATH_VNI_UPDATE % ( nve_int_num , vni ) body = snipp . BODY_VNI_UPDATE % ( vni , vni , vni , mcast_group ) self . send_edit_string ( nexus_host , path , body ) self . capture_and_print_timeshot ( starttime , "create_nve" , switch = nexus_host ) | Add a member configuration to the NVE interface . |
37,970 | def delete_nve_member ( self , nexus_host , nve_int_num , vni ) : starttime = time . time ( ) path_snip = snipp . PATH_VNI_UPDATE % ( nve_int_num , vni ) self . client . rest_delete ( path_snip , nexus_host ) self . capture_and_print_timeshot ( starttime , "delete_nve" , switch = nexus_host ) | Delete a member configuration on the NVE interface . |
37,971 | def _get_vrf_name ( self , ri ) : router_id = ri . router_name ( ) [ : self . DEV_NAME_LEN ] is_multi_region_enabled = cfg . CONF . multi_region . enable_multi_region if is_multi_region_enabled : region_id = cfg . CONF . multi_region . region_id vrf_name = "%s-%s" % ( router_id , region_id ) else : vrf_name = router_id return vrf_name | overloaded method for generating a vrf_name that supports region_id |
37,972 | def _get_item ( list_containing_dicts_entries , attribute_value , attribute_name = 'subnet_id' ) : for item in list_containing_dicts_entries : if item . get ( attribute_name ) == attribute_value : return item return { } | Searches a list of dicts and returns the first matching entry |
37,973 | def _nat_rules_for_internet_access ( self , acl_no , network , netmask , inner_itfc , outer_itfc , vrf_name ) : acl_present = self . _check_acl ( acl_no , network , netmask ) if not acl_present : conf_str = snippets . CREATE_ACL % ( acl_no , network , netmask ) self . _edit_running_config ( conf_str , 'CREATE_ACL' ) pool_name = "%s_nat_pool" % vrf_name conf_str = asr1k_snippets . SET_DYN_SRC_TRL_POOL % ( acl_no , pool_name , vrf_name ) try : self . _edit_running_config ( conf_str , 'SET_DYN_SRC_TRL_POOL' ) except Exception as dyn_nat_e : LOG . info ( "Ignore exception for SET_DYN_SRC_TRL_POOL: %s. " "The config seems to be applied properly but netconf " "seems to report an error." , dyn_nat_e ) conf_str = snippets . SET_NAT % ( inner_itfc , 'inside' ) self . _edit_running_config ( conf_str , 'SET_NAT' ) conf_str = snippets . SET_NAT % ( outer_itfc , 'outside' ) self . _edit_running_config ( conf_str , 'SET_NAT' ) | Configure the NAT rules for an internal network . |
37,974 | def _remove_internal_nw_nat_rules ( self , ri , ports , ext_port , intf_deleted = False ) : acls = [ ] for port in ports : in_itfc_name = self . _get_interface_name_from_hosting_port ( port ) acls . append ( self . _generate_acl_num_from_port ( port ) ) is_alone = len ( port [ 'change_details' ] [ 'current_ports' ] ) == 1 if not intf_deleted and is_alone is True : self . _remove_interface_nat ( in_itfc_name , 'inside' ) vrf_name = self . _get_vrf_name ( ri ) ext_itfc_name = self . _get_interface_name_from_hosting_port ( ext_port ) for acl in acls : self . _remove_dyn_nat_rule ( acl , ext_itfc_name , vrf_name ) | Removes the NAT rules already configured when an internal network is removed . |
37,975 | def _do_add_floating_ip_asr1k ( self , floating_ip , fixed_ip , vrf , ex_gw_port ) : vlan = ex_gw_port [ 'hosting_info' ] [ 'segmentation_id' ] hsrp_grp = ex_gw_port [ ha . HA_INFO ] [ 'group' ] LOG . debug ( "add floating_ip: %(fip)s, fixed_ip: %(fixed_ip)s, " "vrf: %(vrf)s, ex_gw_port: %(port)s" , { 'fip' : floating_ip , 'fixed_ip' : fixed_ip , 'vrf' : vrf , 'port' : ex_gw_port } ) confstr = ( asr1k_snippets . SET_STATIC_SRC_TRL_NO_VRF_MATCH % ( fixed_ip , floating_ip , vrf , hsrp_grp , vlan ) ) self . _edit_running_config ( confstr , 'SET_STATIC_SRC_TRL_NO_VRF_MATCH' ) | To implement a floating ip an ip static nat is configured in the underlying router ex_gw_port contains data to derive the vlan associated with related subnet for the fixed ip . The vlan in turn is applied to the redundancy parameter for setting the IP NAT . |
37,976 | def report_non_responding_hosting_devices ( self , context , host , hosting_device_ids ) : self . update_hosting_device_status ( context , host , { const . HD_DEAD : hosting_device_ids } ) | Report that a hosting device is determined to be dead . |
37,977 | def update_hosting_device_status ( self , context , host , status_info ) : for status , hd_ids in six . iteritems ( status_info ) : hd_spec = { 'hosting_device' : { 'status' : status } } for hd_id in hd_ids : self . _dmplugin . update_hosting_device ( context , hd_id , hd_spec ) if status == const . HD_DEAD or status == const . HD_ERROR : self . _dmplugin . handle_non_responding_hosting_devices ( context , host , hd_ids ) | Report status changes for hosting devices . |
37,978 | def get_hosting_devices_for_agent ( self , context , host ) : agent_ids = self . _dmplugin . get_cfg_agents ( context , active = None , filters = { 'host' : [ host ] } ) if agent_ids : return [ self . _dmplugin . get_device_info_for_agent ( context , hd_db ) for hd_db in self . _dmplugin . get_hosting_devices_db ( context , filters = { 'cfg_agent_id' : [ agent_ids [ 0 ] . id ] } ) ] return [ ] | Fetches routers that a Cisco cfg agent is managing . |
37,979 | def remove_router_from_hosting_device ( self , context , hosting_device_id , router_id ) : e_context = context . elevated ( ) r_hd_binding_db = self . _get_router_binding_info ( e_context , router_id ) if r_hd_binding_db . hosting_device_id != hosting_device_id : raise routertypeawarescheduler . RouterNotHostedByHostingDevice ( router_id = router_id , hosting_device_id = hosting_device_id ) router = self . get_router ( context , router_id ) self . add_type_and_hosting_device_info ( e_context , router , r_hd_binding_db , schedule = False ) self . remove_router_from_backlog ( id ) l3_cfg_notifier = self . agent_notifiers . get ( AGENT_TYPE_L3_CFG ) if l3_cfg_notifier : l3_cfg_notifier . router_removed_from_hosting_device ( context , router ) LOG . debug ( "Unscheduling router %s" , r_hd_binding_db . router_id ) self . unschedule_router_from_hosting_device ( context , r_hd_binding_db ) with e_context . session . begin ( subtransactions = True ) : r_hd_binding_db . hosting_device_id = None e_context . session . add ( r_hd_binding_db ) | Remove the router from hosting device . |
37,980 | def get_number_of_agents_for_scheduling ( self , context ) : num_agents = len ( self . get_l3_agents ( context , active = True , filters = { 'agent_modes' : [ bc . constants . L3_AGENT_MODE_LEGACY , bc . constants . L3_AGENT_MODE_DVR_SNAT ] } ) ) max_agents = cfg . CONF . max_l3_agents_per_router if max_agents : if max_agents > num_agents : LOG . info ( "Number of active agents lower than " "max_l3_agents_per_router. L3 agents " "available: %s" , num_agents ) else : num_agents = max_agents return num_agents | Return number of agents on which the router will be scheduled . |
37,981 | def _notify_subnet_create ( resource , event , trigger , ** kwargs ) : context = kwargs [ 'context' ] subnet = kwargs [ 'subnet' ] l3plugin = bc . get_plugin ( L3_ROUTER_NAT ) for router in l3plugin . get_routers ( context ) : if ( router [ 'external_gateway_info' ] and ( router [ 'external_gateway_info' ] [ 'network_id' ] == subnet [ 'network_id' ] ) ) : router_data = { 'router' : router } l3plugin . update_router ( context , router [ 'id' ] , router_data ) | Called when a new subnet is created in the external network |
37,982 | def is_port_profile_created ( self , vlan_id , device_id ) : entry = self . session . query ( ucsm_model . PortProfile ) . filter_by ( vlan_id = vlan_id , device_id = device_id ) . first ( ) return entry and entry . created_on_ucs | Indicates if port profile has been created on UCS Manager . |
37,983 | def get_port_profile_for_vlan ( self , vlan_id , device_id ) : entry = self . session . query ( ucsm_model . PortProfile ) . filter_by ( vlan_id = vlan_id , device_id = device_id ) . first ( ) return entry . profile_id if entry else None | Returns Vlan id associated with the port profile . |
37,984 | def add_port_profile ( self , profile_name , vlan_id , device_id ) : if not self . get_port_profile_for_vlan ( vlan_id , device_id ) : port_profile = ucsm_model . PortProfile ( profile_id = profile_name , vlan_id = vlan_id , device_id = device_id , created_on_ucs = False ) with self . session . begin ( subtransactions = True ) : self . session . add ( port_profile ) return port_profile | Adds a port profile and its vlan_id to the table . |
37,985 | def set_port_profile_created ( self , vlan_id , profile_name , device_id ) : with self . session . begin ( subtransactions = True ) : port_profile = self . session . query ( ucsm_model . PortProfile ) . filter_by ( vlan_id = vlan_id , profile_id = profile_name , device_id = device_id ) . first ( ) if port_profile : port_profile . created_on_ucs = True self . session . merge ( port_profile ) else : new_profile = ucsm_model . PortProfile ( profile_id = profile_name , vlan_id = vlan_id , device_id = device_id , created_on_ucs = True ) self . session . add ( new_profile ) | Sets created_on_ucs flag to True . |
37,986 | def delete_vlan_entry ( self , vlan_id ) : with self . session . begin ( subtransactions = True ) : try : self . session . query ( ucsm_model . PortProfile ) . filter_by ( vlan_id = vlan_id ) . delete ( ) except orm . exc . NoResultFound : return | Deletes entry for a vlan_id if it exists . |
37,987 | def set_sp_template_updated ( self , vlan_id , sp_template , device_id ) : entry = self . get_sp_template_vlan_entry ( vlan_id , sp_template , device_id ) if entry : entry . updated_on_ucs = True self . session . merge ( entry ) return entry else : return False | Sets update_on_ucs flag to True . |
37,988 | def delete_sp_template_for_vlan ( self , vlan_id ) : with self . session . begin ( subtransactions = True ) : try : self . session . query ( ucsm_model . ServiceProfileTemplate ) . filter_by ( vlan_id = vlan_id ) . delete ( ) except orm . exc . NoResultFound : return | Deletes SP Template for a vlan_id if it exists . |
37,989 | def set_vnic_template_updated ( self , vlan_id , ucsm_ip , vnic_template , physnet ) : with self . session . begin ( subtransactions = True ) : entry = self . get_vnic_template_vlan_entry ( vlan_id , vnic_template , ucsm_ip , physnet ) if entry : entry . updated_on_ucs = True self . session . merge ( entry ) return entry | Sets update_on_ucs flag to True for a Vnic Template entry . |
37,990 | def delete_vnic_template_for_vlan ( self , vlan_id ) : with self . session . begin ( subtransactions = True ) : try : self . session . query ( ucsm_model . VnicTemplate ) . filter_by ( vlan_id = vlan_id ) . delete ( ) except orm . exc . NoResultFound : return | Deletes VNIC Template for a vlan_id and physnet if it exists . |
37,991 | def has_port_profile_to_delete ( self , profile_name , device_id ) : count = self . session . query ( ucsm_model . PortProfileDelete ) . filter_by ( profile_id = profile_name , device_id = device_id ) . count ( ) return count != 0 | Returns True if port profile delete table containes PP . |
37,992 | def add_port_profile_to_delete_table ( self , profile_name , device_id ) : if not self . has_port_profile_to_delete ( profile_name , device_id ) : port_profile = ucsm_model . PortProfileDelete ( profile_id = profile_name , device_id = device_id ) with self . session . begin ( subtransactions = True ) : self . session . add ( port_profile ) return port_profile | Adds a port profile to the delete table . |
37,993 | def remove_port_profile_to_delete ( self , profile_name , device_id ) : with self . session . begin ( subtransactions = True ) : self . session . query ( ucsm_model . PortProfileDelete ) . filter_by ( profile_id = profile_name , device_id = device_id ) . delete ( ) | Removes port profile to be deleted from table . |
37,994 | def parse ( cls , buf ) : pkt = DhcpPacket ( ) ( pkt . ciaddr , ) = cls . struct ( '4s' ) . unpack_from ( buf , 12 ) ( pkt . giaddr , ) = cls . struct ( '4s' ) . unpack_from ( buf , 24 ) cls . struct ( '4s' ) . pack_into ( buf , 24 , b'' ) pos = 240 while pos < len ( buf ) : ( opttag , ) = cls . struct ( 'B' ) . unpack_from ( buf , pos ) if opttag == 0 : pos += 1 continue if opttag == END : pkt . end = pos break ( optlen , ) = cls . struct ( 'B' ) . unpack_from ( buf , pos + 1 ) startpos = pos pos += 2 if opttag != RELAY_AGENT_INFO : pos += optlen continue optend = pos + optlen while pos < optend : ( subopttag , suboptlen ) = cls . struct ( 'BB' ) . unpack_from ( buf , pos ) fmt = '%is' % ( suboptlen , ) ( val , ) = cls . struct ( fmt ) . unpack_from ( buf , pos + 2 ) pkt . relay_options [ subopttag ] = val pos += suboptlen + 2 cls . struct ( '%is' % ( optlen + 2 ) ) . pack_into ( buf , startpos , b'' ) pkt . buf = buf return pkt | Parse DHCP Packet . |
37,995 | def register_for_duty ( self , context ) : cctxt = self . client . prepare ( ) return cctxt . call ( context , 'register_for_duty' , host = self . host ) | Report that a config agent is ready for duty . |
37,996 | def get_hosting_devices_for_agent ( self , context ) : cctxt = self . client . prepare ( ) return cctxt . call ( context , 'get_hosting_devices_for_agent' , host = self . host ) | Get a list of hosting devices assigned to this agent . |
37,997 | def process_services ( self , device_ids = None , removed_devices_info = None ) : LOG . debug ( "Processing services started" ) if self . routing_service_helper : self . routing_service_helper . process_service ( device_ids , removed_devices_info ) else : LOG . warning ( "No routing service helper loaded" ) LOG . debug ( "Processing services completed" ) | Process services managed by this config agent . |
37,998 | def _process_backlogged_hosting_devices ( self , context ) : driver_mgr = self . get_routing_service_helper ( ) . driver_manager res = self . _dev_status . check_backlogged_hosting_devices ( driver_mgr ) if res [ 'reachable' ] : self . process_services ( device_ids = res [ 'reachable' ] ) if res [ 'revived' ] : LOG . debug ( "Reporting revived hosting devices: %s " % res [ 'revived' ] ) if self . conf . cfg_agent . enable_heartbeat is True : self . devmgr_rpc . report_revived_hosting_devices ( context , hd_ids = res [ 'revived' ] ) self . process_services ( device_ids = res [ 'revived' ] ) if res [ 'dead' ] : LOG . debug ( "Reporting dead hosting devices: %s" , res [ 'dead' ] ) self . devmgr_rpc . report_dead_hosting_devices ( context , hd_ids = res [ 'dead' ] ) | Process currently backlogged devices . |
37,999 | def agent_updated ( self , context , payload ) : try : if payload [ 'admin_state_up' ] : pass except KeyError as e : LOG . error ( "Invalid payload format for received RPC message " "`agent_updated`. Error is %(error)s. Payload is " "%(payload)s" , { 'error' : e , 'payload' : payload } ) | Deal with agent updated RPC message . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.