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

Commit

Permalink
fix(Volumes):fixed deatachment
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Mar 27, 2019
1 parent a9ffc62 commit 891b28a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
39 changes: 22 additions & 17 deletions VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def get_client_version(self):
:return: Version of the client.
"""
self.logger.info("Get Version of Client: {}".format(VERSION))
#self.logger.info("Get Version of Client: {}".format(VERSION))
return str(VERSION)


Expand Down Expand Up @@ -531,36 +531,40 @@ def checkStatusVolume(volume, conn):

status = conn.block_storage.get_volume(
volume).to_dict()['status']
self.logger.info("Volume {} Status:{}".format(volume_id,status))
if status =='in-use':
return False

if status != 'available':

time.sleep(3)
else:
done = True
time.sleep(2)
return volume
return True

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

self.logger.info(
'Attaching volume {0} to virtualmachine {1}'.format(
volume_id, openstack_id))
try:
self.conn.compute.create_volume_attachment(
server=server, volumeId=volume_id)
except Exception as e:
self.logger.error(
'Trying to attache volume {0} to vm {1} error : {2}'.format(
volume_id, openstack_id, e), exc_info=True)
self.logger.info("Delete Volume {0}".format(volume_id))
self.conn.block_storage.delete_volume(volume=volume_id)
return False
self.logger.info(
'Attaching volume {0} to virtualmachine {1}'.format(
volume_id, openstack_id))
try:
self.conn.compute.create_volume_attachment(
server=server, volumeId=volume_id)
except Exception as e:
self.logger.error(
'Trying to attache volume {0} to vm {1} error : {2}'.format(
volume_id, openstack_id, e), exc_info=True)
self.logger.info("Delete Volume {0}".format(volume_id))
self.conn.block_storage.delete_volume(volume=volume_id)
return False

return True
return True

def check_server_status(self, openstack_id, diskspace, volume_id):
Expand Down Expand Up @@ -643,7 +647,7 @@ def get_IP_PORT(self, openstack_id):
return {'IP': str(self.GATEWAY_IP), 'PORT': str(port)}

else:
floating_ip = self.get_server(openstack_id).floating_ip
floating_ip = self.get_server(openstack_id)
return {'IP': str(floating_ip)}
except Exception as e:
self.logger.error(
Expand Down Expand Up @@ -767,6 +771,7 @@ def netcat(self, host, port):
:return: True if successfully connected, False if not
"""
self.logger.info("Checking SSH Connection {0}:{1}".format(host, port))
return True

with closing(
socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
Expand Down
6 changes: 6 additions & 0 deletions VirtualMachineService/VirtualMachineServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from thrift.server import TServer
import yaml
import click
import socket
from contextlib import closing

@click.command()
@click.argument('config')
Expand All @@ -40,4 +42,8 @@ def startServer(config):


if __name__ == '__main__':
with closing(
socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
r = sock.connect_ex(('129.70.51.6', 30072))
print(r)
startServer()

0 comments on commit 891b28a

Please sign in to comment.