예제 #1
0
def update_asynchronous_task_details(details: str):
    """

    Update Asynchronous Task details.

    Print task details during Process execution.

    Parameters
    ----------
    detail: String
            The message to display in msa-ui

    Returns
    -------
    object: Orchestration

    """
    context = Variables.task_call()
    process_instance_id = context['PROCESSINSTANCEID']
    task_id = context['TASKID']
    exec_number = context['EXECNUMBER']
    orch = Orchestration(None)
    orch.update_asynchronous_task_details(process_instance_id, task_id,
                                          exec_number, details)
    return orch
예제 #2
0
#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(
        ms_ipam_device,
        objects_list[counter])[ms_ipam_device][objects_list[counter]]
    if device_object['role'] == 'CE' and device_object['site'] == site:
        ce_device_name = device_object['object_id']
예제 #3
0
async_update_list = (context['PROCESSINSTANCEID'], context['TASKID'],
                     context['EXECNUMBER'])

#Create IPAM order object
IpamOrderObject = Order(ipam_device_id)
IpamOrderObject.command_synchronize(300)

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
Orchestration.update_asynchronous_task_details(
    *async_update_list, 'Retrieve information about CE device on the site... ')
while ce_device_name is None or counter < len(objects_list):
    util.log_to_process_file(
        process_id, 'DEBUG: {}'.format(
            IpamOrderObject.command_objects_instances_by_id(
                ms_ipam_device, objects_list[counter])))
    device_object = IpamOrderObject.command_objects_instances_by_id(
        ms_ipam_device,
        objects_list[counter])[ms_ipam_device][objects_list[counter]]
    if device_object['role'] == 'CE' and device_object['site'] == site:
        ce_device_name = device_object['object_id']
    counter += 1

#Find device ID value
MsaLookup = lookup.Lookup()
MsaLookup.look_list_device_ids()
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']
    counter += 1

#If the customer does not exist in IPAM system, finish the task as fail
if not does_tenant_exists:
    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)
    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
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(
예제 #7
0
def info_message(text, timeout=1):
    Orchestration.update_asynchronous_task_details(*async_update_list, text)
    time.sleep(timeout)
for me in device_list:
    if me['name'] == context['vm_name'] + '-1':
        master_id = me['id']
    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:
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']

#Find all devices on the site
site_device_list = list()
for device in context['customer_details']['devices_list']:
    device_object = IpamOrderObject.command_objects_instances_by_id(ms_ipam_device, 
                                                                    device)[ms_ipam_device][device]
    try:
        if device_object['site'] == context['site']:
from msa_sdk.order import Order
from msa_sdk.msa_api import MSA_API

dev_var = Variables()
context = Variables.task_call()

Orchestration = Orchestration(context['UBIQUBEID'])
async_update_list = (context['PROCESSINSTANCEID'], context['TASKID'],
                     context['EXECNUMBER'])

device_id = context['k8s_api'][3:]

k8_pods_list = {'k8_pods_list': {'': {'object_id': ''}}}

try:
    Orchestration.update_asynchronous_task_details(*async_update_list,
                                                   f'Sync in progress...')
    order = Order(str(device_id))
    order.command_synchronize(timeout=60)
    Orchestration.update_asynchronous_task_details(*async_update_list,
                                                   f'Syncronized.')
    time.sleep(2)
    Orchestration.update_asynchronous_task_details(*async_update_list,
                                                   f'Check in progress...')
    order.command_execute('IMPORT', k8_pods_list)
    data = json.loads(order.content)
except Exception as e:
    ret = MSA_API.process_content('FAILED', f'ERROR: {str(e)}', context, True)
    print(ret)

if 'message' in data.keys():
    container_list = json.loads(data['message'])['k8_pods_list'].keys()
예제 #11
0
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()

Orchestration.update_asynchronous_task_details(*async_update_list,
                                               'Configuring CE device... ')
for interface, connection in ce_connections.items():

    Orchestration.update_asynchronous_task_details(
        *async_update_list,
        'Configuring CE device... IP address on link toward {}... '.format(
            connection['neighbour']['device']))
    #Create oreder object for PE
    pe_order_list.append(Order(connection['neighbour']['device_id']))
    response = pe_order_list[-1].command_synchronize(300)

    #Configure IP address on CE link
    ms_dict = {
        ms_router_interface: {
            interface: {
                'object_id': interface,
예제 #12
0
    for me in device_list:
        if me['name'] == context['vm_name'] + '-1':
            master_prim = me['id']
        for item in range(start, stop):
            if me['name'] == context['vm_name'] + '-' + str(item):
                msa_rm_vm.append(me['id'])

    # (1) drain and remove node from k8s cluster
    # primary master hardcoded
    try:
        for item in range(start, stop):

            node_name = context['vm_name'] + '-' + str(item)
            Orchestration.update_asynchronous_task_details(
                *async_update_list,
                f'Removing {node_name} from k8s cluster...')

            del_worker_me(str(master_prim), node_name)

            Orchestration.update_asynchronous_task_details(
                *async_update_list, f'{node_name} removed from k8s cluster.')

    except Exception as e:
        ret = MSA_API.process_content('WARNING', f'ERROR: {str(e)}', context,
                                      True)
        print(ret)

    # (2) remove from Azure
    try:
        one = AZDelete(client_id=context['client_id'],
    'Station Ethernet port VLAN configuration']
ms_hostname = context['ms_aliases']['Station hostname']
ms_port_settings = context['ms_aliases']['Station Ethernet port settings']

#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'])

Orchestration.update_asynchronous_task_details(
    *async_update_list, 'Import current configuration... ')

#Create Station device order object
StationOrderObject = Order(context['station_device_id'])
response = StationOrderObject.command_synchronize(300)
Orchestration.update_asynchronous_task_details(
    *async_update_list, 'Import current configuration... OK')
time.sleep(3)

#Check VLAN IDs
Orchestration.update_asynchronous_task_details(*async_update_list,
                                               'Verifying VLANs... ')
objects_list = StationOrderObject.command_objects_instances(ms_vlan)
do_vlans_exist = list()
for number, vlan in context['vlan_list'].items():
    Orchestration.update_asynchronous_task_details(
#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 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]
예제 #15
0
                        manufacturer_id="20060101",
                        model_id="20060101",
                        login="******",
                        password="******",
                        password_admin="admin",
                        management_address=k8s_api_ip)

        entity.create()
    except Exception as e:
        ret = MSA_API.process_content('WARNING',
                                      f'Can\'t call device {me_id} : {str(e)}',
                                      context, True)
        print(ret)
        exit()
        
    Orchestration.update_asynchronous_task_details(*async_update_list,
                                                   f'K8S API ME CREATED...')
    
    time.sleep(2)
    # set k8s specific parameters
    try:
        three.set_params(str(entity.device_id), 'KUBE_TOKEN', k8s_token)
        three.set_params(str(entity.device_id), 'KUBE_AUTH_METHOD', 'KUBERNETES')
        three.set_params(str(entity.device_id), 'KUBE_HTTP_PROTOCOL', 'https')
        three.set_params(str(entity.device_id), 'KUBE_PORT', '6443')
    except Exception as e:
        ret = MSA_API.process_content('WARNING',
                                      f'Can\'t set custom params {me_id} : {str(e)}',
                                      context, True)
        print(ret)
        exit()
    
}

# stub here - actually k8s master nodes should be selected according to the user input
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)
예제 #17
0
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()

#Wait until provisioning is done
while CeDeviceObject.provision_status()['status'] != 'OK':
    pretty_formatted_bar.insert(0,'*')
    Orchestration.update_asynchronous_task_details(*async_update_list, 'Provisioning of CE device... [{}]'.format(''.join(pretty_formatted_bar)))
    time.sleep(10)
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(
        *async_update_list,
        'Configuring CE device... Clean up IP address on link toward {}... '.
        format(connection['neighbour']['device']))

    #Clean up IP address on CE link
    ms_dict = {ms_router_interface: {interface: {'object_id': interface}}}
    CeOrderObject.command_execute('UPDATE', ms_dict)
    Orchestration.update_asynchronous_task_details(
        *async_update_list,
                        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'],
                         context['msa_user'],
                         context['msa_pass'])
        while len(vm_id_list) > 0:
            for me in vm_id_list:
                if len(two.get_device_asset(me)['serialNb']) > 1:
                    vm_id_list.remove(me)
                    Orchestration.update_asynchronous_task_details(*async_update_list,
                                                                   f'ME id:{Device(device_id=me).name} = Ready')
            time.sleep(3)
search = Lookup()
search.look_list_device_by_customer_ref(cust_ref)
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)
예제 #21
0
    if me['name'] == context['vm_name'] + '-1':
        master_id = me['id']
    elif me['name'] == context['vm_name'] + '-2':
        backup_id = me['id']
    elif me['name'] == context['vm_name'] + '-3':
        lb_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": Device(device_id=str(lb_id)).management_address,
    "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')
'''
# open when master selection option available
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')
'''
예제 #22
0
            context, True)
        print(ret)
        exit()
    except HTTPError:
        ret = MSA_API.process_content(
            'WARNING', f'AZConnection.vm_create - HTTP Error - Check API',
            context, True)
        print(ret)
        exit()

    except Exception as e:
        ret = MSA_API.process_content('FAILED', f'{vm}', context, True)
        print(ret)
        exit()

    Orchestration.update_asynchronous_task_details(
        *async_update_list, f'VMs have just been STARTED, waiting...')

    counter = 0
    try:
        while len(vm_id_list) > 0:
            for id in vm_id_list:
                status = one.get_resource_status(id, '2020-06-01')
                if status == 'Succeeded':
                    vm_id_list.remove(id)
                    Orchestration.update_asynchronous_task_details(
                        *async_update_list, f'{id[-10:]} = {status}')
            time.sleep(4)
            counter = counter + 4
            if counter >= 300:
                break
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]
                                    				 }
                        }
        }
CeOrderObject.command_execute('UPDATE', ms_dict)
Orchestration.update_asynchronous_task_details(*async_update_list, 'Configuring IP address on CE device internal link... OK') 
CeOrderObject.command_synchronize(300)


#Configure route filter
Orchestration.update_asynchronous_task_details(*async_update_list, 'Configuring route filter for internal prefix... ') 
예제 #24
0
                    subnet_id = item['id']

        return subnet_id


if __name__ == "__main__":

    try:
        one = AZGetVMs(client_id=context['client_id'],
                       client_secret=context['client_secret'],
                       subscription_id=context['subscription_id'],
                       tenant_id=context['tenant_id'],
                       resource_group=context['resource_group'],
                       location=context['location'])

        Orchestration.update_asynchronous_task_details(
            *async_update_list, f'Retrieving last index...')

        vms = one.get_virtual_machines(context['subscription_id'],
                                       context['resource_group'])

        Orchestration.update_asynchronous_task_details(
            *async_update_list, f'Retrieving security groups...')

        sec_group_id = one.get_sec_group(context['subscription_id'],
                                         context['resource_group'])

        Orchestration.update_asynchronous_task_details(
            *async_update_list, f'Retrieving subnets...')

        subnet_id = one.get_subnet(context['subscription_id'],
                                   context['resource_group'])
예제 #25
0
                           tenant_id=context['tenant_id'],
                           resource_group=context['resource_group'],
                           location=context['location'])

        start = int(context['vm_index']) + 1
        stop = start + int(context['scale_lvl'])

        for i in range(start, stop):
            ip_name = context['public_ip_name'] + '-' + str(i) + '-ip'
            fqdn = context['vm_label'] + '-' + str(i)
            public_ip = one.public_ip_create(public_ip_name=ip_name,
                                             vm_label=fqdn)
            pub_ip_id = public_ip['id']
            one.get_status_loop(pub_ip_id, '2020-05-01')
            status = one.get_resource_status(pub_ip_id, '2020-05-01')
            Orchestration.update_asynchronous_task_details(
                *async_update_list, f'{ip_name} = {status}')

    except ConnectionError:
        ret = MSA_API.process_content('WARNING',
                                      f'Connection Error - Check Internet',
                                      context, True)
        print(ret)
        exit()
    except HTTPError:
        ret = MSA_API.process_content('WARNING', f'HTTP Error - Check API',
                                      context, True)
        print(ret)
        exit()

    # need only prefix from any ip address
    context['pub_ip_id_new'] = pub_ip_id
예제 #26
0
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... ')
context['site_prefixes_list'] = list()
objects_list = IpamOrderObject.command_objects_instances(ms_ipam_prefix)


for object in objects_list:
    prefix_object = IpamOrderObject.command_objects_instances_by_id(ms_ipam_prefix, 
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)
IpamOrderObject.command_synchronize(300)


#Remove site prefixes
for prefix in context['site_prefixes_list']:
  Orchestration.update_asynchronous_task_details(*async_update_list, 'Remove site {} prefix {} from IPAM... '.format(site, prefix['object_id']))
  ms_dict = {ms_ipam_prefix: 
                           {prefix['object_id'].replace('.', '_'): {'object_id': prefix['object_id']}
                           }
            }
  IpamOrderObject.command_execute('DELETE', ms_dict)
  Orchestration.update_asynchronous_task_details(*async_update_list, 'Remove site {} prefix {} from IPAM... OK'.format(site, prefix['object_id']))
  time.sleep(3)
IpamOrderObject.command_synchronize(300)


#Remove site IP addresses
for ip_address in context['site_address_list']:
  Orchestration.update_asynchronous_task_details(*async_update_list, 'Remove site {} address {} from IPAM... '.format(site, ip_address['object_id']))
  ms_dict = {ms_ipam_address: 
                           {ip_address['object_id'].replace('.', '_'): {'object_id': ip_address['object_id']}