Skip to content

Commit

Permalink
Merge pull request #148 from openmsa/mpls_demo_clean_up
Browse files Browse the repository at this point in the history
Processes for MPLS demo clean up have been added
  • Loading branch information
asi-ubi authored Nov 23, 2020
2 parents 4365c33 + 6227c2b commit d229f7b
Show file tree
Hide file tree
Showing 14 changed files with 941 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<metadata>
<map>
<entry>
<key>DATE_MODIFICATION</key>
<value>1603113617483</value>
</entry>
<entry>
<key>REPOSITORY</key>
<value>Process</value>
</entry>
<entry>
<key>DATE_CREATION</key>
<value>1603113617477</value>
</entry>
<entry>
<key>TAG</key>
</entry>
<entry>
<key>FILE_TYPE</key>
<value>text</value>
</entry>
<entry>
<key>TYPE</key>
<value>UPLOAD</value>
</entry>
<entry>
<key>COMMENT</key>
</entry>
</map>
</metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<metadata>
<map>
<entry>
<key>DATE_MODIFICATION</key>
<value>1606077676711</value>
</entry>
<entry>
<key>REPOSITORY</key>
<value>Process</value>
</entry>
<entry>
<key>DATE_CREATION</key>
<value>1606077676704</value>
</entry>
<entry>
<key>TAG</key>
</entry>
<entry>
<key>FILE_TYPE</key>
<value>text</value>
</entry>
<entry>
<key>TYPE</key>
<value>UPLOAD</value>
</entry>
<entry>
<key>COMMENT</key>
</entry>
</map>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<map>
<entry>
<key>DATE_MODIFICATION</key>
<value>1603818839562</value>
<value>1606077677406</value>
</entry>
<entry>
<key>REPOSITORY</key>
<value>Process</value>
</entry>
<entry>
<key>DATE_CREATION</key>
<value>1603818839557</value>
<value>1606077677403</value>
</entry>
<entry>
<key>MODEL</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<map>
<entry>
<key>DATE_MODIFICATION</key>
<value>1602174167103</value>
<value>1606049330235</value>
</entry>
<entry>
<key>REPOSITORY</key>
<value>Process</value>
</entry>
<entry>
<key>DATE_CREATION</key>
<value>1602174167092</value>
<value>1606049330228</value>
</entry>
<entry>
<key>TAG</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<metadata>
<map>
<entry>
<key>DATE_MODIFICATION</key>
<value>1606074382556</value>
</entry>
<entry>
<key>REPOSITORY</key>
<value>Process</value>
</entry>
<entry>
<key>DATE_CREATION</key>
<value>1606074382548</value>
</entry>
<entry>
<key>TAG</key>
</entry>
<entry>
<key>FILE_TYPE</key>
<value>text</value>
</entry>
<entry>
<key>TYPE</key>
<value>UPLOAD</value>
</entry>
<entry>
<key>COMMENT</key>
</entry>
</map>
</metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<metadata>
<map>
<entry>
<key>DATE_MODIFICATION</key>
<value>1606074391321</value>
</entry>
<entry>
<key>REPOSITORY</key>
<value>Process</value>
</entry>
<entry>
<key>DATE_CREATION</key>
<value>1606074391314</value>
</entry>
<entry>
<key>TAG</key>
</entry>
<entry>
<key>FILE_TYPE</key>
<value>text</value>
</entry>
<entry>
<key>TYPE</key>
<value>UPLOAD</value>
</entry>
<entry>
<key>COMMENT</key>
</entry>
</map>
</metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<metadata>
<map>
<entry>
<key>DATE_MODIFICATION</key>
<value>1606074373168</value>
</entry>
<entry>
<key>REPOSITORY</key>
<value>Process</value>
</entry>
<entry>
<key>DATE_CREATION</key>
<value>1606074373160</value>
</entry>
<entry>
<key>TAG</key>
</entry>
<entry>
<key>FILE_TYPE</key>
<value>text</value>
</entry>
<entry>
<key>TYPE</key>
<value>UPLOAD</value>
</entry>
<entry>
<key>COMMENT</key>
</entry>
</map>
</metadata>
54 changes: 54 additions & 0 deletions General_Network_Service_Automation/Clean_up_the_demo_Clean_up.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'''
Visit http://[YOUR_MSA_URL]/msa_sdk/ to see what you can import.
'''
from msa_sdk.variables import Variables
from msa_sdk.msa_api import MSA_API

'''
List all the parameters required by the task
You can use var_name convention for your variables
They will display automaticaly as "Var Name"
The allowed types are:
'String', 'Boolean', 'Integer', 'Password', 'IpAddress',
'IpMask', 'Ipv6Address', 'Composite', 'OBMFRef', 'Device'
Add as many variables as needed
'''
dev_var = Variables()
dev_var.add('var_name', var_type='String')
dev_var.add('var_name2', var_type='Integer')

'''
context => Service Context variable per Service Instance
All the user-inputs of Tasks are automatically stored in context
Also, any new variables should be stored in context which are used across Service Instance
The variables stored in context can be used across all the Tasks and Processes of a particular Service
Update context array [add/update/delete variables] as per requirement
ENTER YOUR CODE HERE
'''
context = Variables.task_call(dev_var)
context['var_name2'] = int(context['var_name2']) + 1

'''
Format of the Task response :
JSON format : {"wo_status":"status","wo_comment":"comment","wo_newparams":{json_body}}
wo_status : ENDED [Green color] or FAILED [Red color] or WARNING [Orange color]
-> While the Task is Running [means no response returned yet], task status is RUNNING [Blue color]
-> When status is returned as FAILED, the Orchestration Engine stops the Process Execution from this Task
wo_comment : Appropriate Comment to display as per the success/failure of the Task
wo_newparams : json_body parameters returned from this Task
Function process_content() takes care of Creating a Json response from inputs
This function definiton can be found at : http://[YOUR_MSA_URL]/msa_sdk/msa_api.html#msa_sdk.msa_api.MSA_API.process_content
NOTE : For 'wo_newparams', always pass "context" [whether wo_status is ENDED/FAILED/WARNING to preserve it across Service Instance]
-> Last argument "true" mentions whether the json_response to be Logged in the logfile : /opt/jboss/latest/logs/process.log
-> If not passed, it's "false"
The response "ret" should be echoed from the Task "print(ret)" which is read by Orchestration Engine
In case of FAILURE/WARNING, the Task can be Terminated by calling "exit" as per Logic
'''
ret = MSA_API.process_content('ENDED', 'Task OK', context, True)
print(ret)

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
from msa_sdk.variables import Variables
from msa_sdk.msa_api import MSA_API
from msa_sdk.order import Order
from msa_sdk.device import Device
from msa_sdk.orchestration import Orchestration
from datetime import datetime
from msa_sdk import constants
from msa_sdk import lookup
from msa_sdk import util
import ipaddress
import time
import re
import json
import xmltodict
import sys
import os


"""
The proposals of the task are:
- Identify site ASN
- Identify site prefixes and IP addresses
- Identify PE and CE devices
"""


#New Variables object
TaskVariables = Variables()

#Add new variables
TaskVariables.add('site', var_type = 'String')
TaskVariables.add('status', var_type = 'String')

#Add vars to context
context = Variables.task_call(TaskVariables)

process_id = context['SERVICEINSTANCEID']
ipam_device_id = context['ipam_device_id']
customer_vrf = context['customer_details']['vrf']
customer_name = context['customer_name']
site = context['site']

ms_ipam_tenant = context['ipam_ms_aliases']['IPAM Tenants']
ms_ipam_site = context['ipam_ms_aliases']['IPAM Sites']
ms_ipam_device = context['ipam_ms_aliases']['IPAM Devices']
ms_interface_connection = context['ipam_ms_aliases']['IPAM Interface Connections']
ms_ipam_prefix = context['ipam_ms_aliases']['IPAM IPv4 prefixes']
ms_ipam_avaliable_prefix = context['ipam_ms_aliases']['IPAM Available Prefixes']
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)

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()

devices = json.loads(MsaLookup.content)

counter = 0
while ce_device_id is None or counter < len(devices):
if devices[counter]['name'] == ce_device_name:
ce_device_id = devices[counter]['id']
counter += 1

Orchestration.update_asynchronous_task_details(*async_update_list, 'Retrieve information about CE device on the site... OK')
time.sleep(3)


Orchestration.update_asynchronous_task_details(*async_update_list, 'Remove CE managed entity... ')
#Create CE device object
CeDeviceObject = Device(device_id = ce_device_id)
CeDeviceObject.delete()
Orchestration.update_asynchronous_task_details(*async_update_list, 'Remove CE managed entity... OK')
time.sleep(3)

#Update IPAM
Orchestration.update_asynchronous_task_details(*async_update_list, 'Update IPAM... ')
ms_dict = {ms_ipam_device:
{ce_device_name: {'object_id': ce_device_name,
'status': context['status'],
'site': device_object['site'],
'role': device_object['role'],
'model': device_object['model']
}
}
}
IpamOrderObject.command_execute('UPDATE', ms_dict)
Orchestration.update_asynchronous_task_details(*async_update_list, 'Update IPAM... OK')
time.sleep(3)


success_comment = 'CE device has been moved to {} on site {}'.format(context['status'], context['site'])
del context['status']
del context['site']
print(IpamOrderObject.process_content('ENDED', success_comment, context, True))
Loading

0 comments on commit d229f7b

Please sign in to comment.