Skip to content

Retrieving host information on all Linode instances #141

@decentral1se

Description

@decentral1se

Again, building the Ansible dynamic inventory and need to collect 'hostvars' which are values against hosts which help to identify them or give further information about the instance. I'm so far doing something like:

        for instance in self.instances:
            hostvars = [
                {'name': 'id', 'value': instance.id},
                {'name': 'ipv4', 'value': instance.ipv4},
                {'name': 'ipv6', 'value': instance.ipv6},
                {'name': 'region', 'value': instance.region.id},
                {'name': 'type', 'value': instance.type.id},
            ]

            for hostvar in hostvars:
                self.inventory.set_variable(
                    instance.label,
                    hostvar['name'],
                    hostvar['value'],
                )

This is OK for now but 1) is missing data (see below about properties) 2) won't include any new information as the instance API evolves and will continue to need updates.

I see that instance.properties exists (and looks to have everything I might need but I am not sure how to use that as I don't really undertand the purpose of Property class). If I could get that payload, serialized, that would be great. I currently see:

ipdb> i1.properties
{'status': <linode_api4.objects.base.Property instance at 0x7ff938ca2b48>, 'updated': <linode_api4.objects.base.Property instance at 0x7ff938ca2bd8>, 'disks': <linode_api4.objects.base.Property instance at 0x7ff938ca2cf8>, 'group': <linode_api4.objects.base.Property instance at 0x7ff938ca2b00>, 'created': <linode_api4.objects.base.Property instance at 0x7ff938ca2b90>, 'hypervisor': <linode_api4.objects.base.Property instance at 0x7ff938ca2e18>, 'region': <linode_api4.objects.base.Property instance at 0x7ff938ca2c20>, 'alerts': <linode_api4.objects.base.Property instance at 0x7ff938ca2c68>, 'label': <linode_api4.objects.base.Property instance at 0x7ff938ca2ab8>, 'specs': <linode_api4.objects.base.Property instance at 0x7ff938ca2e60>, 'backups': <linode_api4.objects.base.Property instance at 0x7ff938ca2dd0>, 'ipv4': <linode_api4.objects.base.Property instance at 0x7ff938c85680>, 'image': <linode_api4.objects.base.Property instance at 0x7ff938ca2cb0>, 'ipv6': <linode_api4.objects.base.Property instance at 0x7ff938c85638>, 'configs': <linode_api4.objects.base.Property instance at 0x7ff938ca2d40>, 'type': <linode_api4.objects.base.Property instance at 0x7ff938ca2d88>, 'id': <linode_api4.objects.base.Property instance at 0x7ff938ca2a70>}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions