In [1]:
import os
import swiftclient.client

In [2]:
config = {'username':os.environ['OS_USERNAME'],
        'api_key':os.environ['OS_PASSWORD'],
        'project_id':os.environ['OS_TENANT_NAME'],
        'auth_url':os.environ['OS_AUTH_URL'],
        }
    
from novaclient.client import Client
nc = Client('2',**config)

In [4]:
#conn = swiftclient.client.Connection(auth_version=2, **config)
nc.images.list()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-4120a2f5248f> in <module>()
      1 #conn = swiftclient.client.Connection(auth_version=2, **config)
----> 2 nc.image.list()

AttributeError: 'Client' object has no attribute 'image'

In [5]:
import time
#nc.keypairs.list()
#nc.images.list()
#nc.flavors.list()
if not nc.keypairs.findall(name="AJ_Hadoop_Cluster"):
    with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
        nc.keypairs.create(name="AJ_Hadoop_Cluster", public_key=fpubkey.read())
image = nc.images.find(name="AJ_Hadoop_Master")
flavor = nc.flavors.find(name="m1.large")
#user_data = open(os.path.expanduser('~/setup.sh'),"r")
#user-data to set-up the instance
instance =nc.servers.create(name='AJ_Hadoop_Slave_1', flavor=flavor, image=image, key_name="AJ_Hadoop_Cluster") #,userdata=user_data)
status = instance.status
while status == 'BUILD':
    time.sleep(5)
# Retrieve the instance again so the status field updates
    instance = nc.servers.get(instance.id)
    status = instance.status
print "status: %s" % status


---------------------------------------------------------------------------
Unauthorized                              Traceback (most recent call last)
<ipython-input-5-d005f3dd3ca5> in <module>()
      3 #nc.images.list()
      4 #nc.flavors.list()
----> 5 nc.keypairs.findall(name="AJ_Hadoop_Cluster")
      6    # with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
      7         #nc.keypairs.create(name="AJ_Hadoop_Cluster", public_key=fpubkey.read())

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/base.pyc in findall(self, **kwargs)
    450                 searches = [(k, v) for k, v in searches if k != 'deleted']
    451 
--> 452         listing = self.list(**list_kwargs)
    453         found.append_request_ids(listing.request_ids)
    454 

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/api_versions.pyc in substitution(obj, *args, **kwargs)
    368                     obj.api_version.get_string(), name)
    369 
--> 370             return methods[-1].func(obj, *args, **kwargs)
    371 
    372         # Let's share "arguments" with original method and substitution to

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/v2/keypairs.pyc in list(self)
    161         Get a list of keypairs.
    162         """
--> 163         return self._list('/%s' % self.keypair_prefix, 'keypairs')
    164 
    165     @api_versions.wraps("2.10")

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/base.pyc in _list(self, url, response_key, obj_class, body)
    240             resp, body = self.api.client.post(url, body=body)
    241         else:
--> 242             resp, body = self.api.client.get(url)
    243 
    244         if obj_class is None:

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/client.pyc in get(self, url, **kwargs)
    450 
    451     def get(self, url, **kwargs):
--> 452         return self._cs_request(url, 'GET', **kwargs)
    453 
    454     def post(self, url, **kwargs):

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/client.pyc in _cs_request(self, url, method, **kwargs)
    406     def _cs_request(self, url, method, **kwargs):
    407         if not self.management_url:
--> 408             self.authenticate()
    409         if url is None:
    410             # To get API version information, it is necessary to GET

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/client.pyc in authenticate(self)
    563             while auth_url:
    564                 if not self.auth_system or self.auth_system == 'keystone':
--> 565                     auth_url = self._v2_auth(auth_url)
    566                 else:
    567                     auth_url = self._plugin_auth(auth_url)

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/client.pyc in _v2_auth(self, url)
    654             body['auth']['tenantName'] = self.projectid
    655 
--> 656         return self._authenticate(url, body)
    657 
    658     def _authenticate(self, url, body, **kwargs):

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/client.pyc in _authenticate(self, url, body, **kwargs)
    667             body=body,
    668             allow_redirects=True,
--> 669             **kwargs)
    670 
    671         return self._extract_service_catalog(url, resp, respbody)

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/client.pyc in _time_request(self, url, method, **kwargs)
    401     def _time_request(self, url, method, **kwargs):
    402         with utils.record_time(self.times, self.timings, method, url):
--> 403             resp, body = self.request(url, method, **kwargs)
    404         return resp, body
    405 

/Users/ajallow/Python/Cloud_Cost_Estimator/venv/lib/python2.7/site-packages/novaclient/client.pyc in request(self, url, method, **kwargs)
    395                                 if resp.headers else None)
    396         if resp.status_code >= 400:
--> 397             raise exceptions.from_response(resp, body, url, method)
    398 
    399         return resp, body

Unauthorized: The request you have made requires authentication. (HTTP 401)

In [ ]:
nc.floating_ips.list()
ip = nc.floating_ips.create(pool="ext-net")
nc.servers.find(name="AJ_Hadoop_Slave_1").add_floating_ip(fip)
nc.servers.find(name="AJ_Hadoop_Slave_1").addresses