Skip to main content

A library to manage resources and offers generated from application requirements

Project description

swchcapreg

library to handle capacity registry

Python library package

This project is published as swchcapreg and imported as swch_capreg.

  • Public class: swch_capreg.SwChCapacityRegistry

Quick start

from swch_capreg import SwChCapacityRegistry

capreg = SwChCapacityRegistry("ra-example")
capreg.initialize_capacity_from_file("sztaki-capacity-raw.yaml")
offers = capreg.resource_offer_generate_from_SAT_file("swarm1", "BookInfo.yaml")
print(offers)

Public API (selected)

Core classes

  • SwChCapacityRegistry: orchestrates capacity loading, offer generation, acceptance/rejection, and resource state transitions.

Exposed registry methods

The following methods are the documented API entry points of SwChCapacityRegistry.

API Reference Table

Method Signature Summary
initialize_capacity_by_content (content: str) Initialize capacity from YAML content string.
initialize_capacity_from_file (filename: str) Initialize capacity from CDT YAML file.
resource_offer_generate_by_SAT_content (swarmid: str, sat_content: str) Generate offers from SAT YAML content.
resource_offer_generate_from_SAT_file (swarmid: str, sat_filename: str) Generate offers from SAT file and reserve resources.
resource_offer_query_all (swarmid: str) Return all offers for a swarm.
resource_offer_accept (offerid: str, offer: list | dict) Accept an offer (reservedassigned).
resource_offer_reject (offerid: str, offer: list | dict) Reject an offer (reservedfree) and remove it.
resource_set_get_from_offer (offerid: str, offer: list | dict) Build normalized resource-set descriptor from an offer.
resource_set_deployed (swarmid: str, msid: str, restype: str, resid: str, count: int) Mark assigned resources as deployed (assignedallocated).
resource_set_undeployed (swarmid: str, msid: str, restype: str, resid: str, count: int) Mark deployed resources as undeployed (allocatedassigned).
resource_set_query_all (swarmid: str, msid: str | None = None) Query tracked resource states for a swarm or microservice.
resources_and_offers_destroy_all (swarmid: str) Release all resources and delete all offers for a swarm.
dump_capacity_registry_info () Print registry snapshot via logger.

initialize_capacity_by_content(content: str)

Initializes registry capacity from YAML text content.

  • Parameters
    • content: Capacity template as YAML string.
  • Behavior
    • Creates a temporary file from the string content and delegates to initialize_capacity_from_file.
  • Returns
    • None

Back to API table

initialize_capacity_from_file(filename: str)

Initializes cloud/edge capacity model from a CDT YAML file.

  • Parameters
    • filename: Path to the capacity descriptor template.
  • Behavior
    • Parses capacities and initializes internal state (free, reserved, assigned, allocated, init) for cloud and/or edge resources.
  • Returns
    • None

Back to API table

resource_offer_generate_by_SAT_content(swarmid: str, sat_content: str)

Generates offers for a swarm from SAT YAML text content.

  • Parameters
    • swarmid: Swarm identifier.
    • sat_content: Application requirements template as YAML string.
  • Behavior
    • Writes SAT content to a temporary file and delegates to resource_offer_generate_from_SAT_file.
  • Returns
    • Offer dictionary for the swarm.

Back to API table

resource_offer_generate_from_SAT_file(swarmid: str, sat_filename: str)

Generates placement/resource offers for each microservice in a swarm.

  • Parameters
    • swarmid: Swarm identifier.
    • sat_filename: Path to SAT (application requirements) file.
  • Behavior
    • Extracts requirements, matches resources, reserves available capacity, and builds offer payloads including IDs and basic characteristics.
    • Stores generated offers under capacity["offers"][swarmid].
  • Returns
    • Offer dictionary keyed by microservice ID and offer ID.

Back to API table

resource_offer_query_all(swarmid: str)

Returns all currently stored offers for a swarm.

  • Parameters
    • swarmid: Swarm identifier.
  • Returns
    • Deep copy of the swarm’s offers (empty dict if missing).

Back to API table

resource_offer_accept(offerid: str, offer: list | dict)

Accepts an offer and moves its resources from reserved to assigned.

  • Parameters
    • offerid: Offer ID ("colocated" is treated as a no-op success).
    • offer: Single offer dict or list of offer instances.
  • Returns
    • True on success, False if state transition fails.

Back to API table

resource_offer_reject(offerid: str, offer: list | dict)

Rejects an offer, releases reservation, and removes it from offer storage.

  • Parameters
    • offerid: Offer ID ("colocated" is treated as a no-op success).
    • offer: Single offer dict or list of offer instances.
  • Returns
    • True on success, False if state transition fails.

Back to API table

resource_set_get_from_offer(offerid: str, offer: list | dict)

Extracts a normalized resource-set descriptor from an offer.

  • Parameters
    • offerid: Offer ID.
    • offer: Single offer dict or list of offer instances.
  • Returns
    • Dict with swarmid, msid, restype, resid, count, or None for colocated placeholder offers.

Back to API table

resource_set_deployed(swarmid: str, msid: str, restype: str, resid: str, count: int)

Marks assigned resources as deployed.

  • Parameters
    • swarmid, msid: Swarm and microservice IDs.
    • restype: Resource type (cloud or edge).
    • resid: Resource identifier (flavor/instance name).
    • count: Number of instances.
  • Behavior
    • Moves state from assigned to allocated.
  • Returns
    • Moved count or None if transition is not possible.

Back to API table

resource_set_undeployed(swarmid: str, msid: str, restype: str, resid: str, count: int)

Marks deployed resources as no longer deployed.

  • Parameters
    • Same as resource_set_deployed.
  • Behavior
    • Moves state from allocated to assigned.
  • Returns
    • Moved count or None if transition is not possible.

Back to API table

resource_set_query_all(swarmid: str, msid: str | None = None)

Returns tracked resource state entries for a swarm (optionally for one MS).

  • Parameters
    • swarmid: Swarm identifier.
    • msid: Optional microservice ID.
  • Returns
    • Deep copy of resource-state subtree.

Back to API table

resources_and_offers_destroy_all(swarmid: str)

Releases all tracked resources and removes all offers for a swarm.

  • Parameters
    • swarmid: Swarm identifier.
  • Behavior
    • Moves all non-zero states back to free, then deletes swarm entries from both resource and offer registries.
  • Returns
    • True

Back to API table

dump_capacity_registry_info()

Prints a human-readable snapshot of cloud/edge capacities and swarm state.

  • Returns
    • None (logging output only).

Back to API table

Notes

  • Demo scripts are available in tests/ (for example tests/test_cloud_offers.py and tests/test_edge_offers.py).
  • swch_capreg/methods.py contains the method-name catalog used for API documentation/discovery.
  • AppReq and ResCap are internal helper modules used by SwChCapacityRegistry.

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

swchcapreg-0.1.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

swchcapreg-0.1.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file swchcapreg-0.1.0.tar.gz.

File metadata

  • Download URL: swchcapreg-0.1.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for swchcapreg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3422f99de9d932bf66996f7011aff1e0cc089e959667c66db3e934439bebfc74
MD5 8afed9e6dca1c08670c0cef5b4a6d755
BLAKE2b-256 8577d31daf14b0ba901d72f1acc7804486e426b7f6eaf6e1630f7c070474cf1d

See more details on using hashes here.

File details

Details for the file swchcapreg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: swchcapreg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for swchcapreg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f68a48a0e9229c3b730c50d7777626d51da015f44194feae4d5efb7a1a01e654
MD5 92fc37eed8128508f81b798c00b5837b
BLAKE2b-256 f808fdcd6ec6e369147fcad8fb1a6ec54664f6070ebb11594a5ce2bde6e41ec3

See more details on using hashes here.

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