Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #36 from BlackSmith/master
Browse files Browse the repository at this point in the history
Fix floating IP & SPEC file
  • Loading branch information
BlackSmith authored Jan 26, 2018
2 parents 532ef42 + df9ba30 commit 491bf2f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
11 changes: 10 additions & 1 deletion 5minute.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: 5minute
Version: 0.2.26
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Command line tool for getting instance from OpenStack

License: GPLv2
Expand All @@ -9,6 +9,15 @@ Source0: https://github.com/BlackSmith/%{name}/archive/%{version}.tar.gz

BuildArch: noarch
BuildRequires: python3-devel
BuildRequires: python3
BuildRequires: python3-cinderclient
BuildRequires: python3-heatclient
BuildRequires: python3-neutronclient
BuildRequires: python3-xmltodict
BuildRequires: python3-prettytable
BuildRequires: python3-novaclient
BuildRequires: python3-keystoneclient
BuildRequires: python3-glanceclient
Requires: python3
Requires: python3-cinderclient
Requires: python3-heatclient
Expand Down
32 changes: 19 additions & 13 deletions vminute/vminute.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def get_volume(self, id):
if re.match(r'^[0-9a-f\-]+$', id) is None:
return self.cinder.volumes.find(display_name=id)
else:
return self.cinder.volgumes.get(id)
return self.cinder.volumes.get(id)

@catch_exception("The snapshot doesn't exist.")
def get_snapshot(self, id):
Expand Down Expand Up @@ -694,9 +694,15 @@ def kill_instances(self, id):
progress(title="Release floating IP:")
# This is stupid method for checking of lock, if it is activated
k, fips = server.addresses.popitem()
fids = []
for fip in fips:
if (fip.get('OS-EXT-IPS:type') == 'floating'):
server.remove_floating_ip(fip.get('addr'))
idip = self.neutron.\
list_floatingips(floating_ip_address=fip.get('addr'))\
.get('floatingips')[0].get('id')
self.neutron.update_floatingip(idip, {"floatingip": {
'port_id': None}})
fids.append(idip)
progress(result="DONE")
vols = self.nova.volumes.get_server_volumes(server.id)
if len(vols) > 0:
Expand All @@ -721,15 +727,14 @@ def kill_instances(self, id):
progress(result="\x1b[31;01mLOCKED\x1b[39;49;00m")
else:
progress(result="FAIL")
for fip in fips:
if (fip.get('OS-EXT-IPS:type') == 'floating'):
for fi in fids:
if done:
# self.nova.floating_ips.delete(fip.get('addr'))
ips = self.neutron.list_floatingips(
floating_ip_address=fip.get('addr')).get('floatingips')
self.neutron.delete_floatingip(ips[0]['id'])
self.neutron.delete_floatingip(fi)
else:
server.add_floating_ip(fip.get('addr'))
interface = server.interface_list().pop()
if interface:
self.neutron.update_floatingip(fi, {"floatingip": {
'port_id': interface.port_id}})
if 'skip-volume' not in self.params:
for vol in vols:
cvol = self.cinder.volumes.get(vol.id)
Expand Down Expand Up @@ -1078,7 +1083,7 @@ def __setup_networking(self):
self.add_variable('hostname', hostname)
progress(result=hostname)

# @catch_exception("The problem with downloading of the userdata script for this image")
@catch_exception("The problem with downloading of the userdata script for this image")
def __setup_userdata_script(self, image):
res = None
filenames = None
Expand Down Expand Up @@ -1161,7 +1166,6 @@ def __create_instance(self, image):
'config_drive': True}
if self.volume:
param_dict['block_device_mapping'] = {'vdb': self.volume.id}
# print(param_dict)
if "cscript" in self.params:
param_dict['userdata'] = self.params['cscript']
server = self.nova.servers.create(**param_dict)
Expand All @@ -1170,13 +1174,15 @@ def __create_instance(self, image):
time.sleep(1)
progress()
status = self.nova.servers.get(server.id).status
# print server.progress
if status == 'ACTIVE':
progress(result="DONE")
else:
progress(result="FAIL")
if "floating-ip" in self.variables:
server.add_floating_ip(self.variables['floating-ip']['floating_ip_address'])
interface = server.interface_list().pop()
self.neutron.update_floatingip(
self.variables['floating-ip']['id'],
{"floatingip": {'port_id': interface.port_id}})
self.__check_console_output(server)

def __check_console_output(self, server):
Expand Down

0 comments on commit 491bf2f

Please sign in to comment.