idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
38,000 | def hosting_devices_assigned_to_cfg_agent ( self , context , payload ) : LOG . debug ( "Got hosting device assigned, payload: %s" % payload ) try : if payload [ 'hosting_device_ids' ] : self . routing_service_helper . fullsync = True except KeyError as e : LOG . error ( "Invalid payload format for received RPC message " "`hosting_devices_assigned_to_cfg_agent`. Error is " "%(error)s. Payload is %(payload)s" , { 'error' : e , 'payload' : payload } ) | Deal with hosting devices assigned to this config agent . |
38,001 | def hosting_devices_unassigned_from_cfg_agent ( self , context , payload ) : try : if payload [ 'hosting_device_ids' ] : pass except KeyError as e : LOG . error ( "Invalid payload format for received RPC message " "`hosting_devices_unassigned_from_cfg_agent`. Error " "is %(error)s. Payload is %(payload)s" , { 'error' : e , 'payload' : payload } ) | Deal with hosting devices unassigned from this config agent . |
38,002 | def hosting_devices_removed ( self , context , payload ) : try : if payload [ 'hosting_data' ] : if payload [ 'hosting_data' ] . keys ( ) : self . process_services ( removed_devices_info = payload ) except KeyError as e : LOG . error ( "Invalid payload format for received RPC message " "`hosting_devices_removed`. Error is %(error)s. Payload " "is %(payload)s" , { 'error' : e , 'payload' : payload } ) | Deal with hosting device removed RPC message . |
38,003 | def _agent_registration ( self ) : for attempts in range ( MAX_REGISTRATION_ATTEMPTS ) : context = bc . context . get_admin_context_without_session ( ) self . send_agent_report ( self . agent_state , context ) try : res = self . devmgr_rpc . register_for_duty ( context ) except Exception : res = False LOG . warning ( "[Agent registration] Rpc exception. Neutron " "may not be available or busy. Retrying " "in %0.2f seconds " , REGISTRATION_RETRY_DELAY ) if res is True : LOG . info ( "[Agent registration] Agent successfully registered" ) return elif res is False : LOG . warning ( "[Agent registration] Neutron server said " "that device manager was not ready. Retrying " "in %0.2f seconds " , REGISTRATION_RETRY_DELAY ) time . sleep ( REGISTRATION_RETRY_DELAY ) elif res is None : LOG . error ( "[Agent registration] Neutron server said that " "no device manager was found. Cannot continue. " "Exiting!" ) raise SystemExit ( _ ( "Cfg Agent exiting" ) ) LOG . error ( "[Agent registration] %d unsuccessful registration " "attempts. Exiting!" , MAX_REGISTRATION_ATTEMPTS ) raise SystemExit ( _ ( "Cfg Agent exiting" ) ) | Register this agent with the server . |
38,004 | def _report_state ( self ) : LOG . debug ( "Report state task started" ) self . keepalive_iteration += 1 if self . keepalive_iteration == self . report_iteration : self . _prepare_full_report_data ( ) self . keepalive_iteration = 0 LOG . debug ( "State report: %s" , pprint . pformat ( self . agent_state ) ) else : self . agent_state . pop ( 'configurations' , None ) self . agent_state [ 'local_time' ] = datetime . now ( ) . strftime ( ISO8601_TIME_FORMAT ) LOG . debug ( "State report: %s" , self . agent_state ) self . send_agent_report ( self . agent_state , self . context ) | Report state to the plugin . |
38,005 | def send_agent_report ( self , report , context ) : try : self . state_rpc . report_state ( context , report , self . use_call ) report . pop ( 'start_flag' , None ) self . use_call = False LOG . debug ( "Send agent report successfully completed" ) except AttributeError : LOG . warning ( "Neutron server does not support state report. " "State report for this agent will be disabled." ) self . heartbeat . stop ( ) return except Exception : LOG . warning ( "Failed sending agent report!" ) | Send the agent report via RPC . |
38,006 | def _get_vlanid ( self , context ) : segment = context . bottom_bound_segment if segment and self . check_segment ( segment ) : return segment . get ( api . SEGMENTATION_ID ) | Returns vlan_id associated with a bound VLAN segment . |
38,007 | def _get_physnet ( self , context ) : segment = context . bottom_bound_segment if segment and self . check_segment ( segment ) : return segment . get ( api . PHYSICAL_NETWORK ) | Returns physnet associated with a bound VLAN segment . |
38,008 | def update_port_precommit ( self , context ) : vnic_type = context . current . get ( bc . portbindings . VNIC_TYPE , bc . portbindings . VNIC_NORMAL ) profile = context . current . get ( bc . portbindings . PROFILE , { } ) host_id = self . _get_host_id ( context . current . get ( bc . portbindings . HOST_ID ) ) if not host_id : LOG . warning ( 'Host id from port context is None. ' 'Ignoring this port' ) return vlan_id = self . _get_vlanid ( context ) if not vlan_id : LOG . warning ( 'Vlan_id is None. Ignoring this port' ) return ucsm_ip = self . driver . get_ucsm_ip_for_host ( host_id ) if not ucsm_ip : LOG . info ( 'Host %s is not controlled by any known ' 'UCS Manager.' , host_id ) return if not self . driver . check_vnic_type_and_vendor_info ( vnic_type , profile ) : physnet = self . _get_physnet ( context ) if not physnet : LOG . debug ( 'physnet is None. Not modifying VNIC ' 'Template config' ) else : ucsm = CONF . ml2_cisco_ucsm . ucsms [ ucsm_ip ] vnic_template = ucsm . vnic_template_list . get ( physnet ) if vnic_template : LOG . debug ( 'vnic_template %s' , vnic_template ) self . ucsm_db . add_vnic_template ( vlan_id , ucsm_ip , vnic_template . name , physnet ) return else : LOG . debug ( 'VNIC Template not configured for ' 'physnet %s' , physnet ) sp_template_info = ( CONF . ml2_cisco_ucsm . ucsms [ ucsm_ip ] . sp_template_list . get ( host_id ) ) if sp_template_info : LOG . debug ( 'SP Template: %s, VLAN_id: %d' , sp_template_info . name , vlan_id ) self . ucsm_db . add_service_profile_template ( vlan_id , sp_template_info . name , ucsm_ip ) return if not self . driver . is_vmfex_port ( profile ) : LOG . debug ( 'This is a SR-IOV port and hence not updating DB.' ) return p_profile_name = self . make_profile_name ( vlan_id ) LOG . debug ( 'Port Profile: %s for VLAN_id: %d' , p_profile_name , vlan_id ) self . ucsm_db . add_port_profile ( p_profile_name , vlan_id , ucsm_ip ) | Adds port profile and vlan information to the DB . |
38,009 | def delete_network_precommit ( self , context ) : segments = context . network_segments for segment in segments : if not self . check_segment ( segment ) : return vlan_id = segment . get ( api . SEGMENTATION_ID ) if not vlan_id : return self . ucsm_db . delete_vlan_entry ( vlan_id ) if any ( [ True for ip , ucsm in CONF . ml2_cisco_ucsm . ucsms . items ( ) if ucsm . sp_template_list ] ) : self . ucsm_db . delete_sp_template_for_vlan ( vlan_id ) if any ( [ True for ip , ucsm in CONF . ml2_cisco_ucsm . ucsms . items ( ) if ucsm . vnic_template_list ] ) : self . ucsm_db . delete_vnic_template_for_vlan ( vlan_id ) | Delete entry corresponding to Network s VLAN in the DB . |
38,010 | def delete_network_postcommit ( self , context ) : segments = context . network_segments network_name = context . current [ 'name' ] for segment in segments : if not self . check_segment ( segment ) : return vlan_id = segment . get ( api . SEGMENTATION_ID ) if not vlan_id : return port_profile = self . make_profile_name ( vlan_id ) trunk_vlans = ( CONF . sriov_multivlan_trunk . network_vlans . get ( network_name , [ ] ) ) self . driver . delete_all_config_for_vlan ( vlan_id , port_profile , trunk_vlans ) | Delete all configuration added to UCS Manager for the vlan_id . |
38,011 | def bind_port ( self , context ) : vnic_type = context . current . get ( bc . portbindings . VNIC_TYPE , bc . portbindings . VNIC_NORMAL ) LOG . debug ( 'Attempting to bind port %(port)s with vnic_type ' '%(vnic_type)s on network %(network)s ' , { 'port' : context . current [ 'id' ] , 'vnic_type' : vnic_type , 'network' : context . network . current [ 'id' ] } ) profile = context . current . get ( bc . portbindings . PROFILE , { } ) if not self . driver . check_vnic_type_and_vendor_info ( vnic_type , profile ) : return for segment in context . network . network_segments : if self . check_segment ( segment ) : vlan_id = segment [ api . SEGMENTATION_ID ] if not vlan_id : LOG . warning ( 'Cannot bind port: vlan_id is None.' ) return LOG . debug ( "Port binding to Vlan_id: %s" , str ( vlan_id ) ) if self . driver . is_vmfex_port ( profile ) : profile_name = self . make_profile_name ( vlan_id ) self . vif_details [ const . VIF_DETAILS_PROFILEID ] = profile_name else : self . vif_details [ bc . portbindings . VIF_DETAILS_VLAN ] = str ( vlan_id ) context . set_binding ( segment [ api . ID ] , self . vif_type , self . vif_details , bc . constants . PORT_STATUS_ACTIVE ) return LOG . error ( 'UCS Mech Driver: Failed binding port ID %(id)s ' 'on any segment of network %(network)s' , { 'id' : context . current [ 'id' ] , 'network' : context . network . current [ 'id' ] } ) | Binds port to current network segment . |
38,012 | def update_rule_entry ( self , rule_info ) : if rule_info . get ( 'status' ) == 'up' : self . add_rule_entry ( rule_info ) if rule_info . get ( 'status' ) == 'down' : self . remove_rule_entry ( rule_info ) | Update the rule_info list . |
38,013 | def add_rule_entry ( self , rule_info ) : new_rule = IpMacPort ( rule_info . get ( 'ip' ) , rule_info . get ( 'mac' ) , rule_info . get ( 'port' ) ) LOG . debug ( 'Added rule info %s to the list' , rule_info ) self . rule_info . append ( new_rule ) | Add host data object to the rule_info list . |
38,014 | def remove_rule_entry ( self , rule_info ) : temp_list = list ( self . rule_info ) for rule in temp_list : if ( rule . ip == rule_info . get ( 'ip' ) and rule . mac == rule_info . get ( 'mac' ) and rule . port == rule_info . get ( 'port' ) ) : LOG . debug ( 'Removed rule info %s from the list' , rule_info ) self . rule_info . remove ( rule ) | Remove host data object from rule_info list . |
38,015 | def _find_chain_name ( self , mac ) : ipt_cmd = [ 'iptables' , '-t' , 'filter' , '-S' ] cmdo = dsl . execute ( ipt_cmd , root_helper = self . _root_helper , log_output = False ) for o in cmdo . split ( '\n' ) : if mac in o . lower ( ) : chain = o . split ( ) [ 1 ] LOG . info ( 'Find %(chain)s for %(mac)s.' , { 'chain' : chain , 'mac' : mac } ) return chain | Find a rule associated with a given mac . |
38,016 | def _find_rule_no ( self , mac ) : ipt_cmd = [ 'iptables' , '-L' , '--line-numbers' ] cmdo = dsl . execute ( ipt_cmd , self . _root_helper , log_output = False ) for o in cmdo . split ( '\n' ) : if mac in o . lower ( ) : rule_no = o . split ( ) [ 0 ] LOG . info ( 'Found rule %(rule)s for %(mac)s.' , { 'rule' : rule_no , 'mac' : mac } ) return rule_no | Find rule number associated with a given mac . |
38,017 | def update_ip_rule ( self , ip , mac ) : rule_no = self . _find_rule_no ( mac ) chain = self . _find_chain_name ( mac ) if not rule_no or not chain : LOG . error ( 'Failed to update ip rule for %(ip)s %(mac)s' , { 'ip' : ip , 'mac' : mac } ) return update_cmd = [ 'iptables' , '-R' , '%s' % chain , '%s' % rule_no , '-s' , '%s/32' % ip , '-m' , 'mac' , '--mac-source' , '%s' % mac , '-j' , 'RETURN' ] LOG . debug ( 'Execute command: %s' , update_cmd ) dsl . execute ( update_cmd , self . _root_helper , log_output = False ) | Update a rule associated with given ip and mac . |
38,018 | def enqueue_event ( self , event ) : LOG . debug ( 'Enqueue iptable event %s.' , event ) if event . get ( 'status' ) == 'up' : for rule in self . rule_info : if ( rule . mac == event . get ( 'mac' ) . lower ( ) and rule . port == event . get ( 'port' ) ) : if rule . ip != event . get ( 'ip' ) : LOG . debug ( 'enqueue_event: Only updating IP from %s' ' to %s.' % ( rule . ip , event . get ( 'ip' ) ) ) rule . ip = event . get ( 'ip' ) return self . _iptq . put ( event ) | Enqueue the given event . |
38,019 | def update_iptables ( self ) : iptables_cmds = [ 'iptables-save' , '-c' ] all_rules = dsl . execute ( iptables_cmds , root_helper = self . _root_helper , log_output = False ) new_rules = [ ] is_modified = False for line in all_rules . split ( '\n' ) : new_line = line line_content = line . split ( ) if '-s' in line_content : tmp_rule_info = list ( self . rule_info ) for rule in tmp_rule_info : if ( rule . mac in line . lower ( ) and rule . chain . lower ( ) in line . lower ( ) and not self . _is_ip_in_rule ( rule . ip , line_content ) ) : ip_loc = line_content . index ( '-s' ) + 1 line_content [ ip_loc ] = rule . ip + '/32' new_line = ' ' . join ( line_content ) LOG . debug ( 'Modified %(old_rule)s. ' 'New rule is %(new_rule)s.' % ( { 'old_rule' : line , 'new_rule' : new_line } ) ) is_modified = True new_rules . append ( new_line ) if is_modified and new_rules : iptables_cmds = [ 'iptables-restore' , '-c' ] dsl . execute ( iptables_cmds , process_input = '\n' . join ( new_rules ) , root_helper = self . _root_helper , log_output = False ) | Update iptables based on information in the rule_info . |
38,020 | def process_rule_info ( self ) : while True : try : event = self . _iptq . get ( block = False ) LOG . debug ( 'Dequeue event: %s.' , event ) self . update_rule_entry ( event ) except queue . Empty : self . update_iptables ( ) time . sleep ( 1 ) except Exception : LOG . exception ( 'ERROR: failed to process queue' ) | Task responsible for processing event queue . |
38,021 | def cleanup ( self , ** kwargs ) : params = kwargs . get ( 'params' ) LOG . info ( "asa_cleanup: tenant %(tenant)s %(in_vlan)d %(out_vlan)d" " %(in_ip)s %(in_mask)s %(out_ip)s %(out_mask)s" , { 'tenant' : params . get ( 'tenant_name' ) , 'in_vlan' : params . get ( 'in_vlan' ) , 'out_vlan' : params . get ( 'out_vlan' ) , 'in_ip' : params . get ( 'in_ip' ) , 'in_mask' : params . get ( 'in_mask' ) , 'out_ip' : params . get ( 'out_ip' ) , 'out_mask' : params . get ( 'out_mask' ) } ) inside_vlan = str ( params . get ( 'in_vlan' ) ) outside_vlan = str ( params . get ( 'out_vlan' ) ) context = params . get ( 'tenant_name' ) cmds = [ "conf t" , "changeto system" ] cmds . append ( "no context " + context + " noconfirm" ) inside_int = params . get ( 'intf_in' ) + '.' + inside_vlan outside_int = params . get ( 'intf_out' ) + '.' + outside_vlan cmds . append ( "no interface " + inside_int ) cmds . append ( "no interface " + outside_int ) cmds . append ( "write memory" ) cmds . append ( "del /noconfirm disk0:/" + context + ".cfg" ) if context in self . tenant_rule : for rule in self . tenant_rule [ context ] . get ( 'rule_lst' ) : del self . rule_tbl [ rule ] del self . tenant_rule [ context ] data = { "commands" : cmds } return self . rest_send_cli ( data ) | cleanup ASA context for an edge tenant pair . |
38,022 | def build_acl_ip ( self , network_obj ) : "Build the acl for IP address. " if str ( network_obj ) == '0.0.0.0/0' : acl = "any " else : acl = "%(ip)s %(mask)s " % { 'ip' : network_obj . network , 'mask' : network_obj . netmask } return acl | Build the acl for IP address . |
38,023 | def build_acl_port ( self , port , enabled = True ) : "Build the acl for L4 Ports. " if port is not None : if ':' in port : range = port . replace ( ':' , ' ' ) acl = "range %(range)s " % { 'range' : range } else : acl = "eq %(port)s " % { 'port' : port } if not enabled : acl += "inactive" return acl | Build the acl for L4 Ports . |
38,024 | def build_acl ( self , tenant_name , rule ) : if rule [ 'action' ] == 'allow' : action = 'permit' else : action = 'deny' acl_str = "access-list %(tenant)s extended %(action)s %(prot)s " acl = acl_str % { 'tenant' : tenant_name , 'action' : action , 'prot' : rule . get ( 'protocol' ) } src_ip = self . get_ip_address ( rule . get ( 'source_ip_address' ) ) ip_acl = self . build_acl_ip ( src_ip ) acl += ip_acl acl += self . build_acl_port ( rule . get ( 'source_port' ) ) dst_ip = self . get_ip_address ( rule . get ( 'destination_ip_address' ) ) ip_acl = self . build_acl_ip ( dst_ip ) acl += ip_acl acl += self . build_acl_port ( rule . get ( 'destination_port' ) , enabled = rule . get ( 'enabled' ) ) return acl | Build the ACL . |
38,025 | def apply_policy ( self , policy ) : tenant_name = policy [ 'tenant_name' ] fw_id = policy [ 'fw_id' ] fw_name = policy [ 'fw_name' ] LOG . info ( "asa_apply_policy: tenant=%(tenant)s fw_id=%(fw_id)s " "fw_name=%(fw_name)s" , { 'tenant' : tenant_name , 'fw_id' : fw_id , 'fw_name' : fw_name } ) cmds = [ "conf t" , "changeto context " + tenant_name ] for rule_id , rule in policy [ 'rules' ] . items ( ) : acl = self . build_acl ( tenant_name , rule ) LOG . info ( "rule[%(rule_id)s]: name=%(name)s enabled=%(enabled)s" " protocol=%(protocol)s dport=%(dport)s " "sport=%(sport)s dip=%(dport)s " "sip=%(sip)s action=%(dip)s" , { 'rule_id' : rule_id , 'name' : rule . get ( 'name' ) , 'enabled' : rule . get ( 'enabled' ) , 'protocol' : rule . get ( 'protocol' ) , 'dport' : rule . get ( 'dst_port' ) , 'sport' : rule . get ( 'src_port' ) , 'dip' : rule . get ( 'destination_ip_address' ) , 'sip' : rule . get ( 'source_ip_address' ) , 'action' : rule . get ( 'action' ) } ) if rule_id in self . rule_tbl : cmds . append ( 'no ' + self . rule_tbl [ rule_id ] ) self . rule_tbl [ rule_id ] = acl if tenant_name in self . tenant_rule : if rule_id not in self . tenant_rule [ tenant_name ] [ 'rule_lst' ] : self . tenant_rule [ tenant_name ] [ 'rule_lst' ] . append ( rule_id ) cmds . append ( acl ) cmds . append ( "access-group " + tenant_name + " global" ) cmds . append ( "write memory" ) LOG . info ( "cmds sent is %s" , cmds ) data = { "commands" : cmds } return self . rest_send_cli ( data ) | Apply a firewall policy . |
38,026 | def _flow_check_handler_internal ( self ) : integ_flow = self . integ_br_obj . dump_flows_for ( in_port = self . int_peer_port_num ) ext_flow = self . ext_br_obj . dump_flows_for ( in_port = self . phy_peer_port_num ) for net_uuid , lvm in six . iteritems ( self . local_vlan_map ) : vdp_vlan = lvm . any_consistent_vlan ( ) flow_required = False if not ( vdp_vlan and ovs_lib . is_valid_vlan_tag ( vdp_vlan ) ) : return if not self . _check_bridge_flow ( integ_flow , vdp_vlan , lvm . lvid ) : LOG . error ( "Flow for VDP Vlan %(vdp_vlan)s, Local vlan " "%(lvid)s not present on Integ bridge" , { 'vdp_vlan' : vdp_vlan , 'lvid' : lvm . lvid } ) flow_required = True if not self . _check_bridge_flow ( ext_flow , lvm . lvid , vdp_vlan ) : LOG . error ( "Flow for VDP Vlan %(vdp_vlan)s, Local vlan " "%(lvid)s not present on External bridge" , { 'vdp_vlan' : vdp_vlan , 'lvid' : lvm . lvid } ) flow_required = True if flow_required : LOG . info ( "Programming flows for lvid %(lvid)s vdp vlan" " %(vdp)s" , { 'lvid' : lvm . lvid , 'vdp' : vdp_vlan } ) self . program_vm_ovs_flows ( lvm . lvid , 0 , vdp_vlan ) | Periodic handler to check if installed flows are present . |
38,027 | def _flow_check_handler ( self ) : LOG . info ( "In _flow_check_handler" ) try : with self . ovs_vdp_lock : self . _flow_check_handler_internal ( ) except Exception as e : LOG . error ( "Exception in _flow_check_handler_internal %s" , str ( e ) ) | Top level routine to check OVS flow consistency . |
38,028 | def gen_veth_str ( self , const_str , intf_str ) : avl_len = constants . MAX_VETH_NAME - len ( const_str ) if avl_len <= 0 : LOG . error ( "veth string name too short" ) raise dfae . DfaAgentFailed ( reason = "Veth Unavailable" ) start_pos = len ( intf_str ) - avl_len veth_str = const_str + intf_str [ start_pos : ] return veth_str | Generate a veth string . |
38,029 | def find_interconnect_ports ( self ) : phy_port_list = self . ext_br_obj . get_port_name_list ( ) int_port_list = self . integ_br_obj . get_port_name_list ( ) for port in phy_port_list : is_patch = ovs_lib . is_patch ( self . root_helper , port ) if is_patch : peer_port = ovs_lib . get_peer ( self . root_helper , port ) if peer_port in int_port_list : return port , peer_port return None , None | Find the internal veth or patch ports . |
38,030 | def get_lvid_vdp_vlan ( self , net_uuid , port_uuid ) : lvm = self . local_vlan_map . get ( net_uuid ) if not lvm : LOG . error ( "lvm not yet created, get_lvid_vdp_lan " "return error" ) return cconstants . INVALID_VLAN , cconstants . INVALID_VLAN vdp_vlan = lvm . get_portid_vlan ( port_uuid ) lvid = lvm . lvid LOG . info ( "Return from lvid_vdp_vlan lvid %(lvid)s vdp_vlan %(vdp)s" , { 'lvid' : lvid , 'vdp' : vdp_vlan } ) return lvid , vdp_vlan | Retrieve the Local Vlan ID and VDP Vlan . |
38,031 | def unprovision_vdp_overlay_networks ( self , net_uuid , lvid , vdp_vlan , oui ) : if not ovs_lib . is_valid_vlan_tag ( vdp_vlan ) : LOG . error ( "Cannot unprovision VDP Overlay network for" " net-id=%(net_uuid)s - Invalid " , { 'net_uuid' : net_uuid } ) return LOG . info ( 'unprovision_vdp_overlay_networks: add_flow for ' 'Local Vlan %(local_vlan)s VDP VLAN %(vdp_vlan)s' , { 'local_vlan' : lvid , 'vdp_vlan' : vdp_vlan } ) self . program_vm_ovs_flows ( lvid , vdp_vlan , 0 ) | Unprovisions a overlay type network configured using VDP . |
38,032 | def provision_vdp_overlay_networks ( self , port_uuid , mac , net_uuid , segmentation_id , lvid , oui ) : lldpad_port = self . lldpad_info if lldpad_port : ovs_cb_data = { 'obj' : self , 'port_uuid' : port_uuid , 'mac' : mac , 'net_uuid' : net_uuid } vdp_vlan , fail_reason = lldpad_port . send_vdp_vnic_up ( port_uuid = port_uuid , vsiid = port_uuid , gid = segmentation_id , mac = mac , new_network = True , oui = oui , vsw_cb_fn = self . vdp_vlan_change , vsw_cb_data = ovs_cb_data ) else : fail_reason = "There is no LLDPad port available." LOG . error ( "%s" , fail_reason ) return { 'result' : False , 'vdp_vlan' : cconstants . INVALID_VLAN , 'fail_reason' : fail_reason } if not ovs_lib . is_valid_vlan_tag ( vdp_vlan ) : LOG . error ( "Cannot provision VDP Overlay network for" " net-id=%(net_uuid)s - Invalid " , { 'net_uuid' : net_uuid } ) return { 'result' : True , 'vdp_vlan' : cconstants . INVALID_VLAN , 'fail_reason' : fail_reason } LOG . info ( 'provision_vdp_overlay_networks: add_flow for ' 'Local Vlan %(local_vlan)s VDP VLAN %(vdp_vlan)s' , { 'local_vlan' : lvid , 'vdp_vlan' : vdp_vlan } ) self . program_vm_ovs_flows ( lvid , 0 , vdp_vlan ) return { 'result' : True , 'vdp_vlan' : vdp_vlan , 'fail_reason' : None } | Provisions a overlay type network configured using VDP . |
38,033 | def pop_local_cache ( self , port_uuid , mac , net_uuid , lvid , vdp_vlan , segmentation_id ) : LOG . info ( "Populating the OVS VDP cache with port %(port_uuid)s, " "mac %(mac)s net %(net_uuid)s lvid %(lvid)s vdpvlan " "%(vdp_vlan)s seg %(seg)s" , { 'port_uuid' : port_uuid , 'mac' : mac , 'net_uuid' : net_uuid , 'lvid' : lvid , 'vdp_vlan' : vdp_vlan , 'seg' : segmentation_id } ) lvm = self . local_vlan_map . get ( net_uuid ) if not lvm : lvm = LocalVlan ( lvid , segmentation_id ) self . local_vlan_map [ net_uuid ] = lvm lvm . lvid = lvid lvm . set_port_uuid ( port_uuid , vdp_vlan , None ) if vdp_vlan != cconstants . INVALID_VLAN : lvm . late_binding_vlan = vdp_vlan lvm . vdp_nego_req = False | Populate the local cache after restart . |
38,034 | def store_dummy_router_net ( self , net_id , subnet_id , rtr_id ) : self . dummy_net_id = net_id self . dummy_subnet_id = subnet_id self . dummy_router_id = rtr_id | Storing the router attributes . |
38,035 | def store_dcnm_net_dict ( self , net_dict , direc ) : if direc == 'in' : self . in_dcnm_net_dict = net_dict else : self . out_dcnm_net_dict = net_dict | Storing the DCNM net dict . |
38,036 | def _parse_subnet ( self , subnet_dict ) : if not subnet_dict : return alloc_pool = subnet_dict . get ( 'allocation_pools' ) cidr = subnet_dict . get ( 'cidr' ) subnet = cidr . split ( '/' ) [ 0 ] start = alloc_pool [ 0 ] . get ( 'start' ) end = alloc_pool [ 0 ] . get ( 'end' ) gateway = subnet_dict . get ( 'gateway_ip' ) sec_gateway = subnet_dict . get ( 'secondary_gw' ) return { 'subnet' : subnet , 'start' : start , 'end' : end , 'gateway' : gateway , 'sec_gateway' : sec_gateway } | Return the subnet start end gateway of a subnet . |
38,037 | def store_dcnm_subnet_dict ( self , subnet_dict , direc ) : if direc == 'in' : self . in_dcnm_subnet_dict = subnet_dict self . in_subnet_dict = self . _parse_subnet ( subnet_dict ) else : self . out_dcnm_subnet_dict = subnet_dict self . out_subnet_dict = self . _parse_subnet ( subnet_dict ) | Store the subnet attributes and dict . |
38,038 | def create_fw_db ( self , fw_id , fw_name , tenant_id ) : fw_dict = { 'fw_id' : fw_id , 'name' : fw_name , 'tenant_id' : tenant_id } self . update_fw_dict ( fw_dict ) | Create FW dict . |
38,039 | def destroy_local_fw_db ( self ) : del self . fw_dict del self . in_dcnm_net_dict del self . in_dcnm_subnet_dict del self . out_dcnm_net_dict del self . out_dcnm_subnet_dict | Delete the FW dict and its attributes . |
38,040 | def update_fw_local_cache ( self , net , direc , start ) : fw_dict = self . get_fw_dict ( ) if direc == 'in' : fw_dict . update ( { 'in_network_id' : net , 'in_service_ip' : start } ) else : fw_dict . update ( { 'out_network_id' : net , 'out_service_ip' : start } ) self . update_fw_dict ( fw_dict ) | Update the fw dict with Net ID and service IP . |
38,041 | def update_fw_local_result_str ( self , os_result = None , dcnm_result = None , dev_result = None ) : fw_dict = self . get_fw_dict ( ) if os_result is not None : fw_dict [ 'os_status' ] = os_result if dcnm_result is not None : fw_dict [ 'dcnm_status' ] = dcnm_result if dev_result is not None : fw_dict [ 'dev_status' ] = dev_result self . update_fw_dict ( fw_dict ) | Update the FW result in the dict . |
38,042 | def update_fw_local_result ( self , os_result = None , dcnm_result = None , dev_result = None ) : self . update_fw_local_result_str ( os_result = os_result , dcnm_result = dcnm_result , dev_result = dev_result ) | Retrieve and update the FW result in the dict . |
38,043 | def update_fw_local_router ( self , net_id , subnet_id , router_id , os_result ) : fw_dict = self . get_fw_dict ( ) fw_dict . update ( { 'router_id' : router_id , 'router_net_id' : net_id , 'router_subnet_id' : subnet_id } ) self . store_dummy_router_net ( net_id , subnet_id , router_id ) self . update_fw_local_result ( os_result = os_result ) | Update the FW with router attributes . |
38,044 | def commit_fw_db ( self ) : fw_dict = self . get_fw_dict ( ) self . update_fw_db ( fw_dict . get ( 'fw_id' ) , fw_dict ) | Calls routine to update the FW DB . |
38,045 | def fixup_state ( self , from_str , state ) : result = self . get_local_final_result ( ) if from_str == fw_const . FW_CR_OP : if result == fw_const . RESULT_FW_DELETE_INIT : return state + 1 if from_str == fw_const . FW_DEL_OP : if result == fw_const . RESULT_FW_CREATE_INIT : return state - 1 return state | Fixup state after retart . |
38,046 | def store_db_obj ( cls , in_obj , out_obj ) : cls . ip_db_obj [ 'in' ] = in_obj cls . ip_db_obj [ 'out' ] = out_obj | Store the IP DB object . |
38,047 | def get_in_ip_addr ( cls , tenant_id ) : if tenant_id not in cls . serv_obj_dict : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return tenant_obj = cls . serv_obj_dict . get ( tenant_id ) return tenant_obj . get_in_ip_addr ( ) | Retrieves the in service subnet attributes . |
38,048 | def get_out_ip_addr ( cls , tenant_id ) : if tenant_id not in cls . serv_obj_dict : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return tenant_obj = cls . serv_obj_dict . get ( tenant_id ) return tenant_obj . get_out_ip_addr ( ) | Retrieves the out service subnet attributes . |
38,049 | def get_in_srvc_node_ip_addr ( cls , tenant_id ) : if tenant_id not in cls . serv_obj_dict : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return tenant_obj = cls . serv_obj_dict . get ( tenant_id ) in_subnet_dict = tenant_obj . get_in_ip_addr ( ) next_hop = str ( netaddr . IPAddress ( in_subnet_dict . get ( 'subnet' ) ) + 2 ) return next_hop | Retrieves the IN service node IP address . |
38,050 | def get_out_srvc_node_ip_addr ( cls , tenant_id ) : if tenant_id not in cls . serv_obj_dict : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return tenant_obj = cls . serv_obj_dict . get ( tenant_id ) out_subnet_dict = tenant_obj . get_out_ip_addr ( ) next_hop = str ( netaddr . IPAddress ( out_subnet_dict . get ( 'subnet' ) ) + 2 ) return next_hop | Retrieves the OUT service node IP address . |
38,051 | def get_dummy_router_net ( cls , tenant_id ) : if tenant_id not in cls . serv_obj_dict : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return tenant_obj = cls . serv_obj_dict . get ( tenant_id ) return tenant_obj . get_dummy_router_net ( ) | Retrieves the dummy router network info . |
38,052 | def get_in_seg_vlan ( cls , tenant_id ) : if tenant_id not in cls . serv_obj_dict : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return None , None tenant_obj = cls . serv_obj_dict . get ( tenant_id ) return tenant_obj . get_in_seg_vlan ( ) | Retrieves the IN Seg VLAN mob domain . |
38,053 | def get_out_seg_vlan ( cls , tenant_id ) : if tenant_id not in cls . serv_obj_dict : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return None , None tenant_obj = cls . serv_obj_dict . get ( tenant_id ) return tenant_obj . get_out_seg_vlan ( ) | Retrieves the OUT Seg VLAN mob domain . |
38,054 | def get_in_subnet_id ( cls , tenant_id ) : if 'in' not in cls . ip_db_obj : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return None db_obj = cls . ip_db_obj . get ( 'in' ) in_subnet_dict = cls . get_in_ip_addr ( tenant_id ) sub = db_obj . get_subnet ( in_subnet_dict . get ( 'subnet' ) ) return sub . subnet_id | Retrieve the subnet ID of IN network . |
38,055 | def get_out_subnet_id ( cls , tenant_id ) : if 'out' not in cls . ip_db_obj : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return None db_obj = cls . ip_db_obj . get ( 'out' ) out_subnet_dict = cls . get_out_ip_addr ( tenant_id ) sub = db_obj . get_subnet ( out_subnet_dict . get ( 'subnet' ) ) return sub . subnet_id | Retrieve the subnet ID of OUT network . |
38,056 | def get_in_net_id ( cls , tenant_id ) : if 'in' not in cls . ip_db_obj : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return None db_obj = cls . ip_db_obj . get ( 'in' ) in_subnet_dict = cls . get_in_ip_addr ( tenant_id ) sub = db_obj . get_subnet ( in_subnet_dict . get ( 'subnet' ) ) return sub . network_id | Retrieve the network ID of IN network . |
38,057 | def get_out_net_id ( cls , tenant_id ) : if 'out' not in cls . ip_db_obj : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return None db_obj = cls . ip_db_obj . get ( 'out' ) out_subnet_dict = cls . get_out_ip_addr ( tenant_id ) sub = db_obj . get_subnet ( out_subnet_dict . get ( 'subnet' ) ) return sub . network_id | Retrieve the network ID of OUT network . |
38,058 | def is_network_source_fw ( cls , nwk , nwk_name ) : if nwk is not None : if nwk . source == fw_const . FW_CONST : return True return False if nwk_name in fw_const . DUMMY_SERVICE_NWK and ( len ( nwk_name ) == len ( fw_const . DUMMY_SERVICE_NWK ) + fw_const . SERVICE_NAME_EXTRA_LEN ) : return True if nwk_name in fw_const . IN_SERVICE_NWK and ( len ( nwk_name ) == len ( fw_const . IN_SERVICE_NWK ) + fw_const . SERVICE_NAME_EXTRA_LEN ) : return True if nwk_name in fw_const . OUT_SERVICE_NWK and ( len ( nwk_name ) == len ( fw_const . OUT_SERVICE_NWK ) + fw_const . SERVICE_NAME_EXTRA_LEN ) : return True return False | Check if SOURCE is FIREWALL if yes return TRUE . |
38,059 | def is_subnet_source_fw ( cls , tenant_id , subnet ) : cfg = config . CiscoDFAConfig ( ) . cfg subnet = subnet . split ( '/' ) [ 0 ] in_sub_dict = cls . get_in_ip_addr ( tenant_id ) if not in_sub_dict : return False if in_sub_dict . get ( 'subnet' ) == subnet : return True out_sub_dict = cls . get_out_ip_addr ( tenant_id ) if not out_sub_dict : return False if out_sub_dict . get ( 'subnet' ) == subnet : return True dummy_sub = cfg . firewall . fw_service_dummy_ip_subnet dummy_sub = dummy_sub . split ( '/' ) [ 0 ] return subnet == dummy_sub | Check if the subnet is created as a result of any FW operation . |
38,060 | def initialize_create_state_map ( self ) : self . fabric_state_map = { fw_const . INIT_STATE_STR : fw_const . OS_IN_NETWORK_STATE , fw_const . OS_IN_NETWORK_CREATE_FAIL : fw_const . OS_IN_NETWORK_STATE , fw_const . OS_IN_NETWORK_CREATE_SUCCESS : fw_const . OS_OUT_NETWORK_STATE , fw_const . OS_OUT_NETWORK_CREATE_FAIL : fw_const . OS_OUT_NETWORK_STATE , fw_const . OS_OUT_NETWORK_CREATE_SUCCESS : fw_const . OS_DUMMY_RTR_STATE , fw_const . OS_DUMMY_RTR_CREATE_FAIL : fw_const . OS_DUMMY_RTR_STATE , fw_const . OS_DUMMY_RTR_CREATE_SUCCESS : fw_const . DCNM_IN_NETWORK_STATE , fw_const . DCNM_IN_NETWORK_CREATE_FAIL : fw_const . DCNM_IN_NETWORK_STATE , fw_const . DCNM_IN_NETWORK_CREATE_SUCCESS : fw_const . DCNM_IN_PART_UPDATE_STATE , fw_const . DCNM_IN_PART_UPDATE_FAIL : fw_const . DCNM_IN_PART_UPDATE_STATE , fw_const . DCNM_IN_PART_UPDATE_SUCCESS : fw_const . DCNM_OUT_PART_STATE , fw_const . DCNM_OUT_PART_CREATE_FAIL : fw_const . DCNM_OUT_PART_STATE , fw_const . DCNM_OUT_PART_CREATE_SUCCESS : fw_const . DCNM_OUT_NETWORK_STATE , fw_const . DCNM_OUT_NETWORK_CREATE_FAIL : fw_const . DCNM_OUT_NETWORK_STATE , fw_const . DCNM_OUT_NETWORK_CREATE_SUCCESS : fw_const . DCNM_OUT_PART_UPDATE_STATE , fw_const . DCNM_OUT_PART_UPDATE_FAIL : fw_const . DCNM_OUT_PART_UPDATE_STATE , fw_const . DCNM_OUT_PART_UPDATE_SUCCESS : fw_const . FABRIC_PREPARE_DONE_STATE } | This is a mapping of create result message string to state . |
38,061 | def initialize_delete_state_map ( self ) : self . fabric_state_del_map = { fw_const . INIT_STATE_STR : fw_const . OS_IN_NETWORK_STATE , fw_const . OS_IN_NETWORK_DEL_FAIL : fw_const . OS_IN_NETWORK_STATE , fw_const . OS_IN_NETWORK_DEL_SUCCESS : fw_const . INIT_STATE , fw_const . OS_OUT_NETWORK_DEL_FAIL : fw_const . OS_OUT_NETWORK_STATE , fw_const . OS_OUT_NETWORK_DEL_SUCCESS : fw_const . OS_IN_NETWORK_STATE , fw_const . OS_DUMMY_RTR_DEL_FAIL : fw_const . OS_DUMMY_RTR_STATE , fw_const . OS_DUMMY_RTR_DEL_SUCCESS : fw_const . OS_OUT_NETWORK_STATE , fw_const . DCNM_IN_NETWORK_DEL_FAIL : fw_const . DCNM_IN_NETWORK_STATE , fw_const . DCNM_IN_NETWORK_DEL_SUCCESS : fw_const . OS_DUMMY_RTR_STATE , fw_const . DCNM_IN_PART_UPDDEL_FAIL : fw_const . DCNM_IN_PART_UPDATE_STATE , fw_const . DCNM_IN_PART_UPDDEL_SUCCESS : fw_const . DCNM_IN_NETWORK_STATE , fw_const . DCNM_OUT_PART_DEL_FAIL : fw_const . DCNM_OUT_PART_STATE , fw_const . DCNM_OUT_PART_DEL_SUCCESS : fw_const . DCNM_IN_PART_UPDATE_STATE , fw_const . DCNM_OUT_NETWORK_DEL_FAIL : fw_const . DCNM_OUT_NETWORK_STATE , fw_const . DCNM_OUT_NETWORK_DEL_SUCCESS : fw_const . DCNM_OUT_PART_STATE , fw_const . DCNM_OUT_PART_UPDDEL_FAIL : fw_const . DCNM_OUT_PART_UPDATE_STATE , fw_const . DCNM_OUT_PART_UPDDEL_SUCCESS : fw_const . DCNM_OUT_NETWORK_STATE } | This is a mapping of delete result message string to state . |
38,062 | def initialize_fsm ( self ) : self . fabric_fsm = { fw_const . INIT_STATE : [ self . init_state , self . init_state ] , fw_const . OS_IN_NETWORK_STATE : [ self . create_os_in_nwk , self . delete_os_in_nwk ] , fw_const . OS_OUT_NETWORK_STATE : [ self . create_os_out_nwk , self . delete_os_out_nwk ] , fw_const . OS_DUMMY_RTR_STATE : [ self . create_os_dummy_rtr , self . delete_os_dummy_rtr ] , fw_const . DCNM_IN_NETWORK_STATE : [ self . create_dcnm_in_nwk , self . delete_dcnm_in_nwk ] , fw_const . DCNM_IN_PART_UPDATE_STATE : [ self . update_dcnm_in_part , self . clear_dcnm_in_part ] , fw_const . DCNM_OUT_PART_STATE : [ self . create_dcnm_out_part , self . delete_dcnm_out_part ] , fw_const . DCNM_OUT_NETWORK_STATE : [ self . create_dcnm_out_nwk , self . delete_dcnm_out_nwk ] , fw_const . DCNM_OUT_PART_UPDATE_STATE : [ self . update_dcnm_out_part , self . clear_dcnm_out_part ] , fw_const . FABRIC_PREPARE_DONE_STATE : [ self . prepare_fabric_done , self . prepare_fabric_done ] } | Initializing the Finite State Machine . |
38,063 | def store_net_db ( self , tenant_id , net , net_dict , result ) : network_dict = { 'name' : net_dict . get ( 'name' ) , 'config_profile' : net_dict . get ( 'config_profile' ) , 'segmentation_id' : net_dict . get ( 'segmentation_id' ) , 'tenant_id' : tenant_id , 'fwd_mode' : net_dict . get ( 'fwd_mode' ) , 'vlan' : net_dict . get ( 'vlan_id' ) } self . add_network_db ( net , network_dict , fw_const . FW_CONST , result ) | Store service network in DB . |
38,064 | def store_fw_db ( self , tenant_id , net , subnet_dict , direc ) : serv_obj = self . get_service_obj ( tenant_id ) sub = subnet_dict . get ( 'allocation_pools' ) [ 0 ] . get ( 'start' ) serv_obj . update_fw_local_cache ( net , direc , sub ) serv_obj . commit_fw_db ( ) | Calls the service object routine to commit the FW entry to DB . |
38,065 | def update_fw_db_result ( self , tenant_id , os_status = None , dcnm_status = None , dev_status = None ) : serv_obj = self . get_service_obj ( tenant_id ) serv_obj . update_fw_local_result ( os_status , dcnm_status , dev_status ) serv_obj . commit_fw_db_result ( ) | Update the FW DB Result and commit it in DB . |
38,066 | def store_fw_db_router ( self , tenant_id , net_id , subnet_id , router_id , os_status ) : serv_obj = self . get_service_obj ( tenant_id ) serv_obj . update_fw_local_router ( net_id , subnet_id , router_id , os_status ) serv_obj . commit_fw_db ( ) serv_obj . commit_fw_db_result ( ) | Store the result of FW router operation in DB . |
38,067 | def store_net_fw_db ( self , tenant_id , net , net_dict , subnet_dict , direc , result , os_status = None , dcnm_status = None , dev_status = None ) : self . store_net_db ( tenant_id , net , net_dict , result ) self . store_fw_db ( tenant_id , net , subnet_dict , direc ) self . update_fw_db_result ( tenant_id , os_status = os_status , dcnm_status = dcnm_status , dev_status = dev_status ) | Save the entries in Network and Firewall DB . |
38,068 | def check_allocate_ip ( self , obj , direc ) : subnet_lst = self . os_helper . get_all_subnets_cidr ( no_mask = True ) ip_next = obj . allocate_subnet ( subnet_lst ) if ip_next is None : LOG . error ( "Unable to allocate a subnet for direction %s" , direc ) return ip_next | This function allocates a subnet from the pool . |
38,069 | def get_next_ip ( self , tenant_id , direc ) : if direc == 'in' : subnet_dict = self . get_in_ip_addr ( tenant_id ) else : subnet_dict = self . get_out_ip_addr ( tenant_id ) if subnet_dict : return subnet_dict if direc == 'in' : ip_next = self . check_allocate_ip ( self . service_in_ip , "in" ) else : ip_next = self . check_allocate_ip ( self . service_out_ip , "out" ) return { 'subnet' : ip_next , 'start' : self . get_start_ip ( ip_next ) , 'end' : self . get_end_ip ( ip_next ) , 'gateway' : self . get_gateway ( ip_next ) , 'sec_gateway' : self . get_secondary_gateway ( ip_next ) } | Retrieve the next available subnet . |
38,070 | def release_subnet ( self , cidr , direc ) : if direc == 'in' : self . service_in_ip . release_subnet ( cidr ) else : self . service_out_ip . release_subnet ( cidr ) | Routine to release a subnet from the DB . |
38,071 | def fill_dcnm_subnet_info ( self , tenant_id , subnet , start , end , gateway , sec_gateway , direc ) : serv_obj = self . get_service_obj ( tenant_id ) fw_dict = serv_obj . get_fw_dict ( ) fw_id = fw_dict . get ( 'fw_id' ) if direc == 'in' : name = fw_id [ 0 : 4 ] + fw_const . IN_SERVICE_SUBNET + ( fw_id [ len ( fw_id ) - 4 : ] ) else : name = fw_id [ 0 : 4 ] + fw_const . OUT_SERVICE_SUBNET + ( fw_id [ len ( fw_id ) - 4 : ] ) subnet_dict = { 'enable_dhcp' : False , 'tenant_id' : tenant_id , 'name' : name , 'cidr' : subnet + '/24' , 'gateway_ip' : gateway , 'secondary_gw' : sec_gateway , 'ip_version' : 4 } subnet_dict [ 'allocation_pools' ] = [ { 'start' : start , 'end' : end } ] return subnet_dict | Fills the DCNM subnet parameters . |
38,072 | def retrieve_dcnm_subnet_info ( self , tenant_id , direc ) : serv_obj = self . get_service_obj ( tenant_id ) subnet_dict = serv_obj . get_dcnm_subnet_dict ( direc ) return subnet_dict | Retrieves the DCNM subnet info for a tenant . |
38,073 | def alloc_retrieve_subnet_info ( self , tenant_id , direc ) : serv_obj = self . get_service_obj ( tenant_id ) subnet_dict = self . retrieve_dcnm_subnet_info ( tenant_id , direc ) if subnet_dict : return subnet_dict ip_subnet_dict = self . get_next_ip ( tenant_id , direc ) subnet_dict = self . fill_dcnm_subnet_info ( tenant_id , ip_subnet_dict . get ( 'subnet' ) , ip_subnet_dict . get ( 'start' ) , ip_subnet_dict . get ( 'end' ) , ip_subnet_dict . get ( 'gateway' ) , ip_subnet_dict . get ( 'sec_gateway' ) , direc ) serv_obj . store_dcnm_subnet_dict ( subnet_dict , direc ) return subnet_dict | Allocate and store Subnet . |
38,074 | def retrieve_dcnm_net_info ( self , tenant_id , direc ) : serv_obj = self . get_service_obj ( tenant_id ) net_dict = serv_obj . get_dcnm_net_dict ( direc ) return net_dict | Retrieves the DCNM network info for a tenant . |
38,075 | def fill_dcnm_net_info ( self , tenant_id , direc , vlan_id = 0 , segmentation_id = 0 ) : serv_obj = self . get_service_obj ( tenant_id ) fw_dict = serv_obj . get_fw_dict ( ) fw_id = fw_dict . get ( 'fw_id' ) net_dict = { 'status' : 'ACTIVE' , 'admin_state_up' : True , 'tenant_id' : tenant_id , 'provider:network_type' : 'local' , 'vlan_id' : vlan_id , 'segmentation_id' : segmentation_id } if vlan_id == 0 : net_dict . update ( { 'mob_domain' : False , 'mob_domain_name' : None } ) else : net_dict . update ( { 'mob_domain' : True } ) if direc == 'in' : name = fw_id [ 0 : 4 ] + fw_const . IN_SERVICE_NWK + ( fw_id [ len ( fw_id ) - 4 : ] ) net_dict . update ( { 'name' : name , 'part_name' : None , 'config_profile' : self . serv_host_prof , 'fwd_mode' : self . serv_host_mode } ) else : name = fw_id [ 0 : 4 ] + fw_const . OUT_SERVICE_NWK + ( fw_id [ len ( fw_id ) - 4 : ] ) net_dict . update ( { 'name' : name , 'part_name' : fw_const . SERV_PART_NAME , 'config_profile' : self . serv_ext_prof , 'fwd_mode' : self . serv_ext_mode } ) return net_dict | Fill DCNM network parameters . |
38,076 | def retrieve_network_info ( self , tenant_id , direc ) : serv_obj = self . get_service_obj ( tenant_id ) net_dict = self . retrieve_dcnm_net_info ( tenant_id , direc ) if net_dict : return net_dict net_dict = self . fill_dcnm_net_info ( tenant_id , direc ) serv_obj . store_dcnm_net_dict ( net_dict , direc ) return net_dict | Retrieve the DCNM Network information . |
38,077 | def alloc_seg ( self , net_id ) : segmentation_id = self . service_segs . allocate_segmentation_id ( net_id , source = fw_const . FW_CONST ) return segmentation_id | Allocates the segmentation ID . |
38,078 | def alloc_vlan ( self , net_id ) : vlan_id = self . service_vlans . allocate_segmentation_id ( net_id , source = fw_const . FW_CONST ) return vlan_id | Allocates the vlan ID . |
38,079 | def update_subnet_db_info ( self , tenant_id , direc , net_id , subnet_id ) : subnet_dict = self . retrieve_dcnm_subnet_info ( tenant_id , direc ) if not subnet_dict : LOG . error ( "Subnet dict not found for tenant %s" , tenant_id ) return subnet = subnet_dict [ 'cidr' ] . split ( '/' ) [ 0 ] if direc == 'in' : self . service_in_ip . update_subnet ( subnet , net_id , subnet_id ) else : self . service_out_ip . update_subnet ( subnet , net_id , subnet_id ) | Update the subnet DB with Net and Subnet ID given the subnet . |
38,080 | def update_net_info ( self , tenant_id , direc , vlan_id , segmentation_id ) : serv_obj = self . get_service_obj ( tenant_id ) net_dict = self . update_dcnm_net_info ( tenant_id , direc , vlan_id , segmentation_id ) serv_obj . store_dcnm_net_dict ( net_dict , direc ) return net_dict | Update the DCNM netinfo with vlan and segmentation ID . |
38,081 | def _create_service_nwk ( self , tenant_id , tenant_name , direc ) : net_dict = self . retrieve_dcnm_net_info ( tenant_id , direc ) net = utils . Dict2Obj ( net_dict ) subnet_dict = self . retrieve_dcnm_subnet_info ( tenant_id , direc ) subnet = utils . Dict2Obj ( subnet_dict ) try : self . dcnm_obj . create_service_network ( tenant_name , net , subnet ) except dexc . DfaClientRequestFailed : LOG . error ( "Failed to create network in DCNM %s" , direc ) return False return True | Function to create the service in network in DCNM . |
38,082 | def _delete_service_nwk ( self , tenant_id , tenant_name , direc ) : net_dict = { } if direc == 'in' : seg , vlan = self . get_in_seg_vlan ( tenant_id ) net_dict [ 'part_name' ] = None else : seg , vlan = self . get_out_seg_vlan ( tenant_id ) net_dict [ 'part_name' ] = fw_const . SERV_PART_NAME net_dict [ 'segmentation_id' ] = seg net_dict [ 'vlan' ] = vlan net = utils . Dict2Obj ( net_dict ) ret = True try : self . dcnm_obj . delete_service_network ( tenant_name , net ) except dexc . DfaClientRequestFailed : LOG . error ( "Failed to delete network in DCNM %s" , direc ) ret = False return ret | Function to delete the service in network in DCNM . |
38,083 | def get_dummy_router_net ( self , tenant_id ) : if tenant_id not in self . service_attr : LOG . error ( "Fabric not prepared for tenant %s" , tenant_id ) return tenant_obj = self . get_service_obj ( tenant_id ) return tenant_obj . get_dummy_router_net ( ) | Retrieves the dummy router information from service object . |
38,084 | def _create_out_partition ( self , tenant_id , tenant_name ) : vrf_prof_str = self . serv_part_vrf_prof self . dcnm_obj . create_partition ( tenant_name , fw_const . SERV_PART_NAME , None , vrf_prof_str , desc = "Service Partition" ) | Function to create a service partition . |
38,085 | def _update_partition_srvc_node_ip ( self , tenant_name , srvc_ip , vrf_prof = None , part_name = None ) : self . dcnm_obj . update_project ( tenant_name , part_name , service_node_ip = srvc_ip , vrf_prof = vrf_prof , desc = "Service Partition" ) | Function to update srvc_node address of partition . |
38,086 | def _update_partition_dci_id ( self , tenant_name , dci_id , vrf_prof = None , part_name = None ) : self . dcnm_obj . update_project ( tenant_name , part_name , dci_id = dci_id , vrf_prof = vrf_prof ) | Function to update DCI ID of partition . |
38,087 | def _delete_partition ( self , tenant_id , tenant_name ) : self . dcnm_obj . delete_partition ( tenant_name , fw_const . SERV_PART_NAME ) | Function to delete a service partition . |
38,088 | def allocate_seg_vlan ( self , net_id , is_fw_virt , direc , tenant_id ) : seg = self . alloc_seg ( net_id ) vlan = 0 if not is_fw_virt : vlan = self . alloc_vlan ( net_id ) self . update_net_info ( tenant_id , direc , vlan , seg ) | allocate segmentation ID and VLAN ID . |
38,089 | def create_openstack_network ( self , subnet , network , tenant_id , tenant_name , direction ) : try : gw = str ( netaddr . IPAddress ( subnet [ 'cidr' ] . split ( '/' ) [ 0 ] ) + 2 ) net_id , subnet_id = self . os_helper . create_network ( network [ 'name' ] , tenant_id , subnet [ 'cidr' ] , gw = gw ) if net_id is None or subnet_id is None : self . release_subnet ( subnet [ 'cidr' ] , direction ) return net_id , subnet_id except Exception as exc : self . release_subnet ( subnet [ 'cidr' ] , direction ) LOG . error ( "Create network for tenant %(tenant)s " "network %(name)s direction %(dir)s failed " "exc %(exc)s " , { 'tenant' : tenant_name , 'name' : network [ 'name' ] , 'dir' : direction , 'exc' : str ( exc ) } ) return None , None | Helper function to create openstack network . |
38,090 | def _create_os_nwk ( self , tenant_id , tenant_name , direc , is_fw_virt = False ) : subnet = self . alloc_retrieve_subnet_info ( tenant_id , direc ) network = self . retrieve_network_info ( tenant_id , direc ) net_id , subnet_id = self . create_openstack_network ( subnet , network , tenant_id , tenant_name , direc ) if not net_id or not subnet_id : return net_id , subnet_id self . allocate_seg_vlan ( net_id , is_fw_virt , direc , tenant_id ) self . update_subnet_db_info ( tenant_id , direc , net_id , subnet_id ) return net_id , subnet_id | Function to create Openstack network . |
38,091 | def _attach_dummy_intf_rtr ( self , tenant_id , tenant_name , rtr_id ) : serv_obj = self . get_service_obj ( tenant_id ) fw_dict = serv_obj . get_fw_dict ( ) fw_id = fw_dict . get ( 'fw_id' ) rtr_nwk = fw_id [ 0 : 4 ] + fw_const . DUMMY_SERVICE_NWK + ( fw_id [ len ( fw_id ) - 4 : ] ) net_id , subnet_id = self . os_helper . create_network ( rtr_nwk , tenant_id , self . servicedummy_ip_subnet ) if net_id is None or subnet_id is None : return None , None net_dict = { } net_dict [ 'name' ] = rtr_nwk self . store_net_db ( tenant_id , net_id , net_dict , 'SUCCESS' ) subnet_lst = set ( ) subnet_lst . add ( subnet_id ) if rtr_id is None : self . os_helper . delete_network ( rtr_nwk , tenant_id , subnet_id , net_id ) return None , None ret = self . os_helper . add_intf_router ( rtr_id , tenant_id , subnet_lst ) if not ret : self . os_helper . delete_network ( rtr_nwk , tenant_id , subnet_id , net_id ) return None , None return net_id , subnet_id | Function to create a dummy router and interface . |
38,092 | def _delete_dummy_intf_rtr ( self , tenant_id , tenant_name , rtr_id ) : dummy_router_dict = self . get_dummy_router_net ( tenant_id ) ret = self . delete_os_dummy_rtr_nwk ( dummy_router_dict . get ( 'router_id' ) , dummy_router_dict . get ( 'net_id' ) , dummy_router_dict . get ( 'subnet_id' ) ) self . delete_network_db ( dummy_router_dict . get ( 'net_id' ) ) return ret | Function to delete a dummy interface of a router . |
38,093 | def create_os_in_nwk ( self , tenant_id , fw_dict , is_fw_virt = False ) : tenant_name = fw_dict . get ( 'tenant_name' ) try : net , subnet = self . _create_os_nwk ( tenant_id , tenant_name , "in" , is_fw_virt = is_fw_virt ) if net is None or subnet is None : return False except Exception as exc : LOG . error ( "Creation of In Openstack Network failed tenant " "%(tenant)s, Exception %(exc)s" , { 'tenant' : tenant_id , 'exc' : str ( exc ) } ) return False ret = fw_const . OS_IN_NETWORK_CREATE_SUCCESS net_dict = self . retrieve_dcnm_net_info ( tenant_id , "in" ) subnet_dict = self . retrieve_dcnm_subnet_info ( tenant_id , "in" ) if not net_dict or not subnet_dict : LOG . error ( "Allocation of net,subnet failed Len net %(len_net)s" "sub %(len_sub)s" , { 'len_net' : len ( net_dict ) , 'len_sub' : len ( subnet_dict ) } ) ret = fw_const . OS_IN_NETWORK_CREATE_FAIL self . store_net_fw_db ( tenant_id , net , net_dict , subnet_dict , "in" , 'SUCCESS' , os_status = ret ) return True | Create the Openstack IN network and stores the values in DB . |
38,094 | def _delete_os_nwk ( self , tenant_id , tenant_name , direc , is_fw_virt = False ) : serv_obj = self . get_service_obj ( tenant_id ) fw_dict = serv_obj . get_fw_dict ( ) fw_id = fw_dict . get ( 'fw_id' ) fw_data , fw_data_dict = self . get_fw ( fw_id ) if fw_data is None : LOG . error ( "Unable to get fw_data for tenant %s" , tenant_name ) return False if direc == 'in' : net_id = fw_data . in_network_id seg , vlan = self . get_in_seg_vlan ( tenant_id ) subnet_dict = self . get_in_ip_addr ( tenant_id ) else : net_id = fw_data . out_network_id seg , vlan = self . get_out_seg_vlan ( tenant_id ) subnet_dict = self . get_out_ip_addr ( tenant_id ) sub = subnet_dict . get ( 'subnet' ) try : ret = self . os_helper . delete_network_all_subnets ( net_id ) if not ret : LOG . error ( "Delete network for ID %(net)s direct %(dir)s " "failed" , { 'net' : net_id , 'dir' : direc } ) return False except Exception as exc : LOG . error ( "Delete network for ID %(net)s direct %(dir)s failed" " Exc %(exc)s" , { 'net' : net_id , 'dir' : direc , 'exc' : exc } ) return False if not is_fw_virt : self . service_vlans . release_segmentation_id ( vlan ) self . service_segs . release_segmentation_id ( seg ) self . release_subnet ( sub , direc ) self . delete_network_db ( net_id ) return True | Delete the network created in Openstack . |
38,095 | def delete_os_in_nwk ( self , tenant_id , fw_dict , is_fw_virt = False ) : ret = True tenant_name = fw_dict . get ( 'tenant_name' ) try : ret = self . _delete_os_nwk ( tenant_id , tenant_name , "in" , is_fw_virt = is_fw_virt ) except Exception as exc : LOG . error ( "Deletion of In Openstack Network failed tenant " "%(tenant)s Exception %(exc)s" , { 'tenant' : tenant_id , 'exc' : str ( exc ) } ) ret = False if ret : res = fw_const . OS_IN_NETWORK_DEL_SUCCESS else : res = fw_const . OS_IN_NETWORK_DEL_FAIL self . update_fw_db_result ( tenant_id , os_status = res ) return ret | Deletes the Openstack In network and update the DB . |
38,096 | def delete_os_out_nwk ( self , tenant_id , fw_dict , is_fw_virt = False ) : ret = True tenant_name = fw_dict . get ( 'tenant_name' ) try : ret = self . _delete_os_nwk ( tenant_id , tenant_name , "out" , is_fw_virt = is_fw_virt ) except Exception as exc : LOG . error ( "Deletion of Out Openstack Network failed tenant " "%(tenant)s, Exception %(exc)s" , { 'tenant' : tenant_id , 'exc' : str ( exc ) } ) ret = False if ret : res = fw_const . OS_OUT_NETWORK_DEL_SUCCESS else : res = fw_const . OS_OUT_NETWORK_DEL_FAIL self . update_fw_db_result ( tenant_id , os_status = res ) return ret | Deletes the Openstack Out network and update the DB . |
38,097 | def create_os_dummy_rtr ( self , tenant_id , fw_dict , is_fw_virt = False ) : res = fw_const . OS_DUMMY_RTR_CREATE_SUCCESS tenant_name = fw_dict . get ( 'tenant_name' ) try : rtr_id = fw_dict . get ( 'router_id' ) if rtr_id is None : LOG . error ( "Invalid router id, attaching dummy interface" " failed" ) return False if is_fw_virt : net_id = subnet_id = None else : net_id , subnet_id = ( self . _attach_dummy_intf_rtr ( tenant_id , tenant_name , rtr_id ) ) if net_id is None or subnet_id is None : LOG . error ( "Invalid net_id or subnet_id, creating dummy" " interface failed" ) return False except Exception as exc : LOG . error ( "Creation of Openstack Router failed " "tenant %(tenant)s, Exception %(exc)s" , { 'tenant' : tenant_id , 'exc' : str ( exc ) } ) res = fw_const . OS_DUMMY_RTR_CREATE_FAIL self . store_fw_db_router ( tenant_id , net_id , subnet_id , rtr_id , res ) return True | Create the dummy interface and attach it to router . |
38,098 | def delete_os_dummy_rtr ( self , tenant_id , fw_dict , is_fw_virt = False ) : ret = True tenant_name = fw_dict . get ( 'tenant_name' ) try : rtr_id = fw_dict . get ( 'router_id' ) if not rtr_id : LOG . error ( "Invalid router id, deleting dummy interface" " failed" ) return False if not is_fw_virt : ret = self . _delete_dummy_intf_rtr ( tenant_id , tenant_name , rtr_id ) except Exception as exc : LOG . error ( "Deletion of Openstack Router failed tenant " "%(tenant)s, Exception %(exc)s" , { 'tenant' : tenant_id , 'exc' : str ( exc ) } ) ret = False if ret : res = fw_const . OS_DUMMY_RTR_DEL_SUCCESS else : res = fw_const . OS_DUMMY_RTR_DEL_FAIL self . update_fw_db_result ( tenant_id , os_status = res ) return ret | Delete the Openstack Dummy router and store the info in DB . |
38,099 | def create_dcnm_in_nwk ( self , tenant_id , fw_dict , is_fw_virt = False ) : tenant_name = fw_dict . get ( 'tenant_name' ) ret = self . _create_service_nwk ( tenant_id , tenant_name , 'in' ) if ret : res = fw_const . DCNM_IN_NETWORK_CREATE_SUCCESS LOG . info ( "In Service network created for tenant %s" , tenant_id ) else : res = fw_const . DCNM_IN_NETWORK_CREATE_FAIL LOG . info ( "In Service network create failed for tenant %s" , tenant_id ) self . update_fw_db_result ( tenant_id , dcnm_status = res ) return ret | Create the DCNM In Network and store the result in DB . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.