Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status of post when object exists #49

Open
rgrueebler opened this issue Apr 24, 2024 · 0 comments
Open

Status of post when object exists #49

rgrueebler opened this issue Apr 24, 2024 · 0 comments

Comments

@rgrueebler
Copy link

Hi

I've tested the netbox.post.dcim.devices action to create a new device in Netbox. If the device doesn't exists, i get the following result:

{
  "stdout": "",
  "stderr": "st2.actions.python.NetboxHTTPAction: DEBUG    Calling base post with kwargs: {'site': 1, 'device_type': 2, 'name': 'Test04', 'role': 1}\n",
  "exit_code": 0,
  "result": {
    "raw": {
      "id": 172,
      "url": "http://netbox:8080/api/dcim/devices/172/",
      "display": "Test04",
      "name": "Test04",
      "device_type": {
        "id": 2,
        "url": "http://netbox:8080/api/dcim/device-types/2/",
        "display": "Autodiscovery",
        "manufacturer": {
          "id": 1,
          "url": "http://netbox:8080/api/dcim/manufacturers/1/",
          "display": "Cisco",
          "name": "Cisco",
          "slug": "cisco"
        },
        "model": "Autodiscovery",
        "slug": "autodiscovery"
      },
    <output omitted>
    },
    "status": 201
  }
}

The device gets created and the action has a status of 'succeeded'. This is expected.

When i execute the same action again, by clicking 'Rerun', i get the following result:

{
  "raw": {},
  "status": 404
}

The status of the action is also 'succeeded'. Is this the expected behavior? I would assume that the status of the action should be 'failed'.

The reason for my assumption is, I have a task which creates devices in Netbox, and the next task should create the interfaces for the particular device.

post_device_to_netbox:
    join: all
    action: netbox.post.dcim.devices
    input:
      device_type: <% ctx(device_type_id) %>
      role: <% ctx(device_role_id) %>
      site: <% ctx(site_id) %>
      name: <% ctx(device).hostname %>
    next:
      - when: <% succeeded() %>
        publish:
          - device_id: <% result().result.raw.id %>
        do: add_interfaces_to_device
      - when: <% failed() %>
        do: fail
add_interfaces_to_device:
    with:
      items: <% ctx(interfaces) %>
    action: netbox.post.dcim.interfaces
    input:
      device: <% str(ctx(device_id)) %>
      name: <% item().name %>
      type: '1000base-t'
      enabled: <% item().enabled %>
      description: <% item().description %>
      untagged_vlan: <% item().access_vlan %>
      tagged_vlans: <% item().trunk_vlans %>
    next:
      - when: <% succeeded() %>
        publish:
          - interfaces: <% result().result %>

The 'post_device_to_netbox:' task only publishes the 'device_id' variable when the device didn't exist in Netbox. In case the devicce already exists, we get a 404 response so '- device_id: <% result().result.raw.id %>' does not work. Here we get this error:

"YaqlEvaluationException: Unable to resolve key 'id' in expression '<% result().result.raw.id %>' from context.",

In this case it would be helpful when the 'post_device_to_netbox:' task failed.

What are your thoughts on this?

Thanks
Remo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant