Somewhat working
This commit is contained in:
parent
e4d0e8c695
commit
85dadb1428
56
main.py
56
main.py
|
@ -1,4 +1,4 @@
|
|||
import os, sys
|
||||
import os, sys,time
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), "lib"))
|
||||
from myOpenstackApp.logger import log
|
||||
|
||||
|
@ -9,6 +9,7 @@ testProjectExists=False
|
|||
testProject=""
|
||||
testNetwork=""
|
||||
testSubnet=""
|
||||
timingText=""
|
||||
|
||||
cleanupResourcesOnCompletion=True
|
||||
|
||||
|
@ -17,12 +18,32 @@ y.initalise()
|
|||
y.ks.getCatalog()
|
||||
# print(y.something())
|
||||
# print(y._keystone)
|
||||
|
||||
log.info("Starting")
|
||||
|
||||
tic = time.perf_counter()
|
||||
|
||||
|
||||
allProjects=y.ks.getAllProjects()
|
||||
toc = time.perf_counter()
|
||||
timingText +=(f"Queried keystone in {toc - tic:0.4f} seconds\n")
|
||||
|
||||
def sendFailureNotice(e,timingText):
|
||||
log.error("JOB FAILED\n\n" + str(e))
|
||||
log.error(timingText)
|
||||
exit()
|
||||
|
||||
|
||||
def cleanUp():
|
||||
log.info("Cleaning up")
|
||||
log.info("Deleting project")
|
||||
y.ks.deleteProject(testProject['id'])
|
||||
#Delete VM
|
||||
#Delete router
|
||||
#Delete Network
|
||||
#Delete project
|
||||
pass
|
||||
|
||||
try:
|
||||
#Does my test project ID already exist?
|
||||
for _project in allProjects['projects']:
|
||||
if _project['name']==testProjectName:
|
||||
|
@ -38,6 +59,15 @@ else:
|
|||
testProject=y.ks.createProject(testProjectName,"Description goes here")['project']
|
||||
log.info("Test project created with ID " + testProject['id'])
|
||||
|
||||
|
||||
toc = time.perf_counter()
|
||||
timingText +=(f"Queried projects in {toc - tic:0.4f} seconds\n")
|
||||
except Exception as e:
|
||||
log.error("Error managing project" + str(e))
|
||||
cleanUp()
|
||||
sendFailureNotice(e,timingText)
|
||||
|
||||
try:
|
||||
#Does my test network exist?
|
||||
allNetworks=y.neutron.getAllNetworks(testProject['id'])
|
||||
log.info(allNetworks)
|
||||
|
@ -65,8 +95,15 @@ else:
|
|||
log.info("Creating new router")
|
||||
testRouter=y.neutron.createRouter(testProjectName + "_router",os.getenv("EXTERNAL_NETWORK_ID"))
|
||||
log.debug(testRouter)
|
||||
toc = time.perf_counter()
|
||||
timingText +=(f"Queried neutron in {toc - tic:0.4f} seconds")
|
||||
except Exception as e:
|
||||
log.error("Error managing network" + str(e))
|
||||
toc = time.perf_counter()
|
||||
timingText +=(f"Neutron failed after {toc - tic:0.4f} seconds\n")
|
||||
|
||||
|
||||
cleanUp()
|
||||
sendFailureNotice(e,timingText)
|
||||
|
||||
#Create
|
||||
#Project
|
||||
|
@ -77,16 +114,11 @@ else:
|
|||
#Volume from image
|
||||
#Vm from volume
|
||||
|
||||
def cleanUp():
|
||||
log.info("Cleaning up")
|
||||
log.info("Deleting project")
|
||||
y.ks.deleteProject(testProject['id'])
|
||||
#Delete VM
|
||||
#Delete router
|
||||
#Delete Network
|
||||
#Delete project
|
||||
pass
|
||||
|
||||
|
||||
|
||||
if cleanupResourcesOnCompletion:
|
||||
cleanUp()
|
||||
|
||||
toc = time.perf_counter()
|
||||
log.info(f"Total runtime {toc - tic:0.4f} seconds")
|
|
@ -35,7 +35,7 @@ class OpenStackConnection_x:
|
|||
self.ks=myopenstack_keystone(self)
|
||||
self.nova=myopenstack_nova(self)
|
||||
self.neutron=myopenstack_neutron(self)
|
||||
self.cinder-myopenstack_cinder(self)
|
||||
self.cinder=myopenstack_cinder(self)
|
||||
|
||||
self.interface=os.getenv("OS_INTERFACE")
|
||||
|
||||
|
@ -71,11 +71,11 @@ class OpenStackConnection_x:
|
|||
url = apiEndpoint + "/" + url
|
||||
|
||||
if getPost=="GET":
|
||||
response = requests.get(url, headers=headers)
|
||||
response = requests.get(url, headers=headers,timeout=15)
|
||||
elif getPost=="POST":
|
||||
response = requests.post(url, data=data_json, headers=headers)
|
||||
response = requests.post(url, data=data_json, headers=headers,timeout=15)
|
||||
elif getPost=="DELETE":
|
||||
response = requests.delete(url, headers=headers)
|
||||
response = requests.delete(url, headers=headers,timeout=15)
|
||||
else:
|
||||
raise ValueError("Unknown request type")
|
||||
|
||||
|
@ -118,12 +118,12 @@ class OpenStackConnection_x:
|
|||
}
|
||||
}
|
||||
|
||||
response = requests.post(url)
|
||||
# response = requests.post(url)
|
||||
headers = {'Content-type': 'application/json'}
|
||||
response = requests.post(url, headers=headers,
|
||||
data=json.dumps(xdata),
|
||||
verify=False,
|
||||
timeout=4)
|
||||
timeout=15)
|
||||
|
||||
if response.status_code == 201:
|
||||
try:
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import time
|
||||
timingText=""
|
||||
tic = time.perf_counter()
|
||||
|
||||
import requests
|
||||
|
||||
toc = time.perf_counter()
|
||||
timingText +=(f"Queried projects in {toc - tic:0.4f} seconds\n")
|
||||
x=requests.get("http://google.com")
|
||||
|
||||
toc = time.perf_counter()
|
||||
time.sleep(1)
|
||||
timingText +=(f"Queried projects in {toc - tic:0.4f} seconds\n")
|
||||
toc = time.perf_counter()
|
||||
timingText +=(f"Queried projects in {toc - tic:0.4f} seconds\n")
|
||||
print(timingText)
|
Loading…
Reference in New Issue