def service_create_vll_remote(task): service = RemoteService.parse_from_task(task) device_1 = service.devices[0] device_2 = service.devices[1] if service.is_local(): raise Exception('For remote VLL service, 2 different devices are expected. Received: %s' % (service.device_ids())) response1 = vll_worker.device_create_vll_remote({'inputData': { 'id': device_1.id, 'service_id': service.id, 'vccid': service.vccid, 'interface': device_1.interface, 'vlan': device_1.vlan, 'remote_ip': device_2.remote_ip, 'mtu': service.mtu if service.mtu is not None else 0 }}) if common_worker.task_failed(response1): return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL' % service.id, response=response1) response2 = vll_worker.device_create_vll_remote({'inputData': { 'id': device_2.id, 'service_id': service.id, 'vccid': service.vccid, 'interface': device_2.interface, 'vlan': device_2.vlan, 'remote_ip': device_1.remote_ip, 'mtu': service.mtu if service.mtu is not None else 0 }}) if common_worker.task_failed(response2): return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL' % service.id, response1=response1, response2=response2) return common_worker.complete('VLL instance: %s configured in uniconfig successfully' % service.id, response1=response1, response2=response2)
def device_delete_bi_instance(task): service = Service.parse_from_task(task) ifc_responses = [] ve_ifc_responses = [] vlan_responses = [] for device in service.devices: response = delete_ve_interface(device) if common_worker.task_failed(response): return common_worker.fail('BI interface %s removal in uniconfig FAIL' % device.ve_interface, response=response) ve_ifc_responses.append(response) response = vll_service_worker.put_minimal_interface(device) if common_worker.task_failed(response): return common_worker.fail('BI interface %s removal in uniconfig FAIL' % device.interface, response=response) ifc_responses.append(response) response = delete_vlan(device) if common_worker.task_failed(response): return common_worker.fail('BI vlan %s removal in uniconfig FAIL' % device.vlan, response=response) vlan_responses.append(response) return common_worker.complete('BI instance: %s removed in uniconfig successfully' % service.id, ifc_response=ifc_responses, ve_ifc_response=ve_ifc_responses, vlan_response=vlan_responses)
def service_delete_vll_remote(task): service = Service.parse_from_task(task) if service.is_local(): raise Exception('For remote VLL service, 2 different devices are expected. Received: %s' % (service.device_ids())) response1 = remove_device_vll(service.devices[0].id, service.id) if common_worker.task_failed(response1): return common_worker.fail('VLL instance: %s removal in uniconfig FAIL' % service.id, response=response1) response2 = remove_device_vll(service.devices[1].id, service.id) if common_worker.task_failed(response2): return common_worker.fail('VLL instance: %s removal in uniconfig FAIL' % service.id, response=response2) return common_worker.complete('VLL instance: %s removed in uniconfig successfully' % service.id, response1=response1, response2=response2)
def service_read_all(task): datastore = task['inputData'].get('datastore', 'actual') if datastore not in ['intent', 'actual']: return common_worker.fail('Unable to read uniconfig datastore: %s' % datastore) response = uniconfig_worker.execute_read_uniconfig_topology_operational(task) if datastore == 'actual' \ else uniconfig_worker.execute_read_uniconfig_topology_config(task) if common_worker.task_failed(response): return common_worker.fail('Unable to read uniconfig', response=response) if 'node' not in response['output']['response_body']['topology'][0]: raise Exception("Uniconfig topology is empty.") uniconfig_nodes = response['output']['response_body']['topology'][0]['node'] devices = [] for node in map(lambda n: (n['node-id'], extract_network_instances(n)), uniconfig_nodes): node_id = node[0] bis = node[1] dev = Service.parse_from_openconfig_network(node_id, bis[0], bis[1], bis[2]) if dev is not None: devices.extend(dev) device_final = [dev.to_dict() for dev in devices] return common_worker.complete('BI instances found successfully', services=device_final)
def service_read_all(task): # TODO add vll-local vs vll selections datastore = task['inputData'].get('datastore', 'actual') strategy, reconciliation = get_filter_strategy(task) if datastore not in ['intent', 'actual']: return common_worker.fail('Unable to read uniconfig datastore: %s' % datastore) response = uniconfig_worker.execute_read_uniconfig_topology_operational(task) if datastore == 'actual' \ else uniconfig_worker.execute_read_uniconfig_topology_config(task) if common_worker.task_failed(response): return common_worker.fail('Unable to read uniconfig', response=response) if reconciliation not in ['name', 'vccid']: return common_worker.fail('Unable to reconcile with strategy: %s' % reconciliation) if 'node' not in response['output']['response_body']['topology'][0]: raise Exception("Uniconfig topology is empty.") uniconfig_nodes = response['output']['response_body']['topology'][0]['node'] node_2_l2p2p = map( lambda n: (n['node-id'], extract_network_instances(n, strategy)), uniconfig_nodes) local_services = [] remote_services = [] for node in node_2_l2p2p: node_id = node[0] l2p2ps = node[1][0] default_ni = node[1][1] ifcs = node[1][2] if len(l2p2ps) is 0: continue for l2p2p in l2p2ps: if vll_type(l2p2p) == 'LOCAL': local_services.append(LocalService.parse_from_openconfig_network(node_id, l2p2p, default_ni, ifcs)) elif vll_type(l2p2p) == 'REMOTE': remote_services.append(RemoteService.parse_from_openconfig_network(node_id, l2p2p, default_ni, ifcs)) else: # incomplete configuration or unknown flavour of l2p2p continue remote_services = aggregate_l2p2p_remote(remote_services) if reconciliation == 'name' \ else aggregate_l2p2p_remote(remote_services, lambda service: service.vccid) services = local_services + remote_services services = map(lambda service: service.to_dict(), services) return common_worker.complete('VLL instances found successfully: %s' % len(services), services=services)
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_vpls_instance(task): service = Service.parse_from_task(task) responses = [] for dev_id in set(service.device_ids()): response1 = remove_device_vpls(dev_id, service.id) if common_worker.task_failed(response1): return common_worker.fail( 'VPLS instance: %s removal in uniconfig FAIL' % service.id, response=response1) responses.append(response1) return common_worker.complete( 'VPLS instance: %s removed in uniconfig successfully' % service.id, responses=responses)
def service_create_vpls_instance(task): service = Service.parse_from_task(task) responses = [] for dev_id in set(service.device_ids()): if dev_id == "UNKNOWN": continue task = { 'inputData': { 'id': dev_id, 'service_id': service.id, 'vccid': service.vccid, 'interface': [], 'remote_ip': [], 'mtu': service.mtu if service.mtu is not None else 0 } } for device in service.devices: if device.id == dev_id: task['inputData']['interface'].append({ 'interface': device.interface, 'vlan': device.vlan, 'untagged': device.untagged }) else: if device.remote_ip == "UNKNOWN": continue task['inputData']['remote_ip'].append(device.remote_ip) response1 = vpls_worker.device_create_vpls(task) if common_worker.task_failed(response1): response1_delete = remove_device_vpls(dev_id, service.id) return common_worker.fail( 'VPLS instance: %s configuration in uniconfig FAIL' % service.id, response_for_rollback=response1_delete, response=response1) responses.append(response1) return common_worker.complete( 'VPLS instance: %s configured in uniconfig successfully' % service.id, responses=responses)
def read_remote_services(task): datastore = task['inputData'].get('datastore', 'actual') strategy, reconciliation = get_filter_strategy(task) if datastore not in ['intent', 'actual']: raise Exception('Unable to read uniconfig datastore: %s' % datastore) response = uniconfig_worker.execute_read_uniconfig_topology_operational(task) if datastore == 'actual' \ else uniconfig_worker.execute_read_uniconfig_topology_config(task) if common_worker.task_failed(response): raise Exception('Unable to read uniconfig', response=response) if reconciliation not in ['name', 'vccid']: raise Exception('Unable to reconcile with strategy: %s' % reconciliation) if 'node' not in response['output']['response_body']['topology'][0]: raise Exception("Uniconfig topology is empty.") uniconfig_nodes = response['output']['response_body']['topology'][0][ 'node'] remote_services = [] for node in map( lambda n: (n['node-id'], extract_network_instances(n, strategy)), uniconfig_nodes): node_id = node[0] l2vsis = node[1][0] default_ni = node[1][1] ifcs = node[1][2] if len(l2vsis) is 0: continue for l2vsi in l2vsis: service = Service.parse_from_openconfig_network( node_id, l2vsi, default_ni, ifcs) if service is not None: remote_services.append(service) remote_services = aggregate_l2vsi_remote(remote_services) if reconciliation == 'name' \ else aggregate_l2vsi_remote(remote_services, lambda s: s.vccid) return remote_services
def service_create_vll_local(task): service = LocalService.parse_from_task(task) device_1 = service.devices[0] device_2 = service.devices[1] if not service.is_local(): 'For local VLL service, 1 device is expected. Received: %s' % (service.device_ids()) response1 = vll_worker.device_create_vll_local({'inputData': { 'id': device_1.id, 'service_id': service.id, 'interface_1': device_1.interface, 'vlan_1': device_1.vlan, 'interface_2': device_2.interface, 'vlan_2': device_2.vlan, 'mtu': service.mtu if service.mtu is not None else 0 }}) if common_worker.task_failed(response1): return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL' % service.id, response=response1) return common_worker.complete('VLL instance: %s configured in uniconfig successfully' % service.id, response=response1)
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)