def reattach_multi_device_templates(self, template_ids): """Re-Attach a template to the devices it it attached to. Args: template_id (str): The template ID to attach to config_type (str): Type of template i.e. device or CLI template is_edited (bool): True if the template has been edited is_master_edited (bool): For CLI device template needs to match is_edited. For device templates using feature templates needs to be set to False. Returns: action_id (str): Returns the action id of the attachment """ payload = self.get_multi_attach_payload(template_ids) if payload['deviceTemplateList'][0]['device']: url = f"{self.base_url}template/device/config/attachfeature" utils = Utilities(self.session, self.host, self.port) response = HttpMethods(self.session, url).request('POST', payload=json.dumps(payload)) action_id = ParseMethods.parse_id(response) utils.waitfor_action_completion(action_id) else: raise RuntimeError( f"Could not retrieve input for template {template_ids}") return action_id
def detach_from_template(self, uuid, device_ip, device_type): """Detach a device from a template (i.e. Put in CLI mode) Args: uuid (str): The UUID of the device to detach device_ip (str): The System IP of the system to detach device_type (str): The device type of the device to detach Returns: action_id (str): Returns the action id of the attachment """ payload = { "deviceType": device_type, "devices": [{ "deviceId": uuid, "deviceIP": device_ip, }] } url = f"{self.base_url}template/config/device/mode/cli" response = HttpMethods(self.session, url).request('POST', payload=json.dumps(payload)) ParseMethods.parse_status(response) action_id = ParseMethods.parse_id(response) return action_id
def push_certificates(self): """Push certificates to all controllers Returns: id (str): The action ID of the push command. """ url = f"{self.base_url}vedge/list?action=push" response = HttpMethods(self.session, url).request('POST', payload={}) utilities = Utilities(self.session, self.host) action_id = ParseMethods.parse_id(response) utilities.waitfor_action_completion(action_id) return action_id
def reattach_device_template(self, template_id, config_type, is_edited=True, is_master_edited=True, wait=True): """Re-Attach a template to the devices it it attached to. Args: template_id (str): The template ID to attach to config_type (str): Type of template i.e. device or CLI template is_edited (bool): True if the template has been edited is_master_edited (bool): For CLI device template needs to match is_edited. For device templates using feature templates needs to be set to False. Returns: action_id (str): Returns the action id of the attachment """ device_list = self.get_template_attachments(template_id, key='uuid') template_input = self.get_template_input(template_id, device_list) # Then we feed that to the attach if 'data' in template_input and template_input['data']: payload = { "deviceTemplateList": [{ "templateId": template_id, "device": template_input['data'], "isEdited": is_edited, "isMasterEdited": is_master_edited }] } if config_type == 'file': url = f"{self.base_url}template/device/config/attachcli" elif config_type == 'template': url = f"{self.base_url}template/device/config/attachfeature" else: raise RuntimeError('Got invalid Config Type') utils = Utilities(self.session, self.host, self.port) response = HttpMethods(self.session, url).request('POST', payload=json.dumps(payload)) action_id = ParseMethods.parse_id(response) if wait: utils.waitfor_action_completion(action_id) else: raise RuntimeError( f"Could not retrieve input for template {template_id}") return action_id
def install_device_cert(self, cert): """Install signed cert on vManage Args: cert (str): The certificate to install. Returns: id (str): The action ID of the install command. """ url = f"{self.base_url}install/signedCert" response = HttpMethods(self.session, url).request('POST', payload=cert) utilities = Utilities(self.session, self.host) action_id = ParseMethods.parse_id(response) utilities.waitfor_action_completion(action_id) return action_id
def reactivate_central_policy(self, policy_id): """reActivates the current active centralized policy Args: policyId (str): ID of the active centralized policy Returns: action_id (str): The Action ID from the activation. """ url = f"{self.base_url}template/policy/vsmart/activate/{policy_id}?confirm=true" payload = {'isEdited': True} response = HttpMethods(self.session, url).request('POST', payload=json.dumps(payload)) ParseMethods.parse_status(response) action_id = ParseMethods.parse_id(response) return action_id
def attach_to_template(self, template_id, config_type, uuid, wait=True): """Attach and device to a template Args: template_id (str): The template ID to attach to config_type (str): Type of template i.e. device or CLI template uuid (dict): The UUIDs of the device to attach and mapping for corresponding variables, system-ip, host-name Returns: action_id (str): Returns the action id of the attachment """ # Construct the variable payload device_template_var_list = list() template_variables = self.get_template_input(template_id) for device_uuid in uuid: device_template_variables = { "csv-status": "complete", "csv-deviceId": device_uuid, "csv-deviceIP": uuid[device_uuid]['system_ip'], "csv-host-name": uuid[device_uuid]['host_name'], '//system/host-name': uuid[device_uuid]['host_name'], '//system/system-ip': uuid[device_uuid]['system_ip'], '//system/site-id': uuid[device_uuid]['site_id'], } # Make sure they passed in the required variables and map # variable name -> property mapping for entry in template_variables['columns']: if entry['variable']: if entry['variable'] in uuid[device_uuid]['variables']: device_template_variables[entry['property']] = uuid[ device_uuid]['variables'][entry['variable']] elif entry['property'] in uuid[device_uuid]['variables']: device_template_variables[entry['property']] = uuid[ device_uuid]['variables'][entry['property']] else: raise RuntimeError( f"{entry['variable']} is missing for template {uuid[device_uuid]['host_name']}" ) device_template_var_list.append(device_template_variables) payload = { "deviceTemplateList": [{ "templateId": template_id, "device": device_template_var_list, "isEdited": False, "isMasterEdited": False }] } if config_type == 'file': url = f"{self.base_url}template/device/config/attachcli" elif config_type == 'template': url = f"{self.base_url}template/device/config/attachfeature" else: raise RuntimeError('Got invalid Config Type') utils = Utilities(self.session, self.host, self.port) response = HttpMethods(self.session, url).request('POST', payload=json.dumps(payload)) action_id = ParseMethods.parse_id(response) if wait: utils.waitfor_action_completion(action_id) return action_id