Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
qucikfix snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Jun 19, 2019
1 parent bdcdf35 commit 016aea4
Showing 1 changed file with 54 additions and 42 deletions.
96 changes: 54 additions & 42 deletions VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def create_connection(self):
)
conn.authorize()
except Exception as e:
self.logger.error("Client failed authentication at Openstack : {0}", e)
self.logger.exception("Client failed authentication at Openstack : {0}", e)
raise authenticationException(
Reason="Client failed authentication at Openstack"
)
Expand Down Expand Up @@ -162,7 +162,7 @@ def findUser(keystone, name):
keystone.users.update(user, password=password)
return password
except Exception as e:
self.logger.error(
self.logger.exception(
"Set Password for user {0} failed : {1}".format(user, str(e))
)
return otherException(Reason=str(e))
Expand Down Expand Up @@ -191,7 +191,7 @@ def get_Flavors(self):
flavors.append(flavor)
return flavors
except Exception as e:
self.logger.error("Get Flavors Error: {0}".format(e))
self.logger.exception("Get Flavors Error: {0}".format(e))
return ()

@deprecated(
Expand All @@ -215,7 +215,7 @@ def check_Version(self, version):
else:
return False
except Exception as e:
self.logger.error("Compare Version Error: {0}".format(e))
self.logger.exception("Compare Version Error: {0}".format(e))
return False

def get_client_version(self):
Expand Down Expand Up @@ -264,7 +264,7 @@ def get_Images(self):

return images
except Exception as e:
self.logger.error("Get Images Error: {0}".format(e))
self.logger.exception("Get Images Error: {0}".format(e))
return ()

def get_Image_with_Tag(self, id):
Expand Down Expand Up @@ -294,7 +294,7 @@ def get_Image_with_Tag(self, id):
)
return image
except Exception as e:
self.logger.error("Get Image {0} with Tag Error: {1}".format(id, e))
self.logger.exception("Get Image {0} with Tag Error: {1}".format(id, e))
return

def import_keypair(self, keyname, public_key):
Expand Down Expand Up @@ -323,7 +323,7 @@ def import_keypair(self, keyname, public_key):
return keypair
return keypair
except Exception as e:
self.logger.error("Import Keypair {0} error:{1}".format(keyname, e))
self.logger.exception("Import Keypair {0} error:{1}".format(keyname, e))
return

def get_server(self, openstack_id):
Expand All @@ -339,10 +339,10 @@ def get_server(self, openstack_id):
try:
server = self.conn.compute.get_server(openstack_id)
except Exception as e:
self.logger.error("No Server found {0} | Error {1}".format(openstack_id, e))
self.logger.exception("No Server found {0} | Error {1}".format(openstack_id, e))
return VM(status="DELETED")
if server is None:
self.logger.error("No Server {0}".format(openstack_id))
self.logger.exception("No Server {0}".format(openstack_id))
raise serverNotFoundException(Reason="No Server {0}".format(openstack_id))
serv = server.to_dict()

Expand All @@ -362,12 +362,12 @@ def get_server(self, openstack_id):
try:
flav = self.conn.compute.get_flavor(serv["flavor"]["id"]).to_dict()
except Exception as e:
self.logger.error(e)
self.logger.exception(e)
flav = None
try:
img = self.get_Image_with_Tag(serv["image"]["id"])
except Exception as e:
self.logger.error(e)
self.logger.exception(e)
img = None
for values in server.addresses.values():
for address in values:
Expand Down Expand Up @@ -448,19 +448,19 @@ def start_server(
metadata = {"elixir_id": elixir_id}
image = self.conn.compute.find_image(image)
if image is None:
self.logger.error("Image {0} not found!".format(image))
self.logger.exception("Image {0} not found!".format(image))
raise imageNotFoundException(
Reason=("Image {0} not fournd".format(image))
)
flavor = self.conn.compute.find_flavor(flavor)
if flavor is None:
self.logger.error("Flavor {0} not found!".format(flavor))
self.logger.exception("Flavor {0} not found!".format(flavor))
raise flavorNotFoundException(
Reason="Flavor {0} not found!".format(flavor)
)
network = self.conn.network.find_network(self.NETWORK)
if network is None:
self.logger.error("Network {0} not found!".format(network))
self.logger.exception("Network {0} not found!".format(network))
raise networkNotFoundException(
Reason="Network {0} not found!".format(network)
)
Expand All @@ -478,7 +478,7 @@ def start_server(
name=volumename, size=int(diskspace)
).to_dict()
except Exception as e:
self.logger.error(
self.logger.exception(
"Trying to create volume with {0}"
" GB for vm {1} error : {2}".format(diskspace, servername, e),
exc_info=True,
Expand Down Expand Up @@ -537,7 +537,7 @@ def create_volume(self, volume_name, diskspace):
volumeId = volume["id"]
return volumeId
except Exception as e:
self.logger.error(
self.logger.exception(
"Trying to create volume with {0} GB error : {1}".format(diskspace, e),
exc_info=True,
)
Expand Down Expand Up @@ -572,7 +572,7 @@ def checkStatusVolume(volume, conn):

server = self.conn.compute.get_server(openstack_id)
if server is None:
self.logger.error("No Server {0} ".format(openstack_id))
self.logger.exception("No Server {0} ".format(openstack_id))
raise serverNotFoundException(Reason="No Server {0}".format(openstack_id))
if checkStatusVolume(volume_id, self.conn):

Expand All @@ -586,7 +586,7 @@ def checkStatusVolume(volume, conn):
server=server, volumeId=volume_id
)
except Exception as e:
self.logger.error(
self.logger.exception(
"Trying to attache volume {0} to vm {1} error : {2}".format(
volume_id, openstack_id, e
),
Expand Down Expand Up @@ -615,10 +615,10 @@ def check_server_status(self, openstack_id, diskspace, volume_id):
try:
server = self.conn.compute.get_server(openstack_id)
except Exception:
self.logger.error("No Server with id {0} ".format(openstack_id))
self.logger.exception("No Server with id {0} ".format(openstack_id))
return None
if server is None:
self.logger.error("No Server with id {0} ".format(openstack_id))
self.logger.exception("No Server with id {0} ".format(openstack_id))
return None
serv = server.to_dict()

Expand Down Expand Up @@ -658,7 +658,7 @@ def check_server_status(self, openstack_id, diskspace, volume_id):
server.status = "BUILD"
return server
except Exception as e:
self.logger.error("Check Status VM {0} error: {1}".format(openstack_id, e))
self.logger.exception("Check Status VM {0} error: {1}".format(openstack_id, e))
return None

def add_security_group_to_server(self, http, https, udp, server_id):
Expand Down Expand Up @@ -739,7 +739,7 @@ def get_ip_ports(self, openstack_id):
floating_ip = self.get_server(openstack_id)
return {"IP": str(floating_ip)}
except Exception as e:
self.logger.error(
self.logger.exception(
"Get IP and PORT for server {0} error:".format(openstack_id, e)
)
return {}
Expand All @@ -765,17 +765,29 @@ def create_snapshot(self, openstack_id, name, elixir_id, base_tag):
server=openstack_id, name=name
)
except Exception:
self.logger.error("Instance {0} not found".format(openstack_id))
self.logger.exception("Instance {0} not found".format(openstack_id))
return
try:
snapshot_id = snapshot_munch["id"]
self.conn.image.add_tag(image=snapshot_id, tag=elixir_id)
self.conn.image.add_tag(
image=snapshot_id, tag="snapshot_image:{0}".format(base_tag)
)
snapshot = self.conn.get_image_by_id(snapshot_munch["id"])
snapshot_id = snapshot["id"]
#todo check again
try:
self.conn.image.add_tag(
image=snapshot_id, tag="snapshot_image:{0}".format(base_tag)
)
except Exception:
self.logger.exception("Tag error catched")
pass
try :
self.logger.exception("Tag error catched")

self.conn.image.add_tag(image=snapshot_id, tag=elixir_id)
except Exception:
pass

return snapshot_id
except Exception as e:
self.logger.error(
self.logger.exception(
"Create Snapshot from Instance {0}"
" with name {1} for {2} error : {3}".format(
openstack_id, name, elixir_id, e
Expand All @@ -794,14 +806,14 @@ def delete_image(self, image_id):
try:
image = self.conn.compute.get_image(image_id)
if image is None:
self.logger.error("Image {0} not found!".format(image))
self.logger.exception("Image {0} not found!".format(image))
raise imageNotFoundException(
Reason=("Image {0} not found".format(image))
)
self.conn.compute.delete_image(image)
return True
except Exception as e:
self.logger.error("Delete Image {0} error : {1}".format(image_id, e))
self.logger.exception("Delete Image {0} error : {1}".format(image_id, e))
return False

def add_floating_ip_to_server(self, openstack_id, network):
Expand All @@ -816,7 +828,7 @@ def add_floating_ip_to_server(self, openstack_id, network):

server = self.conn.compute.get_server(openstack_id)
if server is None:
self.logger.error("Instance {0} not found".format(openstack_id))
self.logger.exception("Instance {0} not found".format(openstack_id))
raise serverNotFoundException
self.logger.info("Checking if Server already got an Floating Ip")
for values in server.addresses.values():
Expand All @@ -839,7 +851,7 @@ def add_floating_ip_to_server(self, openstack_id, network):

networkID = self.conn.network.find_network(network)
if networkID is None:
self.logger.error("Network " + network + " not found")
self.logger.exception("Network " + network + " not found")
raise networkNotFoundException
networkID = networkID.to_dict()["id"]
floating_ip = self.conn.network.create_ip(floating_network_id=networkID)
Expand All @@ -850,7 +862,7 @@ def add_floating_ip_to_server(self, openstack_id, network):

return floating_ip
except Exception as e:
self.logger.error(
self.logger.exception(
"Adding Floating IP to {0} with network {1} error:{2}".format(
openstack_id, network, e
)
Expand Down Expand Up @@ -887,7 +899,7 @@ def delete_server(self, openstack_id):
try:
server = self.conn.compute.get_server(openstack_id)
if server is None:
self.logger.error("Instance {0} not found".format(openstack_id))
self.logger.exception("Instance {0} not found".format(openstack_id))
raise serverNotFoundException

if server.status == "SUSPENDED":
Expand All @@ -906,7 +918,7 @@ def delete_server(self, openstack_id):

return True
except Exception as e:
self.logger.error("Delete Server {0} error: {1}".format(openstack_id, e))
self.logger.exception("Delete Server {0} error: {1}".format(openstack_id, e))
return False

def delete_volume_attachment(self, volume_id, server_id):
Expand Down Expand Up @@ -966,7 +978,7 @@ def checkStatusVolume(volume, conn):
self.conn.block_storage.delete_volume(volume=volume_id)
return True
except Exception as e:
self.logger.error("Delete Volume {0} error".format(volume_id, e))
self.logger.exception("Delete Volume {0} error".format(volume_id, e))
return False

def stop_server(self, openstack_id):
Expand All @@ -980,7 +992,7 @@ def stop_server(self, openstack_id):
server = self.conn.compute.get_server(openstack_id)
try:
if server is None:
self.logger.error("Instance {0} not found".format(openstack_id))
self.logger.exception("Instance {0} not found".format(openstack_id))
raise serverNotFoundException

if server.status == "ACTIVE":
Expand All @@ -995,7 +1007,7 @@ def stop_server(self, openstack_id):

return False
except Exception as e:
self.logger.error("Stop Server {0} error:".format(openstack_id, e))
self.logger.exception("Stop Server {0} error:".format(openstack_id, e))

return False

Expand All @@ -1011,7 +1023,7 @@ def reboot_server(self, server_id, reboot_type):
try:
server = self.conn.compute.get_server(server_id)
if server is None:
self.logger.error("Instance {0} not found".format(server_id))
self.logger.exception("Instance {0} not found".format(server_id))
raise serverNotFoundException
else:
self.conn.compute.reboot_server(server, reboot_type)
Expand All @@ -1033,7 +1045,7 @@ def resume_server(self, openstack_id):
try:
server = self.conn.compute.get_server(openstack_id)
if server is None:
self.logger.error("Instance {0} not found".format(openstack_id))
self.logger.exception("Instance {0} not found".format(openstack_id))
raise serverNotFoundException

if server.status == "SUSPENDED":
Expand All @@ -1047,7 +1059,7 @@ def resume_server(self, openstack_id):

return False
except Exception as e:
self.logger.error("Resume Server {0} error:".format(openstack_id, e))
self.logger.exception("Resume Server {0} error:".format(openstack_id, e))
return False

def create_security_group(
Expand Down

0 comments on commit 016aea4

Please sign in to comment.