def del_worker_me(master_prim, node_name): # (1) remove node with k8s_delete_node ms / primary master k8s_delete_node_data = { "object_id": "123", "node_name": node_name, } k8s_delete_node_ms = {"k8s_delete_node": {"123": k8s_delete_node_data}} order = Order(master_prim) order.command_execute('CREATE', k8s_delete_node_ms, timeout=300)
def order_fixture(): """Order fixture.""" with patch('requests.post') as mock_post: mock_post.return_value.json.return_value = {'token': '12345qwert'} with patch('requests.get') as mock_call_get: mock_call_get.return_value.text = device_info() with patch('msa_sdk.msa_api.host_port') as mock_host_port: mock_host_port.return_value = ('api_hostname', '8080') order = Order(1234) return order
ipam_device_id = context['ipam_device_id'] customer_name = context['customer_name'] site = context['site'] #Variables to finish the task properlly fail_comment = str() success_comment = str() fail_string = f'{{"wo_status": "FAIL", "wo_comment": "{fail_comment}"}}' success_string = f'{{"wo_status": "ENDED", "wo_comment": "{success_comment}"}}' #Create Orchestration object to update GUI dynamically Orchestration = Orchestration(context['UBIQUBEID']) async_update_list = (context['PROCESSINSTANCEID'], context['TASKID'], context['EXECNUMBER']) #Create order object IpamOrderObject = Order(ipam_device_id) #Find site ID objects_list = IpamOrderObject.command_objects_instances(ms_ipam_site) #Looking for CE device in STAGED state on the site Orchestration.update_asynchronous_task_details(*async_update_list, 'Looking for CE device on site {} in "staged" state... '.format(site)) #Collect cusromer sites object_id for future use for site in objects_list: site_object = IpamOrderObject.command_objects_instances_by_id(ms_ipam_site, site)[ms_ipam_site][site] if site_object['object_id'] == site: context['site_id'] = site_object['id']
ipam_device_id = context['ipam_device_id'] customer_name = context['customer_name'] #Variables to finish the task properlly fail_comment = str() success_comment = str() fail_string = f'{{"wo_status": "FAIL", "wo_comment": "{fail_comment}"}}' success_string = f'{{"wo_status": "ENDED", "wo_comment": "{success_comment}"}}' #Create Orchestration object to update GUI dynamically Orchestration = Orchestration(context['UBIQUBEID']) async_update_list = (context['PROCESSINSTANCEID'], context['TASKID'], context['EXECNUMBER']) #Create order object IpamOrderObject = Order(ipam_device_id) IpamOrderObject.command_synchronize(300) #Retrieve info about tenants Orchestration.update_asynchronous_task_details(*async_update_list, 'Retrieving information about customer... ') objects_list = IpamOrderObject.command_objects_instances(ms_ipam_tenant) #Check if customer exists in IPAM system does_tenant_exists = False counter = 0 while not does_tenant_exists and counter < len(objects_list): tenant_object = IpamOrderObject.command_objects_instances_by_id(ms_ipam_tenant, objects_list[counter])[ms_ipam_tenant][objects_list[counter]] if tenant_object['object_id'] == customer_name: does_tenant_exists = True customer_id = tenant_object['id']
"firewall": "true", "vpn": "true", "application_control": "true", "ips": "true", "content_awareness": "true", "url_filtering": "true", "anti_virus": "true", "anti_bot": "true", "anti_spam": "true", "threat_emulation": "true", "threat_extraction": "true" } gateway = {"Gateway": {object_id: micro_service_vars_array}} # call the CREATE for simple_firewall MS for each device order = Order(devicelongid) order.command_execute('CREATE', gateway) # convert dict object into json content = json.loads(order.content) # check if the response is OK if order.response.ok: # ret = MSA_API.process_content('ENDED', # f'STATUS: {content["status"]}, \ # MESSAGE: {content["message"]}', # context, True) ret = MSA_API.process_content( 'ENDED', f'STATUS: {content["status"]}, \ MESSAGE: Gateway {object_id}', context, True)
from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API from msa_sdk.order import Order dev_var = Variables() dev_var.add('id', var_type='Integer') dev_var.add('device_id', var_type='Device') context = Variables.task_call(dev_var) short_device_id = context['device_id'][-3:] context['short_device_id'] = short_device_id ms_sdwan_ipsec_start = {context['id']: {"object_id": context['id']}} context['ms_sdwan_ipsec_start'] = ms_sdwan_ipsec_start try: order = Order(context['short_device_id']) order.command_execute('CREATE', {"sdwan_ipsec_start": ms_sdwan_ipsec_start}) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) ret = MSA_API.process_content('ENDED', f'Take IPsec control.', context, True) print(ret)
device_list = search.content device_list = json.loads(device_list) worker_id_list = [] master = context['vm_name'] + '-1' backup = context['vm_name'] + '-2' # add all vms that are not k8s masters to the list for me in device_list: if me['name'] != (master and backup): worker_id_list.append(me['id']) # (4) kubeadm loop on workers Orchestration.update_asynchronous_task_details(*async_update_list, f'Worker nodes processing...') for me in worker_id_list: try: order = Order(str(me)) order.command_execute('CREATE', context['k8s_join_worker'], timeout=300) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) Orchestration.update_asynchronous_task_details(*async_update_list, f'Worker Initiated: {me}') ret = MSA_API.process_content('ENDED', 'K8S cluster ready - Enjoy!', context, True) print(ret)
import random import time from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API from msa_sdk.order import Order context = Variables.task_call() device_id_list = context["device_id_list"] ms_vars_dict_list = context["ms_vars_dict_list"] def rand_int(): return ''.join(random.choice('0123456789') for i in range(8)) for device in device_id_list.values(): for ms_var_dict in ms_vars_dict_list.values(): Order(device).command_execute('CREATE', {'k8s_pods': { rand_int(): ms_var_dict }}) time.sleep(3 * int(context['packet_count'])) ret = MSA_API.process_content('ENDED', f'PODs have been created', context, True) print(ret)
from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API from msa_sdk.order import Order dev_var = Variables() context = Variables.task_call() # (4) cryptomap try: order = Order(context["left_device_id"]) order.command_execute("CREATE", context["sdwan_ipsec_conf_crypto_map_left"]) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) try: order = Order(context["right_device_id"]) order.command_execute('CREATE', context["sdwan_ipsec_conf_crypto_map_right"]) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) ret = MSA_API.process_content('ENDED', f'IPsec Crypto_map Created.', context, True) print(ret)
# throw message def info_message(text, timeout=1): Orchestration.update_asynchronous_task_details(*async_update_list, text) time.sleep(timeout) def rand_int(): return ''.join(random.choice('0123456789') for i in range(8)) if __name__ == "__main__": info_message('Deploying service PODs...') for device in device_id_list: d_name = Device(device_id=device).name info_message(f'Deploying service PODs on: {d_name}...') for ms_var_dict in ms_vars_dict_list: Order(device).command_execute( 'CREATE', {'icmp_probes': { rand_int(): ms_var_dict }}) info_message(f'Deploying service PODs on: {d_name} done.') # wait while ping is being executed counter = 3 * int(context['pkt_count']) for i in range(counter): info_message(f'Packets counter: {counter-i}') ret = MSA_API.process_content('ENDED', f'Probation network deployed.', context, True) print(ret)
from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API from msa_sdk.order import Order dev_var = Variables() context = Variables.task_call() # left device cleanup try: order = Order(context["left_device_id"]) order.command_execute("DELETE", {"sdwan_loopback": context['id']}) order.command_execute("DELETE", {"sdwan_ipsec_secret": context['id']}) order.command_execute("DELETE", {"sdwan_ipsec_conf": context['id']}) order.command_execute("DELETE", {"sdwan_ipsec_conf_cryptomap": context['id']}) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) # right device cleanup try: order = Order(context["right_device_id"]) order.command_execute("DELETE", {"sdwan_loopback": context['id']}) order.command_execute("DELETE", {"sdwan_ipsec_secret": context['id']}) order.command_execute("DELETE", {"sdwan_ipsec_conf": context['id']}) order.command_execute("DELETE", {"sdwan_ipsec_conf_cryptomap": context['id']}) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret)
import json from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API from msa_sdk.order import Order dev_var = Variables() context = Variables.task_call() device_id_list = context["device_id_list"] for device in device_id_list.values(): order = Order(device) order.command_objects_instances('k8s_pods') ms_instances = json.loads(order.content.decode()) for instance in ms_instances: Order(device).command_execute('DELETE', {'k8s_pods': instance}) ret = MSA_API.process_content('ENDED', f'workflow deleted, pods cleared', context, True) print(ret)
import json from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API from msa_sdk.order import Order dev_var = Variables() context = Variables.task_call() device_id_list = context["device_id_list"] target_device_id = context['target_device_id'] # remove metrics pods for device in device_id_list.values(): order = Order(device) order.command_objects_instances('k8s_pods') ms_instances = json.loads(order.content.decode()) for instance in ms_instances: Order(device).command_execute('DELETE', {'k8s_pods': instance}) # remove user app order = Order(target_device_id) order.command_objects_instances('k8s_user_app') ms_instances = json.loads(order.content.decode()) for instance in ms_instances: Order(target_device_id).command_execute('DELETE', {'k8s_user_app': instance}) ret = MSA_API.process_content('ENDED', f'pods cleared, app removed', context, True) print(ret)
customer_name = context['customer_name'] ipam_device_id = context['ipam_device_id'] #Variables to finish the task properlly fail_comment = str() success_comment = str() fail_string = f'{{"wo_status": "FAIL", "wo_comment": "{fail_comment}"}}' success_string = f'{{"wo_status": "ENDED", "wo_comment": "{success_comment}"}}' #Create Orchestration object to update GUI dynamically Orchestration = Orchestration(context['UBIQUBEID']) async_update_list = (context['PROCESSINSTANCEID'], context['TASKID'], context['EXECNUMBER']) #IPAM order object IpamOrderObject = Order(ipam_device_id) #Create CE device object CeDeviceObject = Device(device_id = ce_device_id, device_external = ce_device_external_reference) pretty_formatted_bar = list('------------------------') Orchestration.update_asynchronous_task_details(*async_update_list, 'Provisioning of CE device... [{}]'.format(''.join(pretty_formatted_bar))) #If the device mgmt interface is REST-based, add required configuration variables if 'rest' in ce_local_context['interface'].lower(): for variable, value in ce_local_context['msa_specific']['rest_headers'].items(): CeDeviceObject.create_configuration_variable(name = variable, value = value) #Provision device CeDeviceObject.initial_provisioning()
if isinstance(three.token, tuple): ret = MSA_API.process_content('WARNING', f'Can\'t get MSA token {three.token[1]}', context, True) print(ret) exit() except HTTPError as http_err: ret = MSA_API.process_content('WARNING', f'HTTP error occured: {http_err}', context, True) print(ret) exit() k8s_create_service_account_2 = {'k8s_create_service_account': {'0':{'object_id': 'token'}}} try: order = Order(str(context['master_id'])) order.command_synchronize(timeout=60) time.sleep(2) order.command_execute('IMPORT', k8s_create_service_account_2) data_5 = json.loads(order.content) data_5 = json.loads(data_5['message']) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) if 'token' in data_5['k8s_create_service_account'].keys(): k8s_token = data_5['k8s_create_service_account']['token']['token'] else: ret = MSA_API.process_content('WARNING',
k8s_ha_proxy_data = { "object_id": "123", "k8s_m_1_ip": list(context['vms'][0].values())[0]['internal'], "k8s_m_2_ip": list(context['vms'][1].values())[0]['internal'], } k8s_ha_proxy_ms = {"k8s_ha_proxy": {"123": k8s_ha_proxy_data}} # (2) get short ME id me_id = context['proxy_host'][3:] # (3) install package on certain me Orchestration.update_asynchronous_task_details( *async_update_list, f'haproxy installation: {Device(device_id=me_id).name}') try: order = Order(me_id) order.command_execute('CREATE', k8s_package_management_ms, timeout=300) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) time.sleep(10) # (4) configure and start proxy try: order = Order(me_id) order.command_execute('CREATE', k8s_ha_proxy_ms) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) ret = MSA_API.process_content('ENDED', f'Loadbalancer prepared.', context, True)
elif me['name'] == context['vm_name'] + '-2': backup_id = me['id'] # (1) kubeadm init on master first # stub here - actually k8s master nodes should be selected according to the user input k8s_kubeadm_init_data = { "object_id": "123", "lb_ip": list(context['vms'][2].values())[0]['internal'], "lb_port": "6443", } k8s_kubeadm_init_ms = {"k8s_kubeadm_init": {"123": k8s_kubeadm_init_data}} Orchestration.update_asynchronous_task_details(*async_update_list, f'k8s-node-1: Provisioning') try: order = Order(str(master_id)) order.command_execute('CREATE', k8s_kubeadm_init_ms, timeout=400) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) Orchestration.update_asynchronous_task_details( *async_update_list, f'Master Initiated: k8s-node-1') # (2) get params from master first # k8s_get_token k8s_get_token = {'k8s_get_token': {'': {'object_id': 'kubeamd'}}} try: order = Order(str(master_id)) order.command_execute('IMPORT', k8s_get_token) data_1 = json.loads(order.content)
order.command_execute('CREATE', k8s_kubeadm_init_ms, timeout=400) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) Orchestration.update_asynchronous_task_details(*async_update_list, f'Master Initiated: k8s-node-1') ''' # (2) get params from master first # k8s_get_token k8s_get_token = {'k8s_get_token': {'': {'object_id': 'kubeamd'}}} try: order = Order(str(master_id)) order.command_execute('IMPORT', k8s_get_token) data_1 = json.loads(order.content) data_1 = json.loads(data_1['message']) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) Orchestration.update_asynchronous_task_details(*async_update_list, f'k8s-node-1: Token retrieved') # k8s_get_key k8s_get_key = {'k8s_get_key': {'': {'object_id': ''}}} try: order = Order(str(master_id)) order.command_execute('IMPORT', k8s_get_key)
'Router Import Connected to BGP'] ms_router_advert_by_bgp = context['ipam_ms_aliases'][ 'Router Import advertised routes by BGP'] #Variables to finish the task properlly fail_comment = str() success_comment = str() fail_string = f'{{"wo_status": "FAIL", "wo_comment": "{fail_comment}"}}' success_string = f'{{"wo_status": "ENDED", "wo_comment": "{success_comment}"}}' #Create Orchestration object to update GUI dynamically Orchestration = Orchestration(context['UBIQUBEID']) async_update_list = (context['PROCESSINSTANCEID'], context['TASKID'], context['EXECNUMBER']) IpamOrderObject = Order(ipam_device_id) #Create CE device order object CeOrderObject = Order(ce_device_id) response = CeOrderObject.command_synchronize(300) pe_order_list = list() #Remove IP addresses from CE-PE links Orchestration.update_asynchronous_task_details(*async_update_list, 'Configuring CE device... ') for interface, connection in ce_connections.items(): #Create oreder object for PE pe_order_list.append(Order(connection['neighbour']['device_id'])) response = pe_order_list[-1].command_synchronize(300) Orchestration.update_asynchronous_task_details(
ms_router_prefix_filter = context['ipam_ms_aliases']['Router Prefix Filter'] ms_router_import_to_bgp = context['ipam_ms_aliases']['Router Import Connected to BGP'] ms_router_advert_by_bgp = context['ipam_ms_aliases']['Router Import advertised routes by BGP'] #Variables to finish the task properlly fail_comment = str() success_comment = str() fail_string = f'{{"wo_status": "FAIL", "wo_comment": "{fail_comment}"}}' success_string = f'{{"wo_status": "ENDED", "wo_comment": "{success_comment}"}}' #Create Orchestration object to update GUI dynamically Orchestration = Orchestration(context['UBIQUBEID']) async_update_list = (context['PROCESSINSTANCEID'], context['TASKID'], context['EXECNUMBER']) #Create CE device order object CeOrderObject = Order(ce_device_id) response = CeOrderObject.command_synchronize(300) #Create IPAM order object IpamOrderObject = Order(ipam_device_id) response = IpamOrderObject.command_synchronize(300) Orchestration.update_asynchronous_task_details(*async_update_list, 'Configuring IP address on CE device internal link... ') #Configure IP address on CE internal interface ms_dict = {ms_router_interface: {ce_internal_interface_name: {'object_id': ce_internal_interface_name, 'ip_addr': ce_internal_interface_ip.split('/')[0], 'ip_prefix': ce_internal_interface_ip.split('/')[1] } } }
def get_pod_ns(pod_name): order.command_objects_instances_by_id('k8_pods_list', pod_name) response = json.loads(order.content) return response['k8_pods_list'][pod_name]['namespace'] if __name__ == "__main__": # remove metrics pods info_message('Removing service pods...') for device in device_id_list: d_name = Device(device_id=device).name info_message(f'Removing service pods: {d_name}...') order = Order(device) # syncronize first k8_pods_list = {'k8_pods_list': {'': {}}} order.command_execute('IMPORT', k8_pods_list) order.command_objects_instances('k8_pods_list') pods_list = json.loads(order.content) for pod in pods_list: if get_pod_ns(pod) == context['service_namespace']: info_message(f'Removing service pods: {d_name} {pod}...') order.command_execute('DELETE', {'k8_pods_list': pod}) # remove all applications from user_namespace info_message(f'Removing user apps: {target_device_name}...') order = Order(target_device_id) # syncronize first k8_pods_list = {'k8_pods_list': {'': {}}}
# read the ID of the selected managed entity device_id = context['device'] object_id = context['gateway'] profile = context['profile'] # extract the database ID devicelongid = device_id[3:] # build the Microservice JSON params for IMPORT #{"Gateway":"0"} #micro_service_vars_array = {"object_id":object_id} gateway = {"Gateway": "0"} # call the CREATE for simple_firewall MS for each device order = Order(devicelongid) order.command_execute('IMPORT', gateway) # convert dict object into json content = json.loads(order.content) # check if the response is OK if order.response.ok: ret = MSA_API.process_content( 'ENDED', f'STATUS: {content["status"]}, \ MESSAGE: {profile} activated on {object_id}', context, True) else: ret = MSA_API.process_content( 'FAILED', f'Import failed \ - {order.content}', context, True)
management_port='22') StationDeviceObject.create() pretty_formatted_bar = list('-' * 12) Orchestration.update_asynchronous_task_details( *async_update_list, 'Creating managed entity for the station... [{}]'.format( ''.join(pretty_formatted_bar))) #Provision device StationDeviceObject.initial_provisioning() #Create station device order object context['station_device_id'] = StationDeviceObject.device_id StationOrderObject = Order(context['station_device_id']) #Wait until provisioning is done while StationDeviceObject.provision_status()['status'] != 'OK': pretty_formatted_bar.insert(0, '*') Orchestration.update_asynchronous_task_details( *async_update_list, 'Creating managed entity for the station... [{}]'.format( ''.join(pretty_formatted_bar))) time.sleep(5) #Attach configuration profile Orchestration.update_asynchronous_task_details( *async_update_list, 'Attaching configuration deployment settings profile... ') StationDeviceObject.profile_attach(nec_ipasolink_profile_name)
return bool(re.search('(\d{1,3}_){3}\d{1,3}', text)) if __name__ == "__main__": ######################################################################################################## # MATH ALGORITHM # ######################################################################################################## info_message('Processing metrics...') cost_summary = {} for device in device_id_list: d_name = Device(device_id=device).name info_message(f'Processing metrics from: {d_name}...') cost_summary[device] = float() order = Order(device) order.command_objects_instances('logs') for ms_item in json.loads(order.content): if check_pod_name(ms_item): order.command_objects_instances_by_id('logs', ms_item) cost = json.loads(order.content)['logs'][ms_item]['min'] cost_summary[device] += float(cost) target_device_id = min(cost_summary, key=cost_summary.get) target_device_name = Device(device_id=target_device_id).name info_message(f'Best offer from: {target_device_name}.', 5) context['target_device_id'] = target_device_id context['target_device_name'] = target_device_name
from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API from msa_sdk.order import Order dev_var = Variables() context = Variables.task_call() # (1) loopback try: '''check if loopback already exists''' # order = Order(left_device_id) # order.command_execute('IMPORT', {"sdwan_loopback": context["id"]}) order = Order(context["left_device_id"]) order.command_execute("CREATE", context["sdwan_loopback_left"]) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) try: order = Order(context["right_device_id"]) order.command_execute('CREATE', context["sdwan_loopback_right"]) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) ret = MSA_API.process_content('ENDED', f'Loopbacks Created.', context, True) print(ret)
ms_ipam_address = context['ipam_ms_aliases']['IPAM IPv4 addresses'] ms_ipam_interface = context['ipam_ms_aliases']['IPAM Interfaces'] #Variables to finish the task properlly fail_comment = str() success_comment = str() fail_string = f'{{"wo_status": "FAIL", "wo_comment": "{fail_comment}"}}' success_string = f'{{"wo_status": "ENDED", "wo_comment": "{success_comment}"}}' #Create Orchestration object to update GUI dynamically Orchestration = Orchestration(context['UBIQUBEID']) async_update_list = (context['PROCESSINSTANCEID'], context['TASKID'], context['EXECNUMBER']) #Create IPAM order object IpamOrderObject = Order(ipam_device_id) IpamOrderObject.command_synchronize(300) Orchestration.update_asynchronous_task_details( *async_update_list, 'Retrieve information about CE device on the site... ') objects_list = IpamOrderObject.command_objects_instances(ms_ipam_device) #Retrieve information about CE device what is located on the site counter = 0 ce_device_id = None ce_device_name = None #Find CE device name first while ce_device_name is None or counter < len(objects_list): device_object = IpamOrderObject.command_objects_instances_by_id(
print(ret) exit() # (1) prepare data for k8s_pre_requirements microservice k8s_pre_requirements_data = {"object_id": "123"} k8s_pre_requirements_ms = { "k8s_pre_requirements": { "123": k8s_pre_requirements_data } } device_list = context['vm_id_list_new'] # deploy required packages for me in device_list: Orchestration.update_asynchronous_task_details( *async_update_list, f'k8s software installation: \ {Device(device_id=me).name}' ) try: order = Order(me) order.command_execute('CREATE', k8s_pre_requirements_ms, timeout=300) except Exception as e: ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True) print(ret) ret = MSA_API.process_content('ENDED', f'K8S software installed on {device_list}.', context, True) print(ret)
context = Variables.task_call(dev_var) # read the ID of the selected managed entity device_id = context['device'] # extract the database ID devicelongid = device_id[-3:] # build the Microservice JSON params for the CREATE micro_service_vars_array = { "playbook_path": "/opt/playbooks/linux_firewall_creation.yml", "extra_vars": "\"dport=" + context['dst_port'] + " ip=" + context['src_ip'] + "\"" } playbook = {"AnsiblePlaybook": {"": micro_service_vars_array}} # call the CREATE for simple_firewall MS for each device order = Order(devicelongid) order.command_execute('CREATE', playbook) # convert dict object into json content = json.loads(order.content) order.command_synchronize(10) # check if the response is OK print( order.process_content( 'ENDED', 'STATUS: {content["status"]}, \ MESSAGE: {content["message"]}', context, True))
ms_ipam_avaliable_prefix = context['ipam_ms_aliases']['IPAM Available Prefixes'] ms_ipam_address = context['ipam_ms_aliases']['IPAM IPv4 addresses'] ms_ipam_interface = context['ipam_ms_aliases']['IPAM Interfaces'] #Variables to finish the task properlly fail_comment = str() success_comment = str() fail_string = f'{{"wo_status": "FAIL", "wo_comment": "{fail_comment}"}}' success_string = f'{{"wo_status": "ENDED", "wo_comment": "{success_comment}"}}' #Create Orchestration object to update GUI dynamically Orchestration = Orchestration(context['UBIQUBEID']) async_update_list = (context['PROCESSINSTANCEID'], context['TASKID'], context['EXECNUMBER']) #Create IPAM order object IpamOrderObject = Order(ipam_device_id) IpamOrderObject.command_synchronize(300) #Identify ASN for the site and save to context Orchestration.update_asynchronous_task_details(*async_update_list, 'Retrieve AS number for the site... ') site_object = IpamOrderObject.command_objects_instances_by_id(ms_ipam_site, site)[ms_ipam_site][site] context['site_asn'] = site_object['asn'] Orchestration.update_asynchronous_task_details(*async_update_list, 'Retrieve AS number for the site... OK') time.sleep(3) #Identify IPv4 subnets for the site and save to context Orchestration.update_asynchronous_task_details(*async_update_list, 'Find out a IPv4 block for the site... ')
#Create Orchestration object to update GUI dynamically Orchestration = Orchestration(context['UBIQUBEID']) async_update_list = (context['PROCESSINSTANCEID'], context['TASKID'], context['EXECNUMBER']) #Create VLAN list if IPAM is used if context['use_ipam'] == 'yes': Orchestration.update_asynchronous_task_details( *async_update_list, 'IPAM integration is used. Retrive VLAN info from IPAM... ') context['ipam_device'] = re.match('^\D+?(\d+?)$', context['ipam_device']).group(1) #Retrive information about VLANs IpamOrderObject = Order(context['ipam_device']) IpamOrderObject.command_synchronize(300) objects_list = IpamOrderObject.command_objects_instances(ms_ipam_vlan) vlan_string = str() counter = 0 context['vlan_list'] = dict() for vlan_name in objects_list: vlan_object = IpamOrderObject.command_objects_instances_by_id( ms_ipam_vlan, vlan_name)[ms_ipam_vlan][vlan_name] if 'site' in vlan_object: if vlan_object['site'] == context['site']: context['vlan_list'][counter] = { 'id': vlan_object['vid'], 'name': vlan_object['object_id'], "__index__": counter