idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
37,600 | def _init_baremetal_trunk_interfaces ( self , port_seg , segment ) : list_to_init = [ ] inactive_switch = [ ] connections = self . _get_baremetal_connections ( port_seg , False , True ) for switch_ip , intf_type , port , is_native , _ in connections : try : nxos_db . get_switch_if_host_mappings ( switch_ip , nexus_help . format_interface_name ( intf_type , port ) ) except excep . NexusHostMappingNotFound : if self . is_switch_active ( switch_ip ) : list_to_init . append ( ( switch_ip , intf_type , port , is_native , 0 ) ) else : inactive_switch . append ( ( switch_ip , intf_type , port , is_native , 0 ) ) self . driver . initialize_baremetal_switch_interfaces ( list_to_init ) host_id = port_seg . get ( 'dns_name' ) if host_id is None : host_id = const . RESERVED_PORT_HOST_ID list_to_init += inactive_switch for switch_ip , intf_type , port , is_native , ch_grp in list_to_init : nxos_db . add_host_mapping ( host_id , switch_ip , nexus_help . format_interface_name ( intf_type , port ) , ch_grp , False ) | Initialize baremetal switch interfaces and DB entry . |
37,601 | def _get_host_switches ( self , host_id ) : all_switches = set ( ) active_switches = set ( ) try : host_list = nxos_db . get_host_mappings ( host_id ) for mapping in host_list : all_switches . add ( mapping . switch_ip ) if self . is_switch_active ( mapping . switch_ip ) : active_switches . add ( mapping . switch_ip ) except excep . NexusHostMappingNotFound : pass return list ( all_switches ) , list ( active_switches ) | Get switch IPs from configured host mapping . |
37,602 | def _get_host_connections ( self , host_id , only_active_switch = False ) : host_found = False host_connections = [ ] try : host_ifs = nxos_db . get_host_mappings ( host_id ) except excep . NexusHostMappingNotFound : host_ifs = [ ] for ifs in host_ifs : host_found = True if ( only_active_switch and not self . is_switch_active ( ifs . switch_ip ) ) : continue intf_type , port = nexus_help . split_interface_name ( ifs . if_id , ifs . ch_grp ) host_connections . append ( ( ifs . switch_ip , intf_type , port , const . NOT_NATIVE , ifs . ch_grp ) ) if not host_found : LOG . warning ( HOST_NOT_FOUND , host_id ) return host_connections | Get switch IPs and interfaces from config host mapping . |
37,603 | def _get_switch_interfaces ( self , requested_switch_ip , cfg_only = False ) : switch_ifs = [ ] try : port_info = nxos_db . get_switch_host_mappings ( requested_switch_ip ) except excep . NexusHostMappingNotFound : port_info = [ ] for binding in port_info : if cfg_only and not binding . is_static : continue intf_type , port = nexus_help . split_interface_name ( binding . if_id ) switch_ifs . append ( ( requested_switch_ip , intf_type , port , const . NOT_NATIVE , binding . ch_grp ) ) return switch_ifs | Get switch interfaces from host mapping DB . |
37,604 | def _configure_nve_db ( self , vni , device_id , mcast_group , host_id ) : host_nve_connections = self . _get_switch_nve_info ( host_id ) for switch_ip in host_nve_connections : if not nxos_db . get_nve_vni_member_bindings ( vni , switch_ip , device_id ) : nxos_db . add_nexusnve_binding ( vni , switch_ip , device_id , mcast_group ) | Create the nexus NVE database entry . |
37,605 | def _configure_nve_member ( self , vni , device_id , mcast_group , host_id ) : host_nve_connections = self . _get_switch_nve_info ( host_id ) for switch_ip in host_nve_connections : if cfg . CONF . ml2_cisco . vxlan_global_config : nve_bindings = nxos_db . get_nve_switch_bindings ( switch_ip ) if len ( nve_bindings ) == 1 : LOG . debug ( "Nexus: create NVE interface" ) loopback = self . get_nve_loopback ( switch_ip ) self . driver . enable_vxlan_feature ( switch_ip , const . NVE_INT_NUM , loopback ) member_bindings = nxos_db . get_nve_vni_switch_bindings ( vni , switch_ip ) if len ( member_bindings ) == 1 : LOG . debug ( "Nexus: add member" ) self . driver . create_nve_member ( switch_ip , const . NVE_INT_NUM , vni , mcast_group ) | Add member vni configuration to the NVE interface . |
37,606 | def _delete_nve_db ( self , vni , device_id , mcast_group , host_id ) : rows = nxos_db . get_nve_vni_deviceid_bindings ( vni , device_id ) for row in rows : nxos_db . remove_nexusnve_binding ( vni , row . switch_ip , device_id ) | Delete the nexus NVE database entry . |
37,607 | def _delete_nve_member ( self , vni , device_id , mcast_group , host_id ) : host_nve_connections = self . _get_switch_nve_info ( host_id ) for switch_ip in host_nve_connections : if not nxos_db . get_nve_vni_switch_bindings ( vni , switch_ip ) : self . driver . delete_nve_member ( switch_ip , const . NVE_INT_NUM , vni ) if ( cfg . CONF . ml2_cisco . vxlan_global_config and not nxos_db . get_nve_switch_bindings ( switch_ip ) ) : self . driver . disable_vxlan_feature ( switch_ip ) | Remove member vni configuration from the NVE interface . |
37,608 | def _configure_nxos_db ( self , port , vlan_id , device_id , host_id , vni , is_provider_vlan ) : connections = self . _get_port_connections ( port , host_id ) for switch_ip , intf_type , nexus_port , is_native , ch_grp in connections : port_id = nexus_help . format_interface_name ( intf_type , nexus_port , ch_grp ) try : nxos_db . get_nexusport_binding ( port_id , vlan_id , switch_ip , device_id ) except excep . NexusPortBindingNotFound : nxos_db . add_nexusport_binding ( port_id , str ( vlan_id ) , str ( vni ) , switch_ip , device_id , is_native ) | Create the nexus database entry . |
37,609 | def _gather_config_parms ( self , is_provider_vlan , vlan_id ) : if is_provider_vlan : auto_create = cfg . CONF . ml2_cisco . provider_vlan_auto_create auto_trunk = cfg . CONF . ml2_cisco . provider_vlan_auto_trunk else : auto_create = True auto_trunk = True return auto_create , auto_trunk | Collect auto_create auto_trunk from config . |
37,610 | def _configure_port_binding ( self , is_provider_vlan , duplicate_type , is_native , switch_ip , vlan_id , intf_type , nexus_port , vni ) : if duplicate_type == const . DUPLICATE_PORT : return auto_create , auto_trunk = self . _gather_config_parms ( is_provider_vlan , vlan_id ) if duplicate_type == const . DUPLICATE_VLAN : auto_create = False if auto_create and auto_trunk : LOG . debug ( "Nexus: create vlan %s and add to interface" , vlan_id ) self . driver . create_and_trunk_vlan ( switch_ip , vlan_id , intf_type , nexus_port , vni , is_native ) elif auto_create : LOG . debug ( "Nexus: create vlan %s" , vlan_id ) self . driver . create_vlan ( switch_ip , vlan_id , vni ) elif auto_trunk : LOG . debug ( "Nexus: trunk vlan %s" , vlan_id ) self . driver . send_enable_vlan_on_trunk_int ( switch_ip , vlan_id , intf_type , nexus_port , is_native ) | Conditionally calls vlan and port Nexus drivers . |
37,611 | def _get_compressed_vlan_list ( self , pvlan_ids ) : if not pvlan_ids : return [ ] pvlan_list = list ( pvlan_ids ) pvlan_list . sort ( ) compressed_list = [ ] begin = - 1 prev_vlan = - 1 for port_vlan in pvlan_list : if prev_vlan == - 1 : prev_vlan = port_vlan else : if ( port_vlan - prev_vlan ) == 1 : if begin == - 1 : begin = prev_vlan prev_vlan = port_vlan else : if begin == - 1 : compressed_list . append ( str ( prev_vlan ) ) else : compressed_list . append ( "%d-%d" % ( begin , prev_vlan ) ) begin = - 1 prev_vlan = port_vlan if begin == - 1 : compressed_list . append ( str ( prev_vlan ) ) else : compressed_list . append ( "%s-%s" % ( begin , prev_vlan ) ) return compressed_list | Generate a compressed vlan list ready for XML using a vlan set . |
37,612 | def _restore_port_binding ( self , switch_ip , pvlan_ids , port , native_vlan ) : intf_type , nexus_port = nexus_help . split_interface_name ( port ) if native_vlan != 0 : self . driver . send_enable_vlan_on_trunk_int ( switch_ip , native_vlan , intf_type , nexus_port , True ) if len ( pvlan_ids ) == 1 : return concat_vlans = '' compressed_vlans = self . _get_compressed_vlan_list ( pvlan_ids ) for pvlan in compressed_vlans : if concat_vlans == '' : concat_vlans = "%s" % pvlan else : concat_vlans += ",%s" % pvlan if len ( concat_vlans ) >= const . CREATE_PORT_VLAN_LENGTH : self . driver . send_enable_vlan_on_trunk_int ( switch_ip , concat_vlans , intf_type , nexus_port , False ) concat_vlans = '' if len ( concat_vlans ) : self . driver . send_enable_vlan_on_trunk_int ( switch_ip , concat_vlans , intf_type , nexus_port , False ) | Restores a set of vlans for a given port . |
37,613 | def _restore_vxlan_entries ( self , switch_ip , vlans ) : count = 1 conf_str = '' vnsegment_sent = 0 path_str , conf_str = self . driver . start_create_vlan ( ) while vnsegment_sent < const . CREATE_VLAN_BATCH and vlans : vlan_id , vni = vlans . pop ( 0 ) conf_str = self . driver . get_create_vlan ( switch_ip , vlan_id , vni , conf_str ) if ( count == const . CREATE_VLAN_SEND_SIZE ) : conf_str = self . driver . end_create_vlan ( conf_str ) self . driver . send_edit_string ( switch_ip , path_str , conf_str ) vnsegment_sent += count conf_str = '' count = 1 else : count += 1 if conf_str : vnsegment_sent += count conf_str = self . driver . end_create_vlan ( conf_str ) self . driver . send_edit_string ( switch_ip , path_str , conf_str ) conf_str = '' LOG . debug ( "Switch %s VLAN vn-segment replay summary: %d" , switch_ip , vnsegment_sent ) | Restore vxlan entries on a Nexus switch . |
37,614 | def _configure_port_entries ( self , port , vlan_id , device_id , host_id , vni , is_provider_vlan ) : connections = self . _get_active_port_connections ( port , host_id ) vlan_already_created = [ ] starttime = time . time ( ) for switch_ip , intf_type , nexus_port , is_native , _ in connections : try : all_bindings = nxos_db . get_nexusvlan_binding ( vlan_id , switch_ip ) except excep . NexusPortBindingNotFound : LOG . warning ( "Switch %(switch_ip)s and Vlan " "%(vlan_id)s not found in port binding " "database. Skipping this update" , { 'switch_ip' : switch_ip , 'vlan_id' : vlan_id } ) continue previous_bindings = [ row for row in all_bindings if row . instance_id != device_id ] if previous_bindings and ( switch_ip in vlan_already_created ) : duplicate_type = const . DUPLICATE_VLAN else : vlan_already_created . append ( switch_ip ) duplicate_type = const . NO_DUPLICATE port_starttime = time . time ( ) try : self . _configure_port_binding ( is_provider_vlan , duplicate_type , is_native , switch_ip , vlan_id , intf_type , nexus_port , vni ) except Exception : with excutils . save_and_reraise_exception ( ) : self . driver . capture_and_print_timeshot ( port_starttime , "port_configerr" , switch = switch_ip ) self . driver . capture_and_print_timeshot ( starttime , "configerr" , switch = switch_ip ) self . driver . capture_and_print_timeshot ( port_starttime , "port_config" , switch = switch_ip ) self . driver . capture_and_print_timeshot ( starttime , "config" ) | Create a nexus switch entry . |
37,615 | def configure_next_batch_of_vlans ( self , switch_ip ) : next_range = self . _pop_vlan_range ( switch_ip , const . CREATE_VLAN_BATCH ) if next_range : try : self . driver . set_all_vlan_states ( switch_ip , next_range ) except Exception : with excutils . save_and_reraise_exception ( ) : LOG . error ( "Error encountered restoring vlans " "for switch %(switch_ip)s" , { 'switch_ip' : switch_ip } ) self . _save_switch_vlan_range ( switch_ip , [ ] ) vxlan_range = self . _get_switch_vxlan_range ( switch_ip ) if vxlan_range : try : self . _restore_vxlan_entries ( switch_ip , vxlan_range ) except Exception : with excutils . save_and_reraise_exception ( ) : LOG . error ( "Error encountered restoring vxlans " "for switch %(switch_ip)s" , { 'switch_ip' : switch_ip } ) self . _save_switch_vxlan_range ( switch_ip , [ ] ) if ( not self . _get_switch_vlan_range ( switch_ip ) and not self . _get_switch_vxlan_range ( switch_ip ) ) : self . set_switch_ip_and_active_state ( switch_ip , const . SWITCH_ACTIVE ) LOG . info ( "Restore of Nexus switch " "ip %(switch_ip)s is complete" , { 'switch_ip' : switch_ip } ) else : LOG . debug ( ( "Restored batch of VLANS on " "Nexus switch ip %(switch_ip)s" ) , { 'switch_ip' : switch_ip } ) | Get next batch of vlans and send them to Nexus . |
37,616 | def configure_switch_entries ( self , switch_ip , port_bindings ) : prev_vlan = - 1 prev_vni = - 1 prev_port = None prev_native_vlan = 0 starttime = time . time ( ) port_bindings . sort ( key = lambda x : ( x . port_id , x . vlan_id , x . vni ) ) self . driver . capture_and_print_timeshot ( starttime , "replay_t2_aft_sort" , switch = switch_ip ) vlans = set ( ) pvlans = set ( ) interface_count = 0 duplicate_port = 0 vlan_count = 0 for port in port_bindings : if nxos_db . is_reserved_binding ( port ) : continue auto_create , auto_trunk = self . _gather_config_parms ( nxos_db . is_provider_vlan ( port . vlan_id ) , port . vlan_id ) if port . port_id == prev_port : if port . vlan_id == prev_vlan and port . vni == prev_vni : duplicate_port += 1 continue else : vlan_count += 1 if auto_create : vlans . add ( ( port . vlan_id , port . vni ) ) if auto_trunk : pvlans . add ( port . vlan_id ) if port . is_native : prev_native_vlan = port . vlan_id else : if prev_port : interface_count += 1 LOG . debug ( "Switch %s port %s replay summary: unique vlan " "count %d, duplicate port entries %d" , switch_ip , prev_port , vlan_count , duplicate_port ) duplicate_port = 0 vlan_count = 0 if pvlans : self . _restore_port_binding ( switch_ip , pvlans , prev_port , prev_native_vlan ) pvlans . clear ( ) prev_native_vlan = 0 if auto_create : vlans . add ( ( port . vlan_id , port . vni ) ) if auto_trunk : pvlans . add ( port . vlan_id ) prev_port = port . port_id if port . is_native : prev_native_vlan = port . vlan_id if pvlans : LOG . debug ( "Switch %s port %s replay summary: unique vlan " "count %d, duplicate port entries %d" , switch_ip , port . port_id , vlan_count , duplicate_port ) self . _restore_port_binding ( switch_ip , pvlans , prev_port , prev_native_vlan ) LOG . debug ( "Replayed total %d ports for Switch %s" , interface_count + 1 , switch_ip ) self . driver . capture_and_print_timeshot ( starttime , "replay_part_1" , switch = switch_ip ) vlans = list ( vlans ) if vlans : vlans . sort ( ) vlan , vni = vlans [ 0 ] if vni == 0 : self . _save_switch_vlan_range ( switch_ip , vlans ) else : self . _save_switch_vxlan_range ( switch_ip , vlans ) self . set_switch_ip_and_active_state ( switch_ip , const . SWITCH_RESTORE_S2 ) self . configure_next_batch_of_vlans ( switch_ip ) self . driver . capture_and_print_timeshot ( starttime , "replay_part_2" , switch = switch_ip ) | Create a nexus switch entry in Nexus . |
37,617 | def _delete_nxos_db ( self , unused , vlan_id , device_id , host_id , vni , is_provider_vlan ) : try : rows = nxos_db . get_nexusvm_bindings ( vlan_id , device_id ) for row in rows : nxos_db . remove_nexusport_binding ( row . port_id , row . vlan_id , row . vni , row . switch_ip , row . instance_id ) except excep . NexusPortBindingNotFound : return | Delete the nexus database entry . |
37,618 | def _delete_port_channel_resources ( self , host_id , switch_ip , intf_type , nexus_port , port_id ) : if intf_type != 'port-channel' : return try : vpc = nxos_db . get_switch_vpc_alloc ( switch_ip , nexus_port ) except excep . NexusVPCAllocNotFound : LOG . debug ( "Switch %s portchannel %s vpc entry not " "found in vpcid alloc table." , switch_ip , nexus_port ) return if not vpc . active : LOG . debug ( "Switch %s portchannel %s vpc entry not " "active." , switch_ip , nexus_port ) return try : nxos_db . get_nexus_switchport_binding ( port_id , switch_ip ) LOG . debug ( "Switch %s portchannel %s port entries " "in use. Skipping port-channel clean-up." , switch_ip , nexus_port ) return except excep . NexusPortBindingNotFound : pass try : mapping = nxos_db . get_switch_and_host_mappings ( host_id , switch_ip ) eth_type , eth_port = nexus_help . split_interface_name ( mapping [ 0 ] . if_id ) except excep . NexusHostMappingNotFound : LOG . warning ( "Switch %s hostid %s host_mapping not " "found. Skipping port-channel clean-up." , switch_ip , host_id ) return if not vpc . learned : self . driver . delete_ch_grp_to_interface ( switch_ip , eth_type , eth_port , nexus_port ) self . driver . delete_port_channel ( switch_ip , nexus_port ) try : nxos_db . free_vpcid_for_switch ( nexus_port , switch_ip ) LOG . info ( "Released portchannel %s resources for " "switch %s" , nexus_port , switch_ip ) except excep . NexusVPCAllocNotFound : LOG . warning ( "Failed to free vpcid %s for switch %s " "since it did not exist in table." , nexus_port , switch_ip ) | This determines if port channel id needs to be freed . |
37,619 | def _delete_switch_entry ( self , port , vlan_id , device_id , host_id , vni , is_provider_vlan ) : connections = self . _get_active_port_connections ( port , host_id ) vlan_already_removed = [ ] for switch_ip , intf_type , nexus_port , is_native , _ in connections : port_id = nexus_help . format_interface_name ( intf_type , nexus_port ) auto_create = True auto_trunk = True if is_provider_vlan : auto_create = cfg . CONF . ml2_cisco . provider_vlan_auto_create auto_trunk = cfg . CONF . ml2_cisco . provider_vlan_auto_trunk try : nxos_db . get_port_vlan_switch_binding ( port_id , vlan_id , switch_ip ) except excep . NexusPortBindingNotFound : pass else : continue if auto_trunk : self . driver . disable_vlan_on_trunk_int ( switch_ip , vlan_id , intf_type , nexus_port , is_native ) if auto_create : try : nxos_db . get_nexusvlan_binding ( vlan_id , switch_ip ) except excep . NexusPortBindingNotFound : if switch_ip not in vlan_already_removed : self . driver . delete_vlan ( switch_ip , vlan_id ) vlan_already_removed . append ( switch_ip ) self . _delete_port_channel_resources ( host_id , switch_ip , intf_type , nexus_port , port_id ) if nexus_help . is_baremetal ( port ) : connections = self . _get_baremetal_connections ( port , False , True ) for switch_ip , intf_type , nexus_port , is_native , _ in connections : if_id = nexus_help . format_interface_name ( intf_type , nexus_port ) try : mapping = nxos_db . get_switch_if_host_mappings ( switch_ip , if_id ) ch_grp = mapping [ 0 ] . ch_grp except excep . NexusHostMappingNotFound : ch_grp = 0 bind_port_id = nexus_help . format_interface_name ( intf_type , nexus_port , ch_grp ) binding = nxos_db . get_port_switch_bindings ( bind_port_id , switch_ip ) if not binding : nxos_db . remove_host_mapping ( if_id , switch_ip ) | Delete the nexus switch entry . |
37,620 | def create_port_postcommit ( self , context ) : vlan_segment , vxlan_segment = self . _get_segments ( context . top_bound_segment , context . bottom_bound_segment ) if not self . _is_valid_segment ( vlan_segment ) : return port = context . current if self . _is_supported_deviceowner ( port ) : if nexus_help . is_baremetal ( context . current ) : all_switches , active_switches = ( self . _get_baremetal_switches ( context . current ) ) else : host_id = context . current . get ( bc . portbindings . HOST_ID ) all_switches , active_switches = ( self . _get_host_switches ( host_id ) ) verified_active_switches = [ ] for switch_ip in active_switches : try : self . driver . get_nexus_type ( switch_ip ) verified_active_switches . append ( switch_ip ) except Exception as e : LOG . error ( "Failed to ping " "switch ip %(switch_ip)s error %(exp_err)s" , { 'switch_ip' : switch_ip , 'exp_err' : e } ) LOG . debug ( "Create Stats: thread %(thid)d, " "all_switches %(all)d, " "active %(active)d, verified %(verify)d" , { 'thid' : threading . current_thread ( ) . ident , 'all' : len ( all_switches ) , 'active' : len ( active_switches ) , 'verify' : len ( verified_active_switches ) } ) if all_switches and not verified_active_switches : raise excep . NexusConnectFailed ( nexus_host = all_switches [ 0 ] , config = "None" , exc = "Create Failed: Port event can not " "be processed at this time." ) | Create port non - database commit event . |
37,621 | def update_port_precommit ( self , context ) : vlan_segment , vxlan_segment = self . _get_segments ( context . top_bound_segment , context . bottom_bound_segment ) orig_vlan_segment , orig_vxlan_segment = self . _get_segments ( context . original_top_bound_segment , context . original_bottom_bound_segment ) if ( self . _is_vm_migrating ( context , vlan_segment , orig_vlan_segment ) or self . _is_status_down ( context . current ) ) : vni = ( self . _port_action_vxlan ( context . original , orig_vxlan_segment , self . _delete_nve_db ) if orig_vxlan_segment else 0 ) self . _port_action_vlan ( context . original , orig_vlan_segment , self . _delete_nxos_db , vni ) elif self . _is_supported_deviceowner ( context . current ) : vni = self . _port_action_vxlan ( context . current , vxlan_segment , self . _configure_nve_db ) if vxlan_segment else 0 self . _port_action_vlan ( context . current , vlan_segment , self . _configure_nxos_db , vni ) | Update port pre - database transaction commit event . |
37,622 | def update_port_postcommit ( self , context ) : vlan_segment , vxlan_segment = self . _get_segments ( context . top_bound_segment , context . bottom_bound_segment ) orig_vlan_segment , orig_vxlan_segment = self . _get_segments ( context . original_top_bound_segment , context . original_bottom_bound_segment ) if ( self . _is_vm_migrating ( context , vlan_segment , orig_vlan_segment ) or self . _is_status_down ( context . current ) ) : vni = ( self . _port_action_vxlan ( context . original , orig_vxlan_segment , self . _delete_nve_member ) if orig_vxlan_segment else 0 ) self . _port_action_vlan ( context . original , orig_vlan_segment , self . _delete_switch_entry , vni ) elif self . _is_supported_deviceowner ( context . current ) : if nexus_help . is_baremetal ( context . current ) : all_switches , active_switches = ( self . _get_baremetal_switches ( context . current ) ) else : host_id = context . current . get ( bc . portbindings . HOST_ID ) all_switches , active_switches = ( self . _get_host_switches ( host_id ) ) if not active_switches and all_switches : raise excep . NexusConnectFailed ( nexus_host = all_switches [ 0 ] , config = "None" , exc = "Update Port Failed: Nexus Switch " "is down or replay in progress" ) vni = self . _port_action_vxlan ( context . current , vxlan_segment , self . _configure_nve_member ) if vxlan_segment else 0 self . _port_action_vlan ( context . current , vlan_segment , self . _configure_port_entries , vni ) | Update port non - database commit event . |
37,623 | def delete_port_precommit ( self , context ) : if self . _is_supported_deviceowner ( context . current ) : vlan_segment , vxlan_segment = self . _get_segments ( context . top_bound_segment , context . bottom_bound_segment ) vni = self . _port_action_vxlan ( context . current , vxlan_segment , self . _delete_nve_db ) if vxlan_segment else 0 self . _port_action_vlan ( context . current , vlan_segment , self . _delete_nxos_db , vni ) | Delete port pre - database commit event . |
37,624 | def delete_port_postcommit ( self , context ) : if self . _is_supported_deviceowner ( context . current ) : vlan_segment , vxlan_segment = self . _get_segments ( context . top_bound_segment , context . bottom_bound_segment ) vni = self . _port_action_vxlan ( context . current , vxlan_segment , self . _delete_nve_member ) if vxlan_segment else 0 self . _port_action_vlan ( context . current , vlan_segment , self . _delete_switch_entry , vni ) | Delete port non - database commit event . |
37,625 | def _detect_iplus ( self ) : ver_expr = "([0-9]+)\.([0-9]+)\((.*)\)" re . compile ( ver_expr ) v1 = re . match ( ver_expr , self . _cur_ver ) v2 = re . match ( ver_expr , self . _base_ver ) if int ( v1 . group ( 1 ) ) > int ( v2 . group ( 1 ) ) : self . _is_iplus = True elif int ( v1 . group ( 1 ) ) == int ( v2 . group ( 1 ) ) : if int ( v1 . group ( 2 ) ) > int ( v2 . group ( 2 ) ) : self . _is_iplus = True elif int ( v1 . group ( 2 ) ) == int ( v2 . group ( 2 ) ) : self . _is_iplus = v1 . group ( 3 ) >= v2 . group ( 3 ) LOG . info ( "DCNM version: %(cur_ver)s, iplus: %(is_iplus)s" , { 'cur_ver' : self . _cur_ver , 'is_iplus' : self . _is_iplus } ) | Check the DCNM version and determine if it s for iplus |
37,626 | def get_segmentid_range ( self , orchestrator_id ) : url = "%s/%s" % ( self . _segmentid_ranges_url , orchestrator_id ) res = self . _send_request ( 'GET' , url , None , 'segment-id range' ) if res and res . status_code in self . _resp_ok : return res . json ( ) | Get segment id range from DCNM . |
37,627 | def set_segmentid_range ( self , orchestrator_id , segid_min , segid_max ) : url = self . _segmentid_ranges_url payload = { 'orchestratorId' : orchestrator_id , 'segmentIdRanges' : "%s-%s" % ( segid_min , segid_max ) } res = self . _send_request ( 'POST' , url , payload , 'segment-id range' ) if not ( res and res . status_code in self . _resp_ok ) : LOG . error ( "Failed to set segment id range for orchestrator " "%(orch)s on DCNM: %(text)s" , { 'orch' : orchestrator_id , 'text' : res . text } ) raise dexc . DfaClientRequestFailed ( reason = self . _failure_msg ( res ) ) | set segment id range in DCNM . |
37,628 | def _set_default_cfg_profile ( self ) : try : cfgplist = self . config_profile_list ( ) if self . default_cfg_profile not in cfgplist : self . default_cfg_profile = ( 'defaultNetworkUniversalEfProfile' if self . _is_iplus else 'defaultNetworkIpv4EfProfile' ) except dexc . DfaClientRequestFailed : LOG . error ( "Failed to send request to DCNM." ) self . default_cfg_profile = 'defaultNetworkIpv4EfProfile' | Set default network config profile . |
37,629 | def _create_network ( self , network_info ) : url = self . _create_network_url % ( network_info [ 'organizationName' ] , network_info [ 'partitionName' ] ) payload = network_info LOG . info ( 'url %(url)s payload %(payload)s' , { 'url' : url , 'payload' : payload } ) return self . _send_request ( 'POST' , url , payload , 'network' ) | Send create network request to DCNM . |
37,630 | def _config_profile_get ( self , thisprofile ) : url = self . _cfg_profile_get_url % ( thisprofile ) payload = { } res = self . _send_request ( 'GET' , url , payload , 'config-profile' ) if res and res . status_code in self . _resp_ok : return res . json ( ) | Get information of a config profile from DCNM . |
37,631 | def _config_profile_list ( self ) : url = self . _cfg_profile_list_url payload = { } try : res = self . _send_request ( 'GET' , url , payload , 'config-profile' ) if res and res . status_code in self . _resp_ok : return res . json ( ) except dexc . DfaClientRequestFailed : LOG . error ( "Failed to send request to DCNM." ) | Get list of supported config profile from DCNM . |
37,632 | def _get_settings ( self ) : url = self . _global_settings_url payload = { } res = self . _send_request ( 'GET' , url , payload , 'settings' ) if res and res . status_code in self . _resp_ok : return res . json ( ) | Get global mobility domain from DCNM . |
37,633 | def _create_org ( self , orch_id , name , desc ) : url = self . _org_url payload = { "organizationName" : name , "description" : name if len ( desc ) == 0 else desc , "orchestrationSource" : orch_id } return self . _send_request ( 'POST' , url , payload , 'organization' ) | Create organization on the DCNM . |
37,634 | def _create_or_update_partition ( self , org_name , part_name , desc , dci_id = UNKNOWN_DCI_ID , vrf_prof = None , service_node_ip = UNKNOWN_SRVN_NODE_IP , operation = 'POST' ) : if part_name is None : part_name = self . _part_name if vrf_prof is None or dci_id == UNKNOWN_DCI_ID or ( service_node_ip == UNKNOWN_SRVN_NODE_IP ) : part_info = self . _get_partition ( org_name , part_name ) if vrf_prof is None : vrf_prof = self . get_partition_vrfProf ( org_name , part_name , part_info = part_info ) if dci_id == UNKNOWN_DCI_ID : dci_id = self . get_partition_dciId ( org_name , part_name , part_info = part_info ) if service_node_ip == UNKNOWN_SRVN_NODE_IP : service_node_ip = self . get_partition_serviceNodeIp ( org_name , part_name , part_info = part_info ) url = ( ( self . _create_part_url % ( org_name ) ) if operation == 'POST' else self . _update_part_url % ( org_name , part_name ) ) payload = { "partitionName" : part_name , "description" : part_name if len ( desc ) == 0 else desc , "serviceNodeIpAddress" : service_node_ip , "organizationName" : org_name } if self . _is_iplus : enable_dci = "true" if dci_id and int ( dci_id ) != 0 else "false" extra_payload = { "vrfProfileName" : vrf_prof , "vrfName" : ':' . join ( ( org_name , part_name ) ) , "dciId" : dci_id , "enableDCIExtension" : enable_dci } payload . update ( extra_payload ) return self . _send_request ( operation , url , payload , 'partition' ) | Send create or update partition request to the DCNM . |
37,635 | def _get_partition ( self , org_name , part_name = None ) : if part_name is None : part_name = self . _part_name url = self . _update_part_url % ( org_name , part_name ) res = self . _send_request ( "GET" , url , '' , 'partition' ) if res and res . status_code in self . _resp_ok : return res . json ( ) | send get partition request to the DCNM . |
37,636 | def update_partition_static_route ( self , org_name , part_name , static_ip_list , vrf_prof = None , service_node_ip = None ) : if part_name is None : part_name = self . _part_name if vrf_prof is None : vrf_prof = self . default_vrf_profile operation = 'PUT' url = ( self . _update_part_url % ( org_name , part_name ) ) ip_str = '' ip_cnt = 0 for ip in static_ip_list : ip_sub = "$n0" + str ( ip_cnt ) + "=" + str ( ip ) + ";" ip_str = ip_str + ip_sub ip_cnt = ip_cnt + 1 cfg_args = { "$vrfName=" + org_name + ':' + part_name + ";" "$include_serviceNodeIpAddress=" + service_node_ip + ";" + ip_str } cfg_args = ';' . join ( cfg_args ) payload = { "partitionName" : part_name , "organizationName" : org_name , "dciExtensionStatus" : "Not configured" , "vrfProfileName" : vrf_prof , "vrfName" : ':' . join ( ( org_name , part_name ) ) , "configArg" : cfg_args } res = self . _send_request ( operation , url , payload , 'partition' ) return ( res is not None and res . status_code in self . _resp_ok ) | Send static route update requests to DCNM . |
37,637 | def _delete_org ( self , org_name ) : url = self . _del_org_url % ( org_name ) return self . _send_request ( 'DELETE' , url , '' , 'organization' ) | Send organization delete request to DCNM . |
37,638 | def _delete_network ( self , network_info ) : org_name = network_info . get ( 'organizationName' , '' ) part_name = network_info . get ( 'partitionName' , '' ) segment_id = network_info [ 'segmentId' ] if 'mobDomainName' in network_info : vlan_id = network_info [ 'vlanId' ] mob_dom_name = network_info [ 'mobDomainName' ] url = self . _network_mob_url % ( org_name , part_name , vlan_id , mob_dom_name ) else : url = self . _network_url % ( org_name , part_name , segment_id ) return self . _send_request ( 'DELETE' , url , '' , 'network' ) | Send network delete request to DCNM . |
37,639 | def _get_network ( self , network_info ) : org_name = network_info . get ( 'organizationName' , '' ) part_name = network_info . get ( 'partitionName' , '' ) segment_id = network_info [ 'segmentId' ] url = self . _network_url % ( org_name , part_name , segment_id ) return self . _send_request ( 'GET' , url , '' , 'network' ) | Send network get request to DCNM . |
37,640 | def _login_request ( self , url_login ) : expiration_time = self . _exp_time payload = { 'expirationTime' : expiration_time } res = requests . post ( url_login , data = jsonutils . dumps ( payload ) , headers = self . _req_headers , auth = ( self . _user , self . _pwd ) , timeout = self . timeout_resp , verify = False ) session_id = '' if res and res . status_code in self . _resp_ok : session_id = res . json ( ) . get ( 'Dcnm-Token' ) self . _req_headers . update ( { 'Dcnm-Token' : session_id } ) | Internal function to send login request . |
37,641 | def _logout_request ( self , url_logout ) : requests . post ( url_logout , headers = self . _req_headers , timeout = self . timeout_resp , verify = False ) | Internal logout request to DCNM . |
37,642 | def _send_request ( self , operation , url , payload , desc ) : res = None try : payload_json = None if payload and payload != '' : payload_json = jsonutils . dumps ( payload ) self . _login ( ) desc_lookup = { 'POST' : ' creation' , 'PUT' : ' update' , 'DELETE' : ' deletion' , 'GET' : ' get' } res = requests . request ( operation , url , data = payload_json , headers = self . _req_headers , timeout = self . timeout_resp , verify = False ) desc += desc_lookup . get ( operation , operation . lower ( ) ) LOG . info ( "DCNM-send_request: %(desc)s %(url)s %(pld)s" , { 'desc' : desc , 'url' : url , 'pld' : payload } ) self . _logout ( ) except ( requests . HTTPError , requests . Timeout , requests . ConnectionError ) as exc : LOG . exception ( 'Error during request: %s' , exc ) raise dexc . DfaClientRequestFailed ( reason = exc ) return res | Send request to DCNM . |
37,643 | def config_profile_list ( self ) : these_profiles = self . _config_profile_list ( ) or [ ] profile_list = [ q for p in these_profiles for q in [ p . get ( 'profileName' ) ] ] return profile_list | Return config profile list from DCNM . |
37,644 | def config_profile_fwding_mode_get ( self , profile_name ) : profile_params = self . _config_profile_get ( profile_name ) fwd_cli = 'fabric forwarding mode proxy-gateway' if profile_params and fwd_cli in profile_params [ 'configCommands' ] : return 'proxy-gateway' else : return 'anycast-gateway' | Return forwarding mode of given config profile . |
37,645 | def get_config_profile_for_network ( self , net_name ) : cfgplist = self . config_profile_list ( ) cfgname = net_name . partition ( ':' ) [ 2 ] cfgtuple = set ( ) for cfg_prof in cfgplist : if cfg_prof . startswith ( 'defaultNetwork' ) : cfg_alias = ( cfg_prof . split ( 'defaultNetwork' ) [ 1 ] . split ( 'Profile' ) [ 0 ] ) elif cfg_prof . endswith ( 'Profile' ) : cfg_alias = cfg_prof . split ( 'Profile' ) [ 0 ] else : cfg_alias = cfg_prof cfgtuple . update ( [ ( cfg_prof , cfg_alias ) ] ) cfgp = [ a for a , b in cfgtuple if cfgname == b ] prof = cfgp [ 0 ] if cfgp else self . default_cfg_profile fwd_mod = self . config_profile_fwding_mode_get ( prof ) return ( prof , fwd_mod ) | Get the list of profiles . |
37,646 | def delete_network ( self , tenant_name , network ) : seg_id = network . segmentation_id network_info = { 'organizationName' : tenant_name , 'partitionName' : self . _part_name , 'segmentId' : seg_id , } LOG . debug ( "Deleting %s network in DCNM." , network_info ) res = self . _delete_network ( network_info ) if res and res . status_code in self . _resp_ok : LOG . debug ( "Deleted %s network in DCNM." , network_info ) else : LOG . error ( "Failed to delete %s network in DCNM." , network_info ) raise dexc . DfaClientRequestFailed ( reason = res ) | Delete network on the DCNM . |
37,647 | def delete_service_network ( self , tenant_name , network ) : network_info = { } part_name = network . part_name if not part_name : part_name = self . _part_name seg_id = str ( network . segmentation_id ) if network . vlan : vlan_id = str ( network . vlan ) if network . mob_domain_name is not None : mob_domain_name = network . mob_domain_name else : if self . _default_md is None : self . _set_default_mobility_domain ( ) mob_domain_name = self . _default_md network_info = { 'organizationName' : tenant_name , 'partitionName' : part_name , 'mobDomainName' : mob_domain_name , 'vlanId' : vlan_id , 'segmentId' : seg_id , } else : network_info = { 'organizationName' : tenant_name , 'partitionName' : part_name , 'segmentId' : seg_id , } LOG . debug ( "Deleting %s network in DCNM." , network_info ) res = self . _delete_network ( network_info ) if res and res . status_code in self . _resp_ok : LOG . debug ( "Deleted %s network in DCNM." , network_info ) else : LOG . error ( "Failed to delete %s network in DCNM." , network_info ) raise dexc . DfaClientRequestFailed ( reason = self . _failure_msg ( res ) ) | Delete service network on the DCNM . |
37,648 | def delete_project ( self , tenant_name , part_name ) : res = self . _delete_partition ( tenant_name , part_name ) if res and res . status_code in self . _resp_ok : LOG . debug ( "Deleted %s partition in DCNM." , part_name ) else : LOG . error ( "Failed to delete %(part)s partition in DCNM." "Response: %(res)s" , { 'part' : part_name , 'res' : res } ) raise dexc . DfaClientRequestFailed ( reason = res ) res = self . _delete_org ( tenant_name ) if res and res . status_code in self . _resp_ok : LOG . debug ( "Deleted %s organization in DCNM." , tenant_name ) else : LOG . error ( "Failed to delete %(org)s organization in DCNM." "Response: %(res)s" , { 'org' : tenant_name , 'res' : res } ) raise dexc . DfaClientRequestFailed ( reason = res ) | Delete project on the DCNM . |
37,649 | def create_project ( self , orch_id , org_name , part_name , dci_id , desc = None ) : desc = desc or org_name res = self . _create_org ( orch_id , org_name , desc ) if res and res . status_code in self . _resp_ok : LOG . debug ( "Created %s organization in DCNM." , org_name ) else : LOG . error ( "Failed to create %(org)s organization in DCNM." "Response: %(res)s" , { 'org' : org_name , 'res' : res } ) raise dexc . DfaClientRequestFailed ( reason = res ) self . create_partition ( org_name , part_name , dci_id , self . default_vrf_profile , desc = desc ) | Create project on the DCNM . |
37,650 | def update_project ( self , org_name , part_name , dci_id = UNKNOWN_DCI_ID , service_node_ip = UNKNOWN_SRVN_NODE_IP , vrf_prof = None , desc = None ) : desc = desc or org_name res = self . _create_or_update_partition ( org_name , part_name , desc , dci_id = dci_id , service_node_ip = service_node_ip , vrf_prof = vrf_prof , operation = 'PUT' ) if res and res . status_code in self . _resp_ok : LOG . debug ( "Update %s partition in DCNM." , part_name ) else : LOG . error ( "Failed to update %(part)s partition in DCNM." "Response: %(res)s" , { 'part' : part_name , 'res' : res } ) raise dexc . DfaClientRequestFailed ( reason = res ) | Update project on the DCNM . |
37,651 | def create_partition ( self , org_name , part_name , dci_id , vrf_prof , service_node_ip = None , desc = None ) : desc = desc or org_name res = self . _create_or_update_partition ( org_name , part_name , desc , dci_id = dci_id , service_node_ip = service_node_ip , vrf_prof = vrf_prof ) if res and res . status_code in self . _resp_ok : LOG . debug ( "Created %s partition in DCNM." , part_name ) else : LOG . error ( "Failed to create %(part)s partition in DCNM." "Response: %(res)s" , ( { 'part' : part_name , 'res' : res } ) ) raise dexc . DfaClientRequestFailed ( reason = self . _failure_msg ( res ) ) | Create partition on the DCNM . |
37,652 | def get_partition_vrfProf ( self , org_name , part_name = None , part_info = None ) : vrf_profile = None if part_info is None : part_info = self . _get_partition ( org_name , part_name ) LOG . info ( "query result from dcnm for partition info is %s" , part_info ) if ( "vrfProfileName" in part_info ) : vrf_profile = part_info . get ( "vrfProfileName" ) return vrf_profile | get VRF Profile for the partition from the DCNM . |
37,653 | def get_partition_dciId ( self , org_name , part_name , part_info = None ) : if part_info is None : part_info = self . _get_partition ( org_name , part_name ) LOG . info ( "query result from dcnm for partition info is %s" , part_info ) if part_info is not None and "dciId" in part_info : return part_info . get ( "dciId" ) | get DCI ID for the partition . |
37,654 | def list_networks ( self , org , part ) : if org and part : list_url = self . _del_part + '/networks' list_url = list_url % ( org , part ) res = self . _send_request ( 'GET' , list_url , '' , 'networks' ) if res and res . status_code in self . _resp_ok : return res . json ( ) | Return list of networks from DCNM . |
37,655 | def list_organizations ( self ) : try : res = self . _send_request ( 'GET' , self . _org_url , '' , 'organizations' ) if res and res . status_code in self . _resp_ok : return res . json ( ) except dexc . DfaClientRequestFailed : LOG . error ( "Failed to send request to DCNM." ) | Return list of organizations from DCNM . |
37,656 | def get_network ( self , org , segid ) : network_info = { 'organizationName' : org , 'partitionName' : self . _part_name , 'segmentId' : segid , } res = self . _get_network ( network_info ) if res and res . status_code in self . _resp_ok : return res . json ( ) | Return given network from DCNM . |
37,657 | def get_version ( self ) : url = '%s://%s/rest/dcnm-version' % ( self . dcnm_protocol , self . _ip ) payload = { } try : res = self . _send_request ( 'GET' , url , payload , 'dcnm-version' ) if res and res . status_code in self . _resp_ok : return res . json ( ) . get ( 'Dcnm-Version' ) except dexc . DfaClientRequestFailed as exc : LOG . error ( "Failed to get DCNM version." ) sys . exit ( "ERROR: Failed to connect to DCNM: %s" , exc ) | Get the DCNM version . |
37,658 | def fill_urls ( self ) : protocol = self . dcnm_protocol self . _org_url = '%s://%s/rest/auto-config/organizations' % ( ( protocol , self . _ip ) ) self . _create_network_url = ( '%s://%s/' % ( protocol , self . _ip ) + 'rest/auto-config/organizations' '/%s/partitions/%s/networks' ) self . host_protocol_url = '%s://%s/' % ( protocol , self . _ip ) self . _create_network_url = self . _build_url ( 'rest/auto-config/organizations' '/%s/partitions/%s/networks' ) self . _cfg_profile_list_url = '%s://%s/rest/auto-config/profiles' % ( ( protocol , self . _ip ) ) self . _cfg_profile_get_url = self . _cfg_profile_list_url + '/%s' self . _global_settings_url = self . _build_url ( 'rest/auto-config/settings' ) self . _create_part_url = self . _build_url ( 'rest/auto-config/organizations/%s/partitions' ) self . _update_part_url = self . _build_url ( 'rest/auto-config/organizations/%s/partitions/%s' ) self . _del_org_url = self . _build_url ( 'rest/auto-config/organizations/%s' ) self . _del_part = self . _build_url ( 'rest/auto-config/organizations/%s/partitions/%s' ) self . _network_url = self . _build_url ( 'rest/auto-config/organizations/%s/partitions/' '%s/networks/segment/%s' ) self . _network_mob_url = self . _build_url ( 'rest/auto-config/organizations/%s/partitions/' '%s/networks/vlan/%s/mobility-domain/%s' ) self . _segmentid_ranges_url = self . _build_url ( 'rest/settings/segmentid-ranges' ) self . _login_url = self . _build_url ( 'rest/logon' ) self . _logout_url = self . _build_url ( 'rest/logout' ) | This assigns the URL s based on the protocol . |
37,659 | def contract_creation_exceptions ( ) : return { sa . Column : [ '.' . join ( [ table , 'project_id' ] ) for table in get_tables ( ) ] , sa . Index : get_tables ( ) } | Special migration for the blueprint to support Keystone V3 . We drop all tenant_id columns and create project_id columns instead . |
37,660 | def _agent_notification_bulk ( self , context , method , routers , hosting_device , operation ) : admin_context = context . is_admin and context or context . elevated ( ) dmplugin = bc . get_plugin ( cisco_constants . DEVICE_MANAGER ) if ( hosting_device is not None and extensions . is_extension_supported ( dmplugin , CFGAGENT_SCHED ) ) : agents = dmplugin . get_cfg_agents_for_hosting_devices ( admin_context , [ hosting_device [ 'id' ] ] , admin_state_up = True , schedule = True ) if agents : agent = agents [ 0 ] LOG . debug ( 'Notify %(agent_type)s at %(topic)s.%(host)s the ' 'message %(method)s [BULK]' , { 'agent_type' : agent . agent_type , 'topic' : CFG_AGENT_L3_ROUTING , 'host' : agent . host , 'method' : method } ) cctxt = self . client . prepare ( server = agent . host , version = '1.1' ) cctxt . cast ( context , method , routers = routers ) | Notify the Cisco cfg agent handling a particular hosting_device . |
37,661 | def _notification ( self , context , method , routers , operation , shuffle_agents ) : if extensions . is_extension_supported ( self . _l3plugin , L3AGENT_SCHED ) : adm_context = ( context . is_admin and context or context . elevated ( ) ) self . _l3plugin . schedule_routers ( adm_context , routers ) self . _agent_notification ( context , method , routers , operation , shuffle_agents ) else : cctxt = self . client . prepare ( topics = topics . L3_AGENT , fanout = True ) cctxt . cast ( context , method , routers = [ r [ 'id' ] for r in routers ] ) | Notify all or individual Cisco cfg agents . |
37,662 | def routers_updated ( self , context , routers , operation = None , data = None , shuffle_agents = False ) : if routers : self . _notification ( context , 'routers_updated' , routers , operation , shuffle_agents ) | Notify cfg agents about configuration changes to routers . |
37,663 | def router_removed_from_hosting_device ( self , context , router ) : self . _notification ( context , 'router_removed_from_hosting_device' , [ router ] , operation = None , shuffle_agents = False ) | Notify cfg agent about router removed from hosting device . |
37,664 | def router_added_to_hosting_device ( self , context , router ) : self . _notification ( context , 'router_added_to_hosting_device' , [ router ] , operation = None , shuffle_agents = False ) | Notify cfg agent about router added to hosting device . |
37,665 | def routers_removed_from_hosting_device ( self , context , router_ids , hosting_device ) : self . _agent_notification_bulk ( context , 'router_removed_from_hosting_device' , router_ids , hosting_device , operation = None ) | Notify cfg agent that routers have been removed from hosting device . |
37,666 | def process_amqp_msgs ( self ) : LOG . info ( 'Starting process_amqp_msgs...' ) while True : ( mtd_fr , hdr_fr , body ) = ( None , None , None ) try : if self . consume_channel : ( mtd_fr , hdr_fr , body ) = self . consume_channel . basic_get ( self . _dcnm_queue_name ) if mtd_fr : LOG . info ( 'RX message: %s' , body ) self . _cb_dcnm_msg ( mtd_fr , body ) self . consume_channel . basic_ack ( mtd_fr . delivery_tag ) else : try : self . _conn . sleep ( 1 ) except AttributeError : time . sleep ( 1 ) except Exception : exc_type , exc_value , exc_tb = sys . exc_info ( ) tb_str = traceback . format_exception ( exc_type , exc_value , exc_tb ) LOG . exception ( "Failed to read from queue: %(queue)s " "%(exc_type)s, %(exc_value)s, %(exc_tb)s." , { 'queue' : self . _dcnm_queue_name , 'exc_type' : exc_type , 'exc_value' : exc_value , 'exc_tb' : tb_str } ) | Process AMQP queue messages . |
37,667 | def _is_pingable ( ip ) : ping_cmd = [ 'ping' , '-c' , '5' , '-W' , '1' , '-i' , '0.2' , ip ] try : linux_utils . execute ( ping_cmd , check_exit_code = True ) return True except RuntimeError : LOG . warning ( "Cannot ping ip address: %s" , ip ) return False | Checks whether an IP address is reachable by pinging . |
37,668 | def _can_connect ( ip , port ) : cs = socket . socket ( ) try : cs . connect ( ( ip , port ) ) cs . close ( ) return True except socket . error : return False | Checks if a TCP port at IP address is possible to connect to |
37,669 | def get_monitored_hosting_devices_info ( self , hd_state_filter = None ) : wait_time = datetime . timedelta ( seconds = cfg . CONF . cfg_agent . hosting_device_dead_timeout ) resp = [ ] for hd_id in self . hosting_devices_backlog : hd = self . hosting_devices_backlog [ hd_id ] [ 'hd' ] display_hd = True if hd_state_filter is not None : if hd [ 'hd_state' ] == hd_state_filter : display_hd = True else : display_hd = False if display_hd : created_time = hd [ 'created_at' ] boottime = datetime . timedelta ( seconds = hd [ 'booting_time' ] ) backlogged_at = hd [ 'backlog_insertion_ts' ] booted_at = created_time + boottime dead_at = backlogged_at + wait_time resp . append ( { 'host id' : hd [ 'id' ] , 'hd_state' : hd [ 'hd_state' ] , 'created at' : str ( created_time ) , 'backlogged at' : str ( backlogged_at ) , 'estimate booted at' : str ( booted_at ) , 'considered dead at' : str ( dead_at ) } ) else : continue return resp | This function returns a list of all hosting devices monitored by this agent |
37,670 | def is_hosting_device_reachable ( self , hosting_device ) : ret_val = False hd = hosting_device hd_id = hosting_device [ 'id' ] hd_mgmt_ip = hosting_device [ 'management_ip_address' ] dead_hd_list = self . get_dead_hosting_devices_info ( ) if hd_id in dead_hd_list : LOG . debug ( "Hosting device: %(hd_id)s@%(ip)s is already marked as" " Dead. It is assigned as non-reachable" , { 'hd_id' : hd_id , 'ip' : hd_mgmt_ip } ) return False if not isinstance ( hd [ 'created_at' ] , datetime . datetime ) : hd [ 'created_at' ] = datetime . datetime . strptime ( hd [ 'created_at' ] , '%Y-%m-%d %H:%M:%S' ) if _is_pingable ( hd_mgmt_ip ) : LOG . debug ( "Hosting device: %(hd_id)s@%(ip)s is reachable." , { 'hd_id' : hd_id , 'ip' : hd_mgmt_ip } ) hd [ 'hd_state' ] = cc . HD_ACTIVE ret_val = True else : LOG . debug ( "Hosting device: %(hd_id)s@%(ip)s is NOT reachable." , { 'hd_id' : hd_id , 'ip' : hd_mgmt_ip } ) hd [ 'hd_state' ] = cc . HD_NOT_RESPONDING ret_val = False if self . enable_heartbeat is True or ret_val is False : self . backlog_hosting_device ( hd ) return ret_val | Check the hosting device which hosts this resource is reachable . |
37,671 | def create_floatingip ( self , context , floatingip ) : return super ( CiscoRouterPlugin , self ) . create_floatingip ( context , floatingip , initial_status = bc . constants . FLOATINGIP_STATUS_DOWN ) | Create floating IP . |
37,672 | def attach_intf_router ( self , tenant_id , tenant_name , router_id ) : in_sub = self . get_in_subnet_id ( tenant_id ) out_sub = self . get_out_subnet_id ( tenant_id ) subnet_lst = set ( ) subnet_lst . add ( in_sub ) subnet_lst . add ( out_sub ) ret = self . os_helper . add_intf_router ( router_id , tenant_id , subnet_lst ) return ret , in_sub , out_sub | Routine to attach the interface to the router . |
37,673 | def get_router_id ( self , tenant_id , tenant_name ) : router_id = None if tenant_id in self . tenant_dict : router_id = self . tenant_dict . get ( tenant_id ) . get ( 'router_id' ) if not router_id : router_list = self . os_helper . get_rtr_by_name ( 'FW_RTR_' + tenant_name ) if len ( router_list ) > 0 : router_id = router_list [ 0 ] . get ( 'id' ) return router_id | Retrieve the router ID . |
37,674 | def delete_intf_router ( self , tenant_id , tenant_name , router_id ) : in_sub = self . get_in_subnet_id ( tenant_id ) out_sub = self . get_out_subnet_id ( tenant_id ) subnet_lst = set ( ) subnet_lst . add ( in_sub ) subnet_lst . add ( out_sub ) router_id = self . get_router_id ( tenant_id , tenant_name ) if router_id : ret = self . os_helper . delete_intf_router ( tenant_name , tenant_id , router_id , subnet_lst ) if not ret : LOG . error ( "Failed to delete router intf id %(rtr)s, " "tenant %(tenant)s" , { 'rtr' : router_id , 'tenant' : tenant_id } ) return ret LOG . error ( "Invalid router ID, can't delete interface from " "router" ) | Routine to delete the router . |
37,675 | def prepare_router_vm_msg ( self , tenant_id , tenant_name , router_id , net_id , subnet_id , seg , status ) : max_get_router_info_retry = True attempt = 0 while max_get_router_info_retry : port_data = self . os_helper . get_router_port_subnet ( subnet_id ) if port_data is None : LOG . error ( "Unable to get router port data" ) return None if port_data . get ( 'binding:host_id' ) == '' : time . sleep ( 3 ) attempt += 1 if attempt > 3 : max_get_router_info_retry = False LOG . error ( "Unable to get router binding host data, " "Max attempts reached" ) else : max_get_router_info_retry = False if status is 'up' : event_type = 'service.vnic.create' else : event_type = 'service.vnic.delete' vnic_data = { 'status' : status , 'mac' : port_data . get ( 'mac_address' ) , 'segid' : seg , 'host' : port_data . get ( 'binding:host_id' ) } if vnic_data [ 'host' ] == '' : LOG . error ( "Null host for seg %(seg)s subnet %(subnet)s" , { 'seg' : seg , 'subnet' : subnet_id } ) if self . tenant_dict . get ( tenant_id ) . get ( 'host' ) is None : LOG . error ( "Null host for tenant %(tenant)s seg %(seg)s " "subnet %(subnet)s" , { 'tenant' : tenant_id , 'seg' : seg , 'subnet' : subnet_id } ) return None else : vnic_data [ 'host' ] = self . tenant_dict . get ( tenant_id ) . get ( 'host' ) else : self . tenant_dict [ tenant_id ] [ 'host' ] = vnic_data [ 'host' ] vm_ip = port_data . get ( 'fixed_ips' ) [ 0 ] . get ( 'ip_address' ) vnic_data . update ( { 'port_id' : port_data . get ( 'id' ) , 'network_id' : net_id , 'vm_name' : 'FW_SRVC_RTR_' + tenant_name , 'vm_ip' : vm_ip , 'vm_uuid' : router_id , 'gw_mac' : None , 'fwd_mod' : 'anycast_gateway' } ) payload = { 'service' : vnic_data } data = ( event_type , payload ) return data | Prepare the message to be sent to Event queue for VDP trigger . |
37,676 | def send_router_port_msg ( self , tenant_id , tenant_name , router_id , net_id , subnet_id , seg , status ) : data = self . prepare_router_vm_msg ( tenant_id , tenant_name , router_id , net_id , subnet_id , seg , status ) if data is None : return False timestamp = time . ctime ( ) pri = Q_PRIORITY LOG . info ( "Sending native FW data into queue %(data)s" , { 'data' : data } ) self . que_obj . put ( ( pri , timestamp , data ) ) return True | Sends the router port message to the queue . |
37,677 | 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 | Add static route in DCNM s partition . |
37,678 | def _create_arg_dict ( self , tenant_id , data , in_sub , out_sub ) : in_seg , in_vlan = self . get_in_seg_vlan ( tenant_id ) out_seg , out_vlan = self . get_out_seg_vlan ( tenant_id ) in_ip_dict = self . get_in_ip_addr ( tenant_id ) out_ip_dict = self . get_out_ip_addr ( tenant_id ) excl_list = [ in_ip_dict . get ( 'subnet' ) , out_ip_dict . get ( 'subnet' ) ] arg_dict = { 'tenant_id' : tenant_id , 'tenant_name' : data . get ( 'tenant_name' ) , 'in_seg' : in_seg , 'in_vlan' : in_vlan , 'out_seg' : out_seg , 'out_vlan' : out_vlan , 'router_id' : data . get ( 'router_id' ) , 'in_sub' : in_sub , 'out_sub' : out_sub , 'in_gw' : in_ip_dict . get ( 'gateway' ) , 'out_gw' : out_ip_dict . get ( 'gateway' ) , 'excl_list' : excl_list } return arg_dict | Create the argument dictionary . |
37,679 | def _create_fw ( self , tenant_id , data ) : LOG . debug ( "In creating Native FW data is %s" , data ) ret , in_sub , out_sub = self . attach_intf_router ( tenant_id , data . get ( 'tenant_name' ) , data . get ( 'router_id' ) ) if not ret : LOG . error ( "Native FW: Attach intf router failed for tenant " "%s" , tenant_id ) return False self . create_tenant_dict ( tenant_id , data . get ( 'router_id' ) ) arg_dict = self . _create_arg_dict ( tenant_id , data , in_sub , out_sub ) ret = self . update_dcnm_partition_static_route ( tenant_id , arg_dict ) if not ret : return False ret = self . program_default_gw ( tenant_id , arg_dict ) if not ret : return False ret = self . program_next_hop ( tenant_id , arg_dict ) if not ret : return False ret = self . send_in_router_port_msg ( tenant_id , arg_dict , 'up' ) if not ret : return False return self . send_out_router_port_msg ( tenant_id , arg_dict , 'up' ) | Internal routine that gets called when a FW is created . |
37,680 | def create_fw ( self , tenant_id , data ) : try : return self . _create_fw ( tenant_id , data ) except Exception as exc : LOG . error ( "Failed to create FW for device native, tenant " "%(tenant)s data %(data)s Exc %(exc)s" , { 'tenant' : tenant_id , 'data' : data , 'exc' : exc } ) return False | Top level routine called when a FW is created . |
37,681 | def _delete_fw ( self , tenant_id , data ) : LOG . debug ( "In Delete fw data is %s" , data ) in_sub = self . get_in_subnet_id ( tenant_id ) out_sub = self . get_out_subnet_id ( tenant_id ) arg_dict = self . _create_arg_dict ( tenant_id , data , in_sub , out_sub ) if arg_dict . get ( 'router_id' ) is None : LOG . error ( "Router ID unknown for tenant %s" , tenant_id ) return False if tenant_id not in self . tenant_dict : self . create_tenant_dict ( tenant_id , arg_dict . get ( 'router_id' ) ) ret = self . send_in_router_port_msg ( tenant_id , arg_dict , 'down' ) if not ret : return False ret = self . send_out_router_port_msg ( tenant_id , arg_dict , 'down' ) if not ret : return False router_ret = self . delete_intf_router ( tenant_id , arg_dict . get ( 'tenant_name' ) , arg_dict . get ( 'router_id' ) ) if not router_ret : LOG . error ( "Unable to delete router for tenant %s, error case" , tenant_id ) return router_ret del self . tenant_dict [ tenant_id ] return router_ret | Internal routine called when a FW is deleted . |
37,682 | def delete_fw ( self , tenant_id , data ) : try : ret = self . _delete_fw ( tenant_id , data ) return ret except Exception as exc : LOG . error ( "Failed to delete FW for device native, tenant " "%(tenant)s data %(data)s Exc %(exc)s" , { 'tenant' : tenant_id , 'data' : data , 'exc' : exc } ) return False | Top level routine called when a FW is deleted . |
37,683 | 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' ) 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 ) 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 | Program DCNM Static Route . |
37,684 | def network_create_notif ( self , tenant_id , tenant_name , cidr ) : router_id = self . get_router_id ( tenant_id , tenant_name ) if not router_id : LOG . error ( "Rout ID not present for tenant" ) return False ret = self . _program_dcnm_static_route ( tenant_id , tenant_name ) if not ret : LOG . error ( "Program DCNM with static routes failed " "for router %s" , router_id ) return False in_ip_dict = self . get_in_ip_addr ( tenant_id ) in_gw = in_ip_dict . get ( 'gateway' ) if in_gw is None : LOG . error ( "No FW service GW present" ) return False ret = self . os_helper . program_rtr_nwk_next_hop ( router_id , in_gw , cidr ) if not ret : LOG . error ( "Unable to program default router next hop %s" , router_id ) return False return True | Tenant Network create Notification . |
37,685 | def network_delete_notif ( self , tenant_id , tenant_name , network_id ) : router_id = self . get_router_id ( tenant_id , tenant_name ) if router_id is None : LOG . error ( "Rout ID not present for tenant" ) return False ret = self . _program_dcnm_static_route ( tenant_id , tenant_name ) if not ret : LOG . error ( "Program DCNM with static routes failed for " "router %s" , router_id ) return False 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' ) 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 ) ret = self . os_helper . remove_rtr_nwk_next_hop ( router_id , in_gw , subnet_lst , excl_list ) if not ret : LOG . error ( "Unable to program default router next hop %s" , router_id ) return False return True | Tenant Network delete Notification . |
37,686 | def create_hosting_device_resources ( self , context , complementary_id , tenant_id , mgmt_context , max_hosted ) : mgmt_port = None if mgmt_context and mgmt_context . get ( 'mgmt_nw_id' ) and tenant_id : p_spec = { 'port' : { 'tenant_id' : tenant_id , 'admin_state_up' : True , 'name' : 'mgmt' , 'network_id' : mgmt_context [ 'mgmt_nw_id' ] , 'mac_address' : bc . constants . ATTR_NOT_SPECIFIED , 'fixed_ips' : self . _mgmt_subnet_spec ( context , mgmt_context ) , 'device_id' : "" , 'device_owner' : complementary_id } } try : mgmt_port = self . _core_plugin . create_port ( context , p_spec ) except n_exc . NeutronException as e : LOG . error ( 'Error %s when creating management port. ' 'Cleaning up.' , e ) self . delete_hosting_device_resources ( context , tenant_id , mgmt_port ) mgmt_port = None return { 'mgmt_port' : mgmt_port , 'ports' : [ ] } | Create resources for a hosting device in a plugin specific way . |
37,687 | def get_hosting_device_resources ( self , context , id , complementary_id , tenant_id , mgmt_nw_id ) : mgmt_port = None query = context . session . query ( models_v2 . Port ) query = query . filter ( expr . or_ ( models_v2 . Port . device_id == id , models_v2 . Port . device_owner == complementary_id ) ) for port in query : if port [ 'network_id' ] != mgmt_nw_id : raise Exception else : mgmt_port = port return { 'mgmt_port' : mgmt_port } | Returns information about all resources for a hosting device . |
37,688 | def delete_hosting_device_resources ( self , context , tenant_id , mgmt_port , ** kwargs ) : if mgmt_port is not None : try : self . _cleanup_hosting_port ( context , mgmt_port [ 'id' ] ) except n_exc . NeutronException as e : LOG . error ( "Unable to delete port:%(port)s after %(tries)d" " attempts due to exception %(exception)s. " "Skipping it" , { 'port' : mgmt_port [ 'id' ] , 'tries' : DELETION_ATTEMPTS , 'exception' : str ( e ) } ) | Deletes resources for a hosting device in a plugin specific way . |
37,689 | def setup_logical_port_connectivity ( self , context , port_db , hosting_device_id ) : hosting_port = port_db . hosting_info . hosting_port if hosting_port : try : self . _dev_mgr . svc_vm_mgr . interface_attach ( hosting_device_id , hosting_port . id ) LOG . debug ( "Setup logical port completed for port:%s" , port_db . id ) except nova_exc . Conflict as e : LOG . debug ( "Failed to attach interface - spawn thread " "error %(error)s" , { 'error' : str ( e ) } ) self . _gt_pool . spawn_n ( self . _attach_hosting_port , hosting_device_id , hosting_port . id ) except Exception as e : LOG . error ( "Failed to attach interface mapped to port:" "%(p_id)s on hosting device:%(hd_id)s due to " "error %(error)s" , { 'p_id' : hosting_port . id , 'hd_id' : hosting_device_id , 'error' : str ( e ) } ) | Establishes connectivity for a logical port . |
37,690 | def teardown_logical_port_connectivity ( self , context , port_db , hosting_device_id ) : if port_db is None or port_db . get ( 'id' ) is None : LOG . warning ( "Port id is None! Cannot remove port " "from hosting_device:%s" , hosting_device_id ) return hosting_port_id = port_db . hosting_info . hosting_port . id try : self . _dev_mgr . svc_vm_mgr . interface_detach ( hosting_device_id , hosting_port_id ) self . _gt_pool . spawn_n ( self . _cleanup_hosting_port , context , hosting_port_id ) LOG . debug ( "Teardown logicalport completed for port:%s" , port_db . id ) except Exception as e : LOG . error ( "Failed to detach interface corresponding to port:" "%(p_id)s on hosting device:%(hd_id)s due to " "error %(error)s" , { 'p_id' : hosting_port_id , 'hd_id' : hosting_device_id , 'error' : str ( e ) } ) | Removes connectivity for a logical port . |
37,691 | def allocate_hosting_port ( self , context , router_id , port_db , network_type , hosting_device_id ) : l3admin_tenant_id = self . _dev_mgr . l3_tenant_id ( ) hostingport_name = 'hostingport_' + port_db [ 'id' ] [ : 8 ] p_spec = { 'port' : { 'tenant_id' : l3admin_tenant_id , 'admin_state_up' : True , 'name' : hostingport_name , 'network_id' : port_db [ 'network_id' ] , 'mac_address' : bc . constants . ATTR_NOT_SPECIFIED , 'fixed_ips' : [ ] , 'device_id' : '' , 'device_owner' : '' , 'port_security_enabled' : False } } try : hosting_port = self . _core_plugin . create_port ( context , p_spec ) except n_exc . NeutronException as e : LOG . error ( 'Error %s when creating hosting port' 'Cleaning up.' , e ) self . delete_hosting_device_resources ( context , l3admin_tenant_id , hosting_port ) hosting_port = None finally : if hosting_port : return { 'allocated_port_id' : hosting_port [ 'id' ] , 'allocated_vlan' : None } else : return None | Allocates a hosting port for a logical port . |
37,692 | def disable ( self , retain_port = False ) : self . update_server ( disabled = True ) if retain_port : return self . update_device ( disabled = True ) if self . conf . dhcp_delete_namespaces and self . network . namespace : ns_ip = ip_lib . IPWrapper ( self . root_helper , self . network . namespace ) try : ns_ip . netns . delete ( self . network . namespace ) except RuntimeError : msg = _ ( 'Failed trying to delete namespace: %s' ) LOG . exception ( msg , self . network . namespace ) | Teardown DHCP . |
37,693 | def recover_devices ( cls ) : if "_devices" in globals ( ) : return global _devices confs_dir = os . path . abspath ( os . path . normpath ( cfg . CONF . dhcp_confs ) ) for netid in os . listdir ( confs_dir ) : conf_dir = os . path . join ( confs_dir , netid ) intf_filename = os . path . join ( conf_dir , 'interface' ) try : with open ( intf_filename , 'r' ) as f : ifname = f . read ( ) _devices [ netid ] = ifname except IOError : LOG . error ( 'Unable to read interface file: %s' , intf_filename ) LOG . debug ( "Recovered device %s for network %s'" , ifname , netid ) | Track devices . |
37,694 | def check_version ( cls ) : super ( SimpleCpnrDriver , cls ) . check_version ( ) model . configure_pnr ( ) cls . recover_networks ( ) ver = model . get_version ( ) if ver < cls . MIN_VERSION : LOG . warning ( "CPNR version does not meet minimum requirements, " "expected: %(ever)f, actual: %(rver)f" , { 'ever' : cls . MIN_VERSION , 'rver' : ver } ) return ver | Checks server version against minimum required version . |
37,695 | def existing_dhcp_networks ( cls , conf ) : global _networks sup = super ( SimpleCpnrDriver , cls ) superkeys = sup . existing_dhcp_networks ( conf ) return set ( _networks . keys ( ) ) & set ( superkeys ) | Return a list of existing networks ids that we have configs for . |
37,696 | def _unsafe_update_server ( self , disabled = False ) : id = self . network . id net = model . Network . from_neutron ( self . network ) if id not in _networks : if disabled : return _networks [ id ] = net _networks [ id ] . create ( ) elif disabled : _networks [ id ] . delete ( ) del _networks [ id ] else : _networks [ id ] . update ( net ) _networks [ id ] = net | Update server with latest network configuration . |
37,697 | def create_network ( self , name , tenant_id , subnet , gw = None ) : try : body = { 'network' : { 'name' : name , 'tenant_id' : tenant_id , 'admin_state_up' : True } } netw = self . neutronclient . create_network ( body = body ) net_dict = netw . get ( 'network' ) net_id = net_dict . get ( 'id' ) except Exception as exc : LOG . error ( "Failed to create network %(name)s, Exc %(exc)s" , { 'name' : name , 'exc' : str ( exc ) } ) return None , None try : if gw is None : body = { 'subnet' : { 'cidr' : subnet , 'ip_version' : 4 , 'network_id' : net_id , 'tenant_id' : tenant_id , 'enable_dhcp' : False } } else : body = { 'subnet' : { 'cidr' : subnet , 'ip_version' : 4 , 'network_id' : net_id , 'tenant_id' : tenant_id , 'enable_dhcp' : False , 'gateway_ip' : gw } } subnet_ret = self . neutronclient . create_subnet ( body = body ) subnet_dict = subnet_ret . get ( 'subnet' ) subnet_id = subnet_dict . get ( 'id' ) except Exception as exc : LOG . error ( "Failed to create subnet %(sub)s, exc %(exc)s" , { 'sub' : subnet , 'exc' : str ( exc ) } ) try : self . neutronclient . delete_network ( net_id ) except Exception as exc : LOG . error ( "Failed to delete network %(net)s, exc %(exc)s" , { 'net' : net_id , 'exc' : str ( exc ) } ) return None , None return net_id , subnet_id | Create the openstack network including the subnet . |
37,698 | def delete_network ( self , name , tenant_id , subnet_id , net_id ) : try : self . neutronclient . delete_subnet ( subnet_id ) except Exception as exc : LOG . error ( "Failed to delete subnet %(sub)s exc %(exc)s" , { 'sub' : subnet_id , 'exc' : str ( exc ) } ) return try : self . neutronclient . delete_network ( net_id ) except Exception as exc : LOG . error ( "Failed to delete network %(name)s exc %(exc)s" , { 'name' : name , 'exc' : str ( exc ) } ) | Delete the openstack subnet and network . |
37,699 | def delete_network_all_subnets ( self , net_id ) : try : body = { 'network_id' : net_id } subnet_list = self . neutronclient . list_subnets ( body = body ) subnet_list = subnet_list . get ( 'subnets' ) for subnet in subnet_list : if subnet . get ( 'network_id' ) == net_id : subnet_id = subnet . get ( 'id' ) self . neutronclient . delete_subnet ( subnet_id ) except Exception as exc : LOG . error ( "Failed to delete subnet for net %(net)s " "Exc %(exc)s" , { 'net' : net_id , 'exc' : str ( exc ) } ) return False try : self . neutronclient . delete_network ( net_id ) except Exception as exc : LOG . error ( "Failed to delete network %(net)s Exc %(exc)s" , { 'net' : net_id , 'exc' : str ( exc ) } ) return False return True | Delete the openstack network including all its subnets . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.