Now creating a project or getting the existing one
This commit is contained in:
parent
c3ca5939b4
commit
5101d81bf7
8
.env
8
.env
|
@ -1,9 +1,11 @@
|
|||
OS_USERNAME=admin
|
||||
OS_PASSWORD=nVgmvBePxqPSxVkN7RwNKDJG
|
||||
OS_PROJECT_NAME=admin
|
||||
OS_PROJECT_ID=8374bf1367ae40fdaf39f836b71d6bdb
|
||||
OS_PROJECT_ID=8f526efe5899415f8cede048c5594aa4
|
||||
OS_USER_DOMAIN_NAME=Default
|
||||
OS_PROJECT_DOMAIN_NAME=Default
|
||||
OS_AUTH_URL=http://192.168.50.75:5000/v3
|
||||
OS_AUTH_URL=https://api.nexgencloud.com:5000/v3
|
||||
OS_IDENTITY_API_VERSION=3
|
||||
OS_INTERFACE=internal
|
||||
OS_INTERFACE=public
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
|
@ -0,0 +1,12 @@
|
|||
.*egg-info.*
|
||||
build*
|
||||
dist*
|
||||
.*python_netflow_v9_softflowd.egg-info/
|
||||
*.swp
|
||||
*.swo
|
||||
__pycache__
|
||||
*.json
|
||||
venv
|
||||
.idea
|
||||
.env
|
||||
/lib/
|
41
main.py
41
main.py
|
@ -1,13 +1,48 @@
|
|||
import os, sys
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), "lib"))
|
||||
from myOpenstackApp.logger import log
|
||||
|
||||
|
||||
import myOpenstackApp
|
||||
|
||||
testProjectName="SmokeTest"
|
||||
testProjectExists=False
|
||||
testProject=""
|
||||
|
||||
y=myOpenstackApp.OSC
|
||||
y.initalise()
|
||||
# y.ks.getCatalog()
|
||||
print(y.something())
|
||||
# print(y.something())
|
||||
# print(y._keystone)
|
||||
|
||||
print("Starting")
|
||||
log.info("Starting")
|
||||
|
||||
allProjects=y.ks.getAllProjects()
|
||||
|
||||
|
||||
#Does my test project ID already exist?
|
||||
for _project in allProjects['projects']:
|
||||
if _project['name']==testProjectName:
|
||||
testProject=_project
|
||||
testProjectExists=True
|
||||
|
||||
|
||||
|
||||
if testProjectExists:
|
||||
log.error("Project already exists")
|
||||
log.info(testProject['id'])
|
||||
|
||||
else:
|
||||
# Create test project
|
||||
log.info("{} project does not exist, creating".format(testProjectName))
|
||||
testProject=y.ks.createProject(testProjectName,"Description goes here")['project']
|
||||
log.info(testProject['id'])
|
||||
|
||||
|
||||
|
||||
|
||||
def cleanUp():
|
||||
#Delete VM
|
||||
#Delete router
|
||||
#Delete Network
|
||||
#Delete project
|
||||
pass
|
|
@ -13,6 +13,8 @@ class OpenStackConnection_x:
|
|||
|
||||
catalogData=""
|
||||
novaURL=""
|
||||
interface=""
|
||||
token=""
|
||||
|
||||
"""
|
||||
It's important not to initalise any of the submodules during the init cycle becuase thic causes cirtucalr import loops
|
||||
|
@ -22,11 +24,13 @@ class OpenStackConnection_x:
|
|||
pass
|
||||
|
||||
def initalise(self) -> None:
|
||||
log.info("Initalising connection")
|
||||
from myOpenstackApp.keystone import myopenstack_keystone
|
||||
from myOpenstackApp.nova import myopenstack_nova
|
||||
|
||||
self.ks=myopenstack_keystone(self)
|
||||
self.nova=myopenstack_nova(self)
|
||||
self.interface=os.getenv("OS_INTERFACE")
|
||||
|
||||
|
||||
pass
|
||||
|
@ -34,7 +38,7 @@ class OpenStackConnection_x:
|
|||
def something(_self):
|
||||
print(1)
|
||||
_self.ks.getCatalog()
|
||||
print(_self.nova.getAllServers(os.getenv("OS_PROJECT_ID")))
|
||||
print(_self.nova.getAllServers(os.getenv("OS_PROJECT_ID"),True))
|
||||
|
||||
|
||||
def make_request(_self, getPost, url, data, apiEndpoint, scopedProjectID=""):
|
||||
|
@ -74,7 +78,7 @@ class OpenStackConnection_x:
|
|||
def getToken(_self,username, password, authDomain, scopeDomain, scopeProject):
|
||||
|
||||
try:
|
||||
return _self.lookupTokenFromRedis(username, authDomain, scopeDomain, scopeProject)
|
||||
return _self.lookupToken(username, authDomain, scopeDomain, scopeProject)
|
||||
except exceptions.ItemNotFoundError:
|
||||
|
||||
url = os.getenv("OS_AUTH_URL") + '/auth/tokens'
|
||||
|
@ -114,16 +118,19 @@ class OpenStackConnection_x:
|
|||
|
||||
if response.status_code == 201:
|
||||
try:
|
||||
_self.saveTokenToRedis( username, authDomain, scopeDomain, scopeProject, response.headers['X-Subject-Token'])
|
||||
_self.saveToken( username, authDomain, scopeDomain, scopeProject, response.headers['X-Subject-Token'])
|
||||
except exceptions.ItemNotSavedError:
|
||||
log.warn("Error saving token to redis..meh")
|
||||
return response.headers['X-Subject-Token']
|
||||
else:
|
||||
raise ValueError("Error in token response to token request:"+response.text)
|
||||
|
||||
def lookupTokenFromRedis(_self, username, authDomain, scopeDomain, scopeProject):
|
||||
def lookupToken(_self, username, authDomain, scopeDomain, scopeProject):
|
||||
if _self.token!="":
|
||||
return _self.token
|
||||
raise exceptions.ItemNotFoundError("OpenstackToken not found in redis")
|
||||
|
||||
def saveTokenToRedis(_self, username, authDomain, scopeDomain, scopeProject,token):
|
||||
raise exceptions.ItemNotSavedError("OpenstackToken not saved in redis")
|
||||
def saveToken(_self, username, authDomain, scopeDomain, scopeProject,token):
|
||||
_self.token=token
|
||||
#raise exceptions.ItemNotSavedError("OpenstackToken not saved in redis")
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -7,11 +7,11 @@ import myOpenstackApp.OpenStackConnection
|
|||
|
||||
|
||||
class myopenstack_keystone():
|
||||
def __init__(self, connection):
|
||||
def __init__(self,conn: myOpenstackApp.OpenStackConnection.OpenStackConnection_x ) -> None:
|
||||
self.serviceData={}
|
||||
self.catalogData={}
|
||||
self.projectData={}
|
||||
self.connection=connection
|
||||
self.connection=conn
|
||||
|
||||
|
||||
|
||||
|
@ -73,6 +73,14 @@ class myopenstack_keystone():
|
|||
"name": name
|
||||
}
|
||||
}
|
||||
_self.newProjectData=_self.requestor.make_request("POST", "projects", data,
|
||||
|
||||
_self.newProjectData=_self.connection.make_request("POST", "projects", data,
|
||||
os.getenv("OS_AUTH_URL")).json()
|
||||
return _self.newProjectData
|
||||
|
||||
def deleteProject(_self,id):
|
||||
log.info("Deleting a project")
|
||||
|
||||
_self.newProjectData=_self.connection.make_request("DELETE", "projects/"+id, "",
|
||||
os.getenv("OS_AUTH_URL")).json()
|
||||
return _self.newProjectData
|
|
@ -13,13 +13,16 @@ class myopenstack_nova():
|
|||
_self.myOpenstackObject.keystone.echo()
|
||||
|
||||
def showNovaURL(_self):
|
||||
return _self.conn.ks.getEndpointByNameAndInterface("nova","internal")["url"]
|
||||
return _self.conn.ks.getEndpointByNameAndInterface("nova",_self.conn.interface)["url"]
|
||||
|
||||
|
||||
def getAllServers(_self,projectID):
|
||||
|
||||
return _self.conn.make_request("GET", "/servers/detail?all_tenants=True&project_id="+projectID,
|
||||
"",_self.conn.ks.getEndpointByNameAndInterface("nova","internal")["url"] ).json()
|
||||
def getAllServers(_self,projectID,all_tenants):
|
||||
queryString=""
|
||||
if all_tenants:
|
||||
queryString="/servers/detail?all_tenants=True"
|
||||
else:
|
||||
queryString="/servers/detail?project_id="+projectID,
|
||||
return _self.conn.make_request("GET", queryString,"",_self.conn.ks.getEndpointByNameAndInterface("nova",_self.conn.interface)["url"] ).json()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue