Ejemplo n.º 1
0
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... ')
context['site_prefixes_list'] = list()
Orchestration.update_asynchronous_task_details(
    *async_update_list,
    'Attaching configuration deployment settings profile... ')
StationDeviceObject.profile_attach(nec_ipasolink_profile_name)
Orchestration.update_asynchronous_task_details(
    *async_update_list,
    'Attaching configuration deployment settings profile... OK')

for counter in range(0, 12):
    pretty_formatted_bar.insert(0, '*')
    pretty_formatted_bar.pop()
    Orchestration.update_asynchronous_task_details(
        *async_update_list,
        'Creating managed entity for the station... [{}]'.format(
            ''.join(pretty_formatted_bar)))
    time.sleep(5)

#Sync up microservices
response = StationOrderObject.command_synchronize(300)

Orchestration.update_asynchronous_task_details(
    *async_update_list,
    'Creating managed entity for the station... [{}] OK'.format(
        ''.join(pretty_formatted_bar)))
time.sleep(3)

success_comment = 'Microwave station managed entity created sucessfully.'
print(
    StationDeviceObject.process_content('ENDED', success_comment, context,
                                        True))
#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(
        *async_update_list,
        'Configuring CE device... Clean up IP address on link toward {}... '.
        format(connection['neighbour']['device']))
Ejemplo n.º 4
0
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))
Ejemplo n.º 5
0
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(
        ms_ipam_device,
Ejemplo n.º 6
0
            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',
                                      f'Token not found: {k8s_token}',