Skip to main content

A client to interact with the Linode Metadata service in Python.

Project description

Linode Metadata Client for Python

Unit Tests E2E Tests PyPI version Documentation Status

This package allows Python projects to easily interact with the Linode Metadata Service.

Getting Started

Prerequisites

Installation

pip install linode-metadata

Building from Source

To build and install this package:

  • Clone this repository
  • make install

Examples

The following code snippets show multiple different ways to use the metadata client and retrieves various metadata of the current Linode.

Basic Usage

from linode_metadata import MetadataClient

client = MetadataClient()

instance_info = client.get_instance()
network_info = client.get_network()
ssh_info = client.get_ssh_keys()
user_data = client.get_user_data()

print("Instance ID:", instance_info.id)
print("Public IPv4:", network_info.ipv4.public[0])
print("SSH Keys:", "; ".join(ssh_info.users))
print("User Data:", user_data)

Asynchronous I/O and Context Manager Support

You can also use the context manager to ensure the HTTP client will be properly closed, and the asyncio enabled client is also available.

import asyncio
from linode_metadata import AsyncMetadataClient

async def get_metadata():
    with AsyncMetadataClient() as client:
        instance_info = await client.get_instance()
        print("Instance ID:", instance_info.id)

asyncio.run(get_metadata())

Watchers

Watchers are useful for monitor changes in the metadata, e.g. newly added IP address to the Linode.

import asyncio
from linode_metadata import AsyncMetadataClient

async def get_metadata():
    async with AsyncMetadataClient() as client:
        watcher = client.get_watcher()
        async for new_network_info in watcher.watch_network():
            print(new_network_info)

asyncio.run(get_metadata())

Testing

Before running tests on this project, please ensure you have a Linode Personal Access Token exported under the LINODE_TOKEN environment variable.

End-to-End Testing Using Ansible

This project contains an Ansible playbook to automatically deploy the necessary infrastructure and run end-to-end tests on it.

To install the dependencies for this playbook, ensure you have Python 3 installed and run the following:

make test-deps

After all dependencies have been installed, you can run the end-to-end test suite by running the following:

make int-test

If your local SSH public key is stored in a location other than ~/.ssh/id_rsa.pub, you may need to override the TEST_PUBKEY argument:

make TEST_PUBKEY=/path/to/my/pubkey int-test

NOTE: To speed up subsequent test runs, the infrastructure provisioned for testing will persist after the test run is complete. This infrastructure is safe to manually remove.

Manual End-to-End Testing

End-to-end tests can also be manually run using the make int-test-local target. This test suite is expected to run from within a Linode instance and will likely fail in other environments.

License

This software is Copyright Akamai Technologies, Inc. and is released under the Apache 2.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linode_metadata-0.3.3.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linode_metadata-0.3.3-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file linode_metadata-0.3.3.tar.gz.

File metadata

  • Download URL: linode_metadata-0.3.3.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for linode_metadata-0.3.3.tar.gz
Algorithm Hash digest
SHA256 138a8e03bc4db9ec5ffe7bd363ca86a1d2ed943d681b3f35792b00de8207986b
MD5 08a76161455c016579f505628aaa6548
BLAKE2b-256 bbb4870c06f401a2a3d04021518fb7c1a13bb7d4841a397ad0da1a27ec1408ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for linode_metadata-0.3.3.tar.gz:

Publisher: publish-pypi.yml on linode/py-metadata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file linode_metadata-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for linode_metadata-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2044ba69b6c46ddd3002ae8d6477098d21835cc9c7f0b686b766b0442c19ed57
MD5 03fce51b4251d59374c3f3a499202023
BLAKE2b-256 981a4fd9bd2ab029627ec9f799daae11948f278d488becb29ba354b700bb61f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for linode_metadata-0.3.3-py3-none-any.whl:

Publisher: publish-pypi.yml on linode/py-metadata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page