Initial blob of thoughts from me
This commit is contained in:
19
README.rst
Normal file
19
README.rst
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
An OpenStack all-in-one SDK
|
||||||
|
===========================
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
import io
|
||||||
|
|
||||||
|
from openstack import OpenStackClient, KeystoneAuth
|
||||||
|
|
||||||
|
|
||||||
|
client = OpenStackClient(KeystoneAuth('http://localhost:8000/', 'alex', '****'))
|
||||||
|
image = client.compute.images.list()[0]
|
||||||
|
server = client.compute.servers.create(image=image)
|
||||||
|
print server.public_ips[0]
|
||||||
|
|
||||||
|
container = client.object_storage.container.create(name='stuff')
|
||||||
|
container.objects.create(name='a thing', contents=io.BytesIO(b'all the bytes'))
|
0
__init__.py
Normal file
0
__init__.py
Normal file
41
auth.py
Normal file
41
auth.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
class KeystoneAuth(object):
|
||||||
|
def __init__(self, authurl, username, password):
|
||||||
|
self._authurl = authurl
|
||||||
|
self._username = username
|
||||||
|
self._password = password
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
return KeystoneTransport(self)
|
||||||
|
|
||||||
|
|
||||||
|
class KeystoneTransport(object):
|
||||||
|
def __init__(self, auth_info):
|
||||||
|
# Set ourselves up:
|
||||||
|
# * Open HTTP session
|
||||||
|
# * Get a token
|
||||||
|
# * Configure session to raise on HTTP error
|
||||||
|
self.auth_info = auth_info
|
||||||
|
|
||||||
|
def make_http_request(method):
|
||||||
|
def inner(self, *args, **kwargs):
|
||||||
|
# get_session() will make sure that the token is valid.
|
||||||
|
return self.get_session().request(method, *args, **kwargs)
|
||||||
|
return inner
|
||||||
|
|
||||||
|
get = make_http_request("GET")
|
||||||
|
post = make_http_request("POST")
|
||||||
|
patch = make_http_request("PATCH")
|
||||||
|
delete = make_http_request("DELETE")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# In reality this would not live inside the main package because it would be
|
||||||
|
# vendor agnostic, but for the purpose of demonstrating that other auth
|
||||||
|
# strategies work fine, it goes here.
|
||||||
|
class RackspaceAuth(object):
|
||||||
|
def __init__(self, username, api_key):
|
||||||
|
self._username = username
|
||||||
|
self._api_key = api_key
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
# ...
|
12
client.py
Normal file
12
client.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class OpenStackClient(object):
|
||||||
|
def __init__(self, auth):
|
||||||
|
self._transport = auth.connect()
|
||||||
|
self._auth = auth
|
||||||
|
|
||||||
|
@property
|
||||||
|
def compute(self):
|
||||||
|
return ComputeClient(self._transport)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def object_storage(self):
|
||||||
|
return ObjectStorageClient(self._transport)
|
Reference in New Issue
Block a user