Skip to content

ITlusions/ITL.ControlPanel.SDK.Client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ITL ControlPlane Client SDK

A Python client library for interacting with the ITL ControlPlane API. Provides typed models and async HTTP operations for managing cloud resources.

Installation

pip install itl-controlplane-client

# With OIDC authentication support
pip install itl-controlplane-client[auth]

Quick Start

from itl_controlplane_client import ControlPlaneClient

async with ControlPlaneClient("https://api.itlusions.com") as client:
    # List subscriptions
    subscriptions = await client.subscriptions.list()
    for sub in subscriptions:
        print(f"{sub.name}: {sub.id}")
    
    # Create a resource group
    rg = await client.resource_groups.create(
        subscription_id="sub-123",
        name="my-rg",
        location="westeurope"
    )
    
    # Get any resource by type
    vm = await client.resources.get(
        subscription_id="sub-123",
        resource_group="my-rg",
        provider="ITL.Compute",
        resource_type="virtualMachines",
        name="my-vm"
    )

Authentication

OIDC (Keycloak)

from itl_controlplane_client import ControlPlaneClient
from itl_controlplane_client.auth import OIDCAuth

auth = OIDCAuth(
    token_url="https://keycloak.example.com/realms/itl/protocol/openid-connect/token",
    client_id="my-app",
    client_secret="secret"
)

async with ControlPlaneClient("https://api.itlusions.com", auth=auth) as client:
    subs = await client.subscriptions.list()

Bearer Token

from itl_controlplane_client.auth import BearerAuth

auth = BearerAuth("your-access-token")
async with ControlPlaneClient("https://api.itlusions.com", auth=auth) as client:
    subs = await client.subscriptions.list()

API Key

from itl_controlplane_client.auth import APIKeyAuth

auth = APIKeyAuth("your-api-key")
async with ControlPlaneClient("https://api.itlusions.com", auth=auth) as client:
    subs = await client.subscriptions.list()

Operations

Subscriptions

# List all subscriptions
subscriptions = await client.subscriptions.list()

# Get a subscription
sub = await client.subscriptions.get("sub-123")

# Create a subscription
sub = await client.subscriptions.create(
    name="my-subscription",
    display_name="My Subscription"
)

# Update a subscription
sub = await client.subscriptions.update(
    subscription_id="sub-123",
    display_name="New Name",
    tags={"env": "prod"}
)

# Delete a subscription
await client.subscriptions.delete("sub-123")

Resource Groups

# List resource groups
rgs = await client.resource_groups.list("sub-123")

# Get a resource group
rg = await client.resource_groups.get("sub-123", "my-rg")

# Create a resource group
rg = await client.resource_groups.create(
    subscription_id="sub-123",
    name="my-rg",
    location="westeurope",
    tags={"team": "platform"}
)

# Delete a resource group
await client.resource_groups.delete("sub-123", "my-rg")

Generic Resources

# List resources by type
vms = await client.resources.list(
    subscription_id="sub-123",
    resource_group="my-rg",
    provider="ITL.Compute",
    resource_type="virtualMachines"
)

# Get a resource
vm = await client.resources.get(
    subscription_id="sub-123",
    resource_group="my-rg",
    provider="ITL.Compute",
    resource_type="virtualMachines",
    name="my-vm"
)

# Create or update a resource
vm = await client.resources.create_or_update(
    subscription_id="sub-123",
    resource_group="my-rg",
    provider="ITL.Compute",
    resource_type="virtualMachines",
    name="my-vm",
    location="westeurope",
    properties={
        "vmSize": "Standard_D2s_v3",
        "osType": "Linux"
    }
)

# Invoke an action
await client.resources.invoke_action(
    subscription_id="sub-123",
    resource_group="my-rg",
    provider="ITL.Compute",
    resource_type="virtualMachines",
    name="my-vm",
    action="restart"
)

# Delete a resource
await client.resources.delete(
    subscription_id="sub-123",
    resource_group="my-rg",
    provider="ITL.Compute",
    resource_type="virtualMachines",
    name="my-vm"
)

Locations

# List available locations
locations = await client.locations.list("sub-123")
for loc in locations:
    print(f"{loc.name}: {loc.display_name}")

Deployments

# Create a deployment
deployment = await client.deployments.create(
    subscription_id="sub-123",
    resource_group="my-rg",
    name="my-deployment",
    template={
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "resources": [
            {
                "type": "ITL.Compute/virtualMachines",
                "name": "my-vm",
                "location": "westeurope",
                "properties": {"vmSize": "Standard_D2s_v3"}
            }
        ]
    }
)

# Check deployment status
deployment = await client.deployments.get("sub-123", "my-rg", "my-deployment")
print(deployment.properties.provisioning_state)

Models

All responses are typed Pydantic models:

from itl_controlplane_client.models import (
    Resource,
    ResourceList,
    Subscription,
    ResourceGroup,
    Location,
    Deployment,
    ProvisioningState,
)

# Models have full type hints
vm: Resource = await client.resources.get(...)
print(vm.name)          # str
print(vm.location)      # str
print(vm.properties)    # Dict[str, Any]
print(vm.tags)          # Optional[Dict[str, str]]

# Pagination
resources: ResourceList = await client.resources.list(...)
for resource in resources:  # Iterable
    print(resource.name)
print(resources.next_link)  # Optional pagination URL

Error Handling

import httpx

try:
    vm = await client.resources.get(...)
except httpx.HTTPStatusError as e:
    if e.response.status_code == 404:
        print("Resource not found")
    elif e.response.status_code == 403:
        print("Access denied")
    else:
        print(f"Error: {e.response.text}")

License

MIT License - see LICENSE for details.

Related Projects

  • ITL.ControlPanel.SDK - Internal SDK for building resource providers (proprietary)
  • ITL.ControlPlane.Api - API Gateway for the ControlPlane platform
  • ITL.ControlPlane.Portal - Customer self-service portal

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages