SlideShare uma empresa Scribd logo
1 de 36
Cloud APIs are great…
   but I want to use Python!



                                     Ed Leafe
                                        Rackspace
                         Boston OpenStack Meetup
                                       2012.02.13
Survey
About
•Developer for 20+ years
•Rackspace for 5 years
•Python developer since 2000
•OpenStack developer since the beginning
•Swift (before OpenStack)
•Nova
•Keystone
Contact
•ed.leafe@rackspace.com
•ed@leafe.com
•ed@openstack.org
APIs


•Documented at: http://docs.rackspace.com/
Jump right in!
        Let's get a list of our Cloud Servers:


import urllib2
uri = "https://dfw.servers.api.rackspacecloud.com/"
      "v2/753591/servers/detail"
resp = urllib2.urlopen(uri)
print resp.read()
Oh, yeah...


HTTP Error 401: Unauthorized
So let's handle auth
uri =
"http://identity.api.rackspacecloud.com/v2.0/tokens"credentials =
{"auth": {"passwordCredentials":
         {"username": "joeuser", "password":
         "abc123def456"}}}
req = urllib2.Request(uri,data=json.dumps(credentials))
req.add_header("Content-Type", "application/json")
req.add_header("Accept", "application/json")
try:
     raw_resp = urllib2.urlopen(req)
except urllib2.HTTPError as e:
     errcode = e.getcode()
     if errcode == 401:
         # Invalid authorization
         print "Invalid credentials"
     else:
         print "Authentication Error: %s" % e
     return
resp = json.load(raw_resp)
Not done yet...

token_info = resp.get("access").get("token")
token = token_info.get("id")
expires = token_info.get("expires")
tenant_info = token_info.get("tenant")
tenant_id = tenant_info.get("id")
Still not finished...

access = resp.get("access")
svc_catalog = access.get("serviceCatalog")
# Let's see what's in this
print svc_catalog
[{u'endpoints': [{u'publicURL': u'https://monitoring.api.rackspacecloud.com/v1.0/753591',
    u'tenantId': u'753591'}],
  u'name': u'cloudMonitoring',
  u'type': u'rax:monitor'},
 {u'endpoints': [{u'publicURL': u'https://ord.loadbalancers.api.rackspacecloud.com/v1.0/753591',
    u'region': u'ORD',
    u'tenantId': u'753591'},
   {u'publicURL': u'https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/753591',
    u'region': u'DFW',
    u'tenantId': u'753591'}],
  u'name': u'cloudLoadBalancers',
  u'type': u'rax:load-balancer'},
 {u'endpoints': [{u'publicURL': u'https://servers.api.rackspacecloud.com/v1.0/753591',
    u'tenantId': u'753591',
    u'versionId': u'1.0',
    u'versionInfo': u'https://servers.api.rackspacecloud.com/v1.0',
    u'versionList': u'https://servers.api.rackspacecloud.com/'}],
  u'name': u'cloudServers',
  u'type': u'compute'},
 {u'endpoints': [{u'publicURL': u'https://cdn1.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d',
    u'region': u'DFW',
    u'tenantId': u'MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d'},
   {u'publicURL': u'https://cdn2.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d',
    u'region': u'ORD',
    u'tenantId': u'MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d'}],
  u'name': u'cloudFilesCDN',
  u'type': u'rax:object-cdn'},
 {u'endpoints': [{u'publicURL': u'https://dfw.blockstorage.api.rackspacecloud.com/v1/753591',
    u'region': u'DFW',
    u'tenantId': u'753591'},
   {u'publicURL': u'https://ord.blockstorage.api.rackspacecloud.com/v1/753591',
    u'region': u'ORD',
    u'tenantId': u'753591'}],
  u'name': u'cloudBlockStorage',
  u'type': u'volume'},
 {u'endpoints': [{u'publicURL': u'https://dfw.databases.api.rackspacecloud.com/v1.0/753591',
    u'region': u'DFW',
    u'tenantId': u'753591'},
   {u'publicURL': u'https://ord.databases.api.rackspacecloud.com/v1.0/753591',
    u'region': u'ORD',
    u'tenantId': u'753591'}],
  u'name': u'cloudDatabases',
  u'type': u'rax:database'},
 {u'endpoints': [{u'publicURL': u'https://dfw.servers.api.rackspacecloud.com/v2/753591',
    u'region': u'DFW',
    u'tenantId': u'753591',
    u'versionId': u'2',
    u'versionInfo': u'https://dfw.servers.api.rackspacecloud.com/v2',
    u'versionList': u'https://dfw.servers.api.rackspacecloud.com/'},
   {u'publicURL': u'https://ord.servers.api.rackspacecloud.com/v2/753591',
    u'region': u'ORD',
    u'tenantId': u'753591',
    u'versionId': u'2',
    u'versionInfo': u'https://ord.servers.api.rackspacecloud.com/v2',
    u'versionList': u'https://ord.servers.api.rackspacecloud.com/'}],
  u'name': u'cloudServersOpenStack',
  u'type': u'compute'},
 {u'endpoints': [{u'internalURL': u'https://snet-storage101.dfw1.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d',
    u'publicURL': u'https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d',
    u'region': u'DFW',
    u'tenantId': u'MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d'},
   {u'internalURL': u'https://snet-storage101.ord1.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d',
    u'publicURL': u'https://storage101.ord1.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d',
    u'region': u'ORD',
    u'tenantId': u'MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d'}],
  u'name': u'cloudFiles',
  u'type': u'object-store'},
 {u'endpoints': [{u'publicURL': u'https://dns.api.rackspacecloud.com/v1.0/753591',
    u'tenantId': u'753591'}],
Simple!
The Service Catalog

•Contains all of the available services and their
endpoints.
•For services that are region-specific, holds the
endpoints for each region.
Compute Service Catalog
{u'endpoints': [{u'publicURL': u'https://dfw.servers.api.
    rackspacecloud.com/v2/753591',
   u'region': u'DFW',
   u'tenantId': u'753591',
   u'versionId': u'2',
   u'versionInfo': u'https://dfw.servers.api.rackspacecloud.com/v2',
   u'versionList': u'https://dfw.servers.api.rackspacecloud.com/'},
  {u'publicURL': u'https://ord.servers.api.rackspacecloud.com/
    v2/753591',
   u'region': u'ORD',
   u'tenantId': u'753591',
   u'versionId': u'2',
   u'versionInfo': u'https://ord.servers.api.rackspacecloud.com/v2',
   u'versionList': u'https://ord.servers.api.rackspacecloud.com/'}],
 u'name': u'cloudServersOpenStack',
 u'type': u'compute'}
Compute Service Catalog
{u'endpoints': [{u'publicURL': u'https://dfw.servers.api.
    rackspacecloud.com/v2/753591',
   u'region': u'DFW',
   u'tenantId': u'753591',
   u'versionId': u'2',
   u'versionInfo': u'https://dfw.servers.api.rackspacecloud.com/v2',
   u'versionList': u'https://dfw.servers.api.rackspacecloud.com/'},
  {u'publicURL': u'https://ord.servers.api.rackspacecloud.com/
    v2/753591',
   u'region': u'ORD',
   u'tenantId': u'753591',
   u'versionId': u'2',
   u'versionInfo': u'https://ord.servers.api.rackspacecloud.com/v2',
   u'versionList': u'https://ord.servers.api.rackspacecloud.com/'}],
 u'name': u'cloudServersOpenStack',
 u'type': u'compute'}
Compute Service Catalog
{u'endpoints': [{u'publicURL': u'https://dfw.servers.api.
    rackspacecloud.com/v2/753591',
   u'region': u'DFW',
   u'tenantId': u'753591',
   u'versionId': u'2',
   u'versionInfo': u'https://dfw.servers.api.rackspacecloud.com/v2',
   u'versionList': u'https://dfw.servers.api.rackspacecloud.com/'},
  {u'publicURL': u'https://ord.servers.api.rackspacecloud.com/
    v2/753591',
   u'region': u'ORD',
   u'tenantId': u'753591',
   u'versionId': u'2',
   u'versionInfo': u'https://ord.servers.api.rackspacecloud.com/v2',
   u'versionList': u'https://ord.servers.api.rackspacecloud.com/'}],
 u'name': u'cloudServersOpenStack',
 u'type': u'compute'}
Find URI by Region

access = resp["access"]
svc_cat = access["serviceCatalog"]
compute_svc = svc_cat["compute"]
eps = compute_svc["endpoints"]
reg_ep = [ep for ep in eps
    if ep["region"] == region][0]
base_uri = reg_ep["public_url"]
list_uri = "%s/servers/detail" % base_uri
Create the Request

import urllib2
req = urllib2.Request(list_uri)
Add the Auth Headers

req.add_header("X-Auth-Token", token)
req.add_header("X-Auth-Project-Id",
    tenant_id)
Add the HTTP Headers

req.add_header("Accept", "application/json")
req.add_header("Content-Type",
    "application/json")
req.add_header("User-Agent", "myapp/1.1")
Make the Request

raw_resp = urllib2.urlopen(req)
resp = json.load(raw_resp)
print resp
{u'servers': [{u'OS-DCF:diskConfig': u'AUTO',
  u'OS-EXT-STS:power_state': 1,
  u'OS-EXT-STS:task_state': None,
  u'OS-EXT-STS:vm_state': u'active',
                                                                                                 Result:
  u'accessIPv4': u'166.78.8.247',
  u'accessIPv6': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae',
  u'addresses': {u'private': [{u'addr': u'10.181.18.164', u'version': 4}],
   u'public': [{u'addr': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae',
     u'version': 6},
    {u'addr': u'166.78.8.247', u'version': 4}]},
  u'created': u'2013-01-24T15:13:23Z',
  u'flavor': {u'id': u'2',
   u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/flavors/2',
     u'rel': u'bookmark'}]},
  u'hostId': u'fcaa2858a7255b1bbba8cf5e3a1550f0f1bea780164a4412709e5d4d',
  u'id': u'19b394eb-17ce-4221-9989-824be1bd2236',
  u'image': {u'id': u'09a4e770-26f7-4377-8893-2b21a0b76ba8',
   u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/images/09a4e770-26f7-4377-8893-2b21a0b76ba8',
     u'rel': u'bookmark'}]},
  u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/v2/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236',
    u'rel': u'self'},
   {u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236',
    u'rel': u'bookmark'}],
  u'metadata': {},
  u'name': u'NM0978FR',
  u'progress': 100,
  u'rax-bandwidth:bandwidth': [],
  u'status': u'ACTIVE',
  u'tenant_id': u'728829',
  u'updated': u'2013-01-24T15:17:55Z',
  u'user_id': u'235799'},
 {u'OS-DCF:diskConfig': u'AUTO',
  u'OS-EXT-STS:power_state': 1,
  u'OS-EXT-STS:task_state': None,
  u'OS-EXT-STS:vm_state': u'active',
  u'accessIPv4': u'198.61.217.238',
  u'accessIPv6': u'2001:4800:780e:0510:8ca7:b42c:ff04:a78e',
  u'addresses': {u'private': [{u'addr': u'10.180.24.4', u'version': 4}],
   u'public': [{u'addr': u'2001:4800:780e:0510:8ca7:b42c:ff04:a78e',
     u'version': 6},
    {u'addr': u'198.61.217.238', u'version': 4}]},
  u'created': u'2012-12-03T17:23:16Z',
  u'flavor': {u'id': u'2',
   u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/flavors/2',
     u'rel': u'bookmark'}]},
  u'hostId': u'ec8d624af62a9cb511daba3c106d27142b3cff0eaf3aa61cda89f1fa',
  u'id': u'5e16de51-724c-4885-8849-65719bb455fd',
  u'image': {u'id': u'5cebb13a-f783-4f8c-8058-c4182c724ccd',
   u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/images/5cebb13a-f783-4f8c-8058-c4182c724ccd',
     u'rel': u'bookmark'}]},
  u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/v2/728829/servers/5e16de51-724c-4885-8849-65719bb455fd',
    u'rel': u'self'},
   {u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/servers/5e16de51-724c-4885-8849-65719bb455fd',
    u'rel': u'bookmark'}],
  u'metadata': {},
  u'name': u'BmwIqtGb',
  u'progress': 100,
  u'rax-bandwidth:bandwidth': [],
  u'status': u'ACTIVE',
  u'tenant_id': u'728829',
  u'updated': u'2013-01-19T16:47:03Z',
  u'user_id': u'235799'}]}
That's just for 2
   servers!
Just One Server:
{u'OS-DCF:diskConfig': u'AUTO',
  u'OS-EXT-STS:power_state': 1,
  u'OS-EXT-STS:task_state': None,
  u'OS-EXT-STS:vm_state': u'active',
  u'accessIPv4': u'166.78.8.247',
  u'accessIPv6': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae',
  u'addresses': {u'private': [{u'addr': u'10.181.18.164', u'version': 4}],
   u'public': [{u'addr': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae',
     u'version': 6},
    {u'addr': u'166.78.8.247', u'version': 4}]},
  u'created': u'2013-01-24T15:13:23Z',
  u'flavor': {u'id': u'2',
   u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/flavors/2',
     u'rel': u'bookmark'}]},
  u'hostId': u'fcaa2858a7255b1bbba8cf5e3a1550f0f1bea780164a4412709e5d4d',
  u'id': u'19b394eb-17ce-4221-9989-824be1bd2236',
  u'image': {u'id': u'09a4e770-26f7-4377-8893-2b21a0b76ba8',
   u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/images/09a4e770-26f7-4377-8893-2b21a0b76ba8',
     u'rel': u'bookmark'}]},
  u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/v2/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236',
    u'rel': u'self'},
   {u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236',
    u'rel': u'bookmark'}],
  u'metadata': {},
  u'name': u'NM0978FR',
  u'progress': 100,
  u'rax-bandwidth:bandwidth': [],
  u'status': u'ACTIVE',
  u'tenant_id': u'728829',
  u'updated': u'2013-01-24T15:17:55Z',
  u'user_id': u'235799'}
Fun, huh?
Just One Server:
{u'OS-DCF:diskConfig': u'AUTO',
  u'OS-EXT-STS:power_state': 1,
  u'OS-EXT-STS:task_state': None,
  u'OS-EXT-STS:vm_state': u'active',
  u'accessIPv4': u'166.78.8.247',
  u'accessIPv6': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae',
  u'addresses': {u'private': [{u'addr': u'10.181.18.164', u'version': 4}],
   u'public': [{u'addr': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae',
     u'version': 6},
    {u'addr': u'166.78.8.247', u'version': 4}]},
  u'created': u'2013-01-24T15:13:23Z',
  u'flavor': {u'id': u'2',
   u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/flavors/2',
     u'rel': u'bookmark'}]},
  u'hostId': u'fcaa2858a7255b1bbba8cf5e3a1550f0f1bea780164a4412709e5d4d',
  u'id': u'19b394eb-17ce-4221-9989-824be1bd2236',
  u'image': {u'id': u'09a4e770-26f7-4377-8893-2b21a0b76ba8',
   u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/images/09a4e770-26f7-4377-8893-2b21a0b76ba8',
     u'rel': u'bookmark'}]},
  u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/v2/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236',
    u'rel': u'self'},
   {u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236',
    u'rel': u'bookmark'}],
  u'metadata': {},
  u'name': u'NM0978FR',
  u'progress': 100,
  u'rax-bandwidth:bandwidth': [],
  u'status': u'ACTIVE',
  u'tenant_id': u'728829',
  u'updated': u'2013-01-24T15:17:55Z',
  u'user_id': u'235799'}
So for each request:
• Retrieve authentication credentials from cache
    • Re-auth when no token, or when token expires
• Determine endpoint for selected region from service catalog
• Form URI from endpoint and API spec
• Add auth header to request
• Add "User-agent: xxx" header
• Add "Content-Type: application/json" header
• Add "Accept: application/json" header
• Transmit request
• Handle all errors
• Retry if possible
...and then

•Parse results
•Headers
•JSON body
•Extract list of resource data
•Return entity (or list of entities) with appropriate info
•Sometimes just a value; e.g.:
      cloud_dns.domain.export() => string
Wouldn't it be better
to work with Python
     objects?
The Resource Class
•Represents an individual cloud entities.
•E.g.: a server; a load balancer
•Has attributes that reflect all the information
about that entity.

•Has methods for interacting with that entity.
The Client Class

•Handles all I/O
•Calls from your app to pyrax
•Calls from pyrax to the API server
The Manager Class
•Configured with base URI for service
•Configured with Resource type for service
•Translates method calls to full URIs
•Interprets responses
 •Creates Resource instances as necessary
Architecture
              list()
Your                   Client          JSON         Cloud
App          objects               GET URI           API

                                                   URI
                 objects list() JSON
                                               method=GET
                                       determine

  Resource
                       Manager         method &
                                         URI
             parse
             JSON
Interacting with
            Resources
•Many calls to the client require a resource
reference; e.g.:
   cloud_blockstorage.create_snapshot(volume)

•Resources have a reference to their manager.
•If you have an instance of that resource, you can
call it directly on the resource; e.g.:
   volume.create_snapshot()
Q &A
Thanks!

Mais conteúdo relacionado

Mais procurados

fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
Wesley Beary
 
Oracle Database 11g R2 Installation
Oracle Database 11g R2 InstallationOracle Database 11g R2 Installation
Oracle Database 11g R2 Installation
Anar Godjaev
 

Mais procurados (20)

Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
Observability with Consul Connect
Observability with Consul ConnectObservability with Consul Connect
Observability with Consul Connect
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp Vault
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
 
Refactoring terraform
Refactoring terraformRefactoring terraform
Refactoring terraform
 
Top Node.js Metrics to Watch
Top Node.js Metrics to WatchTop Node.js Metrics to Watch
Top Node.js Metrics to Watch
 
Terraform 0.9 + good practices
Terraform 0.9 + good practicesTerraform 0.9 + good practices
Terraform 0.9 + good practices
 
Integrating Consul and Puppet
Integrating Consul and PuppetIntegrating Consul and Puppet
Integrating Consul and Puppet
 
Integrating Consul and Puppet
Integrating Consul and PuppetIntegrating Consul and Puppet
Integrating Consul and Puppet
 
Using ngx_lua in UPYUN 2
Using ngx_lua in UPYUN 2Using ngx_lua in UPYUN 2
Using ngx_lua in UPYUN 2
 
Node.js streaming csv downloads proxy
Node.js streaming csv downloads proxyNode.js streaming csv downloads proxy
Node.js streaming csv downloads proxy
 
How to create a multi tenancy for an interactive data analysis
How to create a multi tenancy for an interactive data analysisHow to create a multi tenancy for an interactive data analysis
How to create a multi tenancy for an interactive data analysis
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet Profiles
 
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECS
 
How to create a secured cloudera cluster
How to create a secured cloudera clusterHow to create a secured cloudera cluster
How to create a secured cloudera cluster
 
Oracle Database 11g R2 Installation
Oracle Database 11g R2 InstallationOracle Database 11g R2 Installation
Oracle Database 11g R2 Installation
 
Fixing Growing Pains With Puppet Data Patterns
Fixing Growing Pains With Puppet Data PatternsFixing Growing Pains With Puppet Data Patterns
Fixing Growing Pains With Puppet Data Patterns
 

Destaque

игра мульт
игра мультигра мульт
игра мульт
bukish
 
внимание анонс мероприятий
внимание анонс мероприятийвнимание анонс мероприятий
внимание анонс мероприятий
bukish
 
22 Campbell's soup
22 Campbell's soup22 Campbell's soup
22 Campbell's soup
Ramon Pujola
 
Aarogyacha Aarasa Bestseller On Health Assessment Dr. Shriniwas Kashalikar
Aarogyacha Aarasa Bestseller On Health Assessment Dr. Shriniwas KashalikarAarogyacha Aarasa Bestseller On Health Assessment Dr. Shriniwas Kashalikar
Aarogyacha Aarasa Bestseller On Health Assessment Dr. Shriniwas Kashalikar
Ameet Fadia
 
Печа Куча 3. Алматы. Тамара Кебурия. Динозавры сегодня дома.
Печа Куча 3. Алматы. Тамара Кебурия. Динозавры сегодня дома. Печа Куча 3. Алматы. Тамара Кебурия. Динозавры сегодня дома.
Печа Куча 3. Алматы. Тамара Кебурия. Динозавры сегодня дома.
Mikka Kakka
 
Presentatie
PresentatiePresentatie
Presentatie
Scholtes
 
Печа Куча 3. Алматы. Оля Веселова. Архитектура Фриденсрайха Хундертвассера
Печа Куча 3. Алматы. Оля Веселова. Архитектура Фриденсрайха ХундертвассераПеча Куча 3. Алматы. Оля Веселова. Архитектура Фриденсрайха Хундертвассера
Печа Куча 3. Алматы. Оля Веселова. Архитектура Фриденсрайха Хундертвассера
Mikka Kakka
 
Obrazovat standart matematika
Obrazovat standart matematikaObrazovat standart matematika
Obrazovat standart matematika
bukish
 

Destaque (20)

игра мульт
игра мультигра мульт
игра мульт
 
внимание анонс мероприятий
внимание анонс мероприятийвнимание анонс мероприятий
внимание анонс мероприятий
 
โบรชัวร์โปรโมชั่น Big c compact store รายปักษ์ 15/2554 วันที่ 29 กค.-12สค.54
โบรชัวร์โปรโมชั่น Big c compact store รายปักษ์ 15/2554 วันที่ 29 กค.-12สค.54โบรชัวร์โปรโมชั่น Big c compact store รายปักษ์ 15/2554 วันที่ 29 กค.-12สค.54
โบรชัวร์โปรโมชั่น Big c compact store รายปักษ์ 15/2554 วันที่ 29 กค.-12สค.54
 
201510211753
201510211753201510211753
201510211753
 
โบรชัวร์โปรโมชั่น Homeworks expo 2011
โบรชัวร์โปรโมชั่น Homeworks expo 2011โบรชัวร์โปรโมชั่น Homeworks expo 2011
โบรชัวร์โปรโมชั่น Homeworks expo 2011
 
Animals 1
Animals 1Animals 1
Animals 1
 
22 Campbell's soup
22 Campbell's soup22 Campbell's soup
22 Campbell's soup
 
Gravitatia Zero
Gravitatia ZeroGravitatia Zero
Gravitatia Zero
 
Aarogyacha Aarasa Bestseller On Health Assessment Dr. Shriniwas Kashalikar
Aarogyacha Aarasa Bestseller On Health Assessment Dr. Shriniwas KashalikarAarogyacha Aarasa Bestseller On Health Assessment Dr. Shriniwas Kashalikar
Aarogyacha Aarasa Bestseller On Health Assessment Dr. Shriniwas Kashalikar
 
Shadow Art
Shadow ArtShadow Art
Shadow Art
 
Apus De Soare
Apus De SoareApus De Soare
Apus De Soare
 
Mountains In Pictures
Mountains In PicturesMountains In Pictures
Mountains In Pictures
 
Печа Куча 3. Алматы. Тамара Кебурия. Динозавры сегодня дома.
Печа Куча 3. Алматы. Тамара Кебурия. Динозавры сегодня дома. Печа Куча 3. Алматы. Тамара Кебурия. Динозавры сегодня дома.
Печа Куча 3. Алматы. Тамара Кебурия. Динозавры сегодня дома.
 
Monografia correã§ã£o
Monografia correã§ã£oMonografia correã§ã£o
Monografia correã§ã£o
 
Transparencias
TransparenciasTransparencias
Transparencias
 
Russian Painters
Russian PaintersRussian Painters
Russian Painters
 
Presentatie
PresentatiePresentatie
Presentatie
 
Печа Куча 3. Алматы. Оля Веселова. Архитектура Фриденсрайха Хундертвассера
Печа Куча 3. Алматы. Оля Веселова. Архитектура Фриденсрайха ХундертвассераПеча Куча 3. Алматы. Оля Веселова. Архитектура Фриденсрайха Хундертвассера
Печа Куча 3. Алматы. Оля Веселова. Архитектура Фриденсрайха Хундертвассера
 
Pisicute 2
Pisicute   2Pisicute   2
Pisicute 2
 
Obrazovat standart matematika
Obrazovat standart matematikaObrazovat standart matematika
Obrazovat standart matematika
 

Semelhante a Pyrax talk

Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
Edward Capriolo
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
Ben Lin
 
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
崇之 清水
 

Semelhante a Pyrax talk (20)

Intro to fog and openstack jp
Intro to fog and openstack jpIntro to fog and openstack jp
Intro to fog and openstack jp
 
Service Discovery using etcd, Consul and Kubernetes
Service Discovery using etcd, Consul and KubernetesService Discovery using etcd, Consul and Kubernetes
Service Discovery using etcd, Consul and Kubernetes
 
Socket.IO
Socket.IOSocket.IO
Socket.IO
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
how to use openstack api
how to use openstack apihow to use openstack api
how to use openstack api
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
 
DJUGL - Django and AWS Lambda
DJUGL - Django and AWS LambdaDJUGL - Django and AWS Lambda
DJUGL - Django and AWS Lambda
 
Introduction to CloudStack API
Introduction to CloudStack APIIntroduction to CloudStack API
Introduction to CloudStack API
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
 
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
 
(Re)discover your AEM
(Re)discover your AEM(Re)discover your AEM
(Re)discover your AEM
 
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
 
Microservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerMicroservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-docker
 
Working with PowerVC via its REST APIs
Working with PowerVC via its REST APIsWorking with PowerVC via its REST APIs
Working with PowerVC via its REST APIs
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and code
 

Mais de Kamesh Pemmaraju

Docker and OpenStack Boston Meetup
Docker and OpenStack Boston MeetupDocker and OpenStack Boston Meetup
Docker and OpenStack Boston Meetup
Kamesh Pemmaraju
 
Software Defined Networking
Software Defined Networking Software Defined Networking
Software Defined Networking
Kamesh Pemmaraju
 

Mais de Kamesh Pemmaraju (20)

kamesh Videos
kamesh Videoskamesh Videos
kamesh Videos
 
OpenStack networking - Neutron deep dive with PLUMgrid
OpenStack networking - Neutron deep dive with PLUMgridOpenStack networking - Neutron deep dive with PLUMgrid
OpenStack networking - Neutron deep dive with PLUMgrid
 
Mirantis OpenStack and Cumulus Linux Webinar
Mirantis OpenStack and Cumulus Linux WebinarMirantis OpenStack and Cumulus Linux Webinar
Mirantis OpenStack and Cumulus Linux Webinar
 
Designing OpenStack Architectures
Designing OpenStack ArchitecturesDesigning OpenStack Architectures
Designing OpenStack Architectures
 
Open stack icehouse microsoftupdate
Open stack icehouse microsoftupdateOpen stack icehouse microsoftupdate
Open stack icehouse microsoftupdate
 
New Ceph capabilities and Reference Architectures
New Ceph capabilities and Reference ArchitecturesNew Ceph capabilities and Reference Architectures
New Ceph capabilities and Reference Architectures
 
OpenStack and Ceph case study at the University of Alabama
OpenStack and Ceph case study at the University of AlabamaOpenStack and Ceph case study at the University of Alabama
OpenStack and Ceph case study at the University of Alabama
 
High Availability for OpenStack
High Availability for OpenStackHigh Availability for OpenStack
High Availability for OpenStack
 
OpenStack 101 update
OpenStack 101 updateOpenStack 101 update
OpenStack 101 update
 
Dell openstack cloud with inktank ceph – large scale customer deployment
Dell openstack cloud with inktank ceph – large scale customer deploymentDell openstack cloud with inktank ceph – large scale customer deployment
Dell openstack cloud with inktank ceph – large scale customer deployment
 
Whats new in neutron for open stack havana
Whats new in neutron for open stack havanaWhats new in neutron for open stack havana
Whats new in neutron for open stack havana
 
Postgres Plus Cloud Database on OpenStack
Postgres Plus Cloud Database on OpenStackPostgres Plus Cloud Database on OpenStack
Postgres Plus Cloud Database on OpenStack
 
Massachusetts Open Cloud Initiative
Massachusetts Open Cloud InitiativeMassachusetts Open Cloud Initiative
Massachusetts Open Cloud Initiative
 
Dell SUSE Cloud Solution, Powered by OpenStack
Dell SUSE Cloud Solution, Powered by OpenStackDell SUSE Cloud Solution, Powered by OpenStack
Dell SUSE Cloud Solution, Powered by OpenStack
 
Docker and OpenStack Boston Meetup
Docker and OpenStack Boston MeetupDocker and OpenStack Boston Meetup
Docker and OpenStack Boston Meetup
 
Ceph and openstack at the boston meetup
Ceph and openstack at the boston meetupCeph and openstack at the boston meetup
Ceph and openstack at the boston meetup
 
Solving Business Challenges with OpenStack
Solving Business Challenges with OpenStackSolving Business Challenges with OpenStack
Solving Business Challenges with OpenStack
 
Openstack 101
Openstack 101Openstack 101
Openstack 101
 
Software Defined Networking
Software Defined Networking Software Defined Networking
Software Defined Networking
 
Open stack qa and tempest
Open stack qa and tempestOpen stack qa and tempest
Open stack qa and tempest
 

Pyrax talk

  • 1. Cloud APIs are great… but I want to use Python! Ed Leafe Rackspace Boston OpenStack Meetup 2012.02.13
  • 3. About •Developer for 20+ years •Rackspace for 5 years •Python developer since 2000 •OpenStack developer since the beginning •Swift (before OpenStack) •Nova •Keystone
  • 6. Jump right in! Let's get a list of our Cloud Servers: import urllib2 uri = "https://dfw.servers.api.rackspacecloud.com/" "v2/753591/servers/detail" resp = urllib2.urlopen(uri) print resp.read()
  • 7. Oh, yeah... HTTP Error 401: Unauthorized
  • 8. So let's handle auth uri = "http://identity.api.rackspacecloud.com/v2.0/tokens"credentials = {"auth": {"passwordCredentials": {"username": "joeuser", "password": "abc123def456"}}} req = urllib2.Request(uri,data=json.dumps(credentials)) req.add_header("Content-Type", "application/json") req.add_header("Accept", "application/json") try: raw_resp = urllib2.urlopen(req) except urllib2.HTTPError as e: errcode = e.getcode() if errcode == 401: # Invalid authorization print "Invalid credentials" else: print "Authentication Error: %s" % e return resp = json.load(raw_resp)
  • 9. Not done yet... token_info = resp.get("access").get("token") token = token_info.get("id") expires = token_info.get("expires") tenant_info = token_info.get("tenant") tenant_id = tenant_info.get("id")
  • 10. Still not finished... access = resp.get("access") svc_catalog = access.get("serviceCatalog") # Let's see what's in this print svc_catalog
  • 11. [{u'endpoints': [{u'publicURL': u'https://monitoring.api.rackspacecloud.com/v1.0/753591', u'tenantId': u'753591'}], u'name': u'cloudMonitoring', u'type': u'rax:monitor'}, {u'endpoints': [{u'publicURL': u'https://ord.loadbalancers.api.rackspacecloud.com/v1.0/753591', u'region': u'ORD', u'tenantId': u'753591'}, {u'publicURL': u'https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/753591', u'region': u'DFW', u'tenantId': u'753591'}], u'name': u'cloudLoadBalancers', u'type': u'rax:load-balancer'}, {u'endpoints': [{u'publicURL': u'https://servers.api.rackspacecloud.com/v1.0/753591', u'tenantId': u'753591', u'versionId': u'1.0', u'versionInfo': u'https://servers.api.rackspacecloud.com/v1.0', u'versionList': u'https://servers.api.rackspacecloud.com/'}], u'name': u'cloudServers', u'type': u'compute'}, {u'endpoints': [{u'publicURL': u'https://cdn1.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d', u'region': u'DFW', u'tenantId': u'MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d'}, {u'publicURL': u'https://cdn2.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d', u'region': u'ORD', u'tenantId': u'MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d'}], u'name': u'cloudFilesCDN', u'type': u'rax:object-cdn'}, {u'endpoints': [{u'publicURL': u'https://dfw.blockstorage.api.rackspacecloud.com/v1/753591', u'region': u'DFW', u'tenantId': u'753591'}, {u'publicURL': u'https://ord.blockstorage.api.rackspacecloud.com/v1/753591', u'region': u'ORD', u'tenantId': u'753591'}], u'name': u'cloudBlockStorage', u'type': u'volume'}, {u'endpoints': [{u'publicURL': u'https://dfw.databases.api.rackspacecloud.com/v1.0/753591', u'region': u'DFW', u'tenantId': u'753591'}, {u'publicURL': u'https://ord.databases.api.rackspacecloud.com/v1.0/753591', u'region': u'ORD', u'tenantId': u'753591'}], u'name': u'cloudDatabases', u'type': u'rax:database'}, {u'endpoints': [{u'publicURL': u'https://dfw.servers.api.rackspacecloud.com/v2/753591', u'region': u'DFW', u'tenantId': u'753591', u'versionId': u'2', u'versionInfo': u'https://dfw.servers.api.rackspacecloud.com/v2', u'versionList': u'https://dfw.servers.api.rackspacecloud.com/'}, {u'publicURL': u'https://ord.servers.api.rackspacecloud.com/v2/753591', u'region': u'ORD', u'tenantId': u'753591', u'versionId': u'2', u'versionInfo': u'https://ord.servers.api.rackspacecloud.com/v2', u'versionList': u'https://ord.servers.api.rackspacecloud.com/'}], u'name': u'cloudServersOpenStack', u'type': u'compute'}, {u'endpoints': [{u'internalURL': u'https://snet-storage101.dfw1.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d', u'publicURL': u'https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d', u'region': u'DFW', u'tenantId': u'MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d'}, {u'internalURL': u'https://snet-storage101.ord1.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d', u'publicURL': u'https://storage101.ord1.clouddrive.com/v1/MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d', u'region': u'ORD', u'tenantId': u'MossoCloudFS_844909d3-431e-4919-8211-beca1e850a5d'}], u'name': u'cloudFiles', u'type': u'object-store'}, {u'endpoints': [{u'publicURL': u'https://dns.api.rackspacecloud.com/v1.0/753591', u'tenantId': u'753591'}],
  • 13. The Service Catalog •Contains all of the available services and their endpoints. •For services that are region-specific, holds the endpoints for each region.
  • 14. Compute Service Catalog {u'endpoints': [{u'publicURL': u'https://dfw.servers.api. rackspacecloud.com/v2/753591', u'region': u'DFW', u'tenantId': u'753591', u'versionId': u'2', u'versionInfo': u'https://dfw.servers.api.rackspacecloud.com/v2', u'versionList': u'https://dfw.servers.api.rackspacecloud.com/'}, {u'publicURL': u'https://ord.servers.api.rackspacecloud.com/ v2/753591', u'region': u'ORD', u'tenantId': u'753591', u'versionId': u'2', u'versionInfo': u'https://ord.servers.api.rackspacecloud.com/v2', u'versionList': u'https://ord.servers.api.rackspacecloud.com/'}], u'name': u'cloudServersOpenStack', u'type': u'compute'}
  • 15. Compute Service Catalog {u'endpoints': [{u'publicURL': u'https://dfw.servers.api. rackspacecloud.com/v2/753591', u'region': u'DFW', u'tenantId': u'753591', u'versionId': u'2', u'versionInfo': u'https://dfw.servers.api.rackspacecloud.com/v2', u'versionList': u'https://dfw.servers.api.rackspacecloud.com/'}, {u'publicURL': u'https://ord.servers.api.rackspacecloud.com/ v2/753591', u'region': u'ORD', u'tenantId': u'753591', u'versionId': u'2', u'versionInfo': u'https://ord.servers.api.rackspacecloud.com/v2', u'versionList': u'https://ord.servers.api.rackspacecloud.com/'}], u'name': u'cloudServersOpenStack', u'type': u'compute'}
  • 16. Compute Service Catalog {u'endpoints': [{u'publicURL': u'https://dfw.servers.api. rackspacecloud.com/v2/753591', u'region': u'DFW', u'tenantId': u'753591', u'versionId': u'2', u'versionInfo': u'https://dfw.servers.api.rackspacecloud.com/v2', u'versionList': u'https://dfw.servers.api.rackspacecloud.com/'}, {u'publicURL': u'https://ord.servers.api.rackspacecloud.com/ v2/753591', u'region': u'ORD', u'tenantId': u'753591', u'versionId': u'2', u'versionInfo': u'https://ord.servers.api.rackspacecloud.com/v2', u'versionList': u'https://ord.servers.api.rackspacecloud.com/'}], u'name': u'cloudServersOpenStack', u'type': u'compute'}
  • 17. Find URI by Region access = resp["access"] svc_cat = access["serviceCatalog"] compute_svc = svc_cat["compute"] eps = compute_svc["endpoints"] reg_ep = [ep for ep in eps if ep["region"] == region][0] base_uri = reg_ep["public_url"] list_uri = "%s/servers/detail" % base_uri
  • 18. Create the Request import urllib2 req = urllib2.Request(list_uri)
  • 19. Add the Auth Headers req.add_header("X-Auth-Token", token) req.add_header("X-Auth-Project-Id", tenant_id)
  • 20. Add the HTTP Headers req.add_header("Accept", "application/json") req.add_header("Content-Type", "application/json") req.add_header("User-Agent", "myapp/1.1")
  • 21. Make the Request raw_resp = urllib2.urlopen(req) resp = json.load(raw_resp) print resp
  • 22. {u'servers': [{u'OS-DCF:diskConfig': u'AUTO', u'OS-EXT-STS:power_state': 1, u'OS-EXT-STS:task_state': None, u'OS-EXT-STS:vm_state': u'active', Result: u'accessIPv4': u'166.78.8.247', u'accessIPv6': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae', u'addresses': {u'private': [{u'addr': u'10.181.18.164', u'version': 4}], u'public': [{u'addr': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae', u'version': 6}, {u'addr': u'166.78.8.247', u'version': 4}]}, u'created': u'2013-01-24T15:13:23Z', u'flavor': {u'id': u'2', u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/flavors/2', u'rel': u'bookmark'}]}, u'hostId': u'fcaa2858a7255b1bbba8cf5e3a1550f0f1bea780164a4412709e5d4d', u'id': u'19b394eb-17ce-4221-9989-824be1bd2236', u'image': {u'id': u'09a4e770-26f7-4377-8893-2b21a0b76ba8', u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/images/09a4e770-26f7-4377-8893-2b21a0b76ba8', u'rel': u'bookmark'}]}, u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/v2/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236', u'rel': u'self'}, {u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236', u'rel': u'bookmark'}], u'metadata': {}, u'name': u'NM0978FR', u'progress': 100, u'rax-bandwidth:bandwidth': [], u'status': u'ACTIVE', u'tenant_id': u'728829', u'updated': u'2013-01-24T15:17:55Z', u'user_id': u'235799'}, {u'OS-DCF:diskConfig': u'AUTO', u'OS-EXT-STS:power_state': 1, u'OS-EXT-STS:task_state': None, u'OS-EXT-STS:vm_state': u'active', u'accessIPv4': u'198.61.217.238', u'accessIPv6': u'2001:4800:780e:0510:8ca7:b42c:ff04:a78e', u'addresses': {u'private': [{u'addr': u'10.180.24.4', u'version': 4}], u'public': [{u'addr': u'2001:4800:780e:0510:8ca7:b42c:ff04:a78e', u'version': 6}, {u'addr': u'198.61.217.238', u'version': 4}]}, u'created': u'2012-12-03T17:23:16Z', u'flavor': {u'id': u'2', u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/flavors/2', u'rel': u'bookmark'}]}, u'hostId': u'ec8d624af62a9cb511daba3c106d27142b3cff0eaf3aa61cda89f1fa', u'id': u'5e16de51-724c-4885-8849-65719bb455fd', u'image': {u'id': u'5cebb13a-f783-4f8c-8058-c4182c724ccd', u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/images/5cebb13a-f783-4f8c-8058-c4182c724ccd', u'rel': u'bookmark'}]}, u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/v2/728829/servers/5e16de51-724c-4885-8849-65719bb455fd', u'rel': u'self'}, {u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/servers/5e16de51-724c-4885-8849-65719bb455fd', u'rel': u'bookmark'}], u'metadata': {}, u'name': u'BmwIqtGb', u'progress': 100, u'rax-bandwidth:bandwidth': [], u'status': u'ACTIVE', u'tenant_id': u'728829', u'updated': u'2013-01-19T16:47:03Z', u'user_id': u'235799'}]}
  • 23. That's just for 2 servers!
  • 24. Just One Server: {u'OS-DCF:diskConfig': u'AUTO', u'OS-EXT-STS:power_state': 1, u'OS-EXT-STS:task_state': None, u'OS-EXT-STS:vm_state': u'active', u'accessIPv4': u'166.78.8.247', u'accessIPv6': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae', u'addresses': {u'private': [{u'addr': u'10.181.18.164', u'version': 4}], u'public': [{u'addr': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae', u'version': 6}, {u'addr': u'166.78.8.247', u'version': 4}]}, u'created': u'2013-01-24T15:13:23Z', u'flavor': {u'id': u'2', u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/flavors/2', u'rel': u'bookmark'}]}, u'hostId': u'fcaa2858a7255b1bbba8cf5e3a1550f0f1bea780164a4412709e5d4d', u'id': u'19b394eb-17ce-4221-9989-824be1bd2236', u'image': {u'id': u'09a4e770-26f7-4377-8893-2b21a0b76ba8', u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/images/09a4e770-26f7-4377-8893-2b21a0b76ba8', u'rel': u'bookmark'}]}, u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/v2/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236', u'rel': u'self'}, {u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236', u'rel': u'bookmark'}], u'metadata': {}, u'name': u'NM0978FR', u'progress': 100, u'rax-bandwidth:bandwidth': [], u'status': u'ACTIVE', u'tenant_id': u'728829', u'updated': u'2013-01-24T15:17:55Z', u'user_id': u'235799'}
  • 26. Just One Server: {u'OS-DCF:diskConfig': u'AUTO', u'OS-EXT-STS:power_state': 1, u'OS-EXT-STS:task_state': None, u'OS-EXT-STS:vm_state': u'active', u'accessIPv4': u'166.78.8.247', u'accessIPv6': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae', u'addresses': {u'private': [{u'addr': u'10.181.18.164', u'version': 4}], u'public': [{u'addr': u'2001:4800:7810:0512:8ca7:b42c:ff04:b4ae', u'version': 6}, {u'addr': u'166.78.8.247', u'version': 4}]}, u'created': u'2013-01-24T15:13:23Z', u'flavor': {u'id': u'2', u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/flavors/2', u'rel': u'bookmark'}]}, u'hostId': u'fcaa2858a7255b1bbba8cf5e3a1550f0f1bea780164a4412709e5d4d', u'id': u'19b394eb-17ce-4221-9989-824be1bd2236', u'image': {u'id': u'09a4e770-26f7-4377-8893-2b21a0b76ba8', u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/images/09a4e770-26f7-4377-8893-2b21a0b76ba8', u'rel': u'bookmark'}]}, u'links': [{u'href': u'https://dfw.servers.api.rackspacecloud.com/v2/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236', u'rel': u'self'}, {u'href': u'https://dfw.servers.api.rackspacecloud.com/728829/servers/19b394eb-17ce-4221-9989-824be1bd2236', u'rel': u'bookmark'}], u'metadata': {}, u'name': u'NM0978FR', u'progress': 100, u'rax-bandwidth:bandwidth': [], u'status': u'ACTIVE', u'tenant_id': u'728829', u'updated': u'2013-01-24T15:17:55Z', u'user_id': u'235799'}
  • 27. So for each request: • Retrieve authentication credentials from cache • Re-auth when no token, or when token expires • Determine endpoint for selected region from service catalog • Form URI from endpoint and API spec • Add auth header to request • Add "User-agent: xxx" header • Add "Content-Type: application/json" header • Add "Accept: application/json" header • Transmit request • Handle all errors • Retry if possible
  • 28. ...and then •Parse results •Headers •JSON body •Extract list of resource data •Return entity (or list of entities) with appropriate info •Sometimes just a value; e.g.: cloud_dns.domain.export() => string
  • 29. Wouldn't it be better to work with Python objects?
  • 30. The Resource Class •Represents an individual cloud entities. •E.g.: a server; a load balancer •Has attributes that reflect all the information about that entity. •Has methods for interacting with that entity.
  • 31. The Client Class •Handles all I/O •Calls from your app to pyrax •Calls from pyrax to the API server
  • 32. The Manager Class •Configured with base URI for service •Configured with Resource type for service •Translates method calls to full URIs •Interprets responses •Creates Resource instances as necessary
  • 33. Architecture list() Your Client JSON Cloud App objects GET URI API URI objects list() JSON method=GET determine Resource Manager method & URI parse JSON
  • 34. Interacting with Resources •Many calls to the client require a resource reference; e.g.: cloud_blockstorage.create_snapshot(volume) •Resources have a reference to their manager. •If you have an instance of that resource, you can call it directly on the resource; e.g.: volume.create_snapshot()
  • 35. Q &A

Notas do Editor

  1. Ask who is an a) OpenStack contributor, b) OpenStack deployment/devops, or c) Just interested