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

      

  • 相关阅读:
    【推荐】英国金融时报推荐的数据可视化图表分类图
    华为方舟编译器开源官网正式上线
    PyTorch官方教程中文版
    《一张图看懂华为云BigData Pro鲲鹏大数据解决方案》
    区块链学习笔记:DAY05 如何使用公有云区块链服务
    python一行写不下,变多行
    python 多窗口编辑
    ant的设置properties
    java的输出类
    python的IndentationError: unexpected indent python
  • 原文地址:https://www.cnblogs.com/schangech/p/5736925.html
Copyright © 2011-2022 走看看