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

Commit

Permalink
Merge pull request #177 from deNBI/dev
Browse files Browse the repository at this point in the history
more logs
  • Loading branch information
dweinholz authored Nov 25, 2019
2 parents fd3942b + c15f7d7 commit b61e8a0
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def get_Image_with_Tag(self, id):
"""
self.logger.info("Get Image {0} with tags".format(id))
try:
img=self.conn.get_image(name_or_id=id)
img = self.conn.get_image(name_or_id=id)
metadata = img["metadata"]
description = metadata.get("description")
tags = img.get("tags")
Expand All @@ -323,7 +323,7 @@ def get_Image_with_Tag(self, id):
return image
except Exception as e:
self.logger.exception("Get Image {0} with Tag Error: {1}".format(id, e))
return
return None

def delete_keypair(self, key_name):
key_pair = self.conn.compute.find_keypair(key_name)
Expand Down Expand Up @@ -472,10 +472,12 @@ def get_server(self, openstack_id):
def get_servers_by_ids(self, ids):
servers = []
for id in ids:
self.logger.info("Get server {}".format(id))
try:
servers.append(self.conn.compute.get_server(id))
except:
self.logger.error("Requested VM {} not found!".format(id))
server = self.conn.get_server_by_id(id)
servers.append(server)
except Exception as e:
self.logger.exception("Requested VM {} not found!\n {}".format(id, e))
pass
server_list = []
for server in servers:
Expand Down Expand Up @@ -867,27 +869,26 @@ def check_server_status(self, openstack_id, diskspace, volume_id):
return None

def openstack_server_to_thrift_server(self, server):
serv = server.to_dict()
self.logger.info(serv)
self.logger.info("Convert server {} to thrift server".format(server))
fixed_ip = None
floating_ip = None

if serv["attached_volumes"]:
volume_id = serv["attached_volumes"][0]["id"]
if server["os-extended-volumes:volumes_attached"]:
volume_id = server["os-extended-volumes:volumes_attached"][0]["id"]
diskspace = self.conn.block_storage.get_volume(volume_id).to_dict()["size"]
else:
diskspace = 0
if serv["launched_at"]:
if server["OS-SRV-USG:launched_at"]:
dt = datetime.datetime.strptime(
serv["launched_at"][:-7], "%Y-%m-%dT%H:%M:%S"
server["OS-SRV-USG:launched_at"][:-7], "%Y-%m-%dT%H:%M:%S"
)
timestamp = time.mktime(dt.timetuple())
else:
timestamp = None
flav = self.openstack_flav_to_thrift_flav(serv["flavor"])
flav = self.openstack_flav_to_thrift_flav(server["flavor"])

try:
img = self.get_Image_with_Tag(serv["image"]["id"])
img = self.get_Image_with_Tag(server["image"]["id"])
except Exception as e:
self.logger.exception(e)
img = None
Expand All @@ -902,12 +903,12 @@ def openstack_server_to_thrift_server(self, server):
server = VM(
flav=flav,
img=img,
status=serv["status"],
metadata=serv["metadata"],
project_id=serv["project_id"],
keyname=serv["key_name"],
openstack_id=serv["id"],
name=serv["name"],
status=server["status"],
metadata=server["metadata"],
project_id=server["project_id"],
keyname=server["key_name"],
openstack_id=server["id"],
name=server["name"],
created_at=str(timestamp),
fixed_ip=fixed_ip,
floating_ip=floating_ip,
Expand Down

0 comments on commit b61e8a0

Please sign in to comment.