OpenStack SDK

repository·master·Indexed 43 days ago

https://github.com/openstack/openstacksdk

A Python client library providing a consistent, multi-layered interface for interacting with OpenStack cloud services. It features a hierarchical architecture consisting of Connection objects for authentication, Proxy layers for high-level service interaction, and Resource objects for low-level REST API mapping and CRUD operations.

Tokens
101.2K
Snippets
428
Records
611
Agent score
55%

What's inside OpenStack SDK

  1. Manage Amphora resources in OpenStack SDK

    master

    The openstack.load_balancer.v2.amphora module provides access to Amphora-related resources. Amphora is the underlying implementation for Octavia load balancers. You can interact with these resources using the following classes, all of which inherit from openstack.resource.Resource:

    • Amphora: Represents an Amphora instance.
    • AmphoraConfig: Manages configuration settings for Amphora.
    • AmphoraFailover: Manages failover configurations for Amphora.
  2. Use the Baremetal Introspection Proxy via Connection

    master

    The Baremetal Introspection high-level interface is accessed through the baremetal_introspection attribute of an openstack.connection.Connection object. Note that the baremetal_introspection member is only attached to the Connection object if the service is detected during connection initialization.

    import openstack
    
    conn = openstack.connect(cloud='my-cloud')
    # The baremetal_introspection proxy is available if the service is detected
    introspection = conn.baremetal_introspection
  3. Naming conventions for OpenStack SDK resources

    master

    When contributing to or extending the OpenStack SDK, follow PEP 8 standards for naming:

    • Module names: Lowercase, underscore-separated (e.g., openstack.object_store).
    • Class names: Capitalized (PascalCase) with no spaces (e.g., ServerMetadata).
    • Attributes and methods: Lowercase, underscore-separated (e.g., allow_list, get_data).

    Service Naming: Services are named after their program name rather than their code name. For example, use compute instead of Nova within the SDK.

  4. Use Proxy for high-level service interaction

    master

    Each service implements a Proxy class (located in openstack/<program_name>/vX/_proxy.py) which inherits from openstack.proxy.Proxy.

    The Proxy acts as a convenience layer between the user and the low-level Resource objects. Instead of interacting with Adapter objects directly, you call methods on the Proxy which internally execute the corresponding Resource methods.

    Example of a Proxy method implementation:

    def list_flavors(self, **params):
        return flavor.Flavor.list(self.session, **params)
  5. Understand the OpenStack SDK architecture

    master

    The OpenStack SDK is organized into a hierarchical structure that moves from low-level resource management to high-level connection handling:

    1. Resource: The fundamental building block. Resource objects map directly to REST API endpoints (e.g., /servers). They handle CRUD operations, URL construction, and attribute mapping.
    2. Proxy: A service-specific layer (e.g., openstack/compute/v2/_proxy.py) that provides a high-level interface. Instead of managing low-level Adapter and Resource objects manually, users interact with Proxy methods which wrap Resource operations.
    3. Connection: The primary entry point for users. A Connection object manages the underlying connection details and exposes the various service Proxy objects.
  6. Understand the components of an OpenStack Resource

    master

    In OpenStack SDK, a Resource is composed of three primary components that define how an object is identified and interacted with via the API:

    1. URI: Represents the unique identifier/path for the resource within the OpenStack service.
    2. Header: Manages the HTTP headers associated with requests for this resource.
    3. Body: Represents the payload or data content of the resource.

    These components work together to encapsulate the full state and identity of a cloud resource.