zoukankan      html  css  js  c++  java
  • Openstack API Cinder

    http://developer.openstack.org/api-ref-blockstorage-v2.html

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    
    import base64
    import urllib, urllib2
    from urllib2 import URLError 
    import requests
    import httplib
    import os
    from urlparse import urlparse
    try:
        import json
    except Exception:
        import simplejson as json
    from auth.Token import AuthToken
    
    tokenID = AuthToken().auth()
    
    #print tokenID
    
    
    class Cinder():
        
        def __init__(self):
            #self.url = "172.16.200.105:8776"
            self.url = "http://172.16.200.105:8776"
            self.header = {"X-Auth-Token": tokenID, "Content-Type": 'application/json'} 
            #self.header = {"X-Auth-Token": tokenID}
            
        def getAllVolumes(self, tenantID):
            #payload = {'key1': 'value1', 'key2': 'value2'}
            req = requests.get(self.url+"/v2/%s/volumes" % tenantID, headers=self.header)
            #print req.headers
            #return req.content
            return req.status_code
            '''
            params = urllib.urlencode({})
            print params
            conn = httplib.HTTPConnection(self.url)
            #conn.request("GET", '/v2/​%s/volumes' % tenantId, params, self.header)
            conn.request("GET", '/v2/​462dc687079d46bb9fb1f14e61b84002/volumes', params, self.header)
            response = conn.getresponse()
            data = response.read()
            res = json.loads(data)
            conn.close()
            return res
            '''
            
        
        def getAllVolumesDetail(self, tenantID):
            req = requests.get(self.url+"/v2/%s/volumes/detail" % tenantID, headers=self.header)
            #print req.url
            #print req.headers
            return req.content
            '''
            params = urllib.urlencode({})
            conn = httplib.HTTPConnection(self.url)
            conn.request("GET", '/v2/​%s​/volumes/detail' % volumesId, params, self.header)
            response = conn.getresponse()
            statusCode = response.status
            data = response.read()
            res = json.loads(data)
            conn.close()
            return statusCode, res
            '''
       
        def showVolumeDetails(self, tenantID, volumeID):
            req = requests.get(self.url+"/v2/%s/volumes/%s" % (tenantID, volumeID), headers=self.header)
            #print req.url
            #print req.headers
            return req.content
    
    
    
    def main():
        CinderStorage = Cinder()
        tenantID = "462dc687079d46bb9fb1f14e61b84002"
        #print json.dumps(Cinder.getAllVolumes(tenantID))
        #volumeID = "300f6442-163a-41e1-97f6-df2f836c33ef"
        #print json.dumps(Cinder.getAllVolumesDetail(tenantID))
        #print json.dumps(Cinder.showVolumeDetails(tenantID, volumeID))
        code = 0
        if CinderStorage.getAllVolumes(tenantID) != 200:
            code = 1
        print code
            
        #print json.dumps(GlanceImage.getAllImages())
        #print json.dumps(Cinder.getAllVolumesDetail(tenantID))
        #print json.dumps(Cinder.showVolumeDetails(tenantID, volumeID))
    
    if __name__ == "__main__":
        main()
    

      

  • 相关阅读:
    vue 父子组件传参
    vue中引入swiper(vue中的滑块组件vue-awesome-swiper)
    border-radius值的解析
    chrome开发工具指南(十四)
    chrome开发工具指南(十三)
    Python动态强类型解释型语言
    go基础 01
    代码发布 04
    代码发布03
    代码发布02
  • 原文地址:https://www.cnblogs.com/schangech/p/5736925.html
Copyright © 2011-2022 走看看