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 update_policy_list(self, policy_list): """Update an existing Policy List on vManage. Args: policy_list (dict): The Policy List Returns: response (dict): Results from attempting to update an existing data prefix list. """ policy_list_type = policy_list['type'].lower() policy_list_id = policy_list['listId'] url = f"{self.base_url}template/policy/list/{policy_list_type}/{policy_list_id}" response = HttpMethods(self.session, url).request('PUT', payload=json.dumps(policy_list)) ParseMethods.parse_status(response) return response
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 deactivate_central_policy(self, policy_id): """Deactivates the current active centralized policy Args: policyId (str): ID of the deactive centralized policy Returns: result (str): The Action ID from the activation. """ url = f"{self.base_url}template/policy/vsmart/deactivate/{policy_id}?confirm=true" response = HttpMethods(self.session, url).request('POST') ParseMethods.parse_status(response) if 'json' in response and 'id' in response['json']: return response['json']['id'] return None
def upload_file(self, input_file): """Upload a file to vManage. Args: input_file (str): The name of the file to upload. Returns: upload_status (str): The status of the file upload. """ url = f"{self.base_url}system/device/fileupload" response = HttpMethods(self.session, url).request('POST', files={'file': open(input_file, 'rb')}, payload={ 'validity': 'valid', 'upload': 'true' }) ParseMethods.parse_status(response) return response['json']['vedgeListUploadStatus']
def put_device_decommission(self, device_id): """Decommission a device Args: device_id (str): uuid for device object Returns: result (list): Device status """ url = f"{self.base_url}system/device/decommission/{device_id}" response = HttpMethods(self.session, url).request('PUT') result = ParseMethods.parse_status(response) return result
def delete_local_policy(self, policy_id): """Deletes the specified local policy Args: policyId (str): ID of the active local policy Returns: result (dict): All data associated with a response. """ url = f"{self.base_url}template/policy/vedge/{policy_id}" response = HttpMethods(self.session, url).request('DELETE') result = ParseMethods.parse_status(response) return result
def post_device_cli_mode(self, deviceId, deviceType): """Update a device to CLI mode Args: deviceId (str): uuid for device object deviceType (str): vedge or controller """ url = f"{self.base_url}template/config/device/mode/cli" devices = f"{{'deviceId':'{deviceId}'}}" payload = f"{{'deviceType':'{deviceType}','devices':[{devices}]}}" response = HttpMethods(self.session, url).request('POST', payload=payload) result = ParseMethods.parse_status(response) return result
def add_policy_list(self, policy_list): """Add a new Policy List to vManage. Args: policy_list (dict): The Policy List Returns: response (dict): Results from attempting to add a new prefix list. """ policy_list_type = policy_list['type'].lower() url = f"{self.base_url}template/policy/list/{policy_list_type}" response = HttpMethods(self.session, url).request('POST', payload=json.dumps(policy_list)) return ParseMethods.parse_status(response)
def deactivate_centralized_policy(self, policyId): """Deactivates the current active centralized policy Args: policyId (str): ID of the active centralized policy Returns: result (dict): All data associated with a response. """ api = f"template/policy/vsmart/deactivate/{policyId}?confirm=true" url = self.base_url + api response = HttpMethods(self.session, url).request('POST') result = ParseMethods.parse_status(response) return result
def delete_security_policy(self, policyId): """Deletes the specified security policy Args: policyId (str): ID of the active security policy Returns: result (dict): All data associated with a response. """ api = f"template/policy/security/{policyId}" url = self.base_url + api response = HttpMethods(self.session, url).request('DELETE') result = ParseMethods.parse_status(response) return result
def delete_device_template(self, templateId): """Obtain a list of all configured device templates. Args: templateId (str): Object ID for device template Returns: result (dict): All data associated with a response. """ api = f"template/device/{templateId}" url = self.base_url + api response = HttpMethods(self.session, url).request('DELETE') result = ParseMethods.parse_status(response) return result
def delete_data_prefix_list(self, listid): """Delete a Data Prefix List from vManage. Args: listid (str): vManaged assigned list identifier Returns: response (dict): Results from deletion attempt. """ api = "template/policy/list/dataprefix/" + listid url = self.base_url + api response = HttpMethods(self.session, url).request('DELETE') result = ParseMethods.parse_status(response) return result
def post_reset_interface(self, device_ip, vpn_id, ifname): """Reset an Interface Args: device_ip (str): device IP for device object vpn_id (int): VPN Id for Interface ifname (str): Interface name to reset Returns: result (int): HTTP response status """ url = f"{self.base_url}device/tools/reset/interface/{device_ip}" payload = f"{{'vpnId':'{vpn_id}','ifname':'{ifname}'}}" response = HttpMethods(self.session, url).request('POST', payload=payload) result = ParseMethods.parse_status(response) return result
def delete_policy_list(self, listType, listId): """Deletes the specified policy list type Args: listType (str): Policy list type listId (str): ID of the policy list Returns: result (dict): All data associated with a response. """ url = f"{self.base_url}template/policy/list/{listType.lower()}/{listId}" response = HttpMethods(self.session, url).request('DELETE') result = ParseMethods.parse_status(response) return result
def post_device(self, device_ip, personality, username, password): """Add control plane device Args: device_ip (str): device interface IP personality (str): controller type (vmanage, vsmart, vbond) username (str): device username password (str): device password Returns: result (list): Device status """ url = f"{self.base_url}system/device" payload = f"{{'deviceIP':'{device_ip}','username':'******','password':'******','personality':'{personality}','generateCSR':'false'}}" response = HttpMethods(self.session, url).request('POST', payload=payload,timeout=35) result = ParseMethods.parse_status(response) return result
def delete_localized_definition(self, definition, definitionId): """Deletes the specified policy definition which include: 'qosmap','rewriterule','acl','aclv6','vedgeroute' Args: definition (str): One of the above policy types definitionId (str): ID of the policy definition Returns: result (dict): All data associated with a response. """ api = f"template/policy/definition/{definition}/{definitionId}" url = self.base_url + api response = HttpMethods(self.session, url).request('DELETE') result = ParseMethods.parse_status(response) return result
def delete_policy_definition(self, definition, definitionId): """Deletes the specified policy definition which include: 'control','mesh','hubandspoke','vpnmembershipgroup', 'approute','data','cflowd' Args: definition (str): One of the above policy types definitionId (str): ID of the policy definition Returns: result (dict): All data associated with a response. """ api = f"template/policy/definition/{definition}/{definitionId}" url = self.base_url + api response = HttpMethods(self.session, url).request('DELETE') result = ParseMethods.parse_status(response) return result
def delete_security_definition(self, definition, definitionId): """Deletes the specified policy definition which include: 'zonebasedfw','urlfiltering', 'dnssecurity','intrusionprevention', 'advancedMalwareProtection' for 18.4.0 or greater and 'zonebasedfw' for Args: definition (str): One of the above policy types definitionId (str): ID of the policy definitions Returns: result (dict): All data associated with a response. """ api = f"template/policy/definition/{definition}/{definitionId}" url = self.base_url + api response = HttpMethods(self.session, url).request('DELETE') result = ParseMethods.parse_status(response) return result
def post_data_prefix_list(self, name, entries): """Add a new Data Prefix List to vManage. Args: name (str): name of the data prefix list entries (list): a list of prefixes to add to the list Returns: response (dict): Results from attempting to add a new data prefix list. """ api = "template/policy/list/dataprefix" url = self.base_url + api payload = f"{{'name':'{name}','type':'dataPrefix',\ 'listId':null,'entries':{entries}}}" response = HttpMethods(self.session, url).request('POST', payload=payload) result = ParseMethods.parse_status(response) return result
def put_data_prefix_list(self, name, listid, entries): """Update an existing Data Prefix List on vManage. Args: name (str): name of the data prefix list listid (str): vManaged assigned list identifier entries (list): a list of prefixes to add to the list Returns: response (dict): Results from attempting to update an existing data prefix list. """ api = f"template/policy/list/dataprefix/{listid}" url = self.base_url + api payload = f"{{'name':'{name}','type':'dataPrefix',\ 'listId':'{listid}','entries':{entries}}}" response = HttpMethods(self.session, url).request('PUT', payload=payload) result = ParseMethods.parse_status(response) return result