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

      

  • 相关阅读:
    防窜货下加密锁使用常见问题
    SQL Server 2000/2005/2008 触发器的管理和查看
    列表显示时,部分凭证会分两行显示,且不能删除
    JDBC 连接 带实例名的SQL Server
    登录软件提示:读取数据源出现错误,pkcs7填充无效,无法被移除
    完美卸载SQL Server 2008的方案
    彻底卸载(删除)SQL server2000
    NCV5取消:授权数到达,或者许可证过期提示的秘诀
    SQL Server日志清空方法 .
    第二天 一列布局
  • 原文地址:https://www.cnblogs.com/schangech/p/5736925.html
Copyright © 2011-2022 走看看