from msa_sdk.device import Device from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API dev_var = Variables() dev_var.add('customer_id', var_type='Customer') dev_var.add('managed_device_name') dev_var.add('manufacturer_id', var_type='Integer') dev_var.add('model_id', var_type='Integer') dev_var.add('device_ip_address', var_type='IP Address', def_value='10.30.19.41') dev_var.add('login') dev_var.add('password', var_type='Password') dev_var.add('password_admin', var_type='Password') context = Variables.task_call(dev_var) new_device = Device(context['customer_id'], context['managed_device_name'], context['manufacturer_id'],context['model_id'], context['login'], context['password'], context['password_admin'],context['device_ip_address']) new_device.create() context['device_id'] = new_device.device_id print(new_device.process_content('ENDED', 'Task OK', context, True))
from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API dev_var = Variables() dev_var.add('device', var_type='Device') context = Variables.task_call(dev_var) ret = MSA_API.process_content( 'ENDED', f'Firewall service created. Managed Entity: {context["device"]}', context, True) print(ret)
import xmltodict import sys """ The proposal of the task is activate ME and attach deployment settings When the task has been finished, details about CE device removed from context. Ops could start to work with another CE """ #New Variables object TaskVariables = Variables() #Add new variables TaskVariables.add('site', var_type = 'String') #Add vars to context context = Variables.task_call(TaskVariables) process_id = context['SERVICEINSTANCEID'] ce_device_id = context['ce_device_details']['device_id'] ce_device_external_reference = context['ce_device_details']['external_reference'] ce_device_name = context['ce_device_details']['ce_device_name'] ce_local_context = context['ce_device_details']['local_context'] ms_ipam_device = context['ipam_ms_aliases']['IPAM Devices'] customer_name = context['customer_name'] ipam_device_id = context['ipam_device_id'] #Variables to finish the task properlly fail_comment = str()
import json import uuid import os import errno import sys import base64 from msa_sdk import constants from msa_sdk.order import Order from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API dev_var = Variables() dev_var.add('vnfd_name', var_type='String') dev_var.add('vnfd_contents', var_type='String') context = Variables.task_call(dev_var) #get uuid from context. uuid_gen = context.get('uuid_gen') vnfd_name = uuid_gen if 'vnfd_name' in context: name = context.get('vnfd_name') if name: vnfd_name = name + '_' + uuid_gen filename = '/opt/fmc_repository/Datafiles/NFV/VNFD/' + vnfd_name + '/Definition/' + vnfd_name + '.yaml' #get VNFD contents from input variable. vnfd_contents = '' if 'vnfd_contents' in context: vnfd_contents = context.get('vnfd_contents')
import json from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API from msa_sdk.order import Order # List all the parameters required by the task dev_var = Variables() dev_var.add('profile', var_type='String') #dev_var.add('gateway', var_type='String') context = Variables.task_call(dev_var) # 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)
import uuid import os import zipfile import shutil from os.path import join from msa_sdk import constants from msa_sdk.order import Order from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API dev_var = Variables() dev_var.add('nsd_name', var_type='String') dev_var.add('nsd_contents', var_type='String') dev_var.add('nsd_csar_file', var_type='String') context = Variables.task_call(dev_var) def zipdir(path, ziph): # ziph is zipfile handle rootlen = len(path) + 1 for root, dirs, files in os.walk(path): for file in files: file_path = join(root, file) ziph.write(file_path, file_path[rootlen:]) if __name__ == '__main__': #get uuid from context. uuid_gen = context.get('uuid_gen') nsd_name = uuid_gen
import re """ The proposals of the task are: - Retrive variables from customer; - Retrieve microservice variables from file - Put the variables to context """ #New Variables object TaskVariables = Variables() #Add new variables TaskVariables.add('customer_name', var_type = 'String') TaskVariables.add('ipam_device_id', var_type = 'Device') #Add vars to context context = Variables.task_call(TaskVariables) context['ipam_device_id'] = re.match('^\D+?(\d+?)$', context['ipam_device_id']).group(1) #Import microservice alias list with open('/opt/fmc_repository/Process/General_Network_Service_Automation/microservices_list.json', 'r') as alias_file: context['ipam_ms_aliases'] = json.load(alias_file) #Finish the task correctlly result = MSA_API.process_content('ENDED', 'All variables have been defined successfully', context, True) print(result)
import json from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API from msa_sdk.order import Order # List all the parameters required by the task dev_var = Variables() dev_var.add('id', var_type='Integer') dev_var.add('src_ip', var_type='String') dev_var.add('dst_port', var_type='Integer') 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 = {"object_id": context['id'], "src_ip": context['src_ip'], "dst_port": context['dst_port'] } object_id = context['id'] simple_firewall = {"simple_firewall": {object_id: micro_service_vars_array}} # call the CREATE for simple_firewall MS for each device order = Order(devicelongid) order.command_execute('CREATE', simple_firewall)
from msa_sdk.variables import Variables from msa_sdk.msa_api import MSA_API from msa_sdk.orchestration import Orchestration import json #Define variables dev_var = Variables() dev_var.add('var_value', var_type='String') context = Variables.task_call(dev_var) #Get sub-tenant ID OrchestrationObject = Orchestration(context['UBIQUBEID']) #active_workflow contains workflow instances what ARE NOT in ARCHIVED state active_workflow = dict() #matched_workflow contains workflow details where requested valued matched matched_workflow = dict() #Retrive all workflow instanes of particular sub-tenant OrchestrationObject.list_service_instances() #Walk through the instances and add to list non archived ones for service in json.loads(OrchestrationObject.content): if service['state'] != 'ARCHIVED' and str(service['id']) != str( context['service_id']): if service['name'] not in active_workflow: active_workflow[service['name']] = list() active_workflow[service['name']].append({ 'id': service['id'], 'state': service['state']