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