Skip to main content

Python package to manage hypervisor/docker/kubernetes stacks

Project description

PyCloudStack (Unified Cloud Stack Operator Framework)

1. Overview

PyCloudStack abstracts the common objects/operations/resources for diverse cloud architectures like hypervisor stack based on libvirt or direct qemu command, container stack orchestrated by Kubernetes or direct docker command, and the running or remote IaaS host.

It can be used to create advance deployment CI/CD operator via python plugin for ansible, end-to-end validation framework with customized the components/configurations in full vertical stack.

The architecture diagram is as follows:

2. Getting Start

Install from PyPI

pip3 install pycloudstack

Install from source

cd ~/pycloudstack
pip3 install --user --upgrade .

3. Examples

Example 1: Operate VM via Libvirt

from pycloudstack.vmguest import VMGuestFactory
from pycloudstack.vmparam import VM_STATE_SHUTDOWN, VM_STATE_RUNNING, \
    VM_STATE_PAUSE, VM_TYPE_TD

vm_factory = VMGuestFactory(vm_image, vm_kernel)

LOG.info("Create TD guest")
inst = vm_factory.new_vm(VM_TYPE_TD, auto_start=True)
inst.wait_for_ssh_ready()

LOG.info("Suspend TD guest")
inst.suspend()
ret = inst.wait_for_state(VM_STATE_PAUSE)
assert ret, "Suspend timeout"

LOG.info("Resume TD guest")
inst.resume()
ret = inst.wait_for_state(VM_STATE_RUNNING)
assert ret, "Resume timeout"

Example 2: Operate VM via Qemu (QMP)

from gpl.vmmqmp import VMMQemu
from pycloudstack.vmparam import VM_TYPE_TD, VM_TYPE_LEGACY,

vm_factory = VMGuestFactory(vm_image, vm_kernel)
inst = vm_factory.new_vm(vm_instance_type, vm_class=VMMQemu,
                         auto_start=True)
inst.wait_for_ssh_ready()

Example 3: Operate Kubernetes Cluster

from pycloudstack.cluster import SGXCluster

DEPLOYMENT_TEMPLATE='''
apiVersion: apps/v1
kind: Deployment
metadata:
  name: %(name)s
spec:
  selector:
    matchLabels:
      app: testapp-redis-gsc-sgx
  template:
    metadata:
      labels:
        app: testapp-redis-gsc-sgx
    spec:
      containers:
      - name: redis-gsc-sgx
        image: gar-registry.caas.intel.com/cpio/gsc-centos8-redis:latest
        ports:
          - containerPort: 6379
        env:
        - name: GSC
          value: %(gsc)s
        resources:
          limits:
            sgx.intel.com/enclave: '1'
            sgx.intel.com/epc: '524288000'
'''
SERVICE_TEMPLATE='''
apiVersion: v1
kind: Service
metadata:
  name: %(name)s
spec:
  ports:
  - port: 6379
    protocol: TCP
  selector:
    app: testapp-redis-gsc-sgx
  type: NodePort
'''

cluster_instance = SGXCluster()
deploy_name = 'deployment-redis-gsc-sgx-' + str(uuid.uuid4())
cluster_instance.create_deployment(
        deploy_name,
        yaml.safe_load(DEPLOYMENT_TEMPLATE % {"name":deploy_name, "gsc":gsc}),
        TEST_NAMESPACE)

svc_name = 'svc-redis-gsc-sgx-' + str(uuid.uuid4())
cluster_instance.create_service(
        svc_name,
        yaml.safe_load(SERVICE_TEMPLATE % {"name":svc_name}),
        TEST_NAMESPACE)
cluster_instance.delete_service(svc_name, TEST_NAMESPACE)
cluster_instance.delete_deployment(deploy_name, TEST_NAMESPACE)

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

pycloudstack-0.0.10.tar.gz (29.5 kB view hashes)

Uploaded Source

Built Distribution

pycloudstack-0.0.10-py3-none-any.whl (37.9 kB view hashes)

Uploaded Python 3

Supported by

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