new-openstackcheck-mk2/main.py

93 lines
2.3 KiB
Python

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=""
testNetwork=""
testSubnet=""
cleanupResourcesOnCompletion=True
y=myOpenstackApp.OSC
y.initalise()
y.ks.getCatalog()
# print(y.something())
# print(y._keystone)
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("Test project already exists with ID " + 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("Test project created with ID " + testProject['id'])
#Does my test network exist?
allNetworks=y.neutron.getAllNetworks(testProject['id'])
log.info(allNetworks)
#Does my test network ID already exist?
for _network in allNetworks['networks']:
if _network['name']==testProjectName+"_network":
testNetwork=_network
if testNetwork != "":
log.info("Test network already exists with ID " + testNetwork['id'])
else:
# Create test network
log.info("{} network does not exist, creating".format(testProjectName))
testNetwork=y.neutron.createNetwork(testProjectName+"_network",testProject['id'],"Test network description")['network']
log.info("Test network created with ID " + testNetwork['id'])
#Create subnet
log.info("Creating new subnet")
testSubnet=y.neutron.createSubnet(testProjectName + "_subnet",testNetwork['id'])
log.debug(testSubnet)
#Create a test router
log.info("Creating new router")
testRouter=y.neutron.createRouter(testProjectName + "_router",os.getenv("EXTERNAL_NETWORK_ID"))
log.debug(testRouter)
#Create
#Project
#Network
#Subnet
#Router
#bind router to network
#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()