netfoundry / developer-tools

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Patching endpoints option in netfoundry_endpoint

dariuszSki opened this issue · comments

I want to update an endpoint attributes but I cant. Is this true or am I doing something wrong? @qrkourier

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Exception: ERROR: got unexpected HTTP code BAD_REQUEST (400) with body {"traceId":"bd00516a3c74d791","errors":["An endpoint with that name already exists."],"status":{"code":400,"label":"Bad Request"}}
failed: [localhost] (item={'name': 'zititestnet.phx-ad-1', 'attributes': ['#us-phoenix-1', '#phx-ad-1', '#ocp']}) => {"ansible_loop_var": "item", "changed": false, "item": {"attributes": ["#us-phoenix-1", "#phx-ad-1", "#ocp"], "name": "zititestnet.phx-ad-1"}, "module_stderr": "Traceback (most recent call last):\n File "/home/dsliwinski/.ansible/tmp/ansible-tmp-1641688024.8708096-5630-37551059380139/AnsiballZ_netfoundry_endpoint.py", line 100, in \n _ansiballz_main()\n File "/home/dsliwinski/.ansible/tmp/ansible-tmp-1641688024.8708096-5630-37551059380139/AnsiballZ_netfoundry_endpoint.py", line 92, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/home/dsliwinski/.ansible/tmp/ansible-tmp-1641688024.8708096-5630-37551059380139/AnsiballZ_netfoundry_endpoint.py", line 40, in invoke_module\n runpy.run_module(mod_name='ansible_collections.netfoundry.platform.plugins.modules.netfoundry_endpoint', init_globals=dict(_module_fqn='ansible_collections.netfoundry.platform.plugins.modules.netfoundry_endpoint', _modlib_path=modlib_path),\n File "/usr/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/lib/python3.8/runpy.py", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File "/usr/lib/python3.8/runpy.py", line 87, in _run_code\n exec(code, run_globals)\n File "/tmp/ansible_netfoundry_endpoint_payload_msdytpdd/ansible_netfoundry_endpoint_payload.zip/ansible_collections/netfoundry/platform/plugins/modules/netfoundry_endpoint.py", line 234, in \n File "/tmp/ansible_netfoundry_endpoint_payload_msdytpdd/ansible_netfoundry_endpoint_payload.zip/ansible_collections/netfoundry/platform/plugins/modules/netfoundry_endpoint.py", line 230, in main\n File "/tmp/ansible_netfoundry_endpoint_payload_msdytpdd/ansible_netfoundry_endpoint_payload.zip/ansible_collections/netfoundry/platform/plugins/modules/netfoundry_endpoint.py", line 180, in run_module\n File "/home/dsliwinski/.local/lib/python3.8/site-packages/netfoundry/network.py", line 800, in create_endpoint\n raise Exception('ERROR: got unexpected HTTP code {:s} ({:d}) with body {:s}'.format(\nException: ERROR: got unexpected HTTP code BAD_REQUEST (400) with body {"traceId":"bd00516a3c74d791","errors":["An endpoint with that name already exists."],"status":{"code":400,"label":"Bad Request"}}\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

code written as this:

- name: Update endpoints type router with the same atributes as hosted edge routers of the same name
  netfoundry_endpoint:
    name: "{{ item.name }}"
    attributes: "{{ item.attributes }}"
    network: "{{ netfoundry_network.network }}"
  loop: "{{ endpoints }}"
  tags: 
    - create

it looks like this issue is in the python module. Trying to trace it

@qrkourier how do you test these ansible modules? The python network scripts seems to be working fine. I am not sure if this part of the code works fine in the netfoundry_endpoint.py module. Want to check if "found" list variable is populated with my endpoint.

# check if UUIDv4
    try: UUID(module.params['name'], version=4)
    except ValueError:
        # else assume is an Endpoint
        found = network.get_resources(type="endpoints",name=module.params['name'],typeId="Device")
    # it's a UUID and so we assign the property directly
    else: 
        found = [network.get_resource(type="endpoint",id=module.params['name'])]

    if len(found) == 0:
        if module.params['state'] == "PROVISIONED":
            result['message'] = network.create_endpoint(name=module.params['name'], attributes=module.params['attributes'], 
                session_identity=module.params['sessionIdentity'], wait=module.params['wait'])

I want to update an endpoint attributes but I cant. Is this true or am I doing something wrong? @qrkourier

@dariuszSki Yes, you can update attributes for any type of entity by providing a new value to an attributes arg for each module. I'll take a dive into the log messages you sent to see what's up.

@dariuszSki Do you get the same result with the latest Py module and Ansible collection?

❯ pip -q uninstall -y netfoundry && pip -q install -U netfoundry && pip show netfoundry
Name: netfoundry
Version: 5.2.9
Summary: Interface to the NetFoundry network-as-code orchestration Platform
Home-page: https://developer.netfoundry.io/guides/python/
Author: Kenneth Bingham
Author-email: support@netfoundry.io
License: MIT
Location: /home/kbingham/.pyenv/versions/3.9.0/lib/python3.9/site-packages
Requires: inflect, pyjwt, pysocks, requests
Required-by: 

❯ rm -rf ~/.ansible/collections/ansible_collections/netfoundry/platform && ansible-galaxy collection install --force-with-deps netfoundry.platform
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Downloading https://galaxy.ansible.com/download/netfoundry-platform-1.15.2.tar.gz to /home/kbingham/.ansible/tmp/ansible-local-1347122xnv0_3q6/tmpkq0nlt7e/netfoundry-platform-1.15.2-gt6d4d99
Installing 'netfoundry.platform:1.15.2' to '/home/kbingham/.ansible/collections/ansible_collections/netfoundry/platform'
netfoundry.platform:1.15.2 was installed successfully

You may also reproduce the problem with latest Py module and Ansible collection by running your playbook with Docker.

❯ docker run \
  --rm \
  --volume ~/.netfoundry/credentials.json:/netfoundry/credentials.json \
  --volume /tmp/MY_PLAYBOOK.yml:/netfoundry/playbook.yml \
  netfoundry/ansible:latest \
    ansible-playbook /netfoundry/playbook.yml
dsliwinski@DariuszDesktop:/mnt/e/NetFoundry/Repos/azure-deploy$ pip show netfoundryName: netfoundry
Version: 5.2.9
Summary: Interface to the NetFoundry network-as-code orchestration Platform
Home-page: https://developer.netfoundry.io/guides/python/
Author: Kenneth Bingham
Author-email: support@netfoundry.io
License: MIT
Location: /home/dsliwinski/.local/lib/python3.8/site-packages
Requires: inflect, pyjwt, pysocks, requests
Required-by: 
dsliwinski@DariuszDesktop:/mnt/e/NetFoundry/Repos/azure-deploy`
```

I have the latest one

Is there a way to test the netfoundry_endpoint.py and step through it?

@dariuszSki Do you have the latest collection 1.15.2?

❯ jq -r '.collection_info.version' ~/.ansible/collections/ansible_collections/netfoundry/platform/MANIFEST.json 
1.15.2

❯ docker run \
  --rm -it \
  netfoundry/ansible:latest \
        jq -r '.collection_info.version' /usr/share/ansible/collections/ansible_collections/netfoundry/platform/MANIFEST.json
1.15.2

ok, It looks like the collection is not the latest 1.14.3

I ask about the collection version because the problem you described was fixed in an earlier release.

let me upgrade it and see if the issue clears

The problem was that routers' built-in tunnelers were filtered out by the module and so it would try to create an endpoint which then collided with the tunneler-enabled router's system-managed endpoint. Now it doesn't filter them out and instead will treat it as existing and just update attributes.

ok, that is what I am thinking, because I noticed that you separated endpoint into device and router when using the info module

perhaps endpoint should have a option type to pass, when using the info module. and looking for endpoints

I was looking for my endpoints under endpoints, but they were under router endpoints :)

ok, it is good now after the upgrade