Network,subnet and router work now
This commit is contained in:
parent
ca6af4f849
commit
e4d0e8c695
|
@ -0,0 +1,13 @@
|
|||
.*egg-info.*
|
||||
build*
|
||||
dist*
|
||||
.*python_netflow_v9_softflowd.egg-info/
|
||||
*.swp
|
||||
*.swo
|
||||
__pycache__
|
||||
*.json
|
||||
venv
|
||||
.idea
|
||||
.env*
|
||||
.env
|
||||
/lib/
|
|
@ -0,0 +1,14 @@
|
|||
OS_USERNAME=admin
|
||||
OS_PASSWORD=
|
||||
OS_PROJECT_NAME=admin
|
||||
OS_PROJECT_ID=8f526efe5899415f8cede048c5594aa4
|
||||
OS_USER_DOMAIN_NAME=Default
|
||||
OS_PROJECT_DOMAIN_NAME=Default
|
||||
OS_AUTH_URL=https://api.mycloud.com:5000/v3
|
||||
OS_IDENTITY_API_VERSION=3
|
||||
OS_INTERFACE=public
|
||||
EXTERNAL_NETWORK_ID=3578d00b-e6f2-4a5d-b379-b79d4fb2d8d0
|
||||
FLAVOR_ID=
|
||||
IMAGE_ID=
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
44
main.py
44
main.py
|
@ -7,11 +7,14 @@ import myOpenstackApp
|
|||
testProjectName="SmokeTest"
|
||||
testProjectExists=False
|
||||
testProject=""
|
||||
testNetwork=""
|
||||
testSubnet=""
|
||||
|
||||
cleanupResourcesOnCompletion=True
|
||||
|
||||
y=myOpenstackApp.OSC
|
||||
y.initalise()
|
||||
# y.ks.getCatalog()
|
||||
y.ks.getCatalog()
|
||||
# print(y.something())
|
||||
# print(y._keystone)
|
||||
|
||||
|
@ -27,19 +30,52 @@ for _project in allProjects['projects']:
|
|||
testProjectExists=True
|
||||
|
||||
if testProjectExists:
|
||||
log.error("Project already exists")
|
||||
log.info(testProject['id'])
|
||||
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(testProject['id'])
|
||||
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")
|
||||
|
|
|
@ -11,6 +11,7 @@ class OpenStackConnection_x:
|
|||
ks=False
|
||||
nova=False
|
||||
neutron=False
|
||||
cinder=False
|
||||
|
||||
catalogData=""
|
||||
novaURL=""
|
||||
|
@ -29,10 +30,13 @@ class OpenStackConnection_x:
|
|||
from myOpenstackApp.keystone import myopenstack_keystone
|
||||
from myOpenstackApp.nova import myopenstack_nova
|
||||
from myOpenstackApp.neutron import myopenstack_neutron
|
||||
from myOpenstackApp.cinder import myopenstack_cinder
|
||||
|
||||
self.ks=myopenstack_keystone(self)
|
||||
self.nova=myopenstack_nova(self)
|
||||
self.neutron=myopenstack_neutron(self)
|
||||
self.cinder-myopenstack_cinder(self)
|
||||
|
||||
self.interface=os.getenv("OS_INTERFACE")
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
import imp
|
||||
import json
|
||||
import myOpenstackApp.OpenStackConnection
|
||||
|
||||
class myopenstack_cinder():
|
||||
def __init__(self,conn: myOpenstackApp.OpenStackConnection.OpenStackConnection_x ) -> None:
|
||||
self.conn=conn
|
||||
|
||||
def getAllVolumes(_self, projectID):
|
||||
result_Data=_self.conn.make_request("GET", "v2.0/volumes?project_id="+projectID, "",
|
||||
_self.conn.ks.getEndpointByNameAndInterface("cinder",_self.conn.interface)["url"]).json()
|
||||
return result_Data
|
||||
|
||||
|
||||
|
||||
def createVolume(_self,name,network_id):
|
||||
data={
|
||||
"router": {
|
||||
"name": name,
|
||||
"external_gateway_info": {
|
||||
"network_id": network_id,
|
||||
"enable_snat": True,
|
||||
},
|
||||
"admin_state_up": True
|
||||
}
|
||||
}
|
||||
result_Data=_self.conn.make_request("POST", "v2.0/routers", data,
|
||||
_self.conn.ks.getEndpointByNameAndInterface("cinder",_self.conn.interface)["url"]).json()
|
||||
return result_Data
|
|
@ -7,12 +7,12 @@ class myopenstack_neutron():
|
|||
self.conn=conn
|
||||
|
||||
def getAllNetworks(_self, projectID):
|
||||
result_Data=_self.conn.make_request("GET", "networks?project_id="+projectID, "",
|
||||
result_Data=_self.conn.make_request("GET", "v2.0/networks?project_id="+projectID, "",
|
||||
_self.conn.ks.getEndpointByNameAndInterface("neutron",_self.conn.interface)["url"]).json()
|
||||
return result_Data
|
||||
|
||||
def listAllFloatingIPsByProject(_self,projectID):
|
||||
result_Data=_self.conn.make_request("GET", "floatingips?project_id="+projectID, "",
|
||||
result_Data=_self.conn.make_request("GET", "v2.0/floatingips?project_id="+projectID, "",
|
||||
_self.conn.ks.getEndpointByNameAndInterface("neutron",_self.conn.interface)["url"]).json()
|
||||
return result_Data
|
||||
|
||||
|
@ -24,10 +24,39 @@ class myopenstack_neutron():
|
|||
data={
|
||||
"network": {
|
||||
"name": name,
|
||||
"admin_state_up": true,
|
||||
"admin_state_up": True,
|
||||
"tenant_id": project_id,
|
||||
"description": description
|
||||
}
|
||||
}
|
||||
newNetwork=_self.requestor.make_request("POST", "projects", data, )
|
||||
return newNetwork
|
||||
result_Data=_self.conn.make_request("POST", "v2.0/networks", data,
|
||||
_self.conn.ks.getEndpointByNameAndInterface("neutron",_self.conn.interface)["url"]).json()
|
||||
return result_Data
|
||||
|
||||
def createSubnet(_self,name,network_id):
|
||||
data={
|
||||
"subnet": {
|
||||
"name": name,
|
||||
"network_id": network_id,
|
||||
"ip_version": 4,
|
||||
"cidr": "192.168.199.0/24"
|
||||
}
|
||||
}
|
||||
result_Data=_self.conn.make_request("POST", "v2.0/subnets", data,
|
||||
_self.conn.ks.getEndpointByNameAndInterface("neutron",_self.conn.interface)["url"]).json()
|
||||
return result_Data
|
||||
|
||||
def createRouter(_self,name,network_id):
|
||||
data={
|
||||
"router": {
|
||||
"name": name,
|
||||
"external_gateway_info": {
|
||||
"network_id": network_id,
|
||||
"enable_snat": True,
|
||||
},
|
||||
"admin_state_up": True
|
||||
}
|
||||
}
|
||||
result_Data=_self.conn.make_request("POST", "v2.0/routers", data,
|
||||
_self.conn.ks.getEndpointByNameAndInterface("neutron",_self.conn.interface)["url"]).json()
|
||||
return result_Data
|
|
@ -1,16 +0,0 @@
|
|||
import myOpenstackApp.OpenStackConnection
|
||||
|
||||
|
||||
class myopenstack_keystone():
|
||||
|
||||
def __init__(self,conn ) -> None:
|
||||
self.conn=conn
|
||||
|
||||
def echo(_self):
|
||||
print("Helllooo")
|
||||
|
||||
|
||||
def getCatalog(_self):
|
||||
catalog="Some shit, more shit"
|
||||
_self.conn.catalogData=catalog
|
||||
_self.conn.novaURL="http://nova"
|
|
@ -0,0 +1,2 @@
|
|||
python-dotenv==0.21.0
|
||||
requests==2.28.1
|
Loading…
Reference in New Issue