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()
    

      

  • 相关阅读:
    Mybatis之批量更新操作
    Spring Quartz *.QRTZ_LOCKS' doesn't exist
    分析NTFS文件系统得到特定文件的内容
    设计模式笔记——设计模式原则总结
    android自己定义ViewPager之——3D效果应用
    Android混淆代码
    百度地图 Android SDK
    NYOJ17,单调递增最长子序列
    令人纠结的两行代码
    XCode中在提示窗体中对已弃用的API接口画上红线
  • 原文地址:https://www.cnblogs.com/schangech/p/5736925.html
Copyright © 2011-2022 走看看