5.1 KiB
5.1 KiB
Python Bindings
The python-cueclient can be used to interact with the Cue API from any other python program.
Introduction
Below is a simple example of how to instantiate and perform basic tasks using the bindings.
#!/usr/bin/env python
from keystoneclient.auth.identity import v3 as keystone_v3_auth
from keystoneclient import session as keystone_session
from cueclient.v1 import client
= keystone_v3_auth.Password(
auth ="http://example.com:5000/v3",
auth_url="admin",
username="password",
password="admin",
project_name="default",
project_domain_name="default"
user_domain_name
)
= keystone_session.Session(auth=auth)
session
# Create an instance of the client
= client.Client(session=session)
cue_client
# Cluster List - returns list of cluster objects
= cue_client.clusters.list()
list_response
# Iterate the list, printing some useful information
for cluster in list_response:
print "Cluster ID: %s \t Name: %s \t NetworkId: %s \t Flavor: %s \t Size: %s" % \
id, cluster.name, cluster.network_id, cluster.flavor, cluster.size) (cluster.
And the output this program might produce:
$ python /example.py
Cluster ID: 213cdd06-c361-4cca-93b5-7ed651d46936 Name: test_binding2 NetworkId: 33333 Flavor: 1 Size: 2
Cluster ID: 24f299fd-0509-4218-bf80-6c0481452480 Name: test_binding4 NetworkId: 44444 Flavor: 1 Size: 2
Authentication
Cue supports Keystone authentication.
Keystone Authentication
Below is a sample of standard authentication with keystone v3:
#!/usr/bin/env python
from keystoneclient.auth.identity import v3 as keystone_v3_auth
from keystoneclient import session as keystone_session
= keystone_v3_auth.Password(
auth ="http://example.com:5000/v3",
auth_url="admin",
username="password",
password="admin",
project_name="default",
project_domain_name="default"
user_domain_name )
Cue Functions
Cluster List
#!/usr/bin/env python
from keystoneclient.auth.identity import v3 as keystone_v3_auth
from keystoneclient import session as keystone_session
from cueclient.v1 import client
= keystone_v3_auth.Password(
auth ="http://example.com:5000/v3",
auth_url="admin",
username="password",
password="admin",
project_name="default",
project_domain_name="default"
user_domain_name
)
= keystone_session.Session(auth=auth)
session = client.Client(session=session)
cue_client
# Cluster List
= cue_client.clusters.list() list_response
Cluster Show
#!/usr/bin/env python
from keystoneclient.auth.identity import v3 as keystone_v3_auth
from keystoneclient import session as keystone_session
from cueclient.v1 import client
= keystone_v3_auth.Password(
auth ="http://example.com:5000/v3",
auth_url="admin",
username="password",
password="admin",
project_name="default",
project_domain_name="default"
user_domain_name
)
= keystone_session.Session(auth=auth)
session = client.Client(session=session)
cue_client
= "0a352f9a-8aa8-411e-9d6d-4e6217d70afd"
cluster_id
# Cluster Show
= cue_client.clusters.get(cluster_id) show_response
Cluster Create
#!/usr/bin/env python
from keystoneclient.auth.identity import v3 as keystone_v3_auth
from keystoneclient import session as keystone_session
from cueclient.v1 import client
= keystone_v3_auth.Password(
auth ="http://example.com:5000/v3",
auth_url="admin",
username="password",
password="admin",
project_name="default",
project_domain_name="default"
user_domain_name
)
= keystone_session.Session(auth=auth)
session = client.Client(session=session)
cue_client
# Cluster create
= cue_client.clusters.create(name="test_binding5",
create_response ="55555", flavor="1",size="2",volume_size="0") nic
Cluster Delete
#!/usr/bin/env python
from keystoneclient.auth.identity import v3 as keystone_v3_auth
from keystoneclient import session as keystone_session
from cueclient.v1 import client
= keystone_v3_auth.Password(
auth ="http://example.com:5000/v3",
auth_url="admin",
username="password",
password="admin",
project_name="default",
project_domain_name="default"
user_domain_name
)
= keystone_session.Session(auth=auth)
session = client.Client(session=session)
cue_client
= "dc86d96f-6b37-4e2d-9805-4542450f427d"
delete_id
# Cluster Delete
= cue_client.clusters.delete(delete_id) delete_response