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
示例#2
0
    def waitfor_action_completion(self, action_id):
        status = 'in_progress'
        response = {}
        action_status = None
        action_activity = None
        action_config = None
        while status == "in_progress":
            url = f"{self.base_url}device/action/status/{action_id}"
            response = HttpMethods(self.session, url).request('GET')
            ParseMethods.parse_data(response)

            if 'json' in response:
                status = response['json']['summary']['status']
                if 'data' in response['json'] and response['json']['data']:
                    action_status = response['json']['data'][0]['statusId']
                    action_activity = response['json']['data'][0]['activity']
                    if 'actionConfig' in response['json']['data'][0]:
                        action_config = response['json']['data'][0][
                            'actionConfig']
                    else:
                        action_config = None
                else:
                    action_status = status
            else:
                raise Exception(msg="Unable to get action status: No response")
            time.sleep(10)

        return {
            'action_response': response['json'],
            'action_id': action_id,
            'action_status': action_status,
            'action_activity': action_activity,
            'action_config': action_config
        }
示例#3
0
    def get_device_config_list(self, device_type):
        """Get the config status of a list of devices.  When 'all' is specified, it concatenats
            the vedges and controller together to provide a single method to retrieve status
            in the same way as get_device_status_list.

        Args:
            device_type (str): 'vedges', 'controllers', or 'all'

        Returns:
            result (list): All data associated with a response.
        """

        if device_type.lower() == 'all':
            # Get vedges
            url = f"{self.base_url}system/device/vedges"
            response = HttpMethods(self.session, url).request('GET')
            vedge_results = ParseMethods.parse_data(response)

            #Get controllers
            url = f"{self.base_url}system/device/controllers"
            response = HttpMethods(self.session, url).request('GET')
            result = ParseMethods.parse_data(response)
            controller_results = ParseMethods.parse_data(response)

            return controller_results + vedge_results

        url = f"{self.base_url}system/device/{device_type}"
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)

        return result
    def update_device_template(self, device_template):
        """Update a single device template to Vmanage.

        Args:
            device_template (dict): Device Template

        Returns:
            result (list): Response from Vmanage

        """
        #
        # File templates are much easier in that they are just a bunch of CLI
        #
        # I'm not sure where this api call was found, but I can't find it in any doc and it doesn't currently work
        # if device_template['configType'] == 'file':
        #     url = f"{self.base_url}template/device/cli/{device_template['templateId']}"
        #     response = HttpMethods(self.session, url).request('PUT', payload=json.dumps(device_template))
        #     ParseMethods.parse_data(response)
        #
        # Feature based templates are just a list of templates Id that make up a device template.  We are
        # given the name of the feature templates, but we need to translate that to the template ID
        #
        #else:
        url = f"{self.base_url}template/device/{device_template['templateId']}"
        response = HttpMethods(self.session, url).request(
            'PUT', payload=json.dumps(device_template))
        ParseMethods.parse_data(response)
        return response
    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_data(response)

        if 'json' in response and 'id' in response['json']:
            action_id = response.json['id']
        else:
            raise Exception(
                'Did not get action ID after attaching device to template.')
        return action_id
示例#6
0
    def get_device_inputs(self, template_id, device_ids):
        """GET vSmart device inputs from vManage.

        Args:
            templateid (str): vManage assigned template identifier.
            device_ids (list): vManage assigned device ids for vSmarts.

        Returns:
            response (dict): device inputs.

        """

        payload = {
            "templateId": template_id,
            "deviceIds": device_ids,
            "isEdited": True,
            "isMasterEdited": False
        }

        api = "template/device/config/input"
        url = self.base_url + api
        response = HttpMethods(self.session,
                               url).request('POST',
                                            payload=json.dumps(payload))
        result = ParseMethods.parse_data(response)

        for item in result:
            item['csv-templateId'] = template_id

        return result
示例#7
0
    def get_central_policy_list(self):
        """Get all Central Policies from vManage.

        Returns:
            response (dict): A list of all policy lists currently
                in vManage.

        """

        api = "template/policy/vsmart"
        url = self.base_url + api
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)

        central_policy_list = result
        # We need to convert the policy definitions from JSON
        for policy in central_policy_list:
            try:
                json_policy = json.loads(policy['policyDefinition'])
                policy['policyDefinition'] = json_policy
            except Exception:  # TODO: figuring out better exception type to catch
                pass
            self.policy_definitions.convert_definition_id_to_name(
                policy['policyDefinition'])
        return central_policy_list
    def get_policy_definition_list(self, definition_type='all'):
        """Get all Policy Definition Lists from vManage.

        Args:
            definition_type (string): The type of Definition List to retreive

        Returns:
            response (dict): A list of all definition lists currently
                in vManage.

        """

        if definition_type == 'all':
            all_definitions_list = []
            for def_type in self.definition_types:
                definition_list = self.get_policy_definition_list(def_type)
                if definition_list:
                    all_definitions_list.extend(definition_list)
            return all_definitions_list

        definition_list = []

        if definition_type == "advancedMalwareProtection":
            url = f"{self.base_url}template/policy/definition/{definition_type}"
        else:
            url = f"{self.base_url}template/policy/definition/{definition_type.lower()}"
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        for definition in result:
            definition_detail = self.get_policy_definition(
                definition_type, definition['definitionId'])
            if definition_detail:
                definition_list.append(definition_detail)
        return definition_list
    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
示例#10
0
 def get_vmanage_version(self):
     api = 'system/device/controllers?model=vmanage&&&&'
     url = self.base_url + api
     response = HttpMethods(self.session, url).request('GET')
     result = ParseMethods.parse_data(response)
     version = result[0]['version']
     return version
    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
示例#12
0
    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
示例#13
0
    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
示例#14
0
    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']
示例#15
0
 def _get_device_type(self, system_ip):
     device_model = self.get_device_system_info(
         system_ip)[0]['device-model']
     url = f"{self.base_url}device/models"
     response = HttpMethods(self.session, url).request('GET')
     result = ParseMethods.parse_data(response)
     device_type = [
         device['deviceClass'] for device in result
         if device_model in device['name']
     ][0]
     return device_type
示例#16
0
    def get_local_policy(self):
        """Obtain a list of all configured local policies

        Returns:
            result (dict): All data associated with a response.

        """

        url = f"{self.base_url}template/policy/vedge"
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result
    def get_device_running_config(self, uuid):
        """
        Get the running configuration of a specific device.

        Args:
            uuid (str): UUID of device
        Returns:
            result (str): The running configuration of the specified device.
        """
        url = f"{self.base_url}template/config/running/{uuid}"
        response = HttpMethods(self.session, url).request('GET')
        return ParseMethods.parse_config(response)
示例#18
0
    def get_active_count(self):
        """Provides number of active tasks on vManage.

        Returns:
            result (dict): All data associated with a response.
        """

        api = "device/action/status/tasks/activeCount"
        url = self.base_url + api
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result
    def get_security_policy(self):
        """Obtain a list of all configured security policies

        Returns:
            result (dict): All data associated with a response.

        """

        api = "template/policy/security"
        url = self.base_url + api
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result
示例#20
0
    def get_vmanage_ca_type(self):
        """Get vManage CA type

        Args:

        Returns:
            certificateSigning (str): The CA type.
        """

        url = f"{self.base_url}certificate"
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result[0]['certificateSigning']
    def get_device_templates(self):
        """Obtain a list of all configured device templates.

        Returns:
            result (dict): All data associated with a response.

        """

        api = "template/device"
        url = self.base_url + api
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result
示例#22
0
    def get_device_list(self, category):
        """Obtain a list of specified device type

        Args:
            category (str): vedges or controllers

        Returns:
            result (dict): All data associated with a response.
        """

        url = f"{self.base_url}system/device/{category}"
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result
示例#23
0
    def get_bfd_history(self, system_ip):
        """Provides BFD history for device.

        Args:
            system_ip (str): Device System IP

        Returns:
            result (dict): All data associated with a response.
        """

        url = f"{self.base_url}device/bfd/history?deviceId={system_ip}"
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result
示例#24
0
    def get_eigrp_routes(self, system_ip):
        """Provides EIGRP route for device.

        Args:
            system_ip (str): Device System IP

        Returns:
            result (dict): All data associated with a response.
        """

        url = f"{self.base_url}device/eigrp/route?deviceId={system_ip}"
        response = HttpMethods(self.session, url).request('GET', timeout=60)
        result = ParseMethods.parse_data(response)
        return result
示例#25
0
    def get_device_config_list(self, device_type):
        """Get the config status of a list of devices

        Args:
            device_type (str): vedge or controller

        Returns:
            result (list): All data associated with a response.
        """

        url = f"{self.base_url}system/device/{device_type}"
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result
示例#26
0
    def get_device_status_list(self):
        """Obtain a list of specified device type

        Args: None

        Returns:
            result (list): Device status
        """

        api = f"device/"
        url = self.base_url + api
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result
示例#27
0
    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
示例#28
0
    def get_device_status(self, system_ip):
        """Provides status for device.

        Args:
            system_ip (str): Device System IP

        Returns:
            result (dict): All data associated with a response.
        """

        url = f"{self.base_url}device?system-ip={system_ip}"
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result
示例#29
0
    def get_control_connections(self, system_ip):
        """Provides current control connections for device.

        Args:
            system_ip (str): Device System IP

        Returns:
            result (dict): All data associated with a response.
        """

        url = f"{self.base_url}device/control/connections?deviceId={system_ip}"
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result
示例#30
0
    def get_ospf_process(self, system_ip):
        """Provides OSPF process for device.

        Args:
            system_ip (str): Device System IP

        Returns:
            result (dict): All data associated with a response.
        """

        url = f"{self.base_url}device/ospf/process?deviceId={system_ip}"
        response = HttpMethods(self.session, url).request('GET')
        result = ParseMethods.parse_data(response)
        return result