示例#1
0
objects_list = IpamOrderObject.command_objects_instances(ms_ipam_interface)

counter = 0
ce_internal_interface_name = None
while ce_internal_interface_name is None or counter < len(objects_list):
    interface_object = IpamOrderObject.command_objects_instances_by_id(ms_ipam_interface, 
                                                                    objects_list[counter])[ms_ipam_interface][objects_list[counter]]
    if  interface_object['device'] == ce_device_name:
        if 'tags' in interface_object:
            for number, tag in interface_object['tags'].items():
                if tag['tag'] == 'internal':
                    ce_internal_interface_name = interface_object['name']
    counter += 1
    
#Because bug
_ce_connections = dict()
for interface, connection in ce_connections.items():
    _ce_connections[interface.replace('.', 'DOT')] = connection

context['ce_connections'] = _ce_connections


context['ce_device_details'] = dict()
context['ce_device_details']['device_id'] = ce_device_id
context['ce_device_details']['name'] = ce_device_name
context['ce_device_details']['internal_interface_name'] = ce_internal_interface_name


success_comment = f'IP plan information for {site} has been prepared successfully.'
print(IpamOrderObject.process_content('ENDED', success_comment, context, True))
            Orchestration.update_asynchronous_task_details(
                *async_update_list,
                'Configuring PE device... Remove BGP peer for {}... '.format(
                    ce_device_name))
            ms_dict = {
                ms_router_bgp_neighbor: {
                    ip_address['object_id'].split('/')[0].replace('.', '_'): {
                        'object_id': ip_address['object_id'].split('/')[0]
                    }
                }
            }
            pe_order_list[-1].command_execute('DELETE', ms_dict)
            Orchestration.update_asynchronous_task_details(
                *async_update_list,
                'Configuring PE device... Remove BGP peer for {}... OK'.format(
                    ce_device_name))
            pe_order_list[-1].command_synchronize(300)

    #Check if customer VRF exists on PE
    Orchestration.update_asynchronous_task_details(
        *async_update_list, 'Configuring PE device... Remove VRF... ')
    ms_dict = {ms_router_vrf: {customer_vrf: {'object_id': customer_vrf}}}
    pe_order_list[-1].command_execute('DELETE', ms_dict)
    Orchestration.update_asynchronous_task_details(
        *async_update_list, 'Configuring PE device... Remove VRF... OK')
    pe_order_list[-1].command_synchronize(300)

print(
    CeOrderObject.process_content(
        'ENDED', 'CE and PE devices have been cleaned successfully.', context,
        True))
示例#3
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))
	CeOrderObject.command_synchronize(300)
	time.sleep(10)

	objects_list = CeOrderObject.command_objects_instances(ms_router_advert_by_bgp)

	is_site_prefix_announced = False
	counter = 0

	while is_site_prefix_announced is False and counter < len(objects_list):
		prefix_object = CeOrderObject.command_objects_instances_by_id(ms_router_advert_by_bgp, 
                                                                  	   objects_list[counter])[ms_router_advert_by_bgp][objects_list[counter]]
		if prefix_object['object_id'] == ce_internal_prefix:
			is_site_prefix_announced = True
			is_site_prefix_announced_to_all_peers.append(is_site_prefix_announced)
		counter += 1

	sed_command = 'sed -i \'s@{original_string}@{rewrite_string}@\' {ms_file}'.format(original_string = connection['neighbour']['ip_address'].split('/')[0],
																				      rewrite_string = '1.1.1.1',
																				      ms_file = ms_advertised_prefix_file_path)
	os.system(sed_command)

	Orchestration.update_asynchronous_task_details(*async_update_list, 'Verify that internal prefix announced to PE device... OK')

if len(is_site_prefix_announced_to_all_peers) > 0 and all(is_site_prefix_announced_to_all_peers):
	context.pop('ce_connections')
	context.pop('ce_device_details')
	print(CeOrderObject.process_content('ENDED', 'Internal networks have been announced successfully to all peers', context, True))
else:
	print(CeOrderObject.process_content('FAILED', 'Internal networks have not been announced successfully to all peers', context, True))
示例#5
0
peering_list = list()
CeOrderObject.command_synchronize(300)
objects_list = CeOrderObject.command_objects_instances(ms_router_bgp_neighbor)
for neighbor in objects_list:
    neighbor_object = CeOrderObject.command_objects_instances_by_id(
        ms_router_bgp_neighbor, neighbor)[ms_router_bgp_neighbor][neighbor]
    if neighbor_object['state'] == 'Established':
        peering_list.append(True)
    else:
        peering_list.append(False)

Orchestration.update_asynchronous_task_details(
    *async_update_list, 'Verifying BGP session status... [{}] OK'.format(
        str(pretty_formatted_bar)))

if len(peering_list) > 0:
    if all(peering_list):
        print(
            CeOrderObject.process_content(
                'ENDED', 'All BGP sessions have been established', context,
                True))
    else:
        print(
            CeOrderObject.process_content(
                'FAILED',
                'One or more BGP sessions are not in Establshed stage',
                context, True))
else:
    print(
        CeOrderObject.process_content('FAILED', 'No BGP peer has been created',
                                      context, True))
                    are_vlans_member.append(True)
                    break
            else:
                Orchestration.update_asynchronous_task_details(
                    *async_update_list,
                    'Verifying VLAN membership for port {}... VLAN ID {}... FAILED'
                    .format(context['trunk_port'], vlan['id']))
                time.sleep(3)
                are_vlans_member.append(False)

if all(do_vlans_exist):
    if is_port_enable:
        if all(are_vlans_member):
            success_comment = 'The station has been configured properlly'
            print(
                StationOrderObject.process_content('ENDED', success_comment,
                                                   context, True))
        else:
            fail_comment = 'Not all required VLANs are memeber of {}'.format(
                context['trunk_port'])
            print(
                StationOrderObject.process_content('FAILED', fail_comment,
                                                   context, True))
    else:
        fail_comment = 'Trunk port {} is not enabled'.format(
            context['trunk_port'])
        print(
            StationOrderObject.process_content('FAILED', fail_comment, context,
                                               True))
else:
    fail_comment = 'Not all required VLANs exist in database'
    print(