upd
This commit is contained in:
parent
e8436e6540
commit
8d19d38a53
26
main.py
26
main.py
|
@ -1,9 +1,25 @@
|
|||
import ng_openstack.auth
|
||||
import ng_openstack.keystone
|
||||
import os
|
||||
import json
|
||||
|
||||
token = ng_openstack.auth.getToken(os.getenv("OS_USERNAME"), os.getenv("OS_PASSWORD"),
|
||||
os.getenv("OS_USER_DOMAIN_NAME"), os.getenv("OS_USER_DOMAIN_NAME"),
|
||||
os.getenv("OS_PROJECT_ID"))
|
||||
print(token)
|
||||
print (ng_openstack.keystone.getCatalog())
|
||||
|
||||
import ng_openstack
|
||||
|
||||
x=ng_openstack.OpenstackConnection("Fido",10)
|
||||
print (x.keystone.getAllProjects())
|
||||
|
||||
|
||||
# token = ng_openstack.auth.getToken(os.getenv("OS_USERNAME"), os.getenv("OS_PASSWORD"),
|
||||
# os.getenv("OS_USER_DOMAIN_NAME"), os.getenv("OS_USER_DOMAIN_NAME"),
|
||||
# os.getenv("OS_PROJECT_ID"))
|
||||
# print(token)
|
||||
|
||||
# # print(json.dumps(ng_openstack.keystone.getAllProjects(), indent=4))
|
||||
# cat=ng_openstack.keystone.getCatalog()
|
||||
|
||||
|
||||
# print (ng_openstack.keystone.getServicebyID("11f21a87fdaa4f5d9bd93c7396bdd93c"))
|
||||
|
||||
# # openstack=newOpenstack.connect()
|
||||
# # projects=openstack.projects.getAll()
|
|
@ -0,0 +1,59 @@
|
|||
import imp
|
||||
from ng_openstack.auth import Openstack_Auth
|
||||
from ng_openstack.openstackRequest import Openstack_Request
|
||||
from ng_openstack.keystone import Openstack_Keystone
|
||||
|
||||
class OpenstackConnection():
|
||||
auth=Openstack_Auth
|
||||
requestor=Openstack_Request()
|
||||
keystone=Openstack_Keystone(requestor)
|
||||
|
||||
|
||||
def __init__(self, name, age):
|
||||
self.name = name
|
||||
self.age = age
|
||||
self.speed = 0
|
||||
self.moving = False
|
||||
|
||||
@property
|
||||
def human_age(self):
|
||||
return self.age * 7
|
||||
|
||||
@human_age.setter
|
||||
def human_age(self, value):
|
||||
self.age = value / 7
|
||||
|
||||
def __str__(self):
|
||||
return '{} is {} years old'.format(
|
||||
self.name, self.age
|
||||
)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.name == other.name and self.age == other.age
|
||||
|
||||
def make_sound(self):
|
||||
print(self.SOUND)
|
||||
|
||||
def bark(self):
|
||||
self.make_sound()
|
||||
|
||||
def walk(self, speed, distance):
|
||||
self._set_speed(speed)
|
||||
self._move(distance)
|
||||
|
||||
@classmethod
|
||||
def can_woof(cls, animal):
|
||||
return animal.SOUND == cls.SOUND
|
||||
|
||||
@staticmethod
|
||||
def is_dog(animal):
|
||||
return animal.can_woof()
|
||||
|
||||
def _set_speed(self, speed):
|
||||
self.speed = speed
|
||||
|
||||
def _move(self, distance):
|
||||
self.moving = True
|
||||
for _ in range(distance):
|
||||
print('.', end='')
|
||||
print('')
|
|
@ -1,14 +1,16 @@
|
|||
import os
|
||||
import exceptions
|
||||
import requests
|
||||
import json
|
||||
import redis
|
||||
import ng_openstack.settings as settings
|
||||
class Openstack_Auth:
|
||||
|
||||
import os
|
||||
import exceptions
|
||||
import requests
|
||||
import json
|
||||
import redis
|
||||
import ng_openstack.settings as settings
|
||||
|
||||
|
||||
appDebug = True
|
||||
appDebug = True
|
||||
|
||||
def getToken(username, password, authDomain, scopeDomain, scopeProject):
|
||||
def getToken(username, password, authDomain, scopeDomain, scopeProject):
|
||||
|
||||
try:
|
||||
return lookupTokenFromRedis(username, authDomain, scopeDomain, scopeProject)
|
||||
|
@ -58,8 +60,7 @@ def getToken(username, password, authDomain, scopeDomain, scopeProject):
|
|||
else:
|
||||
raise ValueError("Error in token response to token request:"+response.text)
|
||||
|
||||
|
||||
def lookupTokenFromRedis(username, authDomain, scopeDomain, scopeProject):
|
||||
def lookupTokenFromRedis(username, authDomain, scopeDomain, scopeProject):
|
||||
|
||||
REDIS=redis.Redis()
|
||||
|
||||
|
@ -78,7 +79,7 @@ def lookupTokenFromRedis(username, authDomain, scopeDomain, scopeProject):
|
|||
except:
|
||||
raise exceptions.ItemNotFoundError("OpenstackToken not found in redis")
|
||||
|
||||
def saveTokenToRedis(username, authDomain, scopeDomain, scopeProject,token):
|
||||
def saveTokenToRedis(username, authDomain, scopeDomain, scopeProject,token):
|
||||
|
||||
REDIS=redis.Redis()
|
||||
|
||||
|
|
|
@ -1,15 +1,38 @@
|
|||
import imp
|
||||
import json
|
||||
import ng_openstack.openstackRequest
|
||||
import ng_openstack.settings
|
||||
import os
|
||||
|
||||
def getAllProjects():
|
||||
projectData=ng_openstack.openstackRequest.openstackRequest("GET", "v3/projects", "",
|
||||
"http://172.25.110.138:5000").json()
|
||||
return projectData
|
||||
class Openstack_Keystone():
|
||||
def __init__(self, requestor):
|
||||
self.serviceData={}
|
||||
self.catalogData={}
|
||||
self.projectData={}
|
||||
self.requestor=requestor
|
||||
|
||||
|
||||
|
||||
def getCatalog():
|
||||
catalogData=ng_openstack.openstackRequest.openstackRequest("GET", "v3/endpoints", "",
|
||||
def getAllProjects(_self):
|
||||
_self.projectData=_self.requestor.make_request("GET", "projects", "",
|
||||
os.getenv("OS_AUTH_URL")).json()
|
||||
return catalogData
|
||||
return _self.projectData
|
||||
|
||||
|
||||
|
||||
def getCatalog():
|
||||
catalogData=json.dumps(ng_openstack.openstackRequest.openstackRequest("GET", "endpoints", "",
|
||||
os.getenv("OS_AUTH_URL")).json())
|
||||
|
||||
serviceData=json.dumps(ng_openstack.openstackRequest.openstackRequest("GET", "services", "",
|
||||
os.getenv("OS_AUTH_URL")).json())
|
||||
print(serviceData)
|
||||
|
||||
return serviceData
|
||||
|
||||
|
||||
def getServicebyID(id):
|
||||
print(serviceData)
|
||||
# for _service in service_Data['services']:
|
||||
# if _service['id']==id:
|
||||
# return(_service)
|
|
@ -1,13 +1,13 @@
|
|||
import requests
|
||||
import json
|
||||
import ng_openstack.auth
|
||||
import settings,os
|
||||
|
||||
def openstackRequest(getPost, url, data, apiEndpoint, scopedProjectID=""):
|
||||
import os
|
||||
class Openstack_Request:
|
||||
def make_request(_self, getPost, url, data, apiEndpoint, scopedProjectID=""):
|
||||
|
||||
# Default the scope project to the value set in .env.example, allow the user to override if required(EG creating backups)
|
||||
if scopedProjectID== "":
|
||||
scopedProjectID=os.getenv("SNGD_OPENSTACK_SCOPEPROJECTID")
|
||||
scopedProjectID=os.getenv("OS_PROJECT_ID")
|
||||
else:
|
||||
scopedProjectID=scopedProjectID
|
||||
|
||||
|
@ -22,7 +22,7 @@ def openstackRequest(getPost, url, data, apiEndpoint, scopedProjectID=""):
|
|||
headers = {'Content-type': 'application/json', 'X-Auth-Token': token}
|
||||
|
||||
url = apiEndpoint + "/" + url
|
||||
# print (url)
|
||||
print (url)
|
||||
# print(data_json)
|
||||
if getPost=="GET":
|
||||
response = requests.get(url, headers=headers)
|
||||
|
|
Loading…
Reference in New Issue