context['EXECNUMBER'])

#Create microwave station object
StationDeviceObject = Device(
    customer_id=re.match('^\D+?(\d+?)$', context['UBIQUBEID']).group(1),
    name='{}[{}]'.format(context['hostname'], context['ip_address']),
    device_external=re.sub(r'[\.\[\]-]', "_", context['hostname']),
    manufacturer_id=nec_ipasolink_manufacture_id,
    password_admin=nec_ipasolink_default_password,
    model_id=nec_ipasolink_model_id,
    login=nec_ipasolink_default_username,
    password=nec_ipasolink_default_password,
    management_address=context['ip_address'],
    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
Ejemplo n.º 2
0
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))
    # manufacturer/model = 14020601 > Linux/Generic
    
    cust_id = context["UBIQUBEID"][4:]
    
    vm_id_list = []
    for vm in context['vms']:
        entity = Device(customer_id=cust_id,
                        name=list(vm.keys())[0],
                        manufacturer_id="14020601",
                        model_id="19112020",
                        login=context['vm_username'],
                        password=context['vm_secret'],
                        password_admin=context['vm_secret'],
                        management_address=list(vm.values())[0]['external'])

        entity.create()
        time.sleep(2)
        vm_id_list.append(str(entity.device_id))
        # assign deployment setting
        entity.profile_switch(context['dpl_linux'], context['dpl_linux'])
        time.sleep(2)
        entity.activate()

    Orchestration.update_asynchronous_task_details(*async_update_list,
                                                   f'MEs created - Activating...')
    
    # check if ME is ready to be configured by veryfing asset
    counter = 0
    
    try:
        two = MSAConnect(context['msa_fqdn'],
                                                            site_device_list[0])[ms_ipam_device][site_device_list[0]]
ce_device_local_context = json.loads(json.dumps(xmltodict.parse(ce_device['local_context_data'])))['local_context_data']

CeDeviceObject = Device(customer_id = re.match('^\D+?(\d+?)$',context['UBIQUBEID']).group(1), 
                        name = ce_device['object_id'], 
                        device_external = re.sub(r'[\.\[\]-]', "_", ce_device['object_id']),
                        manufacturer_id = ce_device_local_context['msa_specific']['manufacture_id'],
                        password_admin = ce_device_local_context['enable_password'],
                        model_id = ce_device_local_context['msa_specific']['model_id'],
                        login = ce_device_local_context['username'], 
                        password = ce_device_local_context['password'], 
                        management_address = ce_device['primary_ip'].split('/')[0],
                        management_port = ce_device_local_context['port']
                        )

CeDeviceObject.create()
Orchestration.update_asynchronous_task_details(*async_update_list, 'Create new MSA ME for CE device {}... OK'.format(site_device_list[0]))
time.sleep(3)

#Put useful variables to context
context['ce_device_details'] = dict()
context['ce_device_details']['local_context']       = ce_device_local_context
context['ce_device_details']['device_id']           = CeDeviceObject.device_id
context['ce_device_details']['ce_device_name']		= ce_device['object_id']
context['ce_device_details']['external_reference']  = re.sub(r'[\.\[\]-]', "_", ce_device['object_id'])

success_comment = 'New MSA ME for CE device has been created successfully'
print(CeDeviceObject.process_content('ENDED', success_comment, context, True))