Git Product home page Git Product logo

python-viptela's Introduction

Cisco Viptela vManage Python SDK/CLI/Ansible

This repo contains a Python SDK for Cisco Viptela vManage as well as a CLI and Ansible modules that leverage the SDK. Stable releases are found in pypi. The master branch is under active development and may not offer a stable interface.

Requirements

  • Python 3.6+

Installation

Creating Python virtual environment

python3 -m venv env
. env/bin/activate

Installation from PyPI

pip install viptela

Installation from github

pip install git+https://github.com/CiscoDevNet/python-viptela.git@specific_branch

Installation from within repo

git clone https://github.com/CiscoDevNet/python-viptela.git
cd python-viptela
pip install -e .

Environment Variables

IP/DNS, port and credentials for the vManage server can be set for the SDK via environment variable

  • VMANAGE_HOST
  • VMANAGE_PORT
  • VMANAGE_USERNAME
  • VMANAGE_PASSWORD

vManage Command Line Interface

Usage: vmanage [OPTIONS] COMMAND [ARGS]...

Options:
  --host TEXT      vManage Host (env: VMANAGE_HOST)  [required]
  --port INTEGER   vManage Port (env: VMANAGE_PORT, default=443)
  --username TEXT  vManage Username (env: VMANAGE_USERNAME)  [required]
  --password TEXT  vManage Password (env: VMANAGE_PASSWORD)  [required]
  --help           Show this message and exit.

Commands:
  activate     Activate commands
  certificate  Certficate commands
  clean        Clean vManage
  deactivate   Deactivate commands
  export       Export commands
  import       Import commands
  set          vManage Settings set commands
  show         Show commands

vManage host and credentials can be also specified via command line options. The command line options override the environment variables. If no password is specified, the user will be prompted for one.

Importing and exporting of templates and policy

Data file format

All template information is exported to a single file with to lists: feature_templates and device_templates. Each list contains dictionaries as pulled from the vManage API with a few additions and modifications. First, a list of attached devices and a list of input variables is added to the device template. Then instance IDs are translated into name so that the templates can be imported into another vManage.

All policy template information is exported to a single file with four lists: policy_lists, policy_definitions, central_policies, local_policies. Each list contains dictionaries as pulled from the vManage API with the instance IDs converted to names so that policies can be imported into another vManage.

Import Options

  • --check: Just check. No changes. (default=False)
  • --update: Update if exists (default=False)
  • --diff: Show diffs (default=False)

The CLI/SDK will import templates and policy idempotently and as non-destructivly as possible. It will only add templates and policies that are not there. When a template or policy does exist but is different than what is in the import file, it will not he updates unless the --update option is given.

Export Templates

Export all templates to a file
vmanage export templates --file vmanage-templates.json
Export templates from a specific vManange
vmanage --host=192.133.178.54 export templates --file vmanage-templates.json
Export specific device templates
vmanage export templates --type=device --file vmanage-templates.json --name=isr4331 --name=ISR1111-8P
Export just feature templates
vmanage export templates --type=feature --file vmanage-templates.json

Import Templates

Import all templates
vmanage import templates --file vmanage-templates.json
Import feature templates
vmanage import templates --type=feature --file vmanage-templates.json
Import specific device templates
vmanage import templates --type=device --file vmanage-templates.json --name=isr4331 --name=ISR1111-8P

Export Policies

vmanage export policies --file vmanage-policies.json

Import Policies

vmanage import policies --file vmanage-policies.json
Diff two templates
vmanage show template g0/0/0-R1 --diff g0/0/0-R2
[ ( 'change',
    'templateDefinition.tunnel-interface.color.value.vipType',
    ('ignore', 'constant')),
  ( 'change',
    'templateDefinition.tunnel-interface.color.value.vipValue',
    ('default', 'custom2')),
  ( 'add',
    'templateDefinition.tunnel-interface.color.restrict',
    [('vipVariableName', 'vpn_if_tunnel_color_restrict')]),
  ( 'change',
    'templateId',
    ( '2a0481f4-a5b2-44bf-baad-59de4d3b4e99',
      '1dc123db-7a14-40f5-9653-1c87ccd5eaa2')),
  ('change', 'createdOn', (1569072320921, 1569072320260)),
  ('change', '@rid', (843, 839)),
  ( 'change',
    'templateDescription',
    ( 'G0/0/0 Interface for R1 router with TLOC extension, adds NAT',
      'G0/0/0 Interface for R2 router with TLOC extension, adds NAT, changes '
      'color to custom2')),
  ('change', 'lastUpdatedOn', (1569072320921, 1569072320260))]

License

GNU General Public License v3.0

python-viptela's People

Contributors

azarack avatar chrishocker avatar craigers521 avatar dependabot[bot] avatar imjustjosh avatar jacobgarder avatar jasonking3 avatar jlothian avatar mtarking avatar ppajersk avatar radtrentasei avatar stevenca avatar suchandanreddy avatar tithomas1 avatar tzarski0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-viptela's Issues

.lower() missing in policy_updates

def update_policy_definition(self, policy_type, name, policy_id, policy_def, new_color, seq_name=None):

"type": policy_def["type"],

Issue

policy.update_policy_definition(
    policy_type=policy_voice_video["type"],
    name=policy_voice_video["name"],
    policy_id=policy_voice_video["definitionId"],
    new_color="mpls",
    policy_def=policy_voice_video,
)

Exception: https://10.10.20.90:443/dataservice/template/policy/definition/appRoute/59e41e53-c2b3-4c57-993d-6a9411e3a17d: Error 404 (not_found)

appRoute comes from the API payload, but should be lower cases.

Workaround

policy.update_policy_definition(
    policy_type=policy_voice_video["type"].lower(),
    name=policy_voice_video["name"],
    policy_id=policy_voice_video["definitionId"],
    new_color="mpls",
    policy_def=policy_voice_video,
)
Master templates affected: ['90f26d2d-8136-4414-84de-4e8df52374e6']
Updated Voice_Video App Route policy successfully

Failed to export attachments with template ID not found error

Failed to export attachments with template ID not found error

Error traceback:

Traceback (most recent call last):
File "/usr/local/bin/vmanage", line 11, in
load_entry_point('viptela==0.2.3', 'console_scripts', 'vmanage')()
File "/Library/Python/3.7/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/Library/Python/3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Library/Python/3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Library/Python/3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Library/Python/3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Library/Python/3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Library/Python/3.7/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/Library/Python/3.7/site-packages/vmanage/cli/export/attachments.py", line 41, in attachments
num = vmanage_files.export_attachments_to_file(output_file, device_type=device_type)
File "/Library/Python/3.7/site-packages/vmanage/apps/files.py", line 271, in export_attachments_to_file
raise Exception(f"Could not find ID for template {device_config['template']}")

Create tests for api and cli

Create tests to deal with any regression/bugs associated with refactoring

  • Create Unit tests for API
  • Create Unit tests for cli

Add Interface Reset Capability

I started working to add Interface Reset Capability to the Python APIs. Here is what I got working. hopefully this will be easy to add.

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

    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

#134

Not updating existing templates

(python-viptela) STEVENCA-M-C6HA:python-viptela stevenca$ vmanage --host=192.133.178.167 import templates --file=branch-4331.json --update
Importing templates from branch-4331.json
Traceback (most recent call last):
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/bin/vmanage", line 10, in
sys.exit(main())
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/click/core.py", line 764, in call
return self.main(*args, **kwargs)
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/vmanage/cli/import_cmd/templates.py", line 25, in templates
result = vmanage_session.import_templates_from_file(file, update=update, check_mode=check, name_list = name, type = type)
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/vmanage/api.py", line 430, in import_templates_from_file
self.add_feature_template(feature_template)
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/vmanage/api.py", line 481, in add_feature_template
return self.request('/template/feature/', method='POST', data=json.dumps(payload))
File "/Users/stevenca/Workspaces/python-viptela/python-viptela/lib/python3.7/site-packages/vmanage/api.py", line 122, in request
raise Exception('{0}: {1}'.format(error, details))
Exception: Failed to create template: Template with name 'system' already exists

Failed to export attachments with error that no host-name key found

Traceback

Traceback (most recent call last):
File "/usr/local/bin/vmanage", line 11, in
load_entry_point('viptela==0.2.3', 'console_scripts', 'vmanage')()
File "/Library/Python/3.7/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/Library/Python/3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Library/Python/3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Library/Python/3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Library/Python/3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Library/Python/3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Library/Python/3.7/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/Library/Python/3.7/site-packages/vmanage/cli/export/attachments.py", line 31, in attachments
num = vmanage_files.export_attachments_to_file(output_file, name_list=name, device_type=device_type)
File "/Library/Python/3.7/site-packages/vmanage/apps/files.py", line 272, in export_attachments_to_file
if name_list == [] or device_config['host-name'] in name_list:
KeyError: 'host-name'

Exceptions generated by authentication.py have type 'Exception'

In authentication.py when login fails (either by timeout or by HTTP code other than 200), script raises exception with type 'Exception'. This type is hard to catch in any external script using the authentication.py. The ask is to provide a more specific exception type for authentication related issues.

in policy list module, push boolean not being parsed from yaml correctly

In order to actually push policy changes to vsmarts, the vmanage_policy_list module requires a push parameter to be passed with a True value.

Typically in yaml this is pretty loose and will allow numerous values that get parsed as True (like yes, Yes, YES, Y, y, on, true, TRUE, True). In order for the updates to get pushed i have to set push exactly to True. Recommend using something like pyYAML to convert boolean value or at the very least get this documented.

InsecureRequestWarning when using vmanage_policy_definition_facts for ansible

I get a failed task when attempting to use vmanage_policy_definition_facts with the error. I am using this within the devnet sandbox for SDWAN. I have other tasks that run without this issue, it seems to only be this module.

fatal: [10.10.20.90]: FAILED! => {"changed": false, "module_stderr": "/home/developer/.local/lib/python2.7/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '10.10.20.90'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n InsecureRequestWarning,\n/home/developer/.local/lib/python2.7/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '10.10.20.90'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n InsecureRequestWarning,\n/home/developer/.local/lib/python2.7/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '10.10.20.90'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n InsecureRequestWarning,\n/home/developer/.local/lib/python2.7/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '10.10.20.90'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n InsecureRequestWarning,\n/home/developer/.local/lib/python2.7/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '10.10.20.90'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n InsecureRequestWarning,\n/home/developer/.local/lib/python2.7/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '10.10.20.90'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n InsecureRequestWarning,\n/home/developer/.local/lib/python2.7/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '10.10.20.90'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n InsecureRequestWarning,\n/home/developer/.local/lib/python2.7/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '10.10.20.90'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n InsecureRequestWarning,\nTraceback (most recent call last):\n File "/home/developer/.ansible/tmp/ansible-tmp-1633462680.0976634-9383-119258551443063/AnsiballZ_vmanage_policy_definition_facts.py", line 100, in \n _ansiballz_main()\n File "/home/developer/.ansible/tmp/ansible-tmp-1633462680.0976634-9383-119258551443063/AnsiballZ_vmanage_policy_definition_facts.py", line 92, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/home/developer/.ansible/tmp/ansible-tmp-1633462680.0976634-9383-119258551443063/AnsiballZ_vmanage_policy_definition_facts.py", line 41, in invoke_module\n run_name='main', alter_sys=True)\n File "/usr/lib64/python2.7/runpy.py", line 176, in run_module\n fname, loader, pkg_name)\n File "/usr/lib64/python2.7/runpy.py", line 82, in _run_module_code\n mod_name, mod_fname, mod_loader, pkg_name)\n File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code\n exec code in run_globals\n File "/tmp/ansible_vmanage_policy_definition_facts_payload_nsfmYg/ansible_vmanage_policy_definition_facts_payload.zip/ansible/modules/vmanage_policy_definition_facts.py", line 60, in \n File "/tmp/ansible_vmanage_policy_definition_facts_payload_nsfmYg/ansible_vmanage_policy_definition_facts_payload.zip/ansible/modules/vmanage_policy_definition_facts.py", line 57, in main\n File "/tmp/ansible_vmanage_policy_definition_facts_payload_nsfmYg/ansible_vmanage_policy_definition_facts_payload.zip/ansible/modules/vmanage_policy_definition_facts.py", line 46, in run_module\nKeyError: 'sequences'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

This is the entirety of my playbook:


  • name: Check policy configurations
    hosts: all
    connection: local
    roles:
    • ansible-viptela
      tasks:
    • name: GET POLICY DEFINITIONS
      vmanage_policy_definition_facts:
      host: "{{ inventory_hostname }}"
      user: "{{ username }}"
      password: "{{ password }}"

ansible vmanage_policy_definition_facts module fails

Attempting to use vmanage_policy_definition_facts module in a playbook fails with error:

Playbook Snippet:

    - name: Get policy definition facts from vManage
      vmanage_policy_definition_facts:
      register: policy_definition_facts

Traceback error

PLAY [localhost] ********************************************************************************************************************************

TASK [Get policy definition facts from vManage] *************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Exception: Could not find name for list self, type zone
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/Users/cse015/.ansible/tmp/ansible-tmp-1620773950.932564-76852-11115608629717/AnsiballZ_vmanage_policy_definition_facts.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/Users/cse015/.ansible/tmp/ansible-tmp-1620773950.932564-76852-11115608629717/AnsiballZ_vmanage_policy_definition_facts.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/cse015/.ansible/tmp/ansible-tmp-1620773950.932564-76852-11115608629717/AnsiballZ_vmanage_policy_definition_facts.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.viptela.vmanage_policy_definition_facts', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/p3/ncsky8252f3d1gm_jr299mf00000gp/T/ansible_vmanage_policy_definition_facts_payload_31itc89k/ansible_vmanage_policy_definition_facts_payload.zip/ansible/modules/viptela/vmanage_policy_definition_facts.py\", line 51, in <module>\n  File \"/var/folders/p3/ncsky8252f3d1gm_jr299mf00000gp/T/ansible_vmanage_policy_definition_facts_payload_31itc89k/ansible_vmanage_policy_definition_facts_payload.zip/ansible/modules/viptela/vmanage_policy_definition_facts.py\", line 47, in main\n  File \"/var/folders/p3/ncsky8252f3d1gm_jr299mf00000gp/T/ansible_vmanage_policy_definition_facts_payload_31itc89k/ansible_vmanage_policy_definition_facts_payload.zip/ansible/modules/viptela/vmanage_policy_definition_facts.py\", line 41, in run_module\n  File \"/Users/cse015/py-venvs/viptela/lib/python3.8/site-packages/vmanage/data/policy_data.py\", line 335, in export_policy_definition_list\n    converted_policy_definition = self.convert_policy_definition_to_name(definition_detail)\n  File \"/Users/cse015/py-venvs/viptela/lib/python3.8/site-packages/vmanage/data/policy_data.py\", line 290, in convert_policy_definition_to_name\n    self.convert_list_id_to_name(policy_definition['definition'])\n  File \"/Users/cse015/py-venvs/viptela/lib/python3.8/site-packages/vmanage/data/policy_data.py\", line 215, in convert_list_id_to_name\n    self.convert_list_id_to_name(value)\n  File \"/Users/cse015/py-venvs/viptela/lib/python3.8/site-packages/vmanage/data/policy_data.py\", line 218, in convert_list_id_to_name\n    self.convert_list_id_to_name(item)\n  File \"/Users/cse015/py-venvs/viptela/lib/python3.8/site-packages/vmanage/data/policy_data.py\", line 197, in convert_list_id_to_name\n    raise Exception(f\"Could not find name for list {value}, type zone\")\nException: Could not find name for list self, type zone\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

support vmanage port number option

For certain deployments vManage APIs/UI would be available through port number other than 443. In this enhancement request we will add support to provide the port number through option --port in the SDK.

vManage 19.2.3 - issue with getting data

Hi,

I have several vManages, on 19.2.2, 20.3.1 vmanage show device status works.
On 19.2.3 i'm getting issue. So I can get some devices but not all. Later it crash.

(venv) root@8f451fdfd84a:~/viptela_api/python-viptela# vmanage show device status
Hostname System IP Model Site Status BFD OMP CON Version UUID Serial
vManage_London 1.1.1.6 vmanage 4294943323 reachable 22 19.2.3 c319dcc2-9320-4d8d-b038-773a4bb15b5c 7D345E3744FC6509A55A0E9033FAA8F633BE637A
vSmart_EU_London 1.1.1.4 vsmart 4294943322 reachable 21 (22) 36 19.2.3 0ed41cb4-9859-482a-97e8-157d559f3c32 22ACABC3C50D7B73E7453AB16242551839417EC0
vSmart_US_Virginia 1.1.1.5 vsmart 4294943321 reachable 21 (22) 36 19.2.3 fcde3948-f252-472d-83da-dca9d2cceccd 587F46A9DF297A1C7F6F469D7034EC91CC373142
VBond_London 1.1.1.2 vedge-cloud 4294943327 reachable -- -- 19.2.3 bbb62bdd-e87c-4f16-9dd2-12501bbfd56d 0932250B7AEC05DC7D6379A6759852DD53CD0592
vBond_Virginia 1.1.1.3 vedge-cloud 4294943326 reachable -- -- 19.2.3 47304062-5f0c-4aa0-9951-ef98d28c1b1e 2F907B228D51EEFC1116B7E86C273E67E387CE31
Traceback (most recent call last):
File "/opt/conda/bin/vmanage", line 33, in
sys.exit(load_entry_point('viptela', 'console_scripts', 'vmanage')())
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/home/jovyan/viptela_api/python-viptela/vmanage/cli/show/device.py", line 62, in status
f"{device_entry['host-name']:20} {device_entry['system-ip']:15} {device_entry['device-model']:15} {device_entry['site-id']:6} {device_entry['reachability']:9} {bfd:>3} {omp:>3} {control:>3} {device_entry['version']:8} {device_entry['uuid']:40} {device_entry['board-serial']}"
KeyError: 'version'

export attachment fails - just last variable was exported - even more exists in template and box is attached to it.

Hello

When I tried export attachments from the box, all the time it exported just last variable, i tried to change variables, number of variables, but all the time just last one was shown and exported.
Those previous are under "null" section.

vManage code 20.1.1
Will try it again on production vManage where I have 19.2.2

Example of such attachments
{
"vmanage_attachments": [
{
"host_name": "vEdge1kupperOld",
"device_type": "vedge",
"uuid": "11OG637181517",
"system_ip": "198.18.6.2",
"site_id": "11000000",
"template": "vEdge1k_upper_template",
"variables": {
"null": "vEdge1kupperOld"
}
}
]
}

I have CLI templates and for sure more variables, in this example I had 3 variables.

`import sys` missing in viptela.py

sys.exit() is used in viptela.py but sys is not imported. Not exactly sure how it was working before, but it needs to be fixed either way.

404 Error when exporting policies - multiple definitions types incompatible with vManage 19.2.2

One of the URLs is giving a 404 error. Should be an easy fix, I tried looking at the API docs to find the correct url, but was not sure what this was trying to access specifically. I ran this against a vManage running 19.2.2. Using code labeled "0.3.0"

(sdwan-viptela-0.3.0) Seths-MacBook-Pro:sdwan-viptela-0.3.0 seth$ vmanage --host vmanage.viptela.net --username admin --password goodpass export policies --file vManage-192-policies.json Exporting policies to vManage-192-policies.json Traceback (most recent call last): File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/bin/vmanage", line 33, in <module> sys.exit(load_entry_point('viptela', 'console_scripts', 'vmanage')()) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 829, in __call__ return self.main(*args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 610, in invoke return callback(*args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/decorators.py", line 33, in new_func return f(get_current_context().obj, *args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/cli/export/policies.py", line 19, in policies vmanage_files.export_policy_to_file(export_file) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/apps/files.py", line 190, in export_policy_to_file policy_definitions_list = self.policy_data.export_policy_definition_list() File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/data/policy_data.py", line 328, in export_policy_definition_list policy_definition_list = self.policy_definitions.get_policy_definition_list(definition_type) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/api/policy_definitions.py", line 120, in get_policy_definition_list definition_list = self.get_policy_definition_list(def_type) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/api/policy_definitions.py", line 131, in get_policy_definition_list response = HttpMethods(self.session, url).request('GET') File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/api/http_methods.py", line 114, in request raise Exception(f"{self.url}: Error {result['status_code']} ({result['status']})") Exception: https://vmanage-1275533.viptela.net:443/dataservice/template/policy/definition/deviceaccesspolicy: Error 404 (not_found)

Authentication fails when vMananage port number is something other than 443

I've been trying to use this SDK against the Cisco always-on Sandbox (https://sandboxsdwan.cisco.com:8443) and it was consistently failing, even after setting port=8443 when calling Authentication, something like this:

vmanage_host = 'sandboxsdwan.cisco.com'
vmanage_username = 'devnetuser'
vmanage_password = 'Cisco123!'
vmanage_port = 8443
auth = Authentication(host=vmanage_host, user=vmanage_username, port=vmanage_port,
                            password=vmanage_password, validate_certs=False).login()

However when doing this I get the following Traceback, and you can see the port number is still 443.

Traceback (most recent call last):
  File "/home/queena2/scripts/vmanage_api_test.py", line 21, in <module>
    password=vmanage_password, validate_certs=False).login()
  File "/home/queena2/scripts/vmanage_api_bug/.venv/lib/python3.6/site-packages/vmanage/api/authentication.py", line 75, in login
    version = Utilities(self.session, self.host).get_vmanage_version()
  File "/home/queena2/scripts/vmanage_api_bug/.venv/lib/python3.6/site-packages/vmanage/api/utilities.py", line 48, in get_vmanage_version
    response = HttpMethods(self.session, url).request('GET')
  File "/home/queena2/scripts/vmanage_api_bug/.venv/lib/python3.6/site-packages/vmanage/api/http_methods.py", line 81, in request
    raise Exception(f'Connection error to {self.url}: {e}')
Exception: Connection error to https://sandboxsdwan.cisco.com:443/dataservice/system/device/controllers?model=vmanage&&&&: HTTPSConnectionPool(host='sandboxsdwan.cisco.com', port=443): Max retries exceeded with url: /dataservice/system/device/controllers?model=vmanage&&&& (Caused by ProxyError('Cannot connect to proxy.', timeout('_ssl.c:835: The handshake operation timed out',)))

It appears that in authentication.py that it calls Utilities to get the current vManage version (as 19.2.x has to be handled a bit differently), but the custom port number isn't passed into Utilities and thus it defaults to 443. Since the server isn't running on this port the connection fails.

version = Utilities(self.session, self.host).get_vmanage_version()

Changing the line above to insert port=self.port appears to fix the issue.

version = Utilities(self.session, self.host, port=self.port).get_vmanage_version()

in vmanage_policy_definition module, push parameter is not used to update vsmart templates

Although a push parameter is in the arg_spec for this module, when its passed to the import_policy_definition_list function, its never used. There is no mechanism to trigger the reattach_template function, as is seen in the import_policy_list_list function, so changes to existing policy definition never actually get pushed to vsmart and the job eventually expires.

vmanage show policies definition -t option is not working

When using the CLI command to show a specific policy definition, it still returns all policy definitions. The same is true for lists -t option as well.

It would also be nice to include all the policy definitions and lists available in the help option.

Exporting Policies fails

Using an ubuntu docker container and a fresh install via 'pip3 install viptela' policies are failing to export.

root@b0cfad95d198:/# vmanage --host 10.10.20.90 --username admin --password admin export policies --file 19-2-1-policy.json
Exporting policies to 19-2-1-policy.json
Traceback (most recent call last):
File "/usr/local/bin/vmanage", line 11, in
sys.exit(vmanage())
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/vmanage/cli/export/policies.py", line 19, in policies
vmanage_files.export_policy_to_file(export_file)
File "/usr/local/lib/python3.6/dist-packages/vmanage/apps/files.py", line 162, in export_policy_to_file
local_policies_list = local_policy.get_local_policy_list()
File "/usr/local/lib/python3.6/dist-packages/vmanage/api/local_policy.py", line 102, in get_local_policy_list
self.convert_definition_id_to_name(policy['policyDefinition'])
AttributeError: 'LocalPolicy' object has no attribute 'convert_definition_id_to_name'

missing reference count in policy list breaks idempotency

Using the vmanage_policy_list module, if you don't define variable "referenceCount" in policy list definition it registers as a change. I dont feel like referenceCount should be tracked in the diff as this is subject to change as list is used additonal places and isnt necessary to define the list.

Example:

"results": [
            {
                "ansible_loop_var": "item",
                "changed": true,
                "failed": false,
                "invocation": {
                    "module_args": {
                        "aggregate": [
                            {
                                "description": "Desc Not Required",
                                "entries": [
                                    {
                                        "siteId": "1101001-1150999"
                                    }
                                ],
                                "infoTag": "",
                                "listId": "d87c5809-3900-44f5-844b-59c1aa9433f0",
                                "name": "CPOL_LIST_SITE_Hub",
                                "owner": "ansible",
                                "readOnly": false,
                                "type": "site",
                                "version": "0"
                            }
                        ],
                        "description": null,
                        "entries": null,
                        "force": false,
                        "force_basic_auth": true,
                        "host": "vmanage-amfament-preprod.sdwan.cisco.com",
                        "name": null,
                        "password": "Sdwan@dm1n",
                        "port": "443",
                        "push": false,
                        "state": "present",
                        "timeout": 30,
                        "type": "all",
                        "update": true,
                        "updates": [
                            {
                                "diff": [
                                    [
                                        "remove",
                                        "",
                                        [
                                            [
                                                "referenceCount",
                                                3
                                            ]
                                        ]
                                    ]
                                ],
                                "name": "CPOL_LIST_SITE_Hub"
                            }
                        ],
                        "user": "ansible",
                        "validate_certs": false
                    }
                },
                "item": "CPOL_LIST_SITE_Hub"
            }
        ],

device_templates.attach_to_template polls w/ utils.waitfor_action_completion

I think the SDK is trying to do too much here. Instead of providing a wrapper for the API it is building in logic that the user may or may not actually want. Would anyone be opposed if I submitted a pull request to remove the waitfor_action_completion from this function and just return the actionId?

Then if someone wants to know the status of the actionId they can request it, loop it, or whatever in their own code.

License information

At the bottom of the main page, you wrote
License
CISCO SAMPLE CODE LICENSE
but in the license file, there is GNU General Public License v3.0
Can you fix this

device_templates.attach_to_device

I would like to modify this function so that it will accept variable or property names in the uuid['variables'] data structure. I'm already constructing this data format to verify whether a sync is needed. It seems redundant to convert it all to variables for the function to then convert it back to property names.

Here is the secion I'm talking about:

           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 Exception(f"{entry['variable']} is missing for template {uuid[device_uuid]['host_name']}")

I would be adding the elif:

 elif entry['property'] in uuid[device_uuid]['variables']:
                        device_template_variables[entry['property']] = uuid[device_uuid]['variables'][entry['property']]

What do you think about that?

CLI option --json does not print proper json

When using the option --json with the cli-tool to format output as json, the output is done by printing the python dictionary.
Eg in show/template.py:
pp.pprint(device_template_list)

which gives:

[{ 'configType': 'template',
    'connectionPreference': True,
...

I think it would be better to use proper json-formatting (dubble quotes instead of single, true instead of True etc).
For example by using json.dumps():
click.echo(json.dumps(device_template_list, indent=2))

which gives:

[
  {
    "configType": "template",
    "connectionPreference": true,
...

This would enable the output to be parsed or manipulated by other clitools (jq, jawk et al), validated with json-validator and also in communicating directly with vmanager, the format must be proper json-format.

It could be argued that this would be a breaking change if people rely on the formatting to be a python dict, but I still think it would be better to change this now than later. What do you think?

Deactivate policy CLI command does not work.

When running

vmanage --host HOST --username USER --password PASSWORD deactivate central-policy --name <POLICY_NAME>

I get the following traceback:

Traceback (most recent call last):
  File "/Users/apiepoli/Venv/venv/bin/vmanage", line 11, in <module>
    load_entry_point('viptela', 'console_scripts', 'vmanage')()
  File "/Users/apiepoli/Venv/venv/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/apiepoli/Venv/venv/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/apiepoli/Venv/venv/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/apiepoli/Venv/venv/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/apiepoli/Venv/venv/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/apiepoli/Venv/venv/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/apiepoli/Venv/venv/lib/python3.7/site-packages/click/decorators.py", line 27, in new_func
    return f(get_current_context().obj, *args, **kwargs)
TypeError: central_policy() got an unexpected keyword argument 'id'

Improve attach_to_template() code

In current implementation attach_to_template() runs one API call to attach each device to a template. However in common deployment scenario there would be multiple devices attached to one device template and for those scenarios we can run one API call with payload for all the device-uuids.

"Exception: Invalid policy: Invalid classMapRef" when importing policies

When importing policies into a fresh vmanage I am getting error "Exception: Invalid policy: Invalid classMapRef ".

I exported policies from an existing vmanage, then immediatley try to import that policy to another vmanage. �Both are running 19.2.1. I can provide the json file to someone privately if needed.

Traceback (most recent call last): File "/Users/seth/Desktop/SDWAN_PE_Build/bin/vmanage", line 11, in <module> load_entry_point('viptela', 'console_scripts', 'vmanage')() File "/Users/seth/Desktop/SDWAN_PE_Build/lib/python3.7/site-packages/click/core.py", line 764, in __call__ return self.main(*args, **kwargs) File "/Users/seth/Desktop/SDWAN_PE_Build/lib/python3.7/site-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/Users/seth/Desktop/SDWAN_PE_Build/lib/python3.7/site-packages/click/core.py", line 1137, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/seth/Desktop/SDWAN_PE_Build/lib/python3.7/site-packages/click/core.py", line 1137, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/seth/Desktop/SDWAN_PE_Build/lib/python3.7/site-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/seth/Desktop/SDWAN_PE_Build/lib/python3.7/site-packages/click/core.py", line 555, in invoke return callback(*args, **kwargs) File "/Users/seth/Desktop/SDWAN_PE_Build/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func return f(get_current_context(), *args, **kwargs) File "/Users/seth/Desktop/SDWAN_PE_Build/python-viptela/vmanage/cli/import_cmd/policies.py", line 24, in policies result = vmanage_session.import_policy_from_file(file, update=update, check_mode=check, push=push) File "/Users/seth/Desktop/SDWAN_PE_Build/python-viptela/vmanage/api.py", line 829, in import_policy_from_file diff = self.import_policy_definition(definition, check_mode=check_mode, update=update, push=push) File "/Users/seth/Desktop/SDWAN_PE_Build/python-viptela/vmanage/api.py", line 938, in import_policy_definition method='POST', payload=payload) File "/Users/seth/Desktop/SDWAN_PE_Build/python-viptela/vmanage/api.py", line 122, in request raise Exception('{0}: {1}'.format(error, details)) Exception: Invalid policy: Invalid classMapRef 1f15b42a-bfd3-4018-bcd7-9db1bfeb7ad9

Key Errors in policy_data.py

I came across the two key errors below, I have included a change I made that fixed it however I will leave it up to someone more familiar with the project to make proper corrections.

First

(sdwan-viptela-0.3.0) Seths-MacBook-Pro:sdwan-viptela-0.3.0 seth$ vmanage --host vmanage.viptela.net --username admin --password goodpass export policies --file vManage-192-policies.json Exporting policies to vManage-192-policies.json Traceback (most recent call last): File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/bin/vmanage", line 33, in <module> sys.exit(load_entry_point('viptela', 'console_scripts', 'vmanage')()) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 829, in __call__ return self.main(*args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 610, in invoke return callback(*args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/decorators.py", line 33, in new_func return f(get_current_context().obj, *args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/cli/export/policies.py", line 19, in policies vmanage_files.export_policy_to_file(export_file) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/apps/files.py", line 190, in export_policy_to_file policy_definitions_list = self.policy_data.export_policy_definition_list() File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/data/policy_data.py", line 331, in export_policy_definition_list definition_detail = self.policy_definitions.get_policy_definition(policy_definition['type'], KeyError: 'type'
fix:
line 332 in policy_data.py
definition_detail = self.policy_definitions.get_policy_definition(policy_definition['data'][0]['type'],
policy_definition['data'][0]['definitionId'])

Second

sdwan-viptela-0.3.0) Seths-MacBook-Pro:sdwan-viptela-0.3.0 seth$ vmanage --host vmanage.viptela.net --username admin --password goodpass export policies --file vManage-192-policies.json Traceback (most recent call last): File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/bin/vmanage", line 33, in <module> sys.exit(load_entry_point('viptela', 'console_scripts', 'vmanage')()) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 829, in __call__ return self.main(*args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 610, in invoke return callback(*args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/decorators.py", line 33, in new_func return f(get_current_context().obj, *args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/cli/export/policies.py", line 19, in policies vmanage_files.export_policy_to_file(export_file) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/apps/files.py", line 191, in export_policy_to_file central_policies_list = self.policy_data.export_central_policy_list() File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/data/policy_data.py", line 499, in export_central_policy_list converted_policy_definition = self.convert_policy_to_name(central_policy) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/data/policy_data.py", line 408, in convert_policy_to_name self.convert_definition_id_to_name(converted_policy_item['policyDefinition']) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/data/policy_data.py", line 251, in convert_definition_id_to_name assembly_item['definitionName'] = policy_definition_detail['name'] KeyError: 'name'

fix:
line 250
assembly_item['definitionName'] = policy_definition_detail['data'][0]['name']

Move CI from Travis to GitHub Actions

We are having ongoing issues with funding for the Travis CI service which is making publishing to pypi (very) unreliable. Probably best to move to GitHub Actions at this point.

404 error for advancedMalwareProtection when exporting policies due to lower()

Error seems to be due to converting a string to lower case without considering advancedMalwareProtection specifically has capital letters.

(sdwan-viptela-0.3.0) Seths-MacBook-Pro:sdwan-viptela-0.3.0 seth$ vmanage --host vmanage.viptela.net --username admin --password goodpass export policies --file vManage-192-policies.json Traceback (most recent call last): File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/bin/vmanage", line 33, in <module> sys.exit(load_entry_point('viptela', 'console_scripts', 'vmanage')()) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 829, in __call__ return self.main(*args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/core.py", line 610, in invoke return callback(*args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/lib/python3.7/site-packages/click/decorators.py", line 33, in new_func return f(get_current_context().obj, *args, **kwargs) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/cli/export/policies.py", line 19, in policies vmanage_files.export_policy_to_file(export_file) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/apps/files.py", line 190, in export_policy_to_file policy_definitions_list = self.policy_data.export_policy_definition_list() File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/data/policy_data.py", line 328, in export_policy_definition_list policy_definition_list = self.policy_definitions.get_policy_definition_list(definition_type) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/api/policy_definitions.py", line 120, in get_policy_definition_list definition_list = self.get_policy_definition_list(def_type) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/api/policy_definitions.py", line 137, in get_policy_definition_list definition_detail = self.get_policy_definition(definition_type, definition['definitionId']) File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/api/policy_definitions.py", line 100, in get_policy_definition response = HttpMethods(self.session, url).request('GET') File "/Users/seth/dev-projects/sdwan-viptela-0.3.0/vmanage/api/http_methods.py", line 114, in request raise Exception(f"{self.url}: Error {result['status_code']} ({result['status']})") Exception: https://vmanage-1275533.viptela.net:443/dataservice/template/policy/definition/advancedmalwareprotection/7476926f-7807-41a8-a0f1-b214f8b16bd0: Error 404 (not_found)

fix:
in policy_definitions.py

for methds delete_policy_definition and update_policy_definition
replace the current url object with

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()}"

for method add_policy_definition

if policy_definition == "advancedMalwareProtection": url = f"{self.base_url}template/policy/definition/{policy_definition}" else: url = f"{self.base_url}template/policy/definition/{policy_definition.lower()}"

Samples how to use the SDK

Can you add information and sample how to use the SDK methods in python code.
How initialize connection etc?

option to set proxy

Hello

I'm getting error when trying to access vmanage (CURL.wget) via CLI. Looks script doesnt use system proxy I found on my MAC.

XYZ@SKLSPMAC005 ~ % sudo networksetup -getwebproxy wi-fi
Password:
Enabled: Yes
Server: XYZ.XYZ.XYZ.XYZ.com
Port: 8000
Authenticated Proxy Enabled: 0

when I try any wget/curl this is not taken. Just when I use --proxy in wget/curl pages works.

The same is with python-viptela/vmanage SDK. via CLI I can not get to vmanage and getting error timeout.
(icmp works).

If we could set what proxy should be used in these SDKs - that would be awesome.

(I replaced some internal stuff by XYZ from security reasons)

(vmanage, username, passwd were exported...just i don want to share them).

XYZ@SKLSPMAC005 ~ % vmanage show device status
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
conn = connection.create_connection(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 84, in create_connection
raise err
File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 74, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 309, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 171, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x11538cc10>: Failed to establish a new connection: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='vmanage-XYZ.viptela.net', port=443): Max retries exceeded with url: /dataservice/j_security_check (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x11538cc10>: Failed to establish a new connection: [Errno 61] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/XYZ/OneDrive - XYZ, Inc/Documents/att_projects/SDWAN/Cisco_SDWAN/API/python-viptela/vmanage/api/authentication.py", line 65, in login
response = self.session.post(url=url,
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 578, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='vmanage-XYZ.viptela.net', port=443): Max retries exceeded with url: /dataservice/j_security_check (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x11538cc10>: Failed to establish a new connection: [Errno 61] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/vmanage", line 33, in
sys.exit(load_entry_point('viptela', 'console_scripts', 'vmanage')())
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/Users/XYZ/OneDrive - XYZ, Inc/Documents/att_projects/SDWAN/Cisco_SDWAN/API/python-viptela/vmanage/cli/show/device.py", line 23, in status
vmanage_device = Device(ctx.auth, ctx.host, ctx.port)
File "/Users/XYZ/OneDrive - XYZ, Inc/Documents/att_projects/SDWAN/Cisco_SDWAN/API/python-viptela/vmanage/main.py", line 37, in auth
self.__auth = Authentication(host=self.host, port=self.port, user=self.username,
File "/Users/XYZ/OneDrive - XYZ, Inc/Documents/att_projects/SDWAN/Cisco_SDWAN/API/python-viptela/vmanage/api/authentication.py", line 84, in login
raise Exception(f'Could not connect to {self.host}: {e}')
Exception: Could not connect to vmanage-XYZ.viptela.net: HTTPSConnectionPool(host='vmanage-XYZ.viptela.net', port=443): Max retries exceeded with url: /dataservice/j_security_check (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x11538cc10>: Failed to establish a new connection: [Errno 61] Connection refused'))

XYZ@SKLSPMAC005 ~ % ping vmanage-XYZ.viptela.net
PING vmanage-XYZ.viptela.net (XYZ): 56 data bytes
64 bytes from XYZ: icmp_seq=0 ttl=33 time=144.315 ms
64 bytes from XYZ: icmp_seq=1 ttl=33 time=143.112 ms
64 bytes from XYZ: icmp_seq=2 ttl=33 time=151.929 ms
64 bytes from XYZ: icmp_seq=3 ttl=33 time=149.090 ms
^C
--- vmanage-XYZ.viptela.net ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 143.112/147.112/151.929/3.569 ms
XYZ@SKLSPMAC005 ~ %

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.