def device_add_to_vpls(task, commit_type): vpls_config = read_remote_services(task) service = create_device_add_to_vpls(task, vpls_config) add_debug_info = task['inputData']['service'].get('debug', False) task = {"inputData": {"service": service.to_dict()}} response_vpls = service_create_vpls_instance(task) dryrun = bool("dry-run" == commit_type) device_ids = list(set(service.device_ids())) if dryrun: response = common_worker.dryrun_commit(device_ids) return common_worker.dryrun_response('VPLS instance: %s dry-run FAIL' % service.id, add_debug_info, response_vpls=response_vpls, response_dryrun=response) else: response = common_worker.commit(device_ids) return common_worker.commit_response(device_ids, 'VPLS instance: %s commit FAIL' % service.id, add_debug_info, response_vpls=response_vpls, response_commit=response)
def service_delete_vpls(task, commit_type): dryrun = bool("dry-run" == commit_type) add_debug_info = task['inputData']['service'].get('debug', False) service_id = task['inputData']['service']['id'] services = read_remote_services({ 'inputData': { 'datastore': 'actual', 'reconciliation': 'name', 'name': service_id } }) number_of_services = len(services) if number_of_services < 1: return common_worker.fail("VPLS instance: %s does not exists" % service_id) if number_of_services > 1: return common_worker.fail( "VPLS instance: %s is not unique. It occurs %s times." % (service_id, number_of_services)) service = services[0] device_ids = list(set(service.device_ids())) response_del = service_delete_vpls_instance( {'inputData': { 'service': service.to_dict() }}) if common_worker.task_failed(response_del): common_worker.replace_cfg_with_oper(device_ids) return common_worker.fail( 'VPLS instance deletion: %s configuration in uniconfig FAIL' % service.id, response=response_del) if dryrun: response = common_worker.dryrun_commit(device_ids) return common_worker.dryrun_response( 'VPLS instance deletion: %s dry-run FAIL' % service.id, add_debug_info, response_delete=response_del, response_dryrun=response) else: response = common_worker.commit(device_ids) return common_worker.commit_response( device_ids, 'VPLS instance deletion: %s commit FAIL' % service.id, add_debug_info, response_delete=response_del, response_commit=response)
def service_delete_bi(task, commit_type): dryrun = bool("dry-run" == commit_type) add_debug_info = task['inputData']['service'].get('debug', False) service = Service.parse_from_task(task) device_ids = service.device_ids() response_del = device_delete_bi_instance(task) if common_worker.task_failed(response_del): common_worker.replace_cfg_with_oper(device_ids) return common_worker.fail('BI instance: %s deletion configuration in uniconfig FAIL' % service.id, response=response_del) if dryrun: response = common_worker.dryrun_commit(device_ids) return common_worker.dryrun_response('BI instance: %s deletion dry-run FAIL' % service.id, add_debug_info, response_delete=response_del, response_dryrun=response) else: response = common_worker.commit(device_ids) return common_worker.commit_response(device_ids, 'BI instance: %s deletion commit FAIL' % service.id, add_debug_info, response_delete=response_del, response_commit=response)
def device_delete_from_vpls(task, commit_type): vpls_config = read_remote_services(task) service = create_device_delete_from_vpls(task, vpls_config) responses_remove = [] remove_ids = list( set(dev['id'] for dev in task['inputData']['service']['devices'])) for dev_id in remove_ids: response_remove = remove_device_vpls(dev_id, service.id) if common_worker.task_failed(responses_remove): return response_remove responses_remove.append(response_remove) device_ids = list(set(service.device_ids())) + remove_ids add_debug_info = task['inputData']['service'].get('debug', False) task = {"inputData": {"service": service.to_dict()}} response_vpls = service_create_vpls_instance(task) dryrun = bool("dry-run" == commit_type) if dryrun: response = common_worker.dryrun_commit(device_ids) return common_worker.dryrun_response('VPLS instance: %s dry-run FAIL' % service.id, add_debug_info, response_remove=responses_remove, response_vpls=response_vpls, response_dryrun=response) else: response = common_worker.commit(device_ids) return common_worker.commit_response(device_ids, 'VPLS instance: %s commit FAIL' % service.id, add_debug_info, response_remove=responses_remove, response_vpls=response_vpls, response_commit=response)
def service_delete_vll_task(task, commit_type): dryrun = bool("dry-run" == commit_type) add_debug_info = task['inputData']['service'].get('debug', False) service_id = task['inputData']['service']['id'] services = service_read_all({'inputData': { 'datastore': 'actual', 'reconciliation': 'name', 'name': service_id }}) number_of_services = len(services['output']['services']) if number_of_services < 1: return common_worker.fail("VLL instance: %s does not exists" % service_id) if number_of_services > 1: return common_worker.fail("VLL instance: %s is not unique. It occurs %s times." % (service_id, number_of_services)) service = Service(services['output']['services'][0]) device_1 = service.devices[0] device_2 = service.devices[1] response = service_delete_vll({'inputData': { 'service': service.to_dict() }}) if common_worker.task_failed(response): common_worker.replace_cfg_with_oper([device_1.id, device_2.id]) return common_worker.fail('VLL instance deletion: %s configuration in uniconfig FAIL' % service.id, response=response) if dryrun: response_dryrun = common_worker.dryrun_commit([device_1.id, device_2.id]) return common_worker.dryrun_response('VLL instance deletion: %s dryrun FAIL' % service.id, add_debug_info, response_create_vpn=response, response_dryrun=response_dryrun) response_commit = common_worker.commit([device_1.id, device_2.id]) return common_worker.commit_response([device_1.id, device_2.id], 'VLL instance deletion: %s commit FAIL' % service.id, add_debug_info, response_create_vpn=response, response_commit=response_commit)
def service_create_vll_task(task, commit_type): dryrun = bool("dry-run" == commit_type) add_debug_info = task['inputData']['service'].get('debug', False) service = Service.parse_from_task(task) device_1 = service.devices[0] device_2 = service.devices[1] # Check interfaces exist ifc_response = read_interface(device_1) if common_worker.task_failed(ifc_response): return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s does not exist' % (service.id, device_1.id, device_1.interface), response=ifc_response) ifc_response = read_interface(device_2) if common_worker.task_failed(ifc_response): return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s does not exist' % (service.id, device_2.id, device_2.interface), response=ifc_response) # Reset interfaces if necessary ifc_delete_policy_response_1 = '' ifc_delete_response_1 = '' if not dryrun and device_1.interface_reset: policy_1 = read_interface_policy(device_1) if not common_worker.task_failed(policy_1): ifc_delete_policy_response_1 = delete_interface_policy(device_1) if ifc_delete_policy_response_1 is not None and common_worker.task_failed(ifc_delete_policy_response_1): common_worker.replace_cfg_with_oper([device_1.id]) return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface policy %s cannot be reset' % (service.id, device_1.id, device_1.interface), response=ifc_delete_policy_response_1) ifc_delete_response_1 = delete_interface(device_1) if common_worker.task_failed(ifc_delete_response_1): common_worker.replace_cfg_with_oper([device_1.id, device_2.id]) return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be reset' % (service.id, device_1.id, device_1.interface), response=ifc_delete_response_1) ifc_delete_policy_response_2 = '' ifc_delete_response_2 = '' if not dryrun and device_2.interface_reset: policy_2 = read_interface_policy(device_2) if not common_worker.task_failed(policy_2): ifc_delete_policy_response_2 = delete_interface_policy(device_2) if ifc_delete_policy_response_2 is not None and common_worker.task_failed(ifc_delete_policy_response_2): common_worker.replace_cfg_with_oper([device_2.id]) return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface policy %s cannot be reset' % (service.id, device_2.id, device_2.interface), response=ifc_delete_policy_response_2) ifc_delete_response_2 = delete_interface(device_2) if common_worker.task_failed(ifc_delete_response_2): common_worker.replace_cfg_with_oper([device_1.id, device_2.id]) return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be reset' % (service.id, device_2.id, device_2.interface), response=ifc_delete_response_2) if not dryrun and (device_1.interface_reset or device_2.interface_reset): response_commit = common_worker.commit([device_1.id, device_2.id]) # Check response from commit RPC. The RPC always succeeds but the status field needs to be checked if common_worker.task_failed(response_commit) or common_worker.uniconfig_task_failed(response_commit): common_worker.replace_cfg_with_oper([device_1.id, device_2.id]) return common_worker.fail('VLL instance: %s commit for interface reset FAIL' % service.id, response_commit=response_commit) response_sync_from_net = common_worker.sync_from_net([device_1.id, device_2.id]) # Check response from commit RPC. The RPC always succeeds but the status field needs to be checked if common_worker.task_failed(response_sync_from_net) or common_worker.uniconfig_task_failed(response_sync_from_net): common_worker.replace_cfg_with_oper([device_1.id, device_2.id]) return common_worker.fail('VLL instance: %s sync_from_network after interface reset FAIL' % service.id, response_sync_from_net=response_sync_from_net) # Configure interface #1 ifc_put_response1 = put_interface(service, device_1) if common_worker.task_failed(ifc_put_response1): common_worker.replace_cfg_with_oper([device_1.id, device_2.id]) return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be configured' % (service.id, device_1.id, device_1.interface), response=ifc_put_response1) ifc_policy_put_response1 = put_interface_policy(device_1) if ifc_policy_put_response1 is not None and common_worker.task_failed(ifc_policy_put_response1): common_worker.replace_cfg_with_oper([device_1.id, device_2.id]) return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface policies %s cannot be configured' % (service.id, device_1.id, device_1.interface), response=ifc_policy_put_response1) ifc_stp_delete_response1 = disable_interface_stp(device_1) # Configure interface #2 ifc_put_response2 = put_interface(service, device_2) if common_worker.task_failed(ifc_put_response2): common_worker.replace_cfg_with_oper([device_1.id, device_2.id]) return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be configured' % (service.id, device_2.id, device_2.interface), response=ifc_put_response2) ifc_policy_put_response2 = put_interface_policy(device_2) if ifc_policy_put_response2 is not None and common_worker.task_failed(ifc_policy_put_response2): common_worker.replace_cfg_with_oper([device_1.id, device_2.id]) return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface policies %s cannot be configured' % (service.id, device_2.id, device_2.interface), response=ifc_policy_put_response2) ifc_stp_delete_response2 = disable_interface_stp(device_2) # Configure service response = service_create_vll(task) if common_worker.task_failed(response): common_worker.replace_cfg_with_oper([device_1.id, device_2.id]) return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL' % service.id, response=response) if dryrun: response_dryrun = common_worker.dryrun_commit([device_1.id, device_2.id]) return common_worker.dryrun_response('VLL instance: %s dryrun FAIL' % service.id, add_debug_info, response_device1_interface=ifc_put_response1, response_device1_interface_policy=ifc_policy_put_response1, response_device1_stp_interface=ifc_stp_delete_response1, response_device2_interface=ifc_put_response2, response_device2_interface_policy=ifc_policy_put_response2, response_device2_stp_interface_policy=ifc_stp_delete_response2, response_create_vpn=response, response_dryrun=response_dryrun) response_commit = common_worker.commit([device_1.id, device_2.id]) return common_worker.commit_response([device_1.id, device_2.id], 'VLL instance: %s commit FAIL' % service.id, add_debug_info, response_device1_interface_reset=ifc_delete_response_1, response_device1_interface_policy_delete=ifc_delete_policy_response_1, response_device1_interface=ifc_put_response1, response_device1_interface_policy=ifc_policy_put_response1, response_device1_stp_interface=ifc_stp_delete_response1, response_device2_interface_reset=ifc_delete_response_2, response_device2_interface_policy_delete=ifc_delete_policy_response_2, response_device2_interface=ifc_put_response2, response_device2_interface_policy=ifc_policy_put_response2, response_device2_stp_interface_policy=ifc_stp_delete_response2, response_create_vpn=response, response_commit=response_commit)
def service_create_bi(task, commit_type): dryrun = bool("dry-run" == commit_type) add_debug_info = task['inputData']['service'].get('debug', False) service = Service.parse_from_task(task) vlan_put_responses = [] ve_ifc_put_responses = [] ifc_put_responses = [] isis_put_responses = [] ifc_policy_put_responses = [] for device in service.devices: if not dryrun and device.interface_reset: policy = vll_service_worker.read_interface_policy(device) if not common_worker.task_failed(policy): ifc_delete_policy = vll_service_worker.delete_interface_policy(device) if ifc_delete_policy is not None and common_worker.task_failed(ifc_delete_policy): common_worker.replace_cfg_with_oper([device.id]) return common_worker.fail('BI instance: %s configuration in uniconfig FAIL. Device: %s interface policy %s cannot be reset' % (service.id, device.id, device.interface), response=ifc_delete_policy) ifc_delete_response = vll_service_worker.delete_interface(device) if common_worker.task_failed(ifc_delete_response): common_worker.replace_cfg_with_oper(service.device_ids()) return common_worker.fail('BI instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be reset' % (service.id, device.id, device.interface), response=ifc_delete_response) response_commit = common_worker.commit([device.id]) # Check response from commit RPC. The RPC always succeeds but the status field needs to be checked if common_worker.task_failed(response_commit) or common_worker.uniconfig_task_failed(response_commit): common_worker.replace_cfg_with_oper(service.device_ids()) return common_worker.fail('BI commit for device %s reset FAIL' % device.id, response_commit=response_commit) response_sync_from_net = common_worker.sync_from_net([device.id]) # Check response from commit RPC. The RPC always succeeds but the status field needs to be checked if common_worker.task_failed(response_sync_from_net) or common_worker.uniconfig_task_failed(response_sync_from_net): common_worker.replace_cfg_with_oper(service.device_ids()) return common_worker.fail('BI sync_from_network after device %s reset FAIL' % device.id, response_sync_from_net=response_sync_from_net) vlan_put_response = put_vlan(service, device) if common_worker.task_failed(vlan_put_response): common_worker.replace_cfg_with_oper(service.device_ids()) return common_worker.fail('BI instance: %s configuration in uniconfig FAIL. Device: %s vlan %s cannot be configured' % (service.id, device.id, device.vlan), response=vlan_put_response) vlan_put_responses.append(vlan_put_response) ifc_put_response = put_interface(service, device) if common_worker.task_failed(ifc_put_response): common_worker.replace_cfg_with_oper(service.device_ids()) return common_worker.fail('BI instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be configured' % (service.id, device.id, device.interface), response=ifc_put_response) ifc_put_responses.append(ifc_put_response) ifc_policy_put_response = vll_service_worker.put_interface_policy(device) if ifc_policy_put_response is not None and common_worker.task_failed(ifc_policy_put_response): common_worker.replace_cfg_with_oper(service.device_ids()) return common_worker.fail('BI instance: %s configuration in uniconfig FAIL. Device: %s interface policies %s cannot be configured' % (service.id, device.id, device.interface), response=ifc_policy_put_response) ifc_policy_put_responses.append(ifc_policy_put_response) vll_service_worker.disable_interface_stp(device) ve_ifc_put_response = put_ve_interface(service, device) if common_worker.task_failed(ve_ifc_put_response): common_worker.replace_cfg_with_oper(service.device_ids()) return common_worker.fail('BI instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be configured' % (service.id, device.id, device.ve_interface), response=ve_ifc_put_response) ve_ifc_put_responses.append(ve_ifc_put_response) isis_put_response = put_isis(device) if common_worker.task_failed(isis_put_response): common_worker.replace_cfg_with_oper(service.device_ids()) return common_worker.fail('BI instance: %s configuration in uniconfig FAIL. Device: %s isis interface %s cannot be configured' % (service.id, device.id, device.interface), response=isis_put_response) isis_put_responses.append(isis_put_response) device_ids = service.device_ids() # Check response from dryrun RPC. The RPC always succeeds but the status field needs to be checked if dryrun: response = common_worker.dryrun_commit(device_ids) return common_worker.dryrun_response('BI instance: %s dry-run FAIL' % service.id, add_debug_info, response_interface=ifc_put_responses, response_ifc_policy=ifc_policy_put_responses, response_ve_interface=ve_ifc_put_responses, response_interface_isis=isis_put_responses, response_vlans=vlan_put_responses, response_dryrun=response) else: response = common_worker.commit(device_ids) return common_worker.commit_response(device_ids, 'BI instance: %s commit FAIL' % service.id, add_debug_info, response_interface=ifc_put_responses, response_ifc_policy=ifc_policy_put_responses, response_ve_interface=ve_ifc_put_responses, response_interface_isis=isis_put_responses, response_vlans=vlan_put_responses, response_commit=response)
def service_create_vpls(task, commit_type): dryrun = bool("dry-run" == commit_type) add_debug_info = task['inputData']['service'].get('debug', False) service = Service.parse_from_task(task) device_ids = list(set(service.device_ids())) if len(device_ids) < 2: raise Exception( "There is need to have at least 2 devices to configure vpls instance" ) ifc_responses = [] ifc_put_responses = [] ifc_policy_put_responses = [] ifc_disable_stp_responses = [] for device in service.devices: ifc_response = vll_service_worker.read_interface(device) if common_worker.task_failed(ifc_response): common_worker.replace_cfg_with_oper(device_ids) return common_worker.fail( 'VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface %s does not exist' % (service.id, device.id, device.interface), response=ifc_response) ifc_responses.append(ifc_response) if not dryrun and device.interface_reset: policy = vll_service_worker.read_interface_policy(device) if not common_worker.task_failed(policy): ifc_delete_policy = vll_service_worker.delete_interface_policy( device) if ifc_delete_policy is not None and common_worker.task_failed( ifc_delete_policy): common_worker.replace_cfg_with_oper([device.id]) return common_worker.fail( 'VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface policy %s cannot be reset' % (service.id, device.id, device.interface), response=ifc_delete_policy) ifc_delete_response = vll_service_worker.delete_interface(device) if common_worker.task_failed(ifc_delete_response): common_worker.replace_cfg_with_oper([device.id]) return common_worker.fail( 'VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be reset' % (service.id, device.id, device.interface), response=ifc_delete_response) response_commit = common_worker.commit([device.id]) # Check response from commit RPC. The RPC always succeeds but the status field needs to be checked if common_worker.task_failed( response_commit) or common_worker.uniconfig_task_failed( response_commit): common_worker.replace_cfg_with_oper([device.id]) return common_worker.fail( 'VPLS instance: %s commit for interface reset FAIL' % service.id, response_commit=response_commit) response_sync_from_net = common_worker.sync_from_net([device.id]) # Check response from commit RPC. The RPC always succeeds but the status field needs to be checked if common_worker.task_failed( response_sync_from_net ) or common_worker.uniconfig_task_failed(response_sync_from_net): common_worker.replace_cfg_with_oper([device.id]) return common_worker.fail( 'VPLS instance: %s sync_from_network after interface reset FAIL' % service.id, response_sync_from_net=response_sync_from_net) ifc_put_response1 = vll_service_worker.put_interface(service, device) if common_worker.task_failed(ifc_put_response1): common_worker.replace_cfg_with_oper(device_ids) return common_worker.fail( 'VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be configured' % (service.id, device.id, device.interface), response=ifc_put_response1) ifc_put_responses.append(ifc_put_response1) ifc_policy_put_response1 = vll_service_worker.put_interface_policy( device) if ifc_policy_put_response1 is not None and common_worker.task_failed( ifc_policy_put_response1): common_worker.replace_cfg_with_oper(device_ids) return common_worker.fail( 'VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface policies %s cannot be configured' % (service.id, device.id, device.interface), response=ifc_policy_put_response1) if ifc_policy_put_response1 is not None: ifc_policy_put_responses.append(ifc_policy_put_response1) ifc_stp_delete_response1 = vll_service_worker.disable_interface_stp( device) # return common_worker.fail('VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface STP %s cannot be configured' # % (service.id, device.id, device.interface), response_delete_stp=ifc_stp_delete_response1) # ifc_disable_stp_responses.append(ifc_stp_delete_response1) response_create = service_create_vpls_instance(task) if common_worker.task_failed(response_create): common_worker.replace_cfg_with_oper(device_ids) return common_worker.fail( 'VPLS instance: %s configuration in uniconfig FAIL' % service.id, response=response_create) # Check response from dryrun RPC. The RPC always succeeds but the status field needs to be checked if dryrun: response = common_worker.dryrun_commit(device_ids) return common_worker.dryrun_response( 'VPLS instance: %s dry-run FAIL' % service.id, add_debug_info, response_interface=ifc_put_responses, response_interface_policy=ifc_policy_put_responses, response_stp_interface_policy=ifc_disable_stp_responses, response_network_instance=response_create, response_dryrun=response) else: response = common_worker.commit(device_ids) return common_worker.commit_response( device_ids, 'VPLS instance: %s commit FAIL' % service.id, add_debug_info, response_interface=ifc_put_responses, response_interface_policy=ifc_policy_put_responses, response_stp_interface_policy=ifc_disable_stp_responses, response_network_instance=response_create, response_commit=response)