idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
38,700
def create_iplist_with_data ( name , iplist ) : iplist = IPList . create ( name = name , iplist = iplist ) return iplist
Create an IPList with initial list contents .
38,701
def enable ( self , ospf_profile = None , router_id = None ) : ospf_profile = element_resolver ( ospf_profile ) if ospf_profile else OSPFProfile ( 'Default OSPFv2 Profile' ) . href self . data . update ( enabled = True , ospfv2_profile_ref = ospf_profile , router_id = router_id )
Enable OSPF on this engine . For master engines enable OSPF on the virtual firewall .
38,702
def create ( cls , name , interface_settings_ref = None , area_id = 1 , area_type = 'normal' , outbound_filters = None , inbound_filters = None , shortcut_capable_area = False , ospfv2_virtual_links_endpoints_container = None , ospf_abr_substitute_container = None , comment = None , ** kwargs ) : interface_settings_ref = element_resolver ( interface_settings_ref ) or OSPFInterfaceSetting ( 'Default OSPFv2 Interface Settings' ) . href if 'inbound_filters_ref' in kwargs : inbound_filters = kwargs . get ( 'inbound_filters_ref' ) if 'outbound_filters_ref' in kwargs : outbound_filters = kwargs . get ( 'outbound_filters_ref' ) json = { 'name' : name , 'area_id' : area_id , 'area_type' : area_type , 'comment' : comment , 'inbound_filters_ref' : element_resolver ( inbound_filters ) , 'interface_settings_ref' : interface_settings_ref , 'ospf_abr_substitute_container' : ospf_abr_substitute_container , 'ospfv2_virtual_links_endpoints_container' : ospfv2_virtual_links_endpoints_container , 'outbound_filters_ref' : element_resolver ( outbound_filters ) , 'shortcut_capable_area' : shortcut_capable_area } return ElementCreator ( cls , json )
Create a new OSPF Area
38,703
def create ( cls , name , dead_interval = 40 , hello_interval = 10 , hello_interval_type = 'normal' , dead_multiplier = 1 , mtu_mismatch_detection = True , retransmit_interval = 5 , router_priority = 1 , transmit_delay = 1 , authentication_type = None , password = None , key_chain_ref = None ) : json = { 'name' : name , 'authentication_type' : authentication_type , 'password' : password , 'key_chain_ref' : element_resolver ( key_chain_ref ) , 'dead_interval' : dead_interval , 'dead_multiplier' : dead_multiplier , 'hello_interval' : hello_interval , 'hello_interval_type' : hello_interval_type , 'mtu_mismatch_detection' : mtu_mismatch_detection , 'retransmit_interval' : retransmit_interval , 'router_priority' : router_priority , 'transmit_delay' : transmit_delay } return ElementCreator ( cls , json )
Create custom OSPF interface settings profile
38,704
def create ( cls , name , key_chain_entry ) : key_chain_entry = key_chain_entry or [ ] json = { 'name' : name , 'ospfv2_key_chain_entry' : key_chain_entry } return ElementCreator ( cls , json )
Create a key chain with list of keys
38,705
def create ( cls , name , abr_type = 'cisco' , auto_cost_bandwidth = 100 , deprecated_algorithm = False , initial_delay = 200 , initial_hold_time = 1000 , max_hold_time = 10000 , shutdown_max_metric_lsa = 0 , startup_max_metric_lsa = 0 ) : json = { 'name' : name , 'abr_type' : abr_type , 'auto_cost_bandwidth' : auto_cost_bandwidth , 'deprecated_algorithm' : deprecated_algorithm , 'initial_delay' : initial_delay , 'initial_hold_time' : initial_hold_time , 'max_hold_time' : max_hold_time , 'shutdown_max_metric_lsa' : shutdown_max_metric_lsa , 'startup_max_metric_lsa' : startup_max_metric_lsa } return ElementCreator ( cls , json )
Create custom Domain Settings
38,706
def exception ( function ) : @ functools . wraps ( function ) def wrapper ( * exception , ** kwargs ) : result = function ( ** kwargs ) if exception : result . exception = exception [ 0 ] return result return wrapper
If exception was specified for prepared_request inject this into SMCRequest so it can be used for return if needed .
38,707
def create ( cls , name , mgmt_ip , mgmt_network , mgmt_interface = 0 , inline_interface = '1-2' , logical_interface = 'default_eth' , log_server_ref = None , domain_server_address = None , zone_ref = None , enable_antivirus = False , enable_gti = False , comment = None ) : interfaces = [ ] interface_id , second_interface_id = inline_interface . split ( '-' ) l2 = { 'interface_id' : interface_id , 'interface' : 'inline_interface' , 'second_interface_id' : second_interface_id , 'logical_interface_ref' : logical_interface } interfaces . append ( { 'physical_interface' : Layer2PhysicalInterface ( ** l2 ) } ) layer3 = { 'interface_id' : mgmt_interface , 'zone_ref' : zone_ref , 'interfaces' : [ { 'nodes' : [ { 'address' : mgmt_ip , 'network_value' : mgmt_network , 'nodeid' : 1 } ] } ] } interfaces . append ( { 'physical_interface' : Layer3PhysicalInterface ( primary_mgt = mgmt_interface , ** layer3 ) } ) engine = super ( Layer2Firewall , cls ) . _create ( name = name , node_type = 'fwlayer2_node' , physical_interfaces = interfaces , domain_server_address = domain_server_address , log_server_ref = log_server_ref , nodes = 1 , enable_gti = enable_gti , enable_antivirus = enable_antivirus , comment = comment ) try : return ElementCreator ( cls , json = engine ) except CreateElementFailed as e : raise CreateEngineFailed ( e )
Create a single layer 2 firewall with management interface and inline pair
38,708
def create ( cls , name , master_type , mgmt_ip , mgmt_network , mgmt_interface = 0 , log_server_ref = None , zone_ref = None , domain_server_address = None , enable_gti = False , enable_antivirus = False , comment = None ) : interface = { 'interface_id' : mgmt_interface , 'interfaces' : [ { 'nodes' : [ { 'address' : mgmt_ip , 'network_value' : mgmt_network } ] } ] , 'zone_ref' : zone_ref , 'comment' : comment } interface = Layer3PhysicalInterface ( primary_mgt = mgmt_interface , primary_heartbeat = mgmt_interface , ** interface ) engine = super ( MasterEngine , cls ) . _create ( name = name , node_type = 'master_node' , physical_interfaces = [ { 'physical_interface' : interface } ] , domain_server_address = domain_server_address , log_server_ref = log_server_ref , nodes = 1 , enable_gti = enable_gti , enable_antivirus = enable_antivirus , comment = comment ) engine . update ( master_type = master_type , cluster_mode = 'standby' ) try : return ElementCreator ( cls , json = engine ) except CreateElementFailed as e : raise CreateEngineFailed ( e )
Create a Master Engine with management interface
38,709
def create ( cls , name , master_type , macaddress , nodes , mgmt_interface = 0 , log_server_ref = None , domain_server_address = None , enable_gti = False , enable_antivirus = False , comment = None , ** kw ) : primary_mgt = primary_heartbeat = mgmt_interface interface = { 'interface_id' : mgmt_interface , 'interfaces' : [ { 'nodes' : nodes } ] , 'macaddress' : macaddress , } interface = Layer3PhysicalInterface ( primary_mgt = primary_mgt , primary_heartbeat = primary_heartbeat , ** interface ) engine = super ( MasterEngineCluster , cls ) . _create ( name = name , node_type = 'master_node' , physical_interfaces = [ { 'physical_interface' : interface } ] , domain_server_address = domain_server_address , log_server_ref = log_server_ref , nodes = len ( nodes ) , enable_gti = enable_gti , enable_antivirus = enable_antivirus , comment = comment ) engine . update ( master_type = master_type , cluster_mode = 'standby' ) try : return ElementCreator ( cls , json = engine ) except CreateElementFailed as e : raise CreateEngineFailed ( e )
Create Master Engine Cluster
38,710
def get_all_loopbacks ( engine ) : data = [ ] if 'fw_cluster' in engine . type : for cvi in engine . data . get ( 'loopback_cluster_virtual_interface' , [ ] ) : data . append ( LoopbackClusterInterface ( cvi , engine ) ) for node in engine . nodes : for lb in node . data . get ( 'loopback_node_dedicated_interface' , [ ] ) : data . append ( LoopbackInterface ( lb , engine ) ) return data
Get all loopback interfaces for a given engine
38,711
def add ( self , interface_id , virtual_mapping = None , virtual_resource_name = None , zone_ref = None , comment = None ) : interface = Layer3PhysicalInterface ( engine = self . _engine , interface_id = interface_id , zone_ref = zone_ref , comment = comment , virtual_resource_name = virtual_resource_name , virtual_mapping = virtual_mapping ) return self . _engine . add_interface ( interface )
Add single physical interface with interface_id . Use other methods to fully add an interface configuration based on engine type . Virtual mapping and resource are only used in Virtual Engines .
38,712
def add_layer3_vlan_cluster_interface ( self , interface_id , vlan_id , nodes = None , cluster_virtual = None , network_value = None , macaddress = None , cvi_mode = 'packetdispatch' , zone_ref = None , comment = None , ** kw ) : interfaces = { 'nodes' : nodes if nodes else [ ] , 'cluster_virtual' : cluster_virtual , 'network_value' : network_value } interfaces . update ( ** kw ) _interface = { 'interface_id' : interface_id , 'interfaces' : [ interfaces ] , 'macaddress' : macaddress , 'cvi_mode' : cvi_mode if macaddress else 'none' , 'zone_ref' : zone_ref , 'comment' : comment } try : interface = self . _engine . interface . get ( interface_id ) vlan = interface . vlan_interface . get ( vlan_id ) if vlan is None : interfaces . update ( vlan_id = vlan_id ) interface . _add_interface ( ** _interface ) else : for k in ( 'macaddress' , 'cvi_mode' ) : _interface . pop ( k ) _interface . update ( interface_id = '{}.{}' . format ( interface_id , vlan_id ) ) vlan . _add_interface ( ** _interface ) return interface . update ( ) except InterfaceNotFound : interfaces . update ( vlan_id = vlan_id ) interface = ClusterPhysicalInterface ( ** _interface ) return self . _engine . add_interface ( interface )
Add IP addresses to VLANs on a firewall cluster . The minimum params required are interface_id and vlan_id . To create a VLAN interface with a CVI specify cluster_virtual cluster_mask and macaddress .
38,713
def add_dhcp_interface ( self , interface_id , dynamic_index , zone_ref = None , vlan_id = None , comment = None ) : _interface = { 'interface_id' : interface_id , 'interfaces' : [ { 'nodes' : [ { 'dynamic' : True , 'dynamic_index' : dynamic_index } ] , 'vlan_id' : vlan_id } ] , 'comment' : comment , 'zone_ref' : zone_ref } if 'single_fw' in self . _engine . type : _interface . update ( interface = 'single_node_interface' ) try : interface = self . _engine . interface . get ( interface_id ) vlan = interface . vlan_interface . get ( vlan_id ) if vlan is None : interface . _add_interface ( ** _interface ) interface . update ( ) except InterfaceNotFound : interface = Layer3PhysicalInterface ( ** _interface ) return self . _engine . add_interface ( interface )
Add a DHCP interface on a single FW
38,714
def add_cluster_interface_on_master_engine ( self , interface_id , macaddress , nodes , zone_ref = None , vlan_id = None , comment = None ) : _interface = { 'interface_id' : interface_id , 'macaddress' : macaddress , 'interfaces' : [ { 'nodes' : nodes if nodes else [ ] , 'vlan_id' : vlan_id } ] , 'zone_ref' : zone_ref , 'comment' : comment } try : interface = self . _engine . interface . get ( interface_id ) vlan = interface . vlan_interface . get ( vlan_id ) if vlan is None : interface . _add_interface ( ** _interface ) interface . update ( ) except InterfaceNotFound : interface = Layer3PhysicalInterface ( ** _interface ) return self . _engine . add_interface ( interface )
Add a cluster address specific to a master engine . Master engine clusters will not use CVI interfaces like normal layer 3 FW clusters instead each node has a unique address and share a common macaddress . Adding multiple addresses to an interface is not supported with this method .
38,715
def add_tunnel_interface ( self , interface_id , address , network_value , zone_ref = None , comment = None ) : interfaces = [ { 'nodes' : [ { 'address' : address , 'network_value' : network_value } ] } ] interface = { 'interface_id' : interface_id , 'interfaces' : interfaces , 'zone_ref' : zone_ref , 'comment' : comment } tunnel_interface = TunnelInterface ( ** interface ) self . _engine . add_interface ( tunnel_interface )
Creates a tunnel interface for a virtual engine .
38,716
def transform_login ( config ) : verify = True if config . pop ( 'smc_ssl' , None ) : scheme = 'https' verify = config . pop ( 'ssl_cert_file' , None ) if config . pop ( 'verify_ssl' , None ) : if not verify : verify = False else : verify = False else : scheme = 'http' config . pop ( 'verify_ssl' , None ) config . pop ( 'ssl_cert_file' , None ) verify = False transformed = { } url = '{}://{}:{}' . format ( scheme , config . pop ( 'smc_address' , None ) , config . pop ( 'smc_port' , None ) ) timeout = config . pop ( 'timeout' , None ) if timeout : try : timeout = int ( timeout ) except ValueError : timeout = None api_version = config . pop ( 'api_version' , None ) if api_version : try : float ( api_version ) except ValueError : api_version = None transformed . update ( url = url , api_key = config . pop ( 'smc_apikey' , None ) , api_version = api_version , verify = verify , timeout = timeout , domain = config . pop ( 'domain' , None ) ) if config : transformed . update ( kwargs = config ) return transformed
Parse login data as dict . Called from load_from_file and also can be used when collecting information from other sources as well .
38,717
def download ( self , timeout = 5 , wait_for_finish = False ) : return Task . execute ( self , 'download' , timeout = timeout , wait_for_finish = wait_for_finish )
Download Package or Engine Update
38,718
def activate ( self , resource = None , timeout = 3 , wait_for_finish = False ) : return Task . execute ( self , 'activate' , json = { 'resource' : resource } , timeout = timeout , wait_for_finish = wait_for_finish )
Activate this package on the SMC
38,719
def create ( cls , name , sandbox_data_center , portal_username = None , comment = None ) : json = { 'name' : name , 'sandbox_data_center' : element_resolver ( sandbox_data_center ) , 'portal_username' : portal_username if portal_username else '' , 'comment' : comment } return ElementCreator ( cls , json )
Create a Sandbox Service element
38,720
def available_api_versions ( base_url , timeout = 10 , verify = True ) : try : r = requests . get ( '%s/api' % base_url , timeout = timeout , verify = verify ) if r . status_code == 200 : j = json . loads ( r . text ) versions = [ ] for version in j [ 'version' ] : versions . append ( version [ 'rel' ] ) return versions raise SMCConnectionError ( 'Invalid status received while getting entry points from SMC. ' 'Status code received %s. Reason: %s' % ( r . status_code , r . reason ) ) except requests . exceptions . RequestException as e : raise SMCConnectionError ( e )
Get all available API versions for this SMC
38,721
def get_api_version ( base_url , api_version = None , timeout = 10 , verify = True ) : versions = available_api_versions ( base_url , timeout , verify ) newest_version = max ( [ float ( i ) for i in versions ] ) if api_version is None : api_version = newest_version else : if api_version not in versions : api_version = newest_version return api_version
Get the API version specified or resolve the latest version
38,722
def _register ( self , session ) : if session . session_id : self . _sessions [ session . name ] = session
Register a session
38,723
def _deregister ( self , session ) : if session in self : self . _sessions . pop ( self . _get_session_key ( session ) , None )
Deregister a session .
38,724
def login ( self , url = None , api_key = None , login = None , pwd = None , api_version = None , timeout = None , verify = True , alt_filepath = None , domain = None , ** kwargs ) : params = { } if not url or ( not api_key and not ( login and pwd ) ) : try : params = load_from_file ( alt_filepath ) if alt_filepath is not None else load_from_file ( ) logger . debug ( 'Read config data from file: %s' , params ) except ConfigLoadError : params = load_from_environ ( ) logger . debug ( 'Read config data from environ: %s' , params ) params = params or dict ( url = url , api_key = api_key , login = login , pwd = pwd , api_version = api_version , verify = verify , timeout = timeout , domain = domain , kwargs = kwargs or { } ) if self . manager and ( self . session and self in self . manager ) : logger . info ( 'An attempt to log in occurred when a session already ' 'exists, bypassing login for session: %s' % self ) return self . _params = { k : v for k , v in params . items ( ) if v is not None } verify_ssl = self . _params . get ( 'verify' , True ) self . _params . update ( api_version = get_api_version ( self . url , self . api_version , self . timeout , verify_ssl ) ) extra_args = self . _params . get ( 'kwargs' , { } ) retry_on_busy = extra_args . pop ( 'retry_on_busy' , False ) request = self . _build_auth_request ( verify_ssl , ** extra_args ) self . _session = self . _get_session ( request ) self . session . verify = verify_ssl if retry_on_busy : self . set_retry_on_busy ( ) load_entry_points ( self ) self . manager . _register ( self ) logger . debug ( 'Login succeeded for admin: %s in domain: %s, session: %s' , self . name , self . domain , self . session_id )
Login to SMC API and retrieve a valid session . Sessions use a pool connection manager to provide dynamic scalability during times of increased load . Each session is managed by a global session manager making it possible to have more than one session per interpreter .
38,725
def _build_auth_request ( self , verify = False , ** kwargs ) : json = { 'domain' : self . domain } credential = self . credential params = { } if credential . provider_name . startswith ( 'lms' ) : params = dict ( login = credential . _login , pwd = credential . _pwd ) else : json . update ( authenticationkey = credential . _api_key ) if kwargs : json . update ( ** kwargs ) self . _extra_args . update ( ** kwargs ) request = dict ( url = self . credential . get_provider_entry_point ( self . url , self . api_version ) , json = json , params = params , headers = { 'content-type' : 'application/json' } , verify = verify ) return request
Build the authentication request to SMC
38,726
def add ( self , data ) : if self . is_none or self . is_any : self . clear ( ) self . data [ self . typeof ] = [ ] try : self . get ( self . typeof ) . append ( element_resolver ( data ) ) except ElementNotFound : pass
Add a single entry to field .
38,727
def all ( self ) : if not self . is_any and not self . is_none : return [ Element . from_href ( href ) for href in self . get ( self . typeof ) ] return [ ]
Return all destinations for this rule . Elements returned are of the object type for the given element for further introspection .
38,728
def create ( cls , name , user = None , network_element = None , domain_name = None , zone = None , executable = None ) : ref_list = [ ] if user : pass if network_element : ref_list . append ( network_element . href ) if domain_name : ref_list . append ( domain_name . href ) if zone : ref_list . append ( zone . href ) if executable : pass json = { 'name' : name , 'ref' : ref_list } return ElementCreator ( cls , json )
Create a match expression
38,729
def enable ( self ) : self . update ( antivirus_enabled = True , virus_mirror = 'update.nai.com/Products/CommonUpdater' if not self . get ( 'virus_mirror' ) else self . virus_mirror , antivirus_update_time = self . antivirus_update_time if self . get ( 'antivirus_update_time' ) else 21600000 )
Enable antivirus on the engine
38,730
def disable ( self ) : self . engine . data . update ( sandbox_type = 'none' ) self . pop ( 'cloud_sandbox_settings' , None ) self . pop ( 'sandbox_settings' , None )
Disable the sandbox on this engine .
38,731
def bind_license ( self , license_item_id = None ) : params = { 'license_item_id' : license_item_id } self . make_request ( LicenseError , method = 'create' , resource = 'bind' , params = params )
Auto bind license uses dynamic if POS is not found
38,732
def initial_contact ( self , enable_ssh = True , time_zone = None , keyboard = None , install_on_server = None , filename = None , as_base64 = False ) : result = self . make_request ( NodeCommandFailed , method = 'create' , raw_result = True , resource = 'initial_contact' , params = { 'enable_ssh' : enable_ssh } ) if result . content : if as_base64 : result . content = b64encode ( result . content ) if filename : try : save_to_file ( filename , result . content ) except IOError as e : raise NodeCommandFailed ( 'Error occurred when attempting to save initial ' 'contact to file: {}' . format ( e ) ) return result . content
Allows to save the initial contact for for the specified node
38,733
def go_offline ( self , comment = None ) : self . make_request ( NodeCommandFailed , method = 'update' , resource = 'go_offline' , params = { 'comment' : comment } )
Executes a Go - Offline operation on the specified node
38,734
def lock_online ( self , comment = None ) : self . make_request ( NodeCommandFailed , method = 'update' , resource = 'lock_online' , params = { 'comment' : comment } )
Executes a Lock - Online operation on the specified node
38,735
def reset_user_db ( self , comment = None ) : self . make_request ( NodeCommandFailed , method = 'update' , resource = 'reset_user_db' , params = { 'comment' : comment } )
Executes a Send Reset LDAP User DB Request operation on this node .
38,736
def reboot ( self , comment = None ) : self . make_request ( NodeCommandFailed , method = 'update' , resource = 'reboot' , params = { 'comment' : comment } )
Send reboot command to this node .
38,737
def ssh ( self , enable = True , comment = None ) : self . make_request ( NodeCommandFailed , method = 'update' , resource = 'ssh' , params = { 'enable' : enable , 'comment' : comment } )
Enable or disable SSH
38,738
def change_ssh_pwd ( self , pwd = None , comment = None ) : self . make_request ( NodeCommandFailed , method = 'update' , resource = 'change_ssh_pwd' , params = { 'comment' : comment } , json = { 'value' : pwd } )
Executes a change SSH password operation on the specified node
38,739
def create ( cls , name , entries = None , comment = None , ** kw ) : access_list_entry = [ ] if entries : for entry in entries : access_list_entry . append ( { '{}_entry' . format ( cls . typeof ) : entry } ) json = { 'name' : name , 'entries' : access_list_entry , 'comment' : comment } json . update ( kw ) return ElementCreator ( cls , json )
Create an Access List Entry .
38,740
def add_entry ( self , ** kw ) : self . data . setdefault ( 'entries' , [ ] ) . append ( { '{}_entry' . format ( self . typeof ) : kw } )
Add an entry to an AccessList . Use the supported arguments for the inheriting class for keyword arguments .
38,741
def remove_entry ( self , ** field_value ) : field , value = next ( iter ( field_value . items ( ) ) ) self . data [ 'entries' ] [ : ] = [ entry for entry in self . data . get ( 'entries' ) if entry . get ( '{}_entry' . format ( self . typeof ) ) . get ( field ) != str ( value ) ]
Remove an AccessList entry by field specified . Use the supported arguments for the inheriting class for keyword arguments .
38,742
def update_status ( self ) : task = self . make_request ( TaskRunFailed , href = self . href ) return Task ( task )
Gets the current status of this task and returns a new task object .
38,743
def add_done_callback ( self , callback ) : if self . _done is None or self . _done . is_set ( ) : raise ValueError ( 'Task has already finished' ) if callable ( callback ) : self . callbacks . append ( callback )
Add a callback to run after the task completes . The callable must take 1 argument which will be the completed Task .
38,744
def wait ( self , timeout = None ) : if self . _thread is None : return self . _thread . join ( timeout = timeout )
Blocking wait for task status .
38,745
def last_message ( self , timeout = 5 ) : if self . _thread is not None : self . _thread . join ( timeout = timeout ) return self . _task . last_message
Wait a specified amount of time and return the last message from the task
38,746
def stop ( self ) : if self . _thread is not None and self . _thread . isAlive ( ) : self . _done . set ( )
Stop the running task
38,747
def save_to_file ( filename , content ) : import os . path path = os . path . abspath ( filename ) with open ( path , "w" ) as text_file : text_file . write ( "{}" . format ( content ) )
Save content to file . Used by node initial contact but can be used anywhere .
38,748
def merge_dicts ( dict1 , dict2 , append_lists = False ) : for key in dict2 : if isinstance ( dict2 [ key ] , dict ) : if key in dict1 and key in dict2 : merge_dicts ( dict1 [ key ] , dict2 [ key ] , append_lists ) else : dict1 [ key ] = dict2 [ key ] elif isinstance ( dict2 [ key ] , list ) and append_lists : if key in dict1 and isinstance ( dict1 [ key ] , list ) : dict1 [ key ] . extend ( [ k for k in dict2 [ key ] if k not in dict1 [ key ] ] ) else : dict1 [ key ] = dict2 [ key ] else : dict1 [ key ] = dict2 [ key ]
Merge the second dict into the first Not intended to merge list of dicts .
38,749
def bytes_to_unicode ( s , encoding = 'utf-8' , errors = 'replace' ) : if compat . PY3 : return str ( s , 'utf-8' ) if isinstance ( s , bytes ) else s return s if isinstance ( s , unicode ) else s . decode ( encoding , errors )
Helper to convert byte string to unicode string for user based input
38,750
def iterator ( self , ** kwargs ) : cls_name = '{0}Collection' . format ( self . _cls . __name__ ) collection_cls = type ( str ( cls_name ) , ( ElementCollection , ) , { } ) params = { 'filter_context' : self . _cls . typeof } params . update ( kwargs ) return collection_cls ( ** params )
Return an iterator from the collection manager . The iterator can be re - used to chain together filters each chaining event will be it s own unique element collection .
38,751
def object_types ( ) : types = [ element . rel for element in entry_point ( ) ] types . extend ( list ( CONTEXTS ) ) return types
Show all available entry points available for searching . An entry point defines a uri that provides unfiltered access to all elements of the entry point type .
38,752
def create_ospf_area_with_message_digest_auth ( ) : OSPFKeyChain . create ( name = 'secure-keychain' , key_chain_entry = [ { 'key' : 'fookey' , 'key_id' : 10 , 'send_key' : True } ] ) key_chain = OSPFKeyChain ( 'secure-keychain' ) OSPFInterfaceSetting . create ( name = 'authenicated-ospf' , authentication_type = 'message_digest' , key_chain_ref = key_chain . href ) for profile in describe_ospfv2_interface_settings ( ) : if profile . name . startswith ( 'Default OSPF' ) : interface_profile = profile . href OSPFArea . create ( name = 'area0' , interface_settings_ref = interface_profile , area_id = 0 )
If you require message - digest authentication for your OSPFArea you must create an OSPF key chain configuration .
38,753
def create_ospf_profile ( ) : OSPFDomainSetting . create ( name = 'custom' , abr_type = 'cisco' ) ospf_domain = OSPFDomainSetting ( 'custom' ) ospf_profile = OSPFProfile . create ( name = 'myospfprofile' , domain_settings_ref = ospf_domain . href ) print ( ospf_profile )
An OSPF Profile contains administrative distance and redistribution settings . An OSPF Profile is applied at the engine level . When creating an OSPF Profile you must reference a OSPFDomainSetting .
38,754
def create ( cls , name , vss_def = None ) : vss_def = { } if vss_def is None else vss_def json = { 'master_type' : 'dcl2fw' , 'name' : name , 'vss_isc' : vss_def } return ElementCreator ( cls , json )
Create a VSS Container . This maps to the Service Manager within NSX .
38,755
def vss_contexts ( self ) : result = self . make_request ( href = fetch_entry_point ( 'visible_virtual_engine_mapping' ) , params = { 'filter' : self . name } ) if result . get ( 'mapping' , [ ] ) : return [ Element . from_href ( ve ) for ve in result [ 'mapping' ] [ 0 ] . get ( 'virtual_engine' , [ ] ) ] return [ ]
Return all virtual contexts for this VSS Container .
38,756
def remove_security_group ( self , name ) : for group in self . security_groups : if group . isc_name == name : group . delete ( )
Remove a security group from container
38,757
def create ( cls , name , gateway , network , input_speed = None , output_speed = None , domain_server_address = None , provider_name = None , probe_address = None , standby_mode_period = 3600 , standby_mode_timeout = 30 , active_mode_period = 5 , active_mode_timeout = 1 , comment = None ) : json = { 'name' : name , 'gateway_ref' : element_resolver ( gateway ) , 'ref' : element_resolver ( network ) , 'input_speed' : input_speed , 'output_speed' : output_speed , 'probe_address' : probe_address , 'nsp_name' : provider_name , 'comment' : comment , 'standby_mode_period' : standby_mode_period , 'standby_mode_timeout' : standby_mode_timeout , 'active_mode_period' : active_mode_period , 'active_mode_timeout' : active_mode_timeout } if domain_server_address : r = RankedDNSAddress ( [ ] ) r . add ( domain_server_address ) json . update ( domain_server_address = r . entries ) return ElementCreator ( cls , json )
Create a new StaticNetlink to be used as a traffic handler .
38,758
def create ( cls , name , input_speed = None , learn_dns_automatically = True , output_speed = None , provider_name = None , probe_address = None , standby_mode_period = 3600 , standby_mode_timeout = 30 , active_mode_period = 5 , active_mode_timeout = 1 , comment = None ) : json = { 'name' : name , 'input_speed' : input_speed , 'output_speed' : output_speed , 'probe_address' : probe_address , 'nsp_name' : provider_name , 'comment' : comment , 'standby_mode_period' : standby_mode_period , 'standby_mode_timeout' : standby_mode_timeout , 'active_mode_period' : active_mode_period , 'active_mode_timeout' : active_mode_timeout , 'learn_dns_server_automatically' : learn_dns_automatically } return ElementCreator ( cls , json )
Create a Dynamic Netlink .
38,759
def fetch_meta_by_name ( name , filter_context = None , exact_match = True ) : result = SMCRequest ( params = { 'filter' : name , 'filter_context' : filter_context , 'exact_match' : exact_match } ) . read ( ) if not result . json : result . json = [ ] return result
Find the element based on name and optional filters . By default the name provided uses the standard filter query . Additional filters can be used based on supported collections in the SMC API .
38,760
def references_by_element ( self , element_href ) : result = self . make_request ( method = 'create' , resource = 'references_by_element' , json = { 'value' : element_href } ) return result
Return all references to element specified .
38,761
def export_elements ( self , filename = 'export_elements.zip' , typeof = 'all' ) : valid_types = [ 'all' , 'nw' , 'ips' , 'sv' , 'rb' , 'al' , 'vpn' ] if typeof not in valid_types : typeof = 'all' return Task . download ( self , 'export_elements' , filename , params = { 'recursive' : True , 'type' : typeof } )
Export elements from SMC .
38,762
def _create ( self , common_name , public_key_algorithm = 'rsa' , signature_algorithm = 'rsa_sha_512' , key_length = 2048 , signing_ca = None ) : if signing_ca is None : signing_ca = VPNCertificateCA . objects . filter ( 'Internal RSA' ) . first ( ) cert_auth = element_resolver ( signing_ca ) return ElementCreator ( GatewayCertificate , exception = CertificateError , href = self . internal_gateway . get_relation ( 'generate_certificate' ) , json = { 'common_name' : common_name , 'public_key_algorithm' : public_key_algorithm , 'signature_algorithm' : signature_algorithm , 'public_key_length' : key_length , 'certificate_authority_href' : cert_auth } )
Internal method called as a reference from the engine . vpn node
38,763
def create ( cls , name , min_dst_port , max_dst_port = None , min_src_port = None , max_src_port = None , protocol_agent = None , comment = None ) : max_dst_port = max_dst_port if max_dst_port is not None else '' json = { 'name' : name , 'min_dst_port' : min_dst_port , 'max_dst_port' : max_dst_port , 'min_src_port' : min_src_port , 'max_src_port' : max_src_port , 'protocol_agent_ref' : element_resolver ( protocol_agent ) or None , 'comment' : comment } return ElementCreator ( cls , json )
Create the TCP service
38,764
def create ( cls , name , protocol_number , protocol_agent = None , comment = None ) : json = { 'name' : name , 'protocol_number' : protocol_number , 'protocol_agent_ref' : element_resolver ( protocol_agent ) or None , 'comment' : comment } return ElementCreator ( cls , json )
Create the IP Service
38,765
def create ( cls , name , frame_type = 'eth2' , value1 = None , comment = None ) : json = { 'frame_type' : frame_type , 'name' : name , 'value1' : int ( value1 , 16 ) , 'comment' : comment } return ElementCreator ( cls , json )
Create an ethernet service
38,766
def pem_as_string ( cert ) : if hasattr ( cert , 'read' ) : return cert cert = cert . encode ( 'utf-8' ) if isinstance ( cert , unicode ) else cert if re . match ( _PEM_RE , cert ) : return True return False
Only return False if the certificate is a file path . Otherwise it is a file object or raw string and will need to be fed to the file open context .
38,767
def send_message ( self , message ) : if self . connected : self . send ( json . dumps ( message . request ) )
Send a message down the socket . The message is expected to have a request attribute that holds the message to be serialized and sent .
38,768
def receive ( self ) : try : itr = 0 while self . connected : r , w , e = select . select ( ( self . sock , ) , ( ) , ( ) , 10.0 ) if r : message = json . loads ( self . recv ( ) ) if 'fetch' in message : self . fetch_id = message [ 'fetch' ] if 'failure' in message : raise InvalidFetch ( message [ 'failure' ] ) if 'records' in message : if 'added' in message [ 'records' ] : num = len ( message [ 'records' ] [ 'added' ] ) else : num = len ( message [ 'records' ] ) logger . debug ( 'Query returned %s records.' , num ) if self . max_recv : itr += 1 if 'end' in message : logger . debug ( 'Received end message: %s' % message [ 'end' ] ) yield message break yield message if self . max_recv and self . max_recv <= itr : break except ( Exception , KeyboardInterrupt , SystemExit , FetchAborted ) as e : logger . info ( 'Caught exception in receive: %s -> %s' , type ( e ) , str ( e ) ) if isinstance ( e , ( SystemExit , InvalidFetch ) ) : raise finally : if self . connected : if self . fetch_id : self . send ( json . dumps ( { 'abort' : self . fetch_id } ) ) self . close ( ) if self . thread : self . event . set ( ) while self . thread . isAlive ( ) : self . event . wait ( 1 ) logger . info ( 'Closed web socket connection normally.' )
Generator yielding results from the web socket . Results will come as they are received . Even though socket select has a timeout the SMC will not reply with a message more than every two minutes .
38,769
def ElementCreator ( cls , json , ** kwargs ) : if 'exception' not in kwargs : kwargs . update ( exception = CreateElementFailed ) href = kwargs . pop ( 'href' ) if 'href' in kwargs else cls . href result = SMCRequest ( href = href , json = json , ** kwargs ) . create ( ) element = cls ( name = json . get ( 'name' ) , type = cls . typeof , href = result . href ) if result . user_session . in_atomic_block : result . user_session . transactions . append ( element ) return element
Helper method for creating elements . If the created element type is a SubElement class type provide href value as kwargs since that class type does not have a direct entry point . This is a lazy load that will provide only the meta for the element . Additional attribute access will load the full data .
38,770
def etag ( self , href ) : if self and self . _etag is None : self . _etag = LoadElement ( href , only_etag = True ) return self . _etag
ETag can be None if a subset of element json is using this container such as the case with Routing .
38,771
def get_link ( self , rel ) : if rel in self . links : return self . links [ rel ] raise ResourceNotFound ( 'Resource requested: %r is not available ' 'on this element.' % rel )
Return link for specified resource
38,772
def add_category ( self , category ) : assert isinstance ( category , list ) , 'Category input was expecting list.' from smc . elements . other import Category for tag in category : category = Category ( tag ) try : category . add_element ( self . href ) except ElementNotFound : Category . create ( name = tag ) category . add_element ( self . href )
Category Tags are used to characterize an element by a type identifier . They can then be searched and returned as a group of elements . If the category tag specified does not exist it will be created . This change will take effect immediately .
38,773
def export ( self , filename = 'element.zip' ) : from smc . administration . tasks import Task return Task . download ( self , 'export' , filename )
Export this element .
38,774
def referenced_by ( self ) : href = fetch_entry_point ( 'references_by_element' ) return [ Element . from_meta ( ** ref ) for ref in self . make_request ( method = 'create' , href = href , json = { 'value' : self . href } ) ]
Show all references for this element . A reference means that this element is being used for example in a policy rule as a member of a group etc .
38,775
def flush_parent_cache ( node ) : if node . _parent is None : node . _del_cache ( ) return node . _del_cache ( ) flush_parent_cache ( node . _parent )
Flush parent cache will recurse back up the tree and wipe the cache from each parent node reference on the given element . This allows the objects to be reused and a clean way to force the object to update itself if attributes or methods are referenced after update .
38,776
def route_level ( root , level ) : def recurse ( nodes ) : for node in nodes : if node . level == level : routing_node . append ( node ) else : recurse ( node ) routing_node = [ ] recurse ( root ) return routing_node
Helper method to recurse the current node and return the specified routing node level .
38,777
def get ( self , interface_id ) : for interface in self : if interface . nicid == str ( interface_id ) or interface . dynamic_nicid == str ( interface_id ) : return interface raise InterfaceNotFound ( 'Specified interface {} does not exist on ' 'this engine.' . format ( interface_id ) )
Obtain routing configuration for a specific interface by ID .
38,778
def add_ospf_area ( self , ospf_area , ospf_interface_setting = None , network = None , communication_mode = 'NOT_FORCED' , unicast_ref = None ) : communication_mode = communication_mode . upper ( ) destinations = [ ] if not ospf_interface_setting else [ ospf_interface_setting ] if communication_mode == 'UNICAST' and unicast_ref : destinations . append ( unicast_ref ) routing_node_gateway = RoutingNodeGateway ( ospf_area , communication_mode = communication_mode , destinations = destinations ) return self . _add_gateway_node ( 'ospfv2_area' , routing_node_gateway , network )
Add OSPF Area to this routing node .
38,779
def create ( cls , name , address = None , ipv6_address = None , secondary = None , comment = None ) : address = address if address else None ipv6_address = ipv6_address if ipv6_address else None secondaries = [ ] if secondary is None else secondary json = { 'name' : name , 'address' : address , 'ipv6_address' : ipv6_address , 'secondary' : secondaries , 'comment' : comment } return ElementCreator ( cls , json )
Create the host element
38,780
def create ( cls , name , ip_range , comment = None ) : json = { 'name' : name , 'ip_range' : ip_range , 'comment' : comment } return ElementCreator ( cls , json )
Create an AddressRange element
38,781
def create ( cls , name , ipv4_network = None , ipv6_network = None , comment = None ) : ipv4_network = ipv4_network if ipv4_network else None ipv6_network = ipv6_network if ipv6_network else None json = { 'name' : name , 'ipv4_network' : ipv4_network , 'ipv6_network' : ipv6_network , 'comment' : comment } return ElementCreator ( cls , json )
Create the network element
38,782
def create ( cls , name , ne_ref = None , operator = 'exclusion' , sub_expression = None , comment = None ) : sub_expression = [ ] if sub_expression is None else [ sub_expression ] json = { 'name' : name , 'operator' : operator , 'ne_ref' : ne_ref , 'sub_expression' : sub_expression , 'comment' : comment } return ElementCreator ( cls , json )
Create the expression
38,783
def download ( self , filename = None , as_type = 'zip' ) : headers = None if as_type in [ 'zip' , 'txt' , 'json' ] : if as_type == 'zip' : if filename is None : raise MissingRequiredInput ( 'Filename must be specified when ' 'downloading IPList as a zip file.' ) filename = '{}' . format ( filename ) elif as_type == 'txt' : headers = { 'accept' : 'text/plain' } elif as_type == 'json' : headers = { 'accept' : 'application/json' } result = self . make_request ( FetchElementFailed , raw_result = True , resource = 'ip_address_list' , filename = filename , headers = headers ) return result . json if as_type == 'json' else result . content
Download the IPList . List format can be either zip text or json . For large lists it is recommended to use zip encoding . Filename is required for zip downloads .
38,784
def upload ( self , filename = None , json = None , as_type = 'zip' ) : headers = { 'content-type' : 'multipart/form-data' } params = None files = None if filename : files = { 'ip_addresses' : open ( filename , 'rb' ) } if as_type == 'json' : headers = { 'accept' : 'application/json' , 'content-type' : 'application/json' } elif as_type == 'txt' : params = { 'format' : 'txt' } self . make_request ( CreateElementFailed , method = 'create' , resource = 'ip_address_list' , headers = headers , files = files , json = json , params = params )
Upload an IPList to the SMC . The contents of the upload are not incremental to what is in the existing IPList . So if the intent is to add new entries you should first retrieve the existing and append to the content then upload . The only upload type that can be done without loading a file as the source is as_type = json .
38,785
def resolve ( self , engine ) : if not self . resolved_value : result = self . make_request ( ElementNotFound , href = self . get_relation ( 'resolve' ) , params = { 'for' : engine } ) self . resolved_value = result . get ( 'resolved_value' ) return self . resolved_value
Resolve this Alias to a specific value . Specify the engine by name to find it s value .
38,786
def name ( self ) : return self . _meta . name if self . _meta . name else 'Rule @%s' % self . tag
Name attribute of rule element
38,787
def create ( self , name , sources = None , destinations = None , services = None , action = 'allow' , log_options = None , authentication_options = None , connection_tracking = None , is_disabled = False , vpn_policy = None , mobile_vpn = False , add_pos = None , after = None , before = None , sub_policy = None , comment = None , ** kw ) : rule_values = self . update_targets ( sources , destinations , services ) rule_values . update ( name = name , comment = comment ) if isinstance ( action , Action ) : rule_action = action else : rule_action = Action ( ) rule_action . action = action if not rule_action . action in self . _actions : raise CreateRuleFailed ( 'Action specified is not valid for this ' 'rule type; action: {}' . format ( rule_action . action ) ) if rule_action . action in ( 'apply_vpn' , 'enforce_vpn' , 'forward_vpn' ) : if vpn_policy is None and not mobile_vpn : raise MissingRequiredInput ( 'You must either specify a vpn_policy or set ' 'mobile_vpn when using a rule with a VPN action' ) if mobile_vpn : rule_action . mobile_vpn = True else : try : vpn = element_resolver ( vpn_policy ) rule_action . vpn = vpn except ElementNotFound : raise MissingRequiredInput ( 'Cannot find VPN policy specified: {}, ' . format ( vpn_policy ) ) elif rule_action . action == 'jump' : try : rule_action . sub_policy = element_resolver ( sub_policy ) except ElementNotFound : raise MissingRequiredInput ( 'Cannot find sub policy specified: {} ' . format ( sub_policy ) ) log_options = LogOptions ( ) if not log_options else log_options if connection_tracking is not None : rule_action . connection_tracking_options . update ( ** connection_tracking ) auth_options = AuthenticationOptions ( ) if not authentication_options else authentication_options rule_values . update ( action = rule_action . data , options = log_options . data , authentication_options = auth_options . data , is_disabled = is_disabled ) params = None href = self . href if add_pos is not None : href = self . add_at_position ( add_pos ) elif before or after : params = self . add_before_after ( before , after ) return ElementCreator ( self . __class__ , exception = CreateRuleFailed , href = href , params = params , json = rule_values )
Create a layer 3 firewall rule
38,788
def create ( self , name , sources = None , destinations = None , services = None , action = 'allow' , is_disabled = False , logical_interfaces = None , add_pos = None , after = None , before = None , comment = None ) : rule_values = self . update_targets ( sources , destinations , services ) rule_values . update ( name = name , comment = comment ) rule_values . update ( is_disabled = is_disabled ) if isinstance ( action , Action ) : rule_action = action else : rule_action = Action ( ) rule_action . action = action if not rule_action . action in self . _actions : raise CreateRuleFailed ( 'Action specified is not valid for this ' 'rule type; action: {}' . format ( rule_action . action ) ) rule_values . update ( action = rule_action . data ) rule_values . update ( self . update_logical_if ( logical_interfaces ) ) params = None href = self . href if add_pos is not None : href = self . add_at_position ( add_pos ) else : params = self . add_before_after ( before , after ) return ElementCreator ( self . __class__ , exception = CreateRuleFailed , href = href , params = params , json = rule_values )
Create an Ethernet rule
38,789
def download ( self , filename = None ) : if not filename : filename = '{}{}' . format ( self . name , '.zip' ) try : self . make_request ( EngineCommandFailed , resource = 'content' , filename = filename ) except IOError as e : raise EngineCommandFailed ( "Snapshot download failed: {}" . format ( e ) )
Download snapshot to filename
38,790
def create ( cls , name , nat = False , mobile_vpn_toplogy_mode = None , vpn_profile = None ) : vpn_profile = element_resolver ( vpn_profile ) or VPNProfile ( 'VPN-A Suite' ) . href json = { 'mobile_vpn_topology_mode' : mobile_vpn_toplogy_mode , 'name' : name , 'nat' : nat , 'vpn_profile' : vpn_profile } try : return ElementCreator ( cls , json ) except CreateElementFailed as err : raise CreatePolicyFailed ( err )
Create a new policy based VPN
38,791
def enable_disable_nat ( self ) : if self . nat : self . data [ 'nat' ] = False else : self . data [ 'nat' ] = True
Enable or disable NAT on this policy . If NAT is disabled it will be enabled and vice versa .
38,792
def update_members ( self , members , append_lists = False , remove_members = False ) : if members : elements = [ element_resolver ( element ) for element in members ] if remove_members : element = [ e for e in self . members if e not in elements ] if set ( element ) == set ( self . members ) : remove_members = element = False append_lists = False elif append_lists : element = [ e for e in elements if e not in self . members ] else : element = list ( set ( elements ) ) if element or remove_members : self . update ( element = element , append_lists = append_lists ) return True return False
Update group members with member list . Set append = True to append to existing members or append = False to overwrite .
38,793
def create ( cls , name , members = None , comment = None ) : element = [ ] if members is None else element_resolver ( members ) json = { 'name' : name , 'element' : element , 'comment' : comment } return ElementCreator ( cls , json )
Create the TCP Service group
38,794
def create_gre_tunnel_no_encryption ( cls , name , local_endpoint , remote_endpoint , mtu = 0 , pmtu_discovery = True , ttl = 0 , enabled = True , comment = None ) : return cls . create_gre_tunnel_mode ( name , local_endpoint , remote_endpoint , policy_vpn = None , mtu = mtu , pmtu_discovery = pmtu_discovery , ttl = ttl , enabled = enabled , comment = comment )
Create a GRE Tunnel with no encryption . See create_gre_tunnel_mode for constructor descriptions .
38,795
def set_auth_request ( self , interface_id , address = None ) : self . interface . set_auth_request ( interface_id , address ) self . _engine . update ( )
Set the authentication request field for the specified engine .
38,796
def name ( self ) : name = super ( Interface , self ) . name return name if name else self . data . get ( 'name' )
Read only name tag
38,797
def _add_interface ( self , interface_id , ** kw ) : base_interface = ElementCache ( ) base_interface . update ( interface_id = str ( interface_id ) , interfaces = [ ] ) if 'zone_ref' in kw : zone_ref = kw . pop ( 'zone_ref' ) base_interface . update ( zone_ref = zone_helper ( zone_ref ) if zone_ref else None ) if 'comment' in kw : base_interface . update ( comment = kw . pop ( 'comment' ) ) self . data = base_interface interfaces = kw . pop ( 'interfaces' , [ ] ) if interfaces : for interface in interfaces : if interface . get ( 'cluster_virtual' , None ) or len ( interface . get ( 'nodes' , [ ] ) ) > 1 : kw . update ( interface_id = interface_id , interfaces = interfaces ) cvi = ClusterPhysicalInterface ( ** kw ) cvi . data . pop ( 'vlanInterfaces' , None ) self . data . update ( cvi . data ) else : for node in interface . get ( 'nodes' , [ ] ) : node . update ( nodeid = 1 ) sni = SingleNodeInterface . create ( interface_id , ** node ) base_interface . setdefault ( 'interfaces' , [ ] ) . append ( { sni . typeof : sni . data } )
Create a tunnel interface . Kw argument list is as follows
38,798
def _add_interface ( self , interface_id , mgt = None , ** kw ) : _kw = copy . deepcopy ( kw ) mgt = mgt if mgt else { } if 'cvi_mode' in _kw : self . data . update ( cvi_mode = _kw . pop ( 'cvi_mode' ) ) if 'macaddress' in _kw : self . data . update ( macaddress = _kw . pop ( 'macaddress' ) ) if 'cvi_mode' not in self . data : self . data . update ( cvi_mode = 'packetdispatch' ) if 'zone_ref' in _kw : zone_ref = _kw . pop ( 'zone_ref' ) self . data . update ( zone_ref = zone_helper ( zone_ref ) if zone_ref else None ) if 'comment' in _kw : self . data . update ( comment = _kw . pop ( 'comment' ) ) interfaces = _kw . pop ( 'interfaces' , [ ] ) for interface in interfaces : vlan_id = interface . pop ( 'vlan_id' , None ) if vlan_id : _interface_id = '{}.{}' . format ( interface_id , vlan_id ) else : _interface_id = interface_id _interface = [ ] if_mgt = { k : str ( v ) == str ( _interface_id ) for k , v in mgt . items ( ) } if 'cluster_virtual' in interface and 'network_value' in interface : cluster_virtual = interface . pop ( 'cluster_virtual' ) network_value = interface . pop ( 'network_value' ) if cluster_virtual and network_value : cvi = ClusterVirtualInterface . create ( _interface_id , cluster_virtual , network_value , auth_request = True if if_mgt . get ( 'primary_mgt' ) else False ) _interface . append ( { cvi . typeof : cvi . data } ) for node in interface . pop ( 'nodes' , [ ] ) : _node = if_mgt . copy ( ) _node . update ( outgoing = True if if_mgt . get ( 'primary_mgt' ) else False ) _node . update ( node ) ndi = NodeInterface . create ( interface_id = _interface_id , ** _node ) _interface . append ( { ndi . typeof : ndi . data } ) if vlan_id : vlan_interface = { 'interface_id' : _interface_id , 'zone_ref' : zone_helper ( interface . pop ( 'zone_ref' , None ) ) , 'comment' : interface . pop ( 'comment' , None ) , 'interfaces' : _interface } for name , value in interface . items ( ) : vlan_interface [ name ] = value self . data . setdefault ( 'vlanInterfaces' , [ ] ) . append ( vlan_interface ) else : self . data . setdefault ( 'interfaces' , [ ] ) . extend ( _interface ) for name , value in _kw . items ( ) : self . data [ name ] = value
Add the Cluster interface . If adding a cluster interface to an existing node retrieve the existing interface and call this method . Use the supported format for defining an interface .
38,799
def create ( cls , name , port = 179 , external_distance = 20 , internal_distance = 200 , local_distance = 200 , subnet_distance = None ) : json = { 'name' : name , 'external' : external_distance , 'internal' : internal_distance , 'local' : local_distance , 'port' : port } if subnet_distance : d = [ { 'distance' : distance , 'subnet' : subnet . href } for subnet , distance in subnet_distance ] json . update ( distance_entry = d ) return ElementCreator ( cls , json )
Create a custom BGP Profile