floating ip commands
This commit is contained in:
@@ -26,6 +26,8 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import IPy
|
||||||
|
|
||||||
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
||||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||||
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
|
||||||
@@ -218,12 +220,41 @@ class ProjectCommands(object):
|
|||||||
with open(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
f.write(zip_file)
|
f.write(zip_file)
|
||||||
|
|
||||||
|
class FloatingIpCommands(object):
|
||||||
|
"""Class for managing floating ip."""
|
||||||
|
|
||||||
|
def create(self, host, range):
|
||||||
|
"""Creates floating ips for host by range
|
||||||
|
arguments: host ip_range"""
|
||||||
|
for address in IPy.IP(range):
|
||||||
|
db.floating_ip_create(None, {'address': str(address),
|
||||||
|
'host': host})
|
||||||
|
|
||||||
|
def delete(self, ip_range):
|
||||||
|
"""Deletes floating ips by range
|
||||||
|
arguments: range"""
|
||||||
|
for address in IPy.IP(ip_range):
|
||||||
|
db.floating_ip_destroy(None, str(address))
|
||||||
|
|
||||||
|
|
||||||
|
def list(self, host=None):
|
||||||
|
"""Lists all floating ips (optionally by host)
|
||||||
|
arguments: [host]"""
|
||||||
|
if host == None:
|
||||||
|
floating_ips = db.floating_ip_get_all(None)
|
||||||
|
else:
|
||||||
|
floating_ips = db.floating_ip_get_all_by_host(None, host)
|
||||||
|
for floating_ip in floating_ips:
|
||||||
|
print "%s\t%s\ti-%s" % (floating_ip['host'],
|
||||||
|
floating_ip['address'],
|
||||||
|
floating_ip['instance_id'])
|
||||||
|
|
||||||
CATEGORIES = [
|
CATEGORIES = [
|
||||||
('user', UserCommands),
|
('user', UserCommands),
|
||||||
('project', ProjectCommands),
|
('project', ProjectCommands),
|
||||||
('role', RoleCommands),
|
('role', RoleCommands),
|
||||||
('vpn', VpnCommands),
|
('vpn', VpnCommands),
|
||||||
|
('floating', FloatingIpCommands)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user