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.auth
|
||||||
import ng_openstack.keystone
|
import ng_openstack.keystone
|
||||||
import os
|
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"),
|
import ng_openstack
|
||||||
os.getenv("OS_PROJECT_ID"))
|
|
||||||
print(token)
|
x=ng_openstack.OpenstackConnection("Fido",10)
|
||||||
print (ng_openstack.keystone.getCatalog())
|
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,3 +1,5 @@
|
||||||
|
class Openstack_Auth:
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import exceptions
|
import exceptions
|
||||||
import requests
|
import requests
|
||||||
|
@ -58,7 +60,6 @@ def getToken(username, password, authDomain, scopeDomain, scopeProject):
|
||||||
else:
|
else:
|
||||||
raise ValueError("Error in token response to token request:"+response.text)
|
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()
|
REDIS=redis.Redis()
|
||||||
|
|
|
@ -1,15 +1,38 @@
|
||||||
|
import imp
|
||||||
import json
|
import json
|
||||||
import ng_openstack.openstackRequest
|
import ng_openstack.openstackRequest
|
||||||
|
import ng_openstack.settings
|
||||||
|
import os
|
||||||
|
|
||||||
def getAllProjects():
|
class Openstack_Keystone():
|
||||||
projectData=ng_openstack.openstackRequest.openstackRequest("GET", "v3/projects", "",
|
def __init__(self, requestor):
|
||||||
"http://172.25.110.138:5000").json()
|
self.serviceData={}
|
||||||
return projectData
|
self.catalogData={}
|
||||||
|
self.projectData={}
|
||||||
|
self.requestor=requestor
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getAllProjects(_self):
|
||||||
|
_self.projectData=_self.requestor.make_request("GET", "projects", "",
|
||||||
|
os.getenv("OS_AUTH_URL")).json()
|
||||||
|
return _self.projectData
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getCatalog():
|
def getCatalog():
|
||||||
catalogData=ng_openstack.openstackRequest.openstackRequest("GET", "v3/endpoints", "",
|
catalogData=json.dumps(ng_openstack.openstackRequest.openstackRequest("GET", "endpoints", "",
|
||||||
os.getenv("OS_AUTH_URL")).json()
|
os.getenv("OS_AUTH_URL")).json())
|
||||||
return catalogData
|
|
||||||
|
|
||||||
|
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 requests
|
||||||
import json
|
import json
|
||||||
import ng_openstack.auth
|
import ng_openstack.auth
|
||||||
import settings,os
|
import os
|
||||||
|
class Openstack_Request:
|
||||||
def openstackRequest(getPost, url, data, apiEndpoint, scopedProjectID=""):
|
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)
|
# Default the scope project to the value set in .env.example, allow the user to override if required(EG creating backups)
|
||||||
if scopedProjectID== "":
|
if scopedProjectID== "":
|
||||||
scopedProjectID=os.getenv("SNGD_OPENSTACK_SCOPEPROJECTID")
|
scopedProjectID=os.getenv("OS_PROJECT_ID")
|
||||||
else:
|
else:
|
||||||
scopedProjectID=scopedProjectID
|
scopedProjectID=scopedProjectID
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ def openstackRequest(getPost, url, data, apiEndpoint, scopedProjectID=""):
|
||||||
headers = {'Content-type': 'application/json', 'X-Auth-Token': token}
|
headers = {'Content-type': 'application/json', 'X-Auth-Token': token}
|
||||||
|
|
||||||
url = apiEndpoint + "/" + url
|
url = apiEndpoint + "/" + url
|
||||||
# print (url)
|
print (url)
|
||||||
# print(data_json)
|
# print(data_json)
|
||||||
if getPost=="GET":
|
if getPost=="GET":
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
|
|
Loading…
Reference in New Issue