Stuck on Neutron catalog URL

This commit is contained in:
Cory Hawkless 2022-11-03 10:59:58 +10:30
parent 48b9345fc0
commit c422a7285c
4 changed files with 49 additions and 62 deletions

28
main.py
View File

@ -7,25 +7,25 @@ import json
from ng_openstack.logger import log
log.info("Starting")
x=ng_openstack.OpenstackConnection("Fido",10)
# x.keystone.getAllProjects()
x.keystone.getCatalog()
myOpenstack=ng_openstack.OpenstackConnection()
myOpenstack.keystone.getCatalog()
# print (x.keystone.catalogData)
# neutronService=x.keystone.getServicebyName("Neutron")
# print(neutronService)
# neutronURL=x.keystone.getEndpointByNameIDAndInterface("NeuTrOn","internal")['url']
# print(neutronURL)
projects=x.keystone.getAllProjects()
print(projects)
allProjects=myOpenstack.keystone.getAllProjects()
testProjectName="SmokeTest"
testProjectExists=False
#Does my test project ID already exist?
if testProjectName in projects['projects']:
for _project in allProjects['projects']:
if _project['name']==testProjectName:
testProjectExists=True
if testProjectExists:
log.error("Project already exists")
log.error(projects['projects'][testProjectName])
else:
# Create test project
log.info("{} project does not exist, creating".format(testProjectName))
x.keystone.createProject(testProjectName,"Description goes here")
#create test project
myOpenstack.keystone.createProject(testProjectName,"Description goes here")

View File

@ -10,11 +10,10 @@ class OpenstackConnection():
keystone=Openstack_Keystone(requestor)
def __init__(self, name, age):
self.name = name
self.age = age
self.speed = 0
self.moving = False
def __init__(self, someVar="", someotherVar=""):
self.someotherVar = someotherVar
self.someVar = someVar
@property
def human_age(self):
@ -34,27 +33,3 @@ class OpenstackConnection():
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('')

View File

@ -9,3 +9,15 @@ def listAllFloatingIPsByProject(projectID):
def ipInSubnet(network,netmask,ip):
#Network, netmask and ip must be supplied in integer form
return (ip & netmask) == network
def createNetwork(_self,name,project_id,description=""):
data={
"network": {
"name": name,
"admin_state_up": true,
"tenant_id": project_id,
"description": description
}
}
newNetwork=_self.requestor.make_request("POST", "projects", data, )
return newNetwork

View File

@ -49,28 +49,28 @@ class Openstack_Request:
url = os.getenv("OS_AUTH_URL") + '/auth/tokens'
xdata = {
"auth": {
"scope": {
"project": {
"domain": {
"name": scopeDomain
},
"id": scopeProject
}
},
"identity": {
"password": {
"user": {
"scope": {
"project": {
"domain": {
"name": authDomain
"name": scopeDomain
},
"password": password,
"name": username
"id": scopeProject
}
},
"methods": [
"password"
]
}
"identity": {
"password": {
"user": {
"domain": {
"name": authDomain
},
"password": password,
"name": username
}
},
"methods": [
"password"
]
}
}
}