def __init__(self, options): super().__init__(options) # Setup the specific container driver provider if "driver" not in options: raise KeyError("key: 'driver' must be specified") if "args" in options["driver"]: driver_args = options["driver"]["args"] else: driver_args = tuple() if "kwargs" in options["driver"]: driver_kwargs = options["driver"]["kwargs"] else: driver_kwargs = {} cls = get_driver(options["driver"]["provider"]) self.client = cls(*driver_args, **driver_kwargs) self.container = None
def work_with_images(): print("Working with images...") # LXD host change accordingly host_lxd = "https://192.168.2.4" # port that LXD server is listening at # change this according to your configuration port_id = 8443 # get the libcloud LXD driver lxd_driver = get_driver(Provider.LXD) # acquire the connection. # certificates should have been added to the LXD server # here we assume they are on the same directory change # accordingly conn = lxd_driver( key="", secret="", secure=False, host=host_lxd, port=port_id, key_file="lxd.key", cert_file="lxd.crt", ) # get the images this LXD server is publishing images = conn.list_images() print("Number of images: ", len(images)) for image in images: print("Image: ", image.name) print("\tPath ", image.path) print("\tVersion ", image.version) conn.create_image()
from libcloud.container.types import Provider from libcloud.container.providers import get_driver cls = get_driver(Provider.KUBERNETES) conn = cls(key='my_username', secret='THIS_IS)+_MY_SECRET_KEY+I6TVkv68o4H', host='126.32.21.4') for container in conn.list_containers(): print(container.name) for cluster in conn.list_clusters(): print(cluster.name)
def work_with_containers(): print("Working with containers...") # LXD API specification can be found at: # https://github.com/lxc/lxd/blob/master/doc/rest-api.md#10containersnamemetadata # LXD host change accordingly host_lxd = 'https://192.168.2.4' # port that LXD server is listening at # change this according to your configuration port_id = 8443 # get the libcloud LXD driver lxd_driver = get_driver(Provider.LXD) # acquire the connection. # certificates should have been added to the LXD server # here we assume they are on the same directory change # accordingly conn = lxd_driver(key='', secret='', secure=False, host=host_lxd, port=port_id, key_file='lxd.key', cert_file='lxd.crt') # this API call does not require authentication api_end_points = conn.ex_get_api_endpoints() print(api_end_points) # this API call is allowed for everyone (but result varies) api_version = conn.ex_get_server_configuration() print(api_version) # get the list of the containers containers = conn.list_containers() if len(containers) == 0: print("\tNo containers have been created") else: print("\tNumber of containers: %s" % len(containers)) for container in containers: print("\t\tContainer: %s is: %s" % (container.name, container.state)) # start the first container print("\tStarting container: %s" % containers[0].name) container = conn.start_container(container=containers[0]) print("\tContainer: %s is: %s" % (container.name, container.state)) # stop the container returned print("\tStopping container: %s" % containers[0].name) container = conn.stop_container(container=container) print("\tContainer: %s is: %s" % (container.name, container.state)) # restart the container print("\tRestarting container: %s" % container.name) container = conn.restart_container(container=container) print("\tContainer: %s is: %s" % (container.name, container.state)) """
def work_with_storage_pools(): print("Working with storage pools...") # LXD host change accordingly host_lxd = 'https://192.168.2.4' # port that LXD server is listening at # change this according to your configuration port_id = 8443 # get the libcloud LXD driver lxd_driver = get_driver(Provider.LXD) # acquire the connection. # certificates should have been added to the LXD server # here we assume they are on the same directory change # accordingly conn = lxd_driver(key='', secret='', secure=False, host=host_lxd, port=port_id, key_file='lxd.key', cert_file='lxd.crt') # get the images this LXD server is publishing pools = conn.ex_list_storage_pools() print("Number of storage pools: ", len(pools)) for pool in pools: print("\tPool: ", pool.name) print("\t\tDriver: ", pool.driver) print("\t\tUsed by: ", pool.used_by) print("\t\tConfig: ", pool.config) #conn.ex_delete_storage_pool(id="Pool100") definition = { "driver": "zfs", "name": "Pool100", "config": { "size": "70MB" } } #conn.ex_create_storage_pool(definition=definition) #conn.ex_delete_storage_pool_volume(storage_pool_id="Pool100", type="custom", name="vol1") volumes = conn.ex_list_storage_pool_volumes(storage_pool_id="Pool100") for volume in volumes: print(volume.name) definition = { "config": { "block.filesystem": "ext4", "block.mount_options": "discard", "size": "10737418240" }, "name": "vol1", "type": "custom" } volume = conn.ex_create_storage_pool_volume(storage_pool_id="Pool100", definition=definition) print("Volume name: ", volume.name) print("Volume size: ", volume.size) definition = { "config": { "block.filesystem": "ext4", "block.mount_options": "discard", "size": "8737418240" } } volume = conn.ex_replace_storage_volume_config(storage_pool_id="Pool100", type="custom", name="vol1", definition=definition) print("Volume name: ", volume.name) print("Volume size: ", volume.size)
from libcloud.container.base import ContainerImage from libcloud.container.types import Provider from libcloud.container.providers import get_driver cls = get_driver(Provider.ECS) conn = cls( access_id="SDHFISJDIFJSIDFJ", secret="THIS_IS)+_MY_SECRET_KEY+I6TVkv68o4H", region="ap-southeast-2", ) for cluster in conn.list_clusters(): print(cluster.name) if cluster.name == "my-cluster": conn.list_containers(cluster=cluster) container = conn.deploy_container( name="my-simple-app", image=ContainerImage(id=None, name="simple-app", path="simple-app", version=None, driver=conn), cluster=cluster, )
from libcloud.container.types import Provider from libcloud.container.providers import get_driver driver = get_driver(Provider.RANCHER) connection = driver("MYRANCHERACCESSKEY", "MYRANCHERSECRETKEY", host="172.30.0.100", port=8080, secure=False) connection.list_containers()
from libcloud.container.providers import get_driver from libcloud.container.types import Provider CREDS = ('user', 'api key') Cls = get_driver(Provider.DOCKER) driver = Cls(*CREDS) image = driver.install_image('tomcat:8.0') container = driver.deploy_container('tomcat', image) container.restart()
from libcloud.container.types import Provider from libcloud.container.providers import get_driver from libcloud.container.utils.docker import HubClient cls = get_driver(Provider.ECS) conn = cls(access_id='SDHFISJDIFJSIDFJ', secret='THIS_IS)+_MY_SECRET_KEY+I6TVkv68o4H', region='ap-southeast-2') hub = HubClient() image = hub.get_image('ubuntu', 'latest') for cluster in conn.list_clusters(): print(cluster.name) if cluster.name == 'default': container = conn.deploy_container( cluster=cluster, name='my-simple-app', image=image)
from libcloud.container.types import Provider from libcloud.container.providers import get_driver driver = get_driver(Provider.RANCHER) connection = driver("MYRANCHERACCESSKEY", "MYRANCHERSECRETKEY", host="172.30.22.1", port=8080, secure=False) search_results = connection.ex_search_containers( search_params={"imageUuid": "docker:mysql", "state": "running"}) id_of_first_result = search_results[0]['id']
from libcloud.container.types import Provider from libcloud.container.providers import get_driver cls = get_driver(Provider.JOYENT) conn = cls( host="us-east-1.docker.joyent.com", port=2376, key_file="key.pem", cert_file="~/.sdc/docker/admin/ca.pem", ) conn.list_images()
from libcloud.container.types import Provider from libcloud.container.providers import get_driver cls = get_driver(Provider.GKE) conn = cls( "*****@*****.**", "libcloud.json", project="testproject", ) conn.list_clusters()
from libcloud.container.types import Provider from libcloud.container.providers import get_driver cls = get_driver(Provider.JOYENT) conn = cls(host='us-east-1.docker.joyent.com', port=2376, key_file='key.pem', cert_file='~/.sdc/docker/admin/ca.pem') conn.list_images()