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

[PR #891/cc7d0f76 backport][stable-1] adding fix for packet_net.py #1396

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Nov 26, 2020

This is a backport of PR #891 as merged into main (cc7d0f7).

SUMMARY

I fixed the broken inventory script for packet_net.py, and I have no idea why it was broken before (I am not the creator), but it appeared that it needed a dictionary object (or subscriptable object (don't know what that means, but looked it up here) and the object had a built in function called __dict__ (which I figured out by importing the python-packet package (import packet) and did a help(packet.OperatingSystem) in python). So, I added that to the objects and the script worked... 🙂

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

packet_net.py

ADDITIONAL INFORMATION

I added the community.general to my collections and did the ansible-galaxy

Before change

command

$ python3 ~/.ansible/collections/ansible_collections/community/general/scripts/inventory/packet_net.py --list

result

Traceback (most recent call last):
  File "/home/vagrant/.ansible/collections/ansible_collections/community/general/scripts/inventory/packet_net.py", line 268, in get_devices_by_project
    self.add_device(device, project)
  File "/home/vagrant/.ansible/collections/ansible_collections/community/general/scripts/inventory/packet_net.py", line 349, in add_device
    self.push(self.inventory, device.operating_system['slug'], dest)
TypeError: 'OperatingSystem' object is not subscriptable
ERROR: "'OperatingSystem' object is not subscriptable", while: getting Packet devices

After change

NOTE: yes, I know there is a root password pasted in the debug logs below, I have already deleted the instances so it is irrelevant

command

$ python3 /vagrant/packet_net.py --list

result

{
  "1d51bfc2-da8d-45fb-9ecd-0585ed4665de": [
    "147.75.198.137"
  ],
  "35659f60-efc5-4a67-a458-d2f6d7badf6e": [
    "147.75.194.173"
  ],
  "_meta": {
    "hostvars": {
      "147.75.194.173": {
        "packet_always_pxe": false,
        "packet_billing_cycle": "hourly",
        "packet_bonding_mode": 5,
        "packet_created_at": "2020-09-16T05:17:57Z",
        "packet_description": "",
        "packet_facility": "ewr1",
        "packet_hardware_reservation_id": "",
        "packet_hostname": "ewr1-t1.small.x86-01",
        "packet_href": "/devices/35659f60-efc5-4a67-a458-d2f6d7badf6e",
        "packet_id": "35659f60-efc5-4a67-a458-d2f6d7badf6e",
        "packet_image_url": "",
        "packet_ipxe_script_url": "",
        "packet_iqn": "iqn.2020-09.net.packet:device.35659f60",
        "packet_locked": false,
        "packet_operating_system": "ubuntu_20_04",
        "packet_plan": "baremetal_0",
        "packet_provisioning_percentage": "",
        "packet_root_password": "9@H3$3Ox>Z",
        "packet_short_id": "35659f60",
        "packet_spot_instance": false,
        "packet_spot_price_max": "",
        "packet_state": "active",
        "packet_switch_uuid": "004ef92c",
        "packet_termination_time": "",
        "packet_updated_at": "2020-09-16T05:21:51Z",
        "packet_user": "root",
        "packet_userdata": ""
      },
      "147.75.198.137": {
        "packet_always_pxe": false,
        "packet_billing_cycle": "hourly",
        "packet_bonding_mode": 5,
        "packet_created_at": "2020-09-16T04:58:49Z",
        "packet_description": "",
        "packet_facility": "ewr1",
        "packet_hardware_reservation_id": "",
        "packet_hostname": "ewr1-t1.small.x86-01",
        "packet_href": "/devices/1d51bfc2-da8d-45fb-9ecd-0585ed4665de",
        "packet_id": "1d51bfc2-da8d-45fb-9ecd-0585ed4665de",
        "packet_image_url": "",
        "packet_ipxe_script_url": "",
        "packet_iqn": "iqn.2020-09.net.packet:device.1d51bfc2",
        "packet_locked": false,
        "packet_operating_system": "ubuntu_20_04",
        "packet_plan": "baremetal_0",
        "packet_provisioning_percentage": "",
        "packet_root_password": "tu)9nGV^32",
        "packet_short_id": "1d51bfc2",
        "packet_spot_instance": false,
        "packet_spot_price_max": "",
        "packet_state": "active",
        "packet_switch_uuid": "675d8200",
        "packet_termination_time": "",
        "packet_updated_at": "2020-09-16T05:02:10Z",
        "packet_user": "root",
        "packet_userdata": ""
      }
    }
  },
  "baremetal_0": [
    "147.75.194.173",
    "147.75.198.137"
  ],
  "dev-packer_kali_linux": [
    "147.75.194.173",
    "147.75.198.137"
  ],
  "ewr1": [
    "147.75.194.173",
    "147.75.198.137"
  ],
  "ewr1-t1.small.x86-01": [
    "147.75.194.173",
    "147.75.198.137"
  ],
  "packet": [
    "147.75.194.173",
    "147.75.198.137"
  ],
  "tag_none": [
    "147.75.194.173",
    "147.75.198.137"
  ],
  "ubuntu_20_04": [
    "147.75.194.173",
    "147.75.198.137"
  ]
}

* adding fix for packet_net.py

* adding changelog fragment

* squashing to fix cascading notifications

Apply suggestions from code review

thanks felixfontein for working with me!

Co-authored-by: Felix Fontein <felix@fontein.de>

adding suggestions from code review (accessing dict in a better way)

modified packet_net fragment to accurate description

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit cc7d0f7)
@ansibullbot ansibullbot added affects_2.10 bug This issue/PR relates to a bug community_review needs_triage new_contributor Help guide this first time contributor python3 small_patch Hopefully easy to review traceback labels Nov 26, 2020
@felixfontein
Copy link
Collaborator

CI failures are unrelated.

@felixfontein felixfontein merged commit 9bb4396 into stable-1 Nov 26, 2020
@felixfontein felixfontein deleted the patchback/backports/stable-1/cc7d0f7670a35b27e862bfdcb2eeabfc28ef2a45/pr-891 branch November 26, 2020 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug community_review needs_triage new_contributor Help guide this first time contributor python3 small_patch Hopefully easy to review traceback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants