From 1aadd5e961a6f1983454f5f49f077f0be0d6cba8 Mon Sep 17 00:00:00 2001 From: Lvov Maxim Date: Fri, 20 May 2011 12:53:49 +0400 Subject: added support for reserving certain network for certain project --- bin/nova-manage | 7 ++++--- nova/network/manager.py | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index db964064d..c64f25c23 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -515,11 +515,11 @@ class NetworkCommands(object): """Class for managing networks.""" def create(self, fixed_range=None, num_networks=None, - network_size=None, vlan_start=None, + network_size=None, vlan_start=None, project_id=None, vpn_start=None, fixed_range_v6=None, label='public'): """Creates fixed ips for host by range arguments: fixed_range=FLAG, [num_networks=FLAG], - [network_size=FLAG], [vlan_start=FLAG], + [network_size=FLAG], [vlan_start=FLAG], [project_id=None], [vpn_start=FLAG], [fixed_range_v6=FLAG]""" if not fixed_range: msg = _('Fixed range in the form of 10.0.0.0/8 is ' @@ -545,7 +545,8 @@ class NetworkCommands(object): vlan_start=int(vlan_start), vpn_start=int(vpn_start), cidr_v6=fixed_range_v6, - label=label) + label=label, + project_id=project_id) except ValueError, e: print e raise e diff --git a/nova/network/manager.py b/nova/network/manager.py index 5a6fdde5a..3422b72c1 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -564,6 +564,8 @@ class VlanManager(NetworkManager): net['dhcp_start'] = str(project_net[3]) net['vlan'] = vlan net['bridge'] = 'br%s' % vlan + if kwargs.has_key('project_id'): + net['project_id'] = kwargs['project_id'] if(FLAGS.use_ipv6): cidr_v6 = '%s/%s' % (fixed_net_v6[start_v6], significant_bits_v6) -- cgit From 4c1fd8a303a8eb1287fd83b04bd767171221d117 Mon Sep 17 00:00:00 2001 From: Lvov Maxim Date: Mon, 30 May 2011 11:25:21 +0400 Subject: add support for keyword arguments --- bin/nova-manage | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/nova-manage b/bin/nova-manage index c64f25c23..3d09f9064 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -1132,9 +1132,18 @@ def main(): action = argv.pop(0) matches = lazy_match(action, actions) action, fn = matches[0] + + fn_args, fn_kwargs = [], {} + for arg in argv: + if '=' in arg: + key, value = arg.split('=') + fn_kwargs[key] = value + else: + fn_args.append(arg) + # call the action with the remaining arguments try: - fn(*argv) + fn(*fn_args, **fn_kwargs) sys.exit(0) except TypeError: print _("Possible wrong number of arguments supplied") -- cgit From b85e089f807249eacc66172e56a1a69d450fafba Mon Sep 17 00:00:00 2001 From: Lvov Maxim Date: Mon, 30 May 2011 11:30:22 +0400 Subject: project_id moved to be last --- bin/nova-manage | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 3d09f9064..8faf072bc 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -515,12 +515,12 @@ class NetworkCommands(object): """Class for managing networks.""" def create(self, fixed_range=None, num_networks=None, - network_size=None, vlan_start=None, project_id=None, - vpn_start=None, fixed_range_v6=None, label='public'): + network_size=None, vlan_start=None, vpn_start=None, + fixed_range_v6=None, label='public', project_id=None): """Creates fixed ips for host by range arguments: fixed_range=FLAG, [num_networks=FLAG], - [network_size=FLAG], [vlan_start=FLAG], [project_id=None], - [vpn_start=FLAG], [fixed_range_v6=FLAG]""" + [network_size=FLAG], [vlan_start=FLAG], [vpn_start=FLAG], + [fixed_range_v6=FLAG], [project_id=None]""" if not fixed_range: msg = _('Fixed range in the form of 10.0.0.0/8 is ' 'required to create networks.') -- cgit From f53e7d16181e0a7141956d835f71c09d76508c2d Mon Sep 17 00:00:00 2001 From: Lvov Maxim Date: Thu, 9 Jun 2011 22:02:01 +0400 Subject: parse options with optparse, options prepended '--' --- bin/nova-manage | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 8faf072bc..76bed16f7 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -62,6 +62,8 @@ import sys import time import IPy +from inspect import getargspec +from optparse import OptionParser # 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... @@ -1133,14 +1135,18 @@ def main(): matches = lazy_match(action, actions) action, fn = matches[0] - fn_args, fn_kwargs = [], {} - for arg in argv: - if '=' in arg: - key, value = arg.split('=') - fn_kwargs[key] = value - else: - fn_args.append(arg) - + func_args = getargspec(fn).args + parser = OptionParser() + for arg in func_args: + dasharg = "--%s" % arg + parser.add_option(dasharg) + + (opts, fn_args) = parser.parse_args(argv) + fn_kwargs = vars(opts) + for k, v in fn_kwargs.items(): + if v is None: + del fn_kwargs[k] + # call the action with the remaining arguments try: fn(*fn_args, **fn_kwargs) -- cgit From 3f69522284833a52373ccf1e1006d9b2f20ccb06 Mon Sep 17 00:00:00 2001 From: Lvov Maxim Date: Fri, 10 Jun 2011 17:33:54 +0400 Subject: decorators for action methods added --- .bzrignore | 3 +++ bin/nova-manage | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/.bzrignore b/.bzrignore index 14d8028f7..351b2bef7 100644 --- a/.bzrignore +++ b/.bzrignore @@ -13,3 +13,6 @@ nova/vcsversion.py clean.sqlite run_tests.log tests.sqlite +nova/tests/instance-* +tags + diff --git a/bin/nova-manage b/bin/nova-manage index 76bed16f7..2903e411c 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -105,6 +105,21 @@ flags.DEFINE_flag(flags.HelpshortFlag()) flags.DEFINE_flag(flags.HelpXMLFlag()) +# Decorators for actions +def positionargs(*args, **kwargs): + def _decorator(func): + req = args[-1] + func.__dict__['arguments'] = ' '.join("%s" % i for i in args[:req]) + func.__dict__['optargs'] = ' '.join("%s" % i for i in args[req:-1]) + return func + return _decorator + +def optionargs(*args, **kwargs): + def _decorator(func): + func.__dict__.setdefault('options', []).insert(0, (args, kwargs)) + return func + return _decorator + def param2id(object_id): """Helper function to convert various id types to internal id. args: [object_id], e.g. 'vol-0000000a' or 'volume-0000000a' or '10' @@ -515,7 +530,11 @@ class FloatingIpCommands(object): class NetworkCommands(object): """Class for managing networks.""" - + @optionargs('--project', dest="project_id", help='Project for network') + @optionargs('--vlan', dest="vlan_start", help='VLAN ID') + @positionargs('fixed_range', 'num_networks', + 'network_size', 'vlan_start', 'vpn_start', + 'fixed_range_v6', 'label', 'project_id', 1) def create(self, fixed_range=None, num_networks=None, network_size=None, vlan_start=None, vpn_start=None, fixed_range_v6=None, label='public', project_id=None): @@ -1135,25 +1154,25 @@ def main(): matches = lazy_match(action, actions) action, fn = matches[0] - func_args = getargspec(fn).args - parser = OptionParser() - for arg in func_args: - dasharg = "--%s" % arg - parser.add_option(dasharg) - + usage = "%prog " + "%s %s %s [%s] [options]" % (sys.argv[2], + sys.argv[3], fn.arguments, fn.optargs) + parser = OptionParser(usage=usage) + for ar, kw in fn.options: + parser.add_option(*ar, **kw) (opts, fn_args) = parser.parse_args(argv) fn_kwargs = vars(opts) + for k, v in fn_kwargs.items(): if v is None: del fn_kwargs[k] - + # call the action with the remaining arguments try: fn(*fn_args, **fn_kwargs) sys.exit(0) except TypeError: print _("Possible wrong number of arguments supplied") - print "%s %s: %s" % (category, action, fn.__doc__) + print "" raise except Exception: print _("Command failed, please check log for more info") -- cgit From 8de8ed78c2d3d6ca8342134234e0cc361611de54 Mon Sep 17 00:00:00 2001 From: Lvov Maxim Date: Sat, 11 Jun 2011 00:30:30 +0400 Subject: removed posargs decorator, all methods decorated --- bin/nova-manage | 146 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 126 insertions(+), 20 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index ce9f07f56..0b92c349a 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -61,7 +61,6 @@ import sys import time import IPy -from inspect import getargspec from optparse import OptionParser # If ../nova/__init__.py exists, add ../ to Python search path, so that @@ -107,15 +106,7 @@ flags.DEFINE_flag(flags.HelpXMLFlag()) # Decorators for actions -def positionargs(*args, **kwargs): - def _decorator(func): - req = args[-1] - func.__dict__['arguments'] = ' '.join("%s" % i for i in args[:req]) - func.__dict__['optargs'] = ' '.join("%s" % i for i in args[req:-1]) - return func - return _decorator - -def optionargs(*args, **kwargs): +def args(*args, **kwargs): def _decorator(func): func.__dict__.setdefault('options', []).insert(0, (args, kwargs)) return func @@ -138,6 +129,7 @@ class VpnCommands(object): self.manager = manager.AuthManager() self.pipe = pipelib.CloudPipe() + @args('--project', dest="project", metavar='', help='Project name') def list(self, project=None): """Print a listing of the VPN data for one or all projects. @@ -183,10 +175,12 @@ class VpnCommands(object): self.pipe.launch_vpn_instance(p.id) time.sleep(10) + @args('--project', dest="project_id", metavar='', help='Project name') def run(self, project_id): """Start the VPN for a given project.""" self.pipe.launch_vpn_instance(project_id) + @args('--project', dest="project_id", metavar='', help='Project name') def change(self, project_id, ip, port): """Change the ip and port for a vpn. @@ -222,6 +216,7 @@ class ShellCommands(object): Falls back to Python shell if unavailable""" self.run('python') + @args('--shell', dest="shell", metavar='', help='Python shell') def run(self, shell=None): """Runs a Python interactive interpreter. @@ -259,6 +254,7 @@ class ShellCommands(object): readline.parse_and_bind("tab:complete") code.interact() + @args('--path', dest='path', metavar='', help='Script path') def script(self, path): """Runs the script from the specifed path with flags set properly. arguments: path""" @@ -271,12 +267,18 @@ class RoleCommands(object): def __init__(self): self.manager = manager.AuthManager() + @args('--user', dest="user", metavar='', help='User name') + @args('--role', dest="role", metavar='', help='User role') + @args('--project', dest="project", metavar='', help='Project name') def add(self, user, role, project=None): """adds role to user if project is specified, adds project specific role arguments: user, role [project]""" self.manager.add_role(user, role, project) + @args('--user', dest="user", metavar='', help='User name') + @args('--role', dest="role", metavar='', help='User role') + @args('--project', dest="project", metavar='', help='Project name') def has(self, user, role, project=None): """checks to see if user has role if project is specified, returns True if user has @@ -284,6 +286,9 @@ class RoleCommands(object): arguments: user, role [project]""" print self.manager.has_role(user, role, project) + @args('--user', dest="user", metavar='', help='User name') + @args('--role', dest="role", metavar='', help='User role') + @args('--project', dest="project", metavar='', help='Project name') def remove(self, user, role, project=None): """removes role from user if project is specified, removes project specific role @@ -311,6 +316,9 @@ class UserCommands(object): def __init__(self): self.manager = manager.AuthManager() + @args('--name', dest="name", metavar='', help='Admin name') + @args('--access', dest="access", metavar='', help='Access') + @args('--secret', dest="secret", metavar='', help='Secret') def admin(self, name, access=None, secret=None): """creates a new admin and prints exports arguments: name [access] [secret]""" @@ -320,6 +328,9 @@ class UserCommands(object): _db_error(e) self._print_export(user) + @args('--name', dest="name", metavar='', help='User name') + @args('--access', dest="access", metavar='', help='Access') + @args('--secret', dest="secret", metavar='', help='Secret') def create(self, name, access=None, secret=None): """creates a new user and prints exports arguments: name [access] [secret]""" @@ -329,11 +340,13 @@ class UserCommands(object): _db_error(e) self._print_export(user) + @args('--name', dest="name", metavar='', help='User name') def delete(self, name): """deletes an existing user arguments: name""" self.manager.delete_user(name) + @args('--name', dest="name", metavar='', help='User name') def exports(self, name): """prints access and secrets for user in export format arguments: name""" @@ -349,6 +362,10 @@ class UserCommands(object): for user in self.manager.get_users(): print user.name + @args('--name', dest="name", metavar='', help='User name') + @args('--access', dest="access_key", metavar='', help='Access key') + @args('--secret', dest="secret_key", metavar='', help='Secret key') + @args('--is_admin', dest='is_admin', metavar="<'T'|'F'>", help='Is admin?') def modify(self, name, access_key, secret_key, is_admin): """update a users keys & admin flag arguments: accesskey secretkey admin @@ -362,6 +379,8 @@ class UserCommands(object): is_admin = False self.manager.modify_user(name, access_key, secret_key, is_admin) + @args('--name', dest="user_id", metavar='', help='User name') + @args('--project', dest="project_id", metavar='', help='Project name') def revoke(self, user_id, project_id=None): """revoke certs for a user arguments: user_id [project_id]""" @@ -377,6 +396,8 @@ class ProjectCommands(object): def __init__(self): self.manager = manager.AuthManager() + @args('--project', dest="project_id", metavar='', help='Project name') + @args('--user', dest="user_id", metavar='', help='User name') def add(self, project_id, user_id): """Adds user to project arguments: project_id user_id""" @@ -386,6 +407,9 @@ class ProjectCommands(object): print ex raise + @args('--project', dest="name", metavar='', help='Project name') + @args('--user', dest="project_manager", metavar='', help='Project manager') + @args('--desc', dest="description", metavar='', help='Description') def create(self, name, project_manager, description=None): """Creates a new project arguments: name project_manager [description]""" @@ -395,6 +419,9 @@ class ProjectCommands(object): print ex raise + @args('--project', dest="name", metavar='', help='Project name') + @args('--user', dest="project_manager", metavar='', help='Project manager') + @args('--desc', dest="description", metavar='', help='Description') def modify(self, name, project_manager, description=None): """Modifies a project arguments: name project_manager [description]""" @@ -404,6 +431,7 @@ class ProjectCommands(object): print ex raise + @args('--project', dest="name", metavar='', help='Project name') def delete(self, name): """Deletes an existing project arguments: name""" @@ -413,6 +441,9 @@ class ProjectCommands(object): print ex raise + @args('--project', dest="project_id", metavar='', help='Project name') + @args('--user', dest="user_id", metavar='', help='User name') + @args('--file', dest="filename", metavar='', help='File name(Default: novarc)') def environment(self, project_id, user_id, filename='novarc'): """Exports environment variables to an sourcable file arguments: project_id user_id [filename='novarc]""" @@ -424,12 +455,16 @@ class ProjectCommands(object): with open(filename, 'w') as f: f.write(rc) + @args('--user', dest="username", metavar='', help='User name') def list(self, username=None): """Lists all projects arguments: [username]""" for project in self.manager.get_projects(username): print project.name + @args('--project', dest="project_id", metavar='', help='Project name') + @args('--key', dest="key", metavar='', help='Key') + @args('--value', dest="value", metavar='', help='Value') def quota(self, project_id, key=None, value=None): """Set or display quotas for project arguments: project_id [key] [value]""" @@ -447,6 +482,8 @@ class ProjectCommands(object): value = 'unlimited' print '%s: %s' % (key, value) + @args('--project', dest="project_id", metavar='', help='Project name') + @args('--user', dest="user_id", metavar='', help='User name') def remove(self, project_id, user_id): """Removes user from project arguments: project_id user_id""" @@ -456,6 +493,7 @@ class ProjectCommands(object): print ex raise + @args('--project', dest="project_id", metavar='', help='Project name') def scrub(self, project_id): """Deletes data associated with project arguments: project_id""" @@ -466,6 +504,9 @@ class ProjectCommands(object): for group in groups: db.security_group_destroy(ctxt, group['id']) + @args('--project', dest="project_id", metavar='', help='Project name') + @args('--user', dest="user_id", metavar='', help='User name') + @args('--file', dest="filename", metavar='', help='File name(Default: nova.zip)') def zipfile(self, project_id, user_id, filename='nova.zip'): """Exports credentials for project to a zip file arguments: project_id user_id [filename='nova.zip]""" @@ -492,6 +533,7 @@ AccountCommands = ProjectCommands class FixedIpCommands(object): """Class for managing fixed ip.""" + @args('--host', dest="host", metavar='', help='Host') def list(self, host=None): """Lists all fixed ips (optionally by host) arguments: [host]""" ctxt = context.get_admin_context() @@ -528,6 +570,8 @@ class FixedIpCommands(object): class FloatingIpCommands(object): """Class for managing floating ip.""" + @args('--host', dest="host", metavar='', help='Host') + @args('--ip_range', dest="range", metavar='', help='IP range') def create(self, host, range): """Creates floating ips for host by range arguments: host ip_range""" @@ -536,6 +580,7 @@ class FloatingIpCommands(object): {'address': str(address), 'host': host}) + @args('--ip_range', dest="ip_range", metavar='', help='IP range') def delete(self, ip_range): """Deletes floating ips by range arguments: range""" @@ -543,6 +588,7 @@ class FloatingIpCommands(object): db.floating_ip_destroy(context.get_admin_context(), str(address)) + @args('--host', dest="host", metavar='', help='Host') def list(self, host=None): """Lists all floating ips (optionally by host) arguments: [host]""" @@ -563,11 +609,14 @@ class FloatingIpCommands(object): class NetworkCommands(object): """Class for managing networks.""" - @optionargs('--project', dest="project_id", help='Project for network') - @optionargs('--vlan', dest="vlan_start", help='VLAN ID') - @positionargs('fixed_range', 'num_networks', - 'network_size', 'vlan_start', 'vpn_start', - 'fixed_range_v6', 'gateway_v6', 'label', 'project_id', 1) + @args('--network', dest="fixed_range", metavar='', help='Network') + @args('--num_networks', dest="num_networks", metavar='', help='How many networks create') + @args('--network_size', dest="network_size", metavar='', help='How many hosts in network') + @args('--vlan', dest="vlan_start", metavar='', help='vlan id') + @args('--vpn', dest="vpn_start", help='vpn start') + @args('--fixed_range_v6', dest="fixed_range_v6", help='fixed ipv6 range') + @args('--gateway_v6', dest="gateway_v6", help='ipv6 gateway') + @args('--project', dest="project_id", metavar='', help='Project for network') def create(self, fixed_range=None, num_networks=None, network_size=None, vlan_start=None, vpn_start=None, fixed_range_v6=None, gateway_v6=None, label='public', project_id=None): @@ -618,6 +667,7 @@ class NetworkCommands(object): network.dhcp_start, network.dns) + @args('--network', dest="fixed_range", metavar='', help='Network to delete') def delete(self, fixed_range): """Deletes a network""" network = db.network_get_by_cidr(context.get_admin_context(), \ @@ -631,6 +681,7 @@ class NetworkCommands(object): class VmCommands(object): """Class for mangaging VM instances.""" + @args('--host', dest="host", metavar='', help='Host') def list(self, host=None): """Show a list of all instances @@ -674,6 +725,8 @@ class VmCommands(object): instance['availability_zone'], instance['launch_index']) + @args('--ec2_id', dest='ec2_id', metavar='', help='EC2 ID') + @args('--dest', dest='dest', metavar='', help='destanation node') def live_migration(self, ec2_id, dest): """Migrates a running instance to a new machine. @@ -710,6 +763,8 @@ class VmCommands(object): class ServiceCommands(object): """Enable and disable running services""" + @args('--host', dest='host', metavar='', help='Host') + @args('--service', dest='service', metavar='', help='Nova service') def list(self, host=None, service=None): """Show a list of all running services. Filter by host & service name. args: [host] [service]""" @@ -731,6 +786,8 @@ class ServiceCommands(object): active, art, svc['updated_at']) + @args('--host', dest='host', metavar='', help='Host') + @args('--service', dest='service', metavar='', help='Nova service') def enable(self, host, service): """Enable scheduling for a service args: host service""" @@ -741,6 +798,8 @@ class ServiceCommands(object): return db.service_update(ctxt, svc['id'], {'disabled': False}) + @args('--host', dest='host', metavar='', help='Host') + @args('--service', dest='service', metavar='', help='Nova service') def disable(self, host, service): """Disable scheduling for a service args: host service""" @@ -751,6 +810,7 @@ class ServiceCommands(object): return db.service_update(ctxt, svc['id'], {'disabled': True}) + @args('--host', dest='host', metavar='', help='Host') def describe_resource(self, host): """Describes cpu/memory/hdd info for host. @@ -784,6 +844,7 @@ class ServiceCommands(object): val['memory_mb'], val['local_gb']) + @args('--host', dest='host', metavar='', help='Host') def update_resource(self, host): """Updates available vcpu/memory/disk info for host. @@ -811,6 +872,7 @@ class DbCommands(object): def __init__(self): pass + @args('--version', dest='version', metavar='', help='Database version') def sync(self, version=None): """Sync the database up to the most recent version.""" return migration.db_sync(version) @@ -834,10 +896,11 @@ class VersionCommands(object): class VolumeCommands(object): """Methods for dealing with a cloud in an odd state""" + @args('--volume', dest='volume_id', metavar='', help='Volume ID') def delete(self, volume_id): """Delete a volume, bypassing the check that it must be available. - args: volume_id_id""" + args: volume_id""" ctxt = context.get_admin_context() volume = db.volume_get(ctxt, param2id(volume_id)) host = volume['host'] @@ -858,6 +921,7 @@ class VolumeCommands(object): {"method": "delete_volume", "args": {"volume_id": volume['id']}}) + @args('--volume', dest='volume_id', metavar='', help='Volume ID') def reattach(self, volume_id): """Re-attach a volume that has previously been attached to an instance. Typically called after a compute host @@ -889,6 +953,14 @@ class InstanceTypeCommands(object): val["flavorid"], val["swap"], val["rxtx_quota"], val["rxtx_cap"], deleted) + @args('--name', dest='name', metavar='', help='Name of instance type/flavor') + @args('--memory', dest='memory', metavar='', help='Memory size') + @args('--cpu', dest='vcpus', metavar='', help='Number cpus') + @args('--local_gb', dest='local_gb', metavar='', help='local_gb') + @args('--flavor', dest='flavorid', metavar='', help='Flavor ID') + @args('--swap', dest='swap', metavar='', help='Swap') + @args('--rxtx_quota', dest='rxtx_quota', metavar='', help='rxtx_quota') + @args('--rxtx_cap', dest='rxtx_cap', metavar='', help='rxtx_cap') def create(self, name, memory, vcpus, local_gb, flavorid, swap=0, rxtx_quota=0, rxtx_cap=0): """Creates instance types / flavors @@ -917,6 +989,7 @@ class InstanceTypeCommands(object): else: print "%s created" % name + @args('--name', dest='name', metavar='', help='Name of instance type/flavor') def delete(self, name, purge=None): """Marks instance types / flavors as deleted arguments: name""" @@ -938,6 +1011,7 @@ class InstanceTypeCommands(object): else: print "%s %s" % (name, verb) + @args('--name', dest='name', metavar='', help='Name of instance type/flavor') def list(self, name=None): """Lists all active or specific instance types / flavors arguments: [name]""" @@ -988,6 +1062,13 @@ class ImageCommands(object): except Exception as exc: print _("Failed to register %(path)s: %(exc)s") % locals() + @args('--image', dest='image', metavar='', help='Image') + @args('--kernel', dest='kernel', metavar='', help='Kernel') + @args('--ram', dest='ramdisk', metavar='', help='RAM disk') + @args('--owner', dest='owner', metavar='', help='Image owner') + @args('--name', dest='name', metavar='', help='Image name') + @args('--public', dest='is_public', metavar="<'T'|'F'>", help='Image public or not') + @args('--arch', dest='architecture', metavar='', help='Architecture') def all_register(self, image, kernel, ramdisk, owner, name=None, is_public='T', architecture='x86_64'): """Uploads an image, kernel, and ramdisk into the image_service @@ -1001,6 +1082,15 @@ class ImageCommands(object): architecture, 'ami', 'ami', kernel_id, ramdisk_id) + @args('--path', dest='path', metavar='', help='Image path') + @args('--owner', dest='owner', metavar='', help='Image owner') + @args('--name', dest='name', metavar='', help='Image name') + @args('--public', dest='is_public', metavar="<'T'|'F'>", help='Image public or not') + @args('--arch', dest='architecture', metavar='', help='Architecture') + @args('--cont_format', dest='container_format', metavar='', help='Container format(default: bare)') + @args('--disk_format', dest='disk_format', metavar='', help='Disk format(default: raw)') + @args('--kernel', dest='kernel_id', metavar='', help='Kernel') + @args('--ram', dest='ramdisk_id', metavar='', help='RAM disk') def image_register(self, path, owner, name=None, is_public='T', architecture='x86_64', container_format='bare', disk_format='raw', kernel_id=None, ramdisk_id=None): @@ -1013,6 +1103,11 @@ class ImageCommands(object): owner, name, is_public, architecture, kernel_id, ramdisk_id) + @args('--path', dest='path', metavar='', help='Image path') + @args('--owner', dest='owner', metavar='', help='Image owner') + @args('--name', dest='name', metavar='', help='Image name') + @args('--public', dest='is_public', metavar="<'T'|'F'>", help='Image public or not') + @args('--arch', dest='architecture', metavar='', help='Architecture') def kernel_register(self, path, owner, name=None, is_public='T', architecture='x86_64'): """Uploads a kernel into the image_service @@ -1021,6 +1116,11 @@ class ImageCommands(object): return self._register('aki', 'aki', path, owner, name, is_public, architecture) + @args('--path', dest='path', metavar='', help='Image path') + @args('--owner', dest='owner', metavar='', help='Image owner') + @args('--name', dest='name', metavar='', help='Image name') + @args('--public', dest='is_public', metavar="<'T'|'F'>", help='Image public or not') + @args('--arch', dest='architecture', metavar='', help='Architecture') def ramdisk_register(self, path, owner, name=None, is_public='T', architecture='x86_64'): """Uploads a ramdisk into the image_service @@ -1074,6 +1174,7 @@ class ImageCommands(object): except Exception as exc: print _("Failed to convert %(old)s: %(exc)s") % locals() + @args('--dir', dest='directory', metavar='', help='Images directory') def convert(self, directory): """Uploads old objectstore images in directory to new service arguments: directory""" @@ -1199,10 +1300,14 @@ def main(): matches = lazy_match(action, actions) action, fn = matches[0] - usage = "%prog " + "%s %s %s [%s] [options]" % (sys.argv[2], - sys.argv[3], fn.arguments, fn.optargs) + # For not decorated methods + arguments = getattr(fn ,'arguments', '') + optargs = getattr(fn ,'optargs', '') + options = getattr(fn ,'options', '') + + usage = "%prog " + "%s %s [options]" % (sys.argv[2], sys.argv[3]) parser = OptionParser(usage=usage) - for ar, kw in fn.options: + for ar, kw in options: parser.add_option(*ar, **kw) (opts, fn_args) = parser.parse_args(argv) fn_kwargs = vars(opts) @@ -1217,7 +1322,8 @@ def main(): sys.exit(0) except TypeError: print _("Possible wrong number of arguments supplied") - print "" + print fn.__doc__ + parser.print_help() raise except Exception: print _("Command failed, please check log for more info") -- cgit From 8ded8e4bde3825efc8a886aad40d54d0c9d126dc Mon Sep 17 00:00:00 2001 From: Lvov Maxim Date: Sat, 11 Jun 2011 00:42:44 +0400 Subject: small pep8 fixes --- bin/nova-manage | 6 +++--- nova/network/manager.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 0b92c349a..23ebe3c93 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -1301,9 +1301,9 @@ def main(): action, fn = matches[0] # For not decorated methods - arguments = getattr(fn ,'arguments', '') - optargs = getattr(fn ,'optargs', '') - options = getattr(fn ,'options', '') + arguments = getattr(fn, 'arguments', '') + optargs = getattr(fn, 'optargs', '') + options = getattr(fn, 'options', '') usage = "%prog " + "%s %s [options]" % (sys.argv[2], sys.argv[3]) parser = OptionParser(usage=usage) diff --git a/nova/network/manager.py b/nova/network/manager.py index ad93114fe..a7f5aac60 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -571,7 +571,7 @@ class VlanManager(NetworkManager): net['dhcp_start'] = str(project_net[3]) net['vlan'] = vlan net['bridge'] = 'br%s' % vlan - if kwargs.has_key('project_id'): + if 'project_id' in kwargs: net['project_id'] = kwargs['project_id'] if(FLAGS.use_ipv6): cidr_v6 = '%s/%s' % (fixed_net_v6[start_v6], -- cgit From 3a83aaf4f14ac25dee8b5a84779a61ca4633012a Mon Sep 17 00:00:00 2001 From: Lvov Maxim Date: Sat, 11 Jun 2011 00:49:03 +0400 Subject: 'network list' prints project id --- bin/nova-manage | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 23ebe3c93..67cf0bd51 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -657,15 +657,17 @@ class NetworkCommands(object): def list(self): """List all created networks""" - print "%-18s\t%-15s\t%-15s\t%-15s" % (_('network'), + print "%-18s\t%-15s\t%-15s\t%-15s\t%-15s" % (_('network'), _('netmask'), _('start address'), - 'DNS') + 'DNS', + 'project') for network in db.network_get_all(context.get_admin_context()): - print "%-18s\t%-15s\t%-15s\t%-15s" % (network.cidr, + print "%-18s\t%-15s\t%-15s\t%-15s\t%-15s" % (network.cidr, network.netmask, network.dhcp_start, - network.dns) + network.dns, + network.project_id) @args('--network', dest="fixed_range", metavar='', help='Network to delete') def delete(self, fixed_range): -- cgit From faed18358f534ed7a743fcd168d649d06da092ab Mon Sep 17 00:00:00 2001 From: Arvind Somy Date: Fri, 17 Jun 2011 14:02:24 -0400 Subject: Fix for Bug lp:796813 - Adding support for distributed virtual portgroups on vmware ESX(i) --- Authors | 1 + nova/virt/vmwareapi/network_utils.py | 29 ++++++++++++++++++++++++----- nova/virt/vmwareapi/vm_util.py | 23 ++++++++++++++++++----- nova/virt/vmwareapi/vmops.py | 7 ++++--- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/Authors b/Authors index 94fcf7f5b..0d79af2c7 100644 --- a/Authors +++ b/Authors @@ -6,6 +6,7 @@ Anne Gentle Anthony Young Antony Messerli Armando Migliaccio +Arvind Somya Bilal Akhtar Brian Lamar Brian Schott diff --git a/nova/virt/vmwareapi/network_utils.py b/nova/virt/vmwareapi/network_utils.py index e77842535..345cd2bd0 100644 --- a/nova/virt/vmwareapi/network_utils.py +++ b/nova/virt/vmwareapi/network_utils.py @@ -45,11 +45,30 @@ def get_network_with_the_name(session, network_name="vmnet0"): networks = session._call_method(vim_util, "get_properties_for_a_collection_of_objects", "Network", vm_networks, ["summary.name"]) - for network in networks: - if network.propSet[0].val == network_name: - return network.obj - return None - + network_obj = {} + for network in vm_networks: + # Get network properties + if network._type == 'DistributedVirtualPortgroup': + props = session._call_method(vim_util, + "get_dynamic_property",network, + "DistributedVirtualPortgroup","config") + # NOTE: This only works on ESXi if the port binding is + # set to ephemeral + if props.name == network_name: + network_obj['type'] = 'DistributedVirtualPortgroup' + network_obj['dvpg'] = props.key + network_obj['dvsw'] = props.distributedVirtualSwitch.value + else: + props = session._call_method(vim_util, + "get_dynamic_property",network, + "Network","summary.name") + if props == network_name: + network_obj['type'] = 'Network' + network_obj['name'] = network_name + if (len(network_obj) > 0): + return network_obj + else: + return None def get_vswitch_for_vlan_interface(session, vlan_interface): """ diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index a2fa7600c..d23472469 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -40,7 +40,7 @@ def split_datastore_path(datastore_path): def get_vm_create_spec(client_factory, instance, data_store_name, network_name="vmnet0", - os_type="otherGuest"): + os_type="otherGuest", network_ref=None): """Builds the VM Create spec.""" config_spec = client_factory.create('ns0:VirtualMachineConfigSpec') config_spec.name = instance.name @@ -89,7 +89,7 @@ def create_controller_spec(client_factory, key): return virtual_device_config -def create_network_spec(client_factory, network_name, mac_address): +def create_network_spec(client_factory, network_name, mac_address,network_ref=None): """ Builds a config spec for the addition of a new network adapter to the VM. @@ -101,9 +101,22 @@ def create_network_spec(client_factory, network_name, mac_address): # Get the recommended card type for the VM based on the guest OS of the VM net_device = client_factory.create('ns0:VirtualPCNet32') - backing = \ - client_factory.create('ns0:VirtualEthernetCardNetworkBackingInfo') - backing.deviceName = network_name + # NOTE: Only works on ESXi if the portgroup binding is set to + # ephemeral. Invalid configuration if set to static and the NIC does + # not come up on boot if set to dynamic. + backing = None + if (network_ref['type'] == "DistributedVirtualPortgroup"): + backing = \ + client_factory.create('ns0:VirtualEthernetCardDistributedVirtualPortBackingInfo') + portgroup = \ + client_factory.create('ns0:DistributedVirtualSwitchPortConnection') + portgroup.switchUuid = network_ref['dvsw'] + portgroup.portgroupKey = network_ref['dvpg'] + backing.port = portgroup + else: + backing = \ + client_factory.create('ns0:VirtualEthernetCardNetworkBackingInfo') + backing.deviceName = network_name connectable_spec = \ client_factory.create('ns0:VirtualDeviceConnectInfo') diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index 5f76b0df5..d23edbdf8 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -116,8 +116,9 @@ class VMWareVMOps(object): net_name) if network_ref is None: raise exception.NetworkNotFoundForBridge(bridge=net_name) - - _check_if_network_bridge_exists() + return network_ref + + network_obj = _check_if_network_bridge_exists() def _get_datastore_ref(): """Get the datastore list and choose the first local storage.""" @@ -176,7 +177,7 @@ class VMWareVMOps(object): # Get the create vm config spec config_spec = vm_util.get_vm_create_spec(client_factory, instance, - data_store_name, net_name, os_type) + data_store_name, net_name, os_type, network_obj) def _execute_create_vm(): """Create VM on ESX host.""" -- cgit From c3af5e65508fb325a4a8e350c9ed6d84d87e7cd8 Mon Sep 17 00:00:00 2001 From: Arvind Somy Date: Fri, 17 Jun 2011 15:12:01 -0400 Subject: Fix for lp:796834 - Fixes and enhancements to the ESX(i) guest_tool.py script. --- nova/virt/vmwareapi/vm_util.py | 4 ++-- nova/virt/vmwareapi/vmops.py | 5 ++++- tools/esx/guest_tool.py | 49 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index d23472469..c823ac710 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -287,9 +287,9 @@ def get_dummy_vm_create_spec(client_factory, name, data_store_name): return config_spec -def get_machine_id_change_spec(client_factory, mac, ip_addr, netmask, gateway): +def get_machine_id_change_spec(client_factory, mac, ip_addr, netmask, gateway, broadcast, dns): """Builds the machine id change config spec.""" - machine_id_str = "%s;%s;%s;%s" % (mac, ip_addr, netmask, gateway) + machine_id_str = "%s;%s;%s;%s;%s;%s" % (mac, ip_addr, netmask, gateway, broadcast, dns) virtual_machine_config_spec = \ client_factory.create('ns0:VirtualMachineConfigSpec') diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index d23edbdf8..9f2a36bf4 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -715,11 +715,14 @@ class VMWareVMOps(object): mac_addr = instance.mac_address net_mask = network["netmask"] gateway = network["gateway"] + broadcast = network["broadcast"] + dns = network["dns"] ip_addr = db.instance_get_fixed_address(context.get_admin_context(), instance['id']) machine_id_chanfge_spec = \ vm_util.get_machine_id_change_spec(client_factory, mac_addr, - ip_addr, net_mask, gateway) + ip_addr, net_mask, gateway, + broadcast, dns) LOG.debug(_("Reconfiguring VM instance %(name)s to set the machine id " "with ip - %(ip_addr)s") % ({'name': instance.name, diff --git a/tools/esx/guest_tool.py b/tools/esx/guest_tool.py index 13b0f8d33..e126721d5 100644 --- a/tools/esx/guest_tool.py +++ b/tools/esx/guest_tool.py @@ -21,6 +21,7 @@ On Windows we require pyWin32 installed on Python. """ import array +import gettext import logging import os import platform @@ -30,6 +31,8 @@ import subprocess import sys import time +_ = gettext.gettext + PLATFORM_WIN = 'win32' PLATFORM_LINUX = 'linux2' ARCH_32_BIT = '32bit' @@ -314,6 +317,43 @@ def _set_rhel_networking(network_details=[]): dns_file.close() _execute(['/sbin/service', 'network', 'restart']) +def _set_ubuntu_networking(network_details=[]): + """ Set IPv4 network settings for Ubuntu """ + all_dns_servers = [] + for network_detail in network_details: + mac_address, ip_address, subnet_mask, gateway, broadcast,\ + dns_servers = network_detail + all_dns_servers.extend(dns_servers) + adapter_name, current_ip_address = \ + _get_linux_adapter_name_and_ip_address(mac_address) + + if adapter_name and not ip_address == current_ip_address: + interface_file_name = \ + '/etc/network/interfaces' + # Remove file + os.remove(interface_file_name) + # Touch file + _execute(['touch', interface_file_name]) + interface_file = open(interface_file_name, 'w') + interface_file.write('\nauto %s' % adapter_name) + interface_file.write('\niface %s inet static' % adapter_name) + interface_file.write('\nbroadcast %s' % broadcast) + interface_file.write('\ngateway %s' % gateway) + interface_file.write('\nnetmask %s' % subnet_mask) + interface_file.write('\naddress %s' % ip_address) + interface_file.close() + if all_dns_servers: + dns_file_name = "/etc/resolv.conf" + os.remove(dns_file_name) + _execute(['touch', dns_file_name]) + dns_file = open(dns_file_name, 'w') + dns_file.write("; generated by OpenStack guest tools") + unique_entries = _filter_duplicates(all_dns_servers) + for dns_server in unique_entries: + dns_file.write("\nnameserver %s" % dns_server) + dns_file.close() + print "\nRestarting networking....\n" + _execute(['/etc/init.d/networking', 'restart']) def _linux_set_networking(): """Set IP address for the Linux VM.""" @@ -330,8 +370,13 @@ def _linux_set_networking(): cmd = [vmware_tools_bin, '--cmd', 'machine.id.get'] network_details = _parse_network_details(_execute(cmd, check_exit_code=False)) - # TODO(sateesh): For other distros like ubuntu, suse, debian, BSD, etc. - _set_rhel_networking(network_details) + # TODO(sateesh): For other distros like suse, debian, BSD, etc. + if(platform.dist()[0] == 'Ubuntu') : + _set_ubuntu_networking(network_details) + elif (platform.dist()[0] == 'redhat') : + _set_rhel_networking(network_details) + else: + logging.warn(_("Distro '%s' not supported") % platform.dist()[0]) else: logging.warn(_("VMware Tools is not installed")) -- cgit From 03db1b862f38fa864316530c0a0b22ef74f25c81 Mon Sep 17 00:00:00 2001 From: "Arvind Somya asomya@cisco.com" <> Date: Fri, 24 Jun 2011 12:15:13 -0400 Subject: Fixing PEP8 compliance issues. --- nova/virt/vmwareapi/network_utils.py | 11 ++++++----- nova/virt/vmwareapi/vm_util.py | 5 +++-- nova/virt/vmwareapi/vmops.py | 8 +++++--- tools/esx/guest_tool.py | 6 ++++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/nova/virt/vmwareapi/network_utils.py b/nova/virt/vmwareapi/network_utils.py index 345cd2bd0..08e3bf0b1 100644 --- a/nova/virt/vmwareapi/network_utils.py +++ b/nova/virt/vmwareapi/network_utils.py @@ -50,9 +50,9 @@ def get_network_with_the_name(session, network_name="vmnet0"): # Get network properties if network._type == 'DistributedVirtualPortgroup': props = session._call_method(vim_util, - "get_dynamic_property",network, - "DistributedVirtualPortgroup","config") - # NOTE: This only works on ESXi if the port binding is + "get_dynamic_property", network, + "DistributedVirtualPortgroup", "config") + # NOTE(asomya): This only works on ESXi if the port binding is # set to ephemeral if props.name == network_name: network_obj['type'] = 'DistributedVirtualPortgroup' @@ -60,8 +60,8 @@ def get_network_with_the_name(session, network_name="vmnet0"): network_obj['dvsw'] = props.distributedVirtualSwitch.value else: props = session._call_method(vim_util, - "get_dynamic_property",network, - "Network","summary.name") + "get_dynamic_property", network, + "Network", "summary.name") if props == network_name: network_obj['type'] = 'Network' network_obj['name'] = network_name @@ -70,6 +70,7 @@ def get_network_with_the_name(session, network_name="vmnet0"): else: return None + def get_vswitch_for_vlan_interface(session, vlan_interface): """ Gets the vswitch associated with the physical network adapter diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index c823ac710..411305081 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -89,7 +89,8 @@ def create_controller_spec(client_factory, key): return virtual_device_config -def create_network_spec(client_factory, network_name, mac_address,network_ref=None): +def create_network_spec(client_factory, network_name, mac_address, + network_ref=None): """ Builds a config spec for the addition of a new network adapter to the VM. @@ -101,7 +102,7 @@ def create_network_spec(client_factory, network_name, mac_address,network_ref=No # Get the recommended card type for the VM based on the guest OS of the VM net_device = client_factory.create('ns0:VirtualPCNet32') - # NOTE: Only works on ESXi if the portgroup binding is set to + # NOTE: Only works on ESXi if the portgroup binding is set to # ephemeral. Invalid configuration if set to static and the NIC does # not come up on boot if set to dynamic. backing = None diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index 9f2a36bf4..6f8b823c5 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -117,7 +117,7 @@ class VMWareVMOps(object): if network_ref is None: raise exception.NetworkNotFoundForBridge(bridge=net_name) return network_ref - + network_obj = _check_if_network_bridge_exists() def _get_datastore_ref(): @@ -176,8 +176,10 @@ class VMWareVMOps(object): vm_folder_mor, res_pool_mor = _get_vmfolder_and_res_pool_mors() # Get the create vm config spec - config_spec = vm_util.get_vm_create_spec(client_factory, instance, - data_store_name, net_name, os_type, network_obj) + config_spec = vm_util.get_vm_create_spec( + client_factory, instance, + data_store_name, net_name, os_type, + network_obj) def _execute_create_vm(): """Create VM on ESX host.""" diff --git a/tools/esx/guest_tool.py b/tools/esx/guest_tool.py index e126721d5..3463be5dd 100644 --- a/tools/esx/guest_tool.py +++ b/tools/esx/guest_tool.py @@ -317,6 +317,7 @@ def _set_rhel_networking(network_details=[]): dns_file.close() _execute(['/sbin/service', 'network', 'restart']) + def _set_ubuntu_networking(network_details=[]): """ Set IPv4 network settings for Ubuntu """ all_dns_servers = [] @@ -355,6 +356,7 @@ def _set_ubuntu_networking(network_details=[]): print "\nRestarting networking....\n" _execute(['/etc/init.d/networking', 'restart']) + def _linux_set_networking(): """Set IP address for the Linux VM.""" vmware_tools_bin = None @@ -371,9 +373,9 @@ def _linux_set_networking(): network_details = _parse_network_details(_execute(cmd, check_exit_code=False)) # TODO(sateesh): For other distros like suse, debian, BSD, etc. - if(platform.dist()[0] == 'Ubuntu') : + if(platform.dist()[0] == 'Ubuntu'): _set_ubuntu_networking(network_details) - elif (platform.dist()[0] == 'redhat') : + elif (platform.dist()[0] == 'redhat'): _set_rhel_networking(network_details) else: logging.warn(_("Distro '%s' not supported") % platform.dist()[0]) -- cgit From 8ec448d2bcf4afce7d0486d9cf6b07e0e30bd6be Mon Sep 17 00:00:00 2001 From: "Arvind Somya asomya@cisco.com" <> Date: Fri, 24 Jun 2011 12:22:14 -0400 Subject: Fixed the default arguments to None instead of an empty list. --- tools/esx/guest_tool.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/esx/guest_tool.py b/tools/esx/guest_tool.py index 3463be5dd..60ecfcd20 100644 --- a/tools/esx/guest_tool.py +++ b/tools/esx/guest_tool.py @@ -278,7 +278,8 @@ def _filter_duplicates(all_entries): return final_list -def _set_rhel_networking(network_details=[]): +def _set_rhel_networking(network_details=None): + network_details = network_details or [] all_dns_servers = [] for network_detail in network_details: mac_address, ip_address, subnet_mask, gateway, broadcast,\ @@ -318,7 +319,8 @@ def _set_rhel_networking(network_details=[]): _execute(['/sbin/service', 'network', 'restart']) -def _set_ubuntu_networking(network_details=[]): +def _set_ubuntu_networking(network_details=None): + network_details = network_details or [] """ Set IPv4 network settings for Ubuntu """ all_dns_servers = [] for network_detail in network_details: -- cgit From 43713a2e45862219c538ede60363053d36bb0f1b Mon Sep 17 00:00:00 2001 From: Arvind Somy Date: Mon, 27 Jun 2011 14:41:07 -0400 Subject: - Modified NOTE in vm_util.py - Changed gettext line to nova default in guest_tool.py --- nova/virt/vmwareapi/vm_util.py | 2 +- tools/esx/guest_tool.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index 411305081..b93c1f81b 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -102,7 +102,7 @@ def create_network_spec(client_factory, network_name, mac_address, # Get the recommended card type for the VM based on the guest OS of the VM net_device = client_factory.create('ns0:VirtualPCNet32') - # NOTE: Only works on ESXi if the portgroup binding is set to + # NOTE(asomya): Only works on ESXi if the portgroup binding is set to # ephemeral. Invalid configuration if set to static and the NIC does # not come up on boot if set to dynamic. backing = None diff --git a/tools/esx/guest_tool.py b/tools/esx/guest_tool.py index 60ecfcd20..97b5302ba 100644 --- a/tools/esx/guest_tool.py +++ b/tools/esx/guest_tool.py @@ -31,7 +31,7 @@ import subprocess import sys import time -_ = gettext.gettext +gettext.install('nova', unicode=1) PLATFORM_WIN = 'win32' PLATFORM_LINUX = 'linux2' -- cgit From ff195162d97f4a1ffaa6127f92cca102705b023b Mon Sep 17 00:00:00 2001 From: Lvov Maxim Date: Tue, 28 Jun 2011 16:46:50 +0400 Subject: remove network to project bind --- bin/nova-manage | 5 ++--- nova/network/manager.py | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 67cf0bd51..a4b221b8c 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -619,7 +619,7 @@ class NetworkCommands(object): @args('--project', dest="project_id", metavar='', help='Project for network') def create(self, fixed_range=None, num_networks=None, network_size=None, vlan_start=None, vpn_start=None, fixed_range_v6=None, - gateway_v6=None, label='public', project_id=None): + gateway_v6=None, label='public'): """Creates fixed ips for host by range""" if not fixed_range: @@ -649,8 +649,7 @@ class NetworkCommands(object): vpn_start=int(vpn_start), cidr_v6=fixed_range_v6, gateway_v6=gateway_v6, - label=label, - project_id=project_id) + label=label) except ValueError, e: print e raise e diff --git a/nova/network/manager.py b/nova/network/manager.py index a7f5aac60..b5352ca0f 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -571,8 +571,6 @@ class VlanManager(NetworkManager): net['dhcp_start'] = str(project_net[3]) net['vlan'] = vlan net['bridge'] = 'br%s' % vlan - if 'project_id' in kwargs: - net['project_id'] = kwargs['project_id'] if(FLAGS.use_ipv6): cidr_v6 = '%s/%s' % (fixed_net_v6[start_v6], significant_bits_v6) -- cgit From 639717b1eadb769f1d77a4ddcdb6618da4defbea Mon Sep 17 00:00:00 2001 From: William Wolf Date: Thu, 30 Jun 2011 10:06:06 -0400 Subject: added FlavorRef exception handling on create instance --- nova/api/openstack/create_instance_helper.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py index 436e524c1..94ae3bb85 100644 --- a/nova/api/openstack/create_instance_helper.py +++ b/nova/api/openstack/create_instance_helper.py @@ -143,6 +143,10 @@ class CreateInstanceHelper(object): except exception.ImageNotFound as error: msg = _("Can not find requested image") raise faults.Fault(exc.HTTPBadRequest(explanation=msg)) + except exception.FlavorNotFound as error: + msg = _("Invalid flavorRef provided.") + raise faults.Fault(exc.HTTPBadRequest(explanation=msg)) + # Let the caller deal with unhandled exceptions. -- cgit -- cgit From 3a65ea2f29ca169779cbd09acf4f7ac50314c969 Mon Sep 17 00:00:00 2001 From: Kevin Bringard Date: Fri, 1 Jul 2011 11:14:30 -0600 Subject: Changed fixed_ip.network to be fixed_ips.network, which is the correct DB field --- nova/db/sqlalchemy/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index ffd009513..7278ad1f5 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1237,7 +1237,7 @@ def instance_get_project_vpn(context, project_id): options(joinedload_all('fixed_ips.floating_ips')).\ options(joinedload('virtual_interfaces')).\ options(joinedload('security_groups')).\ - options(joinedload_all('fixed_ip.network')).\ + options(joinedload_all('fixed_ips.network')).\ options(joinedload('metadata')).\ options(joinedload('instance_type')).\ filter_by(project_id=project_id).\ -- cgit From 42ef4e0adb7b0ec939f40d5356d4a3d2d03dec9f Mon Sep 17 00:00:00 2001 From: Kevin Bringard Date: Fri, 1 Jul 2011 12:32:26 -0600 Subject: Found some additional fixed_ip. entries in the Intance model contest that needed to be updated --- nova/db/sqlalchemy/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 7278ad1f5..fd7ace4c7 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1141,9 +1141,9 @@ def instance_get_active_by_window(context, begin, end=None): """Return instances that were continuously active over the given window""" session = get_session() query = session.query(models.Instance).\ - options(joinedload_all('fixed_ip.floating_ips')).\ + options(joinedload_all('fixed_ips.floating_ips')).\ options(joinedload('security_groups')).\ - options(joinedload_all('fixed_ip.network')).\ + options(joinedload_all('fixed_ips.network')).\ options(joinedload('instance_type')).\ filter(models.Instance.launched_at < begin) if end: -- cgit From b8b96769bfc49e75d2eee3ae561e4e9ee7615473 Mon Sep 17 00:00:00 2001 From: Yoshiaki Tamura Date: Mon, 4 Jul 2011 13:53:17 +0900 Subject: Fix boot from volume failure for network block devices. This patch looks up the device_path and swithes between 'block' and 'network' when creating libvirt.xml. --- nova/virt/libvirt.xml.template | 6 +++++- nova/virt/libvirt/connection.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index e1a683da8..36d8c5aaa 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -82,9 +82,13 @@ #end if #for $vol in $volumes - + + #if $vol.type == 'network' + + #else + #end if #end for diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 0c6eaab84..3168bb9df 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -971,6 +971,7 @@ class LibvirtConnection(driver.ComputeDriver): return True return False + @exception.wrap_exception def _prepare_xml_info(self, instance, rescue=False, network_info=None, block_device_mapping=None): block_device_mapping = block_device_mapping or [] @@ -993,6 +994,16 @@ class LibvirtConnection(driver.ComputeDriver): for vol in block_device_mapping: vol['mount_device'] = _strip_dev(vol['mount_device']) + if vol['device_path'].startswith('/dev/'): + vol['type'] = 'block' + elif ':' in vol['device_path']: + (protocol, name) = vol['device_path'].split(':') + vol['type'] = 'network' + vol['protocol'] = protocol + vol['device_path'] = name + else: + raise exception.InvalidDevicePath(path=vol['device_path']) + ebs_root = self._volume_in_mapping(self.root_mount_device, block_device_mapping) if self._volume_in_mapping(self.local_mount_device, -- cgit From 01b9d211e606ee0be221b27edae8aab1d35096ff Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 5 Jul 2011 11:51:46 -0700 Subject: First round of changes for ha-flatdhcp. * added 'host' column to fixed_ips to allow associating with a host * added 'multi_host' column to network for multi_host possibility * moved extra db access from linux_net to manager * added host parameter to network calls --- bin/nova-manage | 2 +- nova/db/api.py | 19 ++++-- nova/db/sqlalchemy/api.py | 29 ++++++--- .../migrate_repo/versions/032_ha_network.py | 37 +++++++++++ nova/db/sqlalchemy/models.py | 1 + nova/exception.py | 5 ++ nova/network/api.py | 13 +++- nova/network/linux_net.py | 15 ++--- nova/network/manager.py | 73 +++++++++++++++------- 9 files changed, 144 insertions(+), 50 deletions(-) create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/032_ha_network.py diff --git a/bin/nova-manage b/bin/nova-manage index 7dfe91698..71c99138f 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -494,7 +494,7 @@ class FixedIpCommands(object): if host is None: fixed_ips = db.fixed_ip_get_all(ctxt) else: - fixed_ips = db.fixed_ip_get_all_by_host(ctxt, host) + fixed_ips = db.fixed_ip_get_all_by_instance_host(ctxt, host) except exception.NotFound as ex: print "error: %s" % ex sys.exit(2) diff --git a/nova/db/api.py b/nova/db/api.py index b7c5700e5..febe33374 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -332,13 +332,15 @@ def fixed_ip_associate(context, address, instance_id): return IMPL.fixed_ip_associate(context, address, instance_id) -def fixed_ip_associate_pool(context, network_id, instance_id): - """Find free ip in network and associate it to instance. +def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None): + """Find free ip in network and associate it to instance or host. + If reserved is true, it will pull the ip from the reserved pool. Raises if one is not available. """ - return IMPL.fixed_ip_associate_pool(context, network_id, instance_id) + return IMPL.fixed_ip_associate_pool(context, network_id, + instance_id, host, reserved) def fixed_ip_create(context, values): @@ -361,9 +363,9 @@ def fixed_ip_get_all(context): return IMPL.fixed_ip_get_all(context) -def fixed_ip_get_all_by_host(context, host): - """Get all defined fixed ips used by a host.""" - return IMPL.fixed_ip_get_all_by_host(context, host) +def fixed_ip_get_all_by_instance_host(context, host): + """Get all allocated fixed ips filtered by instance host.""" + return IMPL.fixed_ip_get_all_instance_by_host(context, host) def fixed_ip_get_by_address(context, address): @@ -376,6 +378,11 @@ def fixed_ip_get_by_instance(context, instance_id): return IMPL.fixed_ip_get_by_instance(context, instance_id) +def fixed_ip_get_by_network_host(context, network_id, host): + """Get fixed ip for a host in a network.""" + return IMPL.fixed_ip_get_by_network_host(context, network_id, host) + + def fixed_ip_get_by_virtual_interface(context, vif_id): """Get fixed ips by virtual interface or raise if none exist.""" return IMPL.fixed_ip_get_by_virtual_interface(context, vif_id) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index ffd009513..6db142276 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -18,7 +18,6 @@ """ Implementation of SQLAlchemy backend. """ -import traceback import warnings from nova import db @@ -33,7 +32,6 @@ from sqlalchemy import or_ from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import joinedload from sqlalchemy.orm import joinedload_all -from sqlalchemy.sql import exists from sqlalchemy.sql import func from sqlalchemy.sql.expression import literal_column @@ -657,7 +655,7 @@ def fixed_ip_associate(context, address, instance_id): @require_admin_context -def fixed_ip_associate_pool(context, network_id, instance_id): +def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None): session = get_session() with session.begin(): network_or_none = or_(models.FixedIp.network_id == network_id, @@ -677,9 +675,12 @@ def fixed_ip_associate_pool(context, network_id, instance_id): fixed_ip_ref.network = network_get(context, network_id, session=session) - fixed_ip_ref.instance = instance_get(context, - instance_id, - session=session) + if instance_id: + fixed_ip_ref.instance = instance_get(context, + instance_id, + session=session) + if host: + fixed_ip_ref.host = host session.add(fixed_ip_ref) return fixed_ip_ref['address'] @@ -735,7 +736,7 @@ def fixed_ip_get_all(context, session=None): @require_admin_context -def fixed_ip_get_all_by_host(context, host=None): +def fixed_ip_get_all_by_instance_host(context, host=None): session = get_session() result = session.query(models.FixedIp).\ @@ -784,6 +785,20 @@ def fixed_ip_get_by_instance(context, instance_id): return rv +@require_context +def fixed_ip_get_by_network_host(context, network_id, host): + session = get_session() + rv = session.query(models.FixedIp).\ + filter_by(network_id=network_id).\ + filter_by(host=host).\ + filter_by(deleted=False).\ + all() + if not rv: + raise exception.FixedIpNotFoundForNetworkHost(network_id=network_id, + host=host) + return rv + + @require_context def fixed_ip_get_by_virtual_interface(context, vif_id): session = get_session() diff --git a/nova/db/sqlalchemy/migrate_repo/versions/032_ha_network.py b/nova/db/sqlalchemy/migrate_repo/versions/032_ha_network.py new file mode 100644 index 000000000..316c36cbc --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/032_ha_network.py @@ -0,0 +1,37 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 MORITA Kazutaka. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from sqlalchemy import Column, Table, MetaData, Boolean, String + +meta = MetaData() + +fixed_ips_host = Column('host', String(255)) + +networks_multi_host = Column('multi_host', Boolean, default=False) + + +def upgrade(migrate_engine): + # Upgrade operations go here. Don't create your own engine; + # bind migrate_engine to your metadata + meta.bind = migrate_engine + + # Add columns to existing tables + fixed_ips = Table('fixed_ips', meta, autoload=True) + fixed_ips.create_column(fixed_ips_host) + + networks = Table('networks', meta, autoload=True) + networks.create_column(networks_multi_host) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index d29d3d6f1..8c86870f0 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -543,6 +543,7 @@ class Network(BASE, NovaBase): injected = Column(Boolean, default=False) cidr = Column(String(255), unique=True) cidr_v6 = Column(String(255), unique=True) + multi_host = Column(Boolean, default=False) gateway_v6 = Column(String(255)) netmask_v6 = Column(String(255)) diff --git a/nova/exception.py b/nova/exception.py index a6776b64f..29a209c3e 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -377,6 +377,11 @@ class FixedIpNotFoundForInstance(FixedIpNotFound): message = _("Instance %(instance_id)s has zero fixed ips.") +class FixedIpNotFoundForNetworkHost(FixedIpNotFound): + message = _("Network host %(host)s has zero fixed ips " + "in network %(network_id)s.") + + class FixedIpNotFoundForVirtualInterface(FixedIpNotFound): message = _("Virtual interface %(vif_id)s has zero associated fixed ips.") diff --git a/nova/network/api.py b/nova/network/api.py index b2b96082b..c57394204 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -18,7 +18,6 @@ """Handles all requests relating to instances (guest vms).""" -from nova import db from nova import exception from nova import flags from nova import log as logging @@ -105,7 +104,10 @@ class API(base.Base): '(%(project)s)') % {'address': floating_ip['address'], 'project': context.project_id}) - host = fixed_ip['network']['host'] + if fixed_ip['network']['multi_gateway']: + host = fixed_ip['instance']['host'] + else: + host = fixed_ip['network']['host'] rpc.cast(context, self.db.queue_get_for(context, FLAGS.network_topic, host), {'method': 'associate_floating_ip', @@ -120,7 +122,10 @@ class API(base.Base): return if not floating_ip.get('fixed_ip'): raise exception.ApiError('Address is not associated.') - host = floating_ip['fixed_ip']['network']['host'] + if floating_ip['fixed_ip']['network']['multi_gateway']: + host = floating_ip['fixed_ip']['instance']['host'] + else: + host = floating_ip['fixed_ip']['network']['host'] rpc.call(context, self.db.queue_get_for(context, FLAGS.network_topic, host), {'method': 'disassociate_floating_ip', @@ -134,7 +139,9 @@ class API(base.Base): args = kwargs args['instance_id'] = instance['id'] args['project_id'] = instance['project_id'] + args['host'] = instance['host'] args['instance_type_id'] = instance['instance_type_id'] + return rpc.call(context, FLAGS.network_topic, {'method': 'allocate_for_instance', 'args': args}) diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index 283a5aca1..8d2bc5c0b 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -573,18 +573,16 @@ def get_dhcp_hosts(context, network_id): # configuration options (like dchp-range, vlan, ...) # aren't reloaded. @utils.synchronized('dnsmasq_start') -def update_dhcp(context, network_id): +def update_dhcp(context, network_ref): """(Re)starts a dnsmasq server for a given network. If a dnsmasq instance is already running then send a HUP signal causing it to reload, otherwise spawn a new instance. """ - network_ref = db.network_get(context, network_id) - conffile = _dhcp_file(network_ref['bridge'], 'conf') with open(conffile, 'w') as f: - f.write(get_dhcp_hosts(context, network_id)) + f.write(get_dhcp_hosts(context, network_ref['id'])) # Make sure dnsmasq can actually read it (it setuid()s to "nobody") os.chmod(conffile, 0644) @@ -612,9 +610,7 @@ def update_dhcp(context, network_id): @utils.synchronized('radvd_start') -def update_ra(context, network_id): - network_ref = db.network_get(context, network_id) - +def update_ra(context, network_ref): conffile = _ra_file(network_ref['bridge'], 'conf') with open(conffile, 'w') as f: conf_str = """ @@ -650,9 +646,6 @@ interface %s LOG.debug(_('Pid %d is stale, relaunching radvd'), pid) command = _ra_cmd(network_ref) _execute(*command) - db.network_update(context, network_id, - {'gateway_v6': - utils.get_my_linklocal(network_ref['bridge'])}) def _host_lease(fixed_ip_ref): @@ -704,7 +697,7 @@ def _dnsmasq_cmd(net): '--conf-file=%s' % FLAGS.dnsmasq_config_file, '--domain=%s' % FLAGS.dhcp_domain, '--pid-file=%s' % _dhcp_file(net['bridge'], 'pid'), - '--listen-address=%s' % net['gateway'], + '--listen-address=%s' % net['dhcp_listen'], '--except-interface=lo', '--dhcp-range=%s,static,120s' % net['dhcp_start'], '--dhcp-lease-max=%s' % len(netaddr.IPNetwork(net['cidr'])), diff --git a/nova/network/manager.py b/nova/network/manager.py index d42bc8c4e..f60763eba 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -124,15 +124,17 @@ class RPCAllocateFixedIP(object): used since they share code to RPC.call allocate_fixed_ip on the correct network host to configure dnsmasq """ - def _allocate_fixed_ips(self, context, instance_id, networks): + def _allocate_fixed_ips(self, context, instance_id, host, networks): """Calls allocate_fixed_ip once for each network.""" green_pool = greenpool.GreenPool() for network in networks: - if network['host'] != self.host: + # NOTE(vish): if we are multi_gateway pass to the specified host + if not network['multi_gateway']: + host = network['host'] + if host != self.host: # need to call allocate_fixed_ip to correct network host - topic = self.db.queue_get_for(context, FLAGS.network_topic, - network['host']) + topic = self.db.queue_get_for(context, FLAGS.network_topic, host) args = {} args['instance_id'] = instance_id args['network_id'] = network['id'] @@ -298,6 +300,21 @@ class NetworkManager(manager.SchedulerDependentManager): super(NetworkManager, self).__init__(service_name='network', *args, **kwargs) + def _update_dchp(self, context, network_ref): + """Sets the listen address before sending update to the driver.""" + network_ref['dhcp_listen'] = self._get_dhcp_ip() + return self.driver.update_dhcp(context, network_ref) + + def _get_dhcp_ip(self, context, network_ref): + """Get the proper dhcp address to listen on. + + If it is a multi_host network, get the ip assigned to this host, + otherwise, assume that dhcp is listening on the gateway.""" + if network_ref['multi_host']: + return self.db.network_get_host_ip(context, FLAGS.host) + else: + return network_ref['gateway'] + def init_host(self): """Do any initialization that needs to be run if this is a standalone service. @@ -360,6 +377,7 @@ class NetworkManager(manager.SchedulerDependentManager): rpc.called by network_api """ instance_id = kwargs.pop('instance_id') + host = kwargs.pop('host') project_id = kwargs.pop('project_id') type_id = kwargs.pop('instance_type_id') admin_context = context.elevated() @@ -368,7 +386,7 @@ class NetworkManager(manager.SchedulerDependentManager): networks = self._get_networks_for_instance(admin_context, instance_id, project_id) self._allocate_mac_addresses(context, instance_id, networks) - self._allocate_fixed_ips(admin_context, instance_id, networks) + self._allocate_fixed_ips(admin_context, instance_id, host, networks) return self.get_instance_nw_info(context, instance_id, type_id) def deallocate_for_instance(self, context, **kwargs): @@ -475,10 +493,10 @@ class NetworkManager(manager.SchedulerDependentManager): random.randint(0x00, 0xff)] return ':'.join(map(lambda x: "%02x" % x, mac)) - def add_fixed_ip_to_instance(self, context, instance_id, network_id): + def add_fixed_ip_to_instance(self, context, instance_id, host, network_id): """Adds a fixed ip to an instance from specified network.""" networks = [self.db.network_get(context, network_id)] - self._allocate_fixed_ips(context, instance_id, networks) + self._allocate_fixed_ips(context, instance_id, host, networks) def allocate_fixed_ip(self, context, instance_id, network, **kwargs): """Gets a fixed ip from the pool.""" @@ -540,8 +558,9 @@ class NetworkManager(manager.SchedulerDependentManager): # means there will stale entries in the conf file # the code below will update the file if necessary if FLAGS.update_dhcp_on_disassociate: - network = self.db.fixed_ip_get_network(context, address) - self.driver.update_dhcp(context, network['id']) + network_ref = self.db.fixed_ip_get_network(context, address) + network_ref['dhcp_listen'] = self._get_dhcp_ip(context, network_ref) + self._update_dhcp(context, network_ref) def create_networks(self, context, label, cidr, num_networks, network_size, cidr_v6, gateway_v6, bridge, @@ -637,7 +656,7 @@ class NetworkManager(manager.SchedulerDependentManager): 'address': address, 'reserved': reserved}) - def _allocate_fixed_ips(self, context, instance_id, networks): + def _allocate_fixed_ips(self, context, instance_id, host, networks): """Calls allocate_fixed_ip once for each network.""" raise NotImplementedError() @@ -684,7 +703,7 @@ class FlatManager(NetworkManager): timeout_fixed_ips = False - def _allocate_fixed_ips(self, context, instance_id, networks): + def _allocate_fixed_ips(self, context, instance_id, host, networks): """Calls allocate_fixed_ip once for each network.""" for network in networks: self.allocate_fixed_ip(context, instance_id, network) @@ -738,8 +757,9 @@ class FlatDHCPManager(FloatingIP, RPCAllocateFixedIP, NetworkManager): """ networks = db.network_get_all_by_instance(context, instance_id) for network in networks: - self.driver.ensure_bridge(network['bridge'], - network['bridge_interface']) + if not network['multi_host']: + self.driver.ensure_bridge(network['bridge'], + network['bridge_interface']) def allocate_fixed_ip(self, context, instance_id, network): """Allocate flat_network fixed_ip, then setup dhcp for this network.""" @@ -747,7 +767,7 @@ class FlatDHCPManager(FloatingIP, RPCAllocateFixedIP, NetworkManager): instance_id, network) if not FLAGS.fake_network: - self.driver.update_dhcp(context, network['id']) + self._update_dhcp(context, network) def _on_set_network_host(self, context, network_id): """Called when this host becomes the host for a project.""" @@ -759,9 +779,13 @@ class FlatDHCPManager(FloatingIP, RPCAllocateFixedIP, NetworkManager): network['bridge_interface'], network) if not FLAGS.fake_network: - self.driver.update_dhcp(context, network_id) + network_ref = self.db.network_get(context, network_id) + self._update_dhcp(context, network_ref) if(FLAGS.use_ipv6): - self.driver.update_ra(context, network_id) + self.driver.update_ra(context, network_ref) + gateway = utils.get_my_linklocal(network_ref['bridge']) + self.db.network_update(context, network_id, + {'gateway_v6': gateway}) class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager): @@ -810,7 +834,7 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager): 'virtual_interface_id': vif['id']} self.db.fixed_ip_update(context, address, values) if not FLAGS.fake_network: - self.driver.update_dhcp(context, network['id']) + self._update_dhcp(context, network) def add_network_to_project(self, context, project_id): """Force adds another network to a project.""" @@ -822,9 +846,10 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager): """ networks = self.db.network_get_all_by_instance(context, instance_id) for network in networks: - self.driver.ensure_vlan_bridge(network['vlan'], - network['bridge'], - network['bridge_interface']) + if not network['multi_host']: + self.driver.ensure_vlan_bridge(network['vlan'], + network['bridge'], + network['bridge_interface']) def _get_networks_for_instance(self, context, instance_id, project_id): """Determine which networks an instance should connect to.""" @@ -874,9 +899,13 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager): network['vpn_public_port'], network['vpn_private_address']) if not FLAGS.fake_network: - self.driver.update_dhcp(context, network_id) + network_ref = self.db.network_get(context, network_id) + self._update_dhcp(context, network_ref) if(FLAGS.use_ipv6): - self.driver.update_ra(context, network_id) + self.driver.update_ra(context, network_ref) + gateway = utils.get_my_linklocal(network_ref['bridge']) + self.db.network_update(context, network_id, + {'gateway_v6': gateway}) @property def _bottom_reserved_ips(self): -- cgit From 9a8254ef2751e1b7502107a9c6afe05ea1e2efd4 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 5 Jul 2011 12:00:11 -0700 Subject: it is multi_host not multi_gateway --- nova/network/api.py | 6 ++++-- nova/network/manager.py | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/nova/network/api.py b/nova/network/api.py index c57394204..c0f0fb8eb 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -104,7 +104,8 @@ class API(base.Base): '(%(project)s)') % {'address': floating_ip['address'], 'project': context.project_id}) - if fixed_ip['network']['multi_gateway']: + # NOTE(vish): if we are multi_host, send to the instances host + if fixed_ip['network']['multi_host']: host = fixed_ip['instance']['host'] else: host = fixed_ip['network']['host'] @@ -122,7 +123,8 @@ class API(base.Base): return if not floating_ip.get('fixed_ip'): raise exception.ApiError('Address is not associated.') - if floating_ip['fixed_ip']['network']['multi_gateway']: + # NOTE(vish): if we are multi_host, send to the instances host + if floating_ip['fixed_ip']['network']['multi_host']: host = floating_ip['fixed_ip']['instance']['host'] else: host = floating_ip['fixed_ip']['network']['host'] diff --git a/nova/network/manager.py b/nova/network/manager.py index f60763eba..84d2cbbcb 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -49,7 +49,6 @@ import datetime import math import netaddr import socket -import pickle from eventlet import greenpool from nova import context @@ -129,8 +128,8 @@ class RPCAllocateFixedIP(object): green_pool = greenpool.GreenPool() for network in networks: - # NOTE(vish): if we are multi_gateway pass to the specified host - if not network['multi_gateway']: + # NOTE(vish): if we are not multi_host pass to the network host + if not network['multi_host']: host = network['host'] if host != self.host: # need to call allocate_fixed_ip to correct network host -- cgit From 8d2f3f26e8089020616312334689f1c594a67b4f Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 5 Jul 2011 12:16:46 -0700 Subject: make sure to filter out ips associated by host and add some sync for allocating ip to host --- nova/db/sqlalchemy/api.py | 1 + nova/network/manager.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 6db142276..7065de00f 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -665,6 +665,7 @@ def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None): filter_by(reserved=False).\ filter_by(deleted=False).\ filter_by(instance=None).\ + filter_by(host=None).\ with_lockmode('update').\ first() # NOTE(vish): if with_lockmode isn't supported, as in sqlite, diff --git a/nova/network/manager.py b/nova/network/manager.py index 84d2cbbcb..55f81da9e 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -310,7 +310,18 @@ class NetworkManager(manager.SchedulerDependentManager): If it is a multi_host network, get the ip assigned to this host, otherwise, assume that dhcp is listening on the gateway.""" if network_ref['multi_host']: - return self.db.network_get_host_ip(context, FLAGS.host) + + @utils.synchronized('get_dhcp') + def _sync_get_dhcp_ip(): + try: + return self.db.fixed_ip_get_by_network_host(context, + FLAGS.host) + except exception.FixedIpNotFoundForNetworkHost: + return self.db.fixed_ip_associate_pool(context.elevated(), + network_ref['id'], + host=FLAGS.host) + return _sync_get_dhcp_ip() + else: return network_ref['gateway'] -- cgit From 9b5adcbe92a4f7e0f9b1592be123c58f743def34 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 5 Jul 2011 15:55:16 -0700 Subject: pass in dhcp server address, fix a bunch of bugs --- nova/compute/manager.py | 17 ++++++++------- nova/db/api.py | 2 +- nova/db/sqlalchemy/api.py | 3 ++- nova/db/sqlalchemy/models.py | 1 + nova/network/linux_net.py | 4 ++-- nova/network/manager.py | 47 ++++++++++++++++++++++++++++------------- nova/virt/libvirt/connection.py | 3 +-- 7 files changed, 48 insertions(+), 29 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index bbbddde0a..b198adc97 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -77,8 +77,6 @@ flags.DEFINE_integer('live_migration_retry_count', 30, flags.DEFINE_integer("rescue_timeout", 0, "Automatically unrescue an instance after N seconds." " Set to 0 to disable.") -flags.DEFINE_bool('auto_assign_floating_ip', False, - 'Autoassigning floating ip to VM') flags.DEFINE_integer('host_state_interval', 120, 'Interval in seconds for querying the host status') @@ -268,16 +266,19 @@ class ComputeManager(manager.SchedulerDependentManager): """Launch a new instance with specified options.""" context = context.elevated() instance = self.db.instance_get(context, instance_id) - instance.injected_files = kwargs.get('injected_files', []) - instance.admin_pass = kwargs.get('admin_password', None) if instance['name'] in self.driver.list_instances(): raise exception.Error(_("Instance has already been created")) LOG.audit(_("instance %s: starting..."), instance_id, context=context) - self.db.instance_update(context, - instance_id, - {'host': self.host, 'launched_on': self.host}) - + updates = {} + updates['host'] = self.host + updates['launched_on'] = self.host + # NOTE(vish): used by virt but not in database + updates['injected_files'] = kwargs.get('injected_files', []) + updates['admin_pass'] = kwargs.get('admin_password', None) + instance = self.db.instance_update(context, + instance_id, + updates) self.db.instance_set_state(context, instance_id, power_state.NOSTATE, diff --git a/nova/db/api.py b/nova/db/api.py index febe33374..ee4cbad57 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -340,7 +340,7 @@ def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None): """ return IMPL.fixed_ip_associate_pool(context, network_id, - instance_id, host, reserved) + instance_id, host) def fixed_ip_create(context, values): diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 7065de00f..9c138d2fd 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -683,6 +683,7 @@ def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None): if host: fixed_ip_ref.host = host session.add(fixed_ip_ref) + LOG.warn("gave address %s to %s, %s", fixed_ip_ref['address'], instance_id, host) return fixed_ip_ref['address'] @@ -793,7 +794,7 @@ def fixed_ip_get_by_network_host(context, network_id, host): filter_by(network_id=network_id).\ filter_by(host=host).\ filter_by(deleted=False).\ - all() + first() if not rv: raise exception.FixedIpNotFoundForNetworkHost(network_id=network_id, host=host) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 8c86870f0..639941dc8 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -602,6 +602,7 @@ class FixedIp(BASE, NovaBase): # leased means dhcp bridge has leased the ip leased = Column(Boolean, default=False) reserved = Column(Boolean, default=False) + host = Column(String(255)) class FloatingIp(BASE, NovaBase): diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index 8d2bc5c0b..0a7a62510 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -497,7 +497,7 @@ def ensure_bridge(bridge, interface, net_attrs=None): suffix = net_attrs['cidr'].rpartition('/')[2] out, err = _execute('sudo', 'ip', 'addr', 'add', '%s/%s' % - (net_attrs['gateway'], suffix), + (net_attrs['dhcp_server'], suffix), 'brd', net_attrs['broadcast'], 'dev', @@ -697,7 +697,7 @@ def _dnsmasq_cmd(net): '--conf-file=%s' % FLAGS.dnsmasq_config_file, '--domain=%s' % FLAGS.dhcp_domain, '--pid-file=%s' % _dhcp_file(net['bridge'], 'pid'), - '--listen-address=%s' % net['dhcp_listen'], + '--listen-address=%s' % net['dhcp_server'], '--except-interface=lo', '--dhcp-range=%s,static,120s' % net['dhcp_start'], '--dhcp-lease-max=%s' % len(netaddr.IPNetwork(net['cidr'])), diff --git a/nova/network/manager.py b/nova/network/manager.py index 55f81da9e..ce631ce75 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -103,7 +103,8 @@ flags.DEFINE_integer('fixed_ip_disassociate_timeout', 600, 'Seconds after which a deallocated ip is disassociated') flags.DEFINE_integer('create_unique_mac_address_attempts', 5, 'Number of attempts to create unique mac address') - +flags.DEFINE_bool('auto_assign_floating_ip', False, + 'Autoassigning floating ip to VM') flags.DEFINE_bool('use_ipv6', False, 'use the ipv6') flags.DEFINE_string('network_host', socket.gethostname(), @@ -192,7 +193,7 @@ class FloatingIP(object): # which is currently the NetworkManager version # do this first so fixed ip is already allocated ips = super(FloatingIP, self).allocate_for_instance(context, **kwargs) - if hasattr(FLAGS, 'auto_assign_floating_ip'): + if FLAGS.auto_assign_floating_ip: # allocate a floating ip (public_ip is just the address string) public_ip = self.allocate_floating_ip(context, project_id) # set auto_assigned column to true for the floating ip @@ -299,9 +300,9 @@ class NetworkManager(manager.SchedulerDependentManager): super(NetworkManager, self).__init__(service_name='network', *args, **kwargs) - def _update_dchp(self, context, network_ref): + def _update_dhcp(self, context, network_ref): """Sets the listen address before sending update to the driver.""" - network_ref['dhcp_listen'] = self._get_dhcp_ip() + network_ref['dhcp_server'] = self._get_dhcp_ip(context, network_ref) return self.driver.update_dhcp(context, network_ref) def _get_dhcp_ip(self, context, network_ref): @@ -313,13 +314,18 @@ class NetworkManager(manager.SchedulerDependentManager): @utils.synchronized('get_dhcp') def _sync_get_dhcp_ip(): + network_id = network_ref['id'] try: - return self.db.fixed_ip_get_by_network_host(context, - FLAGS.host) + fip = self.db.fixed_ip_get_by_network_host(context, + network_id, + self.host) + return fip['address'] except exception.FixedIpNotFoundForNetworkHost: - return self.db.fixed_ip_associate_pool(context.elevated(), - network_ref['id'], - host=FLAGS.host) + addr = self.db.fixed_ip_associate_pool(context.elevated(), + network_id, + host=self.host) + return addr + return _sync_get_dhcp_ip() else: @@ -334,6 +340,11 @@ class NetworkManager(manager.SchedulerDependentManager): ctxt = context.get_admin_context() for network in self.db.network_get_all_by_host(ctxt, self.host): self._on_set_network_host(ctxt, network['id']) + for network in self.db.network_get_all(ctxt): + # NOTE(vish): multi_host networks need to be set on all boxes + if network['multi_host']: + self._on_set_network_host(ctxt, network['id']) + def periodic_tasks(self, context=None): """Tasks to be run at a periodic interval.""" @@ -349,7 +360,7 @@ class NetworkManager(manager.SchedulerDependentManager): LOG.debug(_('Dissassociated %s stale fixed ip(s)'), num) # setup any new networks which have been created - self.set_network_hosts(context) + #self.set_network_hosts(context) def set_network_host(self, context, network_id): """Safely sets the host of the network.""" @@ -378,8 +389,8 @@ class NetworkManager(manager.SchedulerDependentManager): networks = self.db.network_get_all(context) # return only networks which are not vlan networks and have host set - return [network for network in networks if - not network['vlan'] and network['host']] + return [network for network in networks if not network['vlan'] + and network['host'] or network['multi_host']] def allocate_for_instance(self, context, **kwargs): """Handles allocating the various network resources for an instance. @@ -395,6 +406,7 @@ class NetworkManager(manager.SchedulerDependentManager): context=context) networks = self._get_networks_for_instance(admin_context, instance_id, project_id) + LOG.warn(networks) self._allocate_mac_addresses(context, instance_id, networks) self._allocate_fixed_ips(admin_context, instance_id, host, networks) return self.get_instance_nw_info(context, instance_id, type_id) @@ -464,6 +476,7 @@ class NetworkManager(manager.SchedulerDependentManager): info = { 'label': network['label'], 'gateway': network['gateway'], + 'dhcp_server': self._get_dhcp_ip(context, network), 'broadcast': network['broadcast'], 'mac': vif['address'], 'rxtx_cap': flavor['rxtx_cap'], @@ -569,7 +582,7 @@ class NetworkManager(manager.SchedulerDependentManager): # the code below will update the file if necessary if FLAGS.update_dhcp_on_disassociate: network_ref = self.db.fixed_ip_get_network(context, address) - network_ref['dhcp_listen'] = self._get_dhcp_ip(context, network_ref) + network_ref['dhcp_server'] = self._get_dhcp_ip(context, network_ref) self._update_dhcp(context, network_ref) def create_networks(self, context, label, cidr, num_networks, @@ -628,6 +641,7 @@ class NetworkManager(manager.SchedulerDependentManager): # robust solution would be to make them uniq per ip net['vpn_public_port'] = kwargs['vpn_start'] + index + net['multi_host'] = True # None if network with cidr or cidr_v6 already exists network = self.db.network_create_safe(context, net) @@ -785,6 +799,7 @@ class FlatDHCPManager(FloatingIP, RPCAllocateFixedIP, NetworkManager): net['dhcp_start'] = FLAGS.flat_network_dhcp_start self.db.network_update(context, network_id, net) network = db.network_get(context, network_id) + network['dhcp_server'] = self._get_dhcp_ip(context, network) self.driver.ensure_bridge(network['bridge'], network['bridge_interface'], network) @@ -866,8 +881,9 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager): # get networks associated with project networks = self.db.project_get_networks(context, project_id) - # return only networks which have host set - return [network for network in networks if network['host']] + # return only networks which have host set or are multi_host + return [network for network in networks + if network['host'] or network['multi_host']] def create_networks(self, context, **kwargs): """Create networks based on parameters.""" @@ -896,6 +912,7 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager): db.network_update(context, network_id, net) else: address = network['vpn_public_address'] + network['dhcp_server'] = self._get_dhcp_ip(context, network) self.driver.ensure_vlan_bridge(network['vlan'], network['bridge'], network['bridge_interface'], diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 0c6eaab84..5e8fcdd2f 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -928,7 +928,6 @@ class LibvirtConnection(driver.ComputeDriver): def _get_nic_for_xml(self, network, mapping): # Assume that the gateway also acts as the dhcp server. - dhcp_server = mapping['gateway'] gateway6 = mapping.get('gateway6') mac_id = mapping['mac'].replace(':', '') @@ -951,7 +950,7 @@ class LibvirtConnection(driver.ComputeDriver): 'bridge_name': network['bridge'], 'mac_address': mapping['mac'], 'ip_address': mapping['ips'][0]['ip'], - 'dhcp_server': dhcp_server, + 'dhcp_server': mapping['dhcp_server'], 'extra_params': extra_params, } -- cgit From 8e1a74e5604e1569e314af67b72966122940330b Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 5 Jul 2011 16:06:20 -0700 Subject: filter the dhcp to only respond to requests from this host --- bin/nova-dhcpbridge | 2 +- nova/network/linux_net.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bin/nova-dhcpbridge b/bin/nova-dhcpbridge index 6d9d85896..325642d52 100755 --- a/bin/nova-dhcpbridge +++ b/bin/nova-dhcpbridge @@ -91,7 +91,7 @@ def init_leases(interface): """Get the list of hosts for an interface.""" ctxt = context.get_admin_context() network_ref = db.network_get_by_bridge(ctxt, interface) - return linux_net.get_dhcp_leases(ctxt, network_ref['id']) + return linux_net.get_dhcp_leases(ctxt, network_ref) def main(): diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index 0a7a62510..848e40643 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -551,21 +551,27 @@ def ensure_bridge(bridge, interface, net_attrs=None): bridge) -def get_dhcp_leases(context, network_id): +def get_dhcp_leases(context, network_ref): """Return a network's hosts config in dnsmasq leasefile format.""" hosts = [] - for fixed_ip_ref in db.network_get_associated_fixed_ips(context, - network_id): - hosts.append(_host_lease(fixed_ip_ref)) + for fixed_ref in db.network_get_associated_fixed_ips(context, + network_ref['id']): + host = fixed_ref['instance']['host'] + if network_ref['multi_host'] and FLAGS.host != host: + continue + hosts.append(_host_lease(fixed_ref)) return '\n'.join(hosts) -def get_dhcp_hosts(context, network_id): +def get_dhcp_hosts(context, network_ref): """Get network's hosts config in dhcp-host format.""" hosts = [] - for fixed_ip_ref in db.network_get_associated_fixed_ips(context, - network_id): - hosts.append(_host_dhcp(fixed_ip_ref)) + for fixed_ref in db.network_get_associated_fixed_ips(context, + network_ref['id']): + host = fixed_ref['instance']['host'] + if network_ref['multi_host'] and FLAGS.host != host: + continue + hosts.append(_host_dhcp(fixed_ref)) return '\n'.join(hosts) @@ -582,7 +588,7 @@ def update_dhcp(context, network_ref): """ conffile = _dhcp_file(network_ref['bridge'], 'conf') with open(conffile, 'w') as f: - f.write(get_dhcp_hosts(context, network_ref['id'])) + f.write(get_dhcp_hosts(context, network_ref)) # Make sure dnsmasq can actually read it (it setuid()s to "nobody") os.chmod(conffile, 0644) -- cgit From 53213dc4cd0f6f940d707c5d5932f4af7e5f988a Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 5 Jul 2011 16:22:41 -0700 Subject: add ability to set multi_host in nova-manage and remove debugging issues --- bin/nova-manage | 9 +++++++-- nova/db/sqlalchemy/api.py | 1 - nova/network/manager.py | 8 +++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 71c99138f..cd43f734f 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -558,12 +558,12 @@ class NetworkCommands(object): """Class for managing networks.""" def create(self, label=None, fixed_range=None, num_networks=None, - network_size=None, vlan_start=None, + network_size=None, multi_host=None, vlan_start=None, vpn_start=None, fixed_range_v6=None, gateway_v6=None, flat_network_bridge=None, bridge_interface=None): """Creates fixed ips for host by range arguments: label, fixed_range, [num_networks=FLAG], - [network_size=FLAG], [vlan_start=FLAG], + [network_size=FLAG], [multi_host=FLAG], [vlan_start=FLAG], [vpn_start=FLAG], [fixed_range_v6=FLAG], [gateway_v6=FLAG], [flat_network_bridge=FLAG], [bridge_interface=FLAG] If you wish to use a later argument fill in the gaps with 0s @@ -583,6 +583,10 @@ class NetworkCommands(object): num_networks = FLAGS.num_networks if not network_size: network_size = FLAGS.network_size + if not multi_host: + multi_host = FLAGS.multi_host + else: + multi_host = multi_host == 'T' if not vlan_start: vlan_start = FLAGS.vlan_start if not vpn_start: @@ -601,6 +605,7 @@ class NetworkCommands(object): net_manager.create_networks(context.get_admin_context(), label=label, cidr=fixed_range, + multi_host=multi_host, num_networks=int(num_networks), network_size=int(network_size), vlan_start=int(vlan_start), diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 9c138d2fd..472513329 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -683,7 +683,6 @@ def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None): if host: fixed_ip_ref.host = host session.add(fixed_ip_ref) - LOG.warn("gave address %s to %s, %s", fixed_ip_ref['address'], instance_id, host) return fixed_ip_ref['address'] diff --git a/nova/network/manager.py b/nova/network/manager.py index ce631ce75..d799d5346 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -86,6 +86,8 @@ flags.DEFINE_integer('num_networks', 1, 'Number of networks to support') flags.DEFINE_string('vpn_ip', '$my_ip', 'Public IP for the cloudpipe VPN servers') flags.DEFINE_integer('vpn_start', 1000, 'First Vpn port for private networks') +flags.DEFINE_bool('multi_host', False, + 'Default value for multi_host in networks') flags.DEFINE_integer('network_size', 256, 'Number of addresses in each private subnet') flags.DEFINE_string('floating_range', '4.4.4.0/24', @@ -360,7 +362,7 @@ class NetworkManager(manager.SchedulerDependentManager): LOG.debug(_('Dissassociated %s stale fixed ip(s)'), num) # setup any new networks which have been created - #self.set_network_hosts(context) + self.set_network_hosts(context) def set_network_host(self, context, network_id): """Safely sets the host of the network.""" @@ -585,7 +587,7 @@ class NetworkManager(manager.SchedulerDependentManager): network_ref['dhcp_server'] = self._get_dhcp_ip(context, network_ref) self._update_dhcp(context, network_ref) - def create_networks(self, context, label, cidr, num_networks, + def create_networks(self, context, label, cidr, multi_host, num_networks, network_size, cidr_v6, gateway_v6, bridge, bridge_interface, **kwargs): """Create networks based on parameters.""" @@ -604,6 +606,7 @@ class NetworkManager(manager.SchedulerDependentManager): net['bridge_interface'] = bridge_interface net['dns'] = FLAGS.flat_network_dns net['cidr'] = cidr + net['multi_host'] = multi_host net['netmask'] = str(project_net.netmask) net['gateway'] = str(project_net[1]) net['broadcast'] = str(project_net.broadcast) @@ -641,7 +644,6 @@ class NetworkManager(manager.SchedulerDependentManager): # robust solution would be to make them uniq per ip net['vpn_public_port'] = kwargs['vpn_start'] + index - net['multi_host'] = True # None if network with cidr or cidr_v6 already exists network = self.db.network_create_safe(context, net) -- cgit From 11dfe937bcfa542c985a977e9ff855f717e80e69 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 5 Jul 2011 16:24:43 -0700 Subject: don't set network host for multi_host networks --- nova/network/manager.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nova/network/manager.py b/nova/network/manager.py index d799d5346..83ab4dd72 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -378,8 +378,7 @@ class NetworkManager(manager.SchedulerDependentManager): """Set the network hosts for any networks which are unset.""" networks = self.db.network_get_all(context) for network in networks: - host = network['host'] - if not host: + if not network['multi_host'] and not network['host']: # return so worker will only grab 1 (to help scale flatter) return self.set_network_host(context, network['id']) -- cgit From 77b655cd16a265eb2b8fc369941d19890766e712 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 5 Jul 2011 17:01:19 -0700 Subject: update tests --- nova/tests/__init__.py | 1 + nova/tests/test_network.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/nova/tests/__init__.py b/nova/tests/__init__.py index e4ed75d37..b885000e1 100644 --- a/nova/tests/__init__.py +++ b/nova/tests/__init__.py @@ -59,6 +59,7 @@ def setup(): network.create_networks(ctxt, label='test', cidr=FLAGS.fixed_range, + multi_host=FLAGS.multi_host, num_networks=FLAGS.num_networks, network_size=FLAGS.network_size, cidr_v6=FLAGS.fixed_range_v6, diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 6d5166019..390cdc003 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -44,6 +44,7 @@ class FakeModel(dict): networks = [{'id': 0, 'label': 'test0', 'injected': False, + 'multi_host': False, 'cidr': '192.168.0.0/24', 'cidr_v6': '2001:db8::/64', 'gateway_v6': '2001:db8::1', @@ -61,6 +62,7 @@ networks = [{'id': 0, {'id': 1, 'label': 'test1', 'injected': False, + 'multi_host': False, 'cidr': '192.168.1.0/24', 'cidr_v6': '2001:db9::/64', 'gateway_v6': '2001:db9::1', @@ -163,6 +165,7 @@ class FlatNetworkTestCase(test.TestCase): self.assertDictMatch(nw[0], check) check = {'broadcast': '192.168.%s.255' % i, + 'dhcp_server': '192.168.%s.1' % i, 'dns': 'DONTCARE', 'gateway': '192.168.%s.1' % i, 'gateway6': '2001:db%s::1' % i8, -- cgit From e24c1d998331444235480be241484b0408cdaf9e Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 5 Jul 2011 17:07:44 -0700 Subject: fix libvirt test --- nova/tests/test_libvirt.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index f99e1713d..6e2ec7ed6 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -58,6 +58,7 @@ def _create_network_info(count=1, ipv6=None): 'cidr': fake_ip, 'cidr_v6': fake_ip} mapping = {'mac': fake, + 'dhcp_server': fake, 'gateway': fake, 'gateway6': fake, 'ips': [{'ip': fake_ip}, {'ip': fake_ip}]} -- cgit From f568d9345d19064c0024523195b17eb9e7d036ef Mon Sep 17 00:00:00 2001 From: Ryu Ishimoto Date: Thu, 7 Jul 2011 01:03:00 +0900 Subject: Added a L2 network driver for bridge/vlan creation --- Authors | 1 + nova/network/l2_drivers.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++ nova/network/manager.py | 32 ++++++++++++++++---------- 3 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 nova/network/l2_drivers.py diff --git a/Authors b/Authors index c3a65f1b4..e0119d63e 100644 --- a/Authors +++ b/Authors @@ -77,6 +77,7 @@ Rick Harris Rob Kost Ryan Lane Ryan Lucio +Ryu Ishimoto Salvatore Orlando Sandy Walsh Sateesh Chodapuneedi diff --git a/nova/network/l2_drivers.py b/nova/network/l2_drivers.py new file mode 100644 index 000000000..1e66dcd26 --- /dev/null +++ b/nova/network/l2_drivers.py @@ -0,0 +1,56 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2011 Midokura KK +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Drivers responsible for managing L2 connectivity for Nova.""" + +from nova.network import linux_net + +class L2Driver(object): + """Base class that defines interfaces for L2 drivers.""" + + def ensure_bridge(bridge, interface, net_attrs=None): + """Create a bridge unless it already exists.""" + raise NotImplementedError() + + def ensure_vlan(vlan_num, bridge_interface): + """Create a vlan unless it already exists.""" + raise NotImplementedError() + + +class LinuxBridgeDriver(L2Driver): + """L2 driver based on Linux Bridge.""" + + def ensure_bridge(bridge, interface, net_attrs=None): + """Create a Linux bridge unless it already eixsts.""" + linux_net.ensure_bridge(bridge, interface, net_attrs) + + def ensure_vlan(vlan_num, bridge_interface): + """Create a vlan unless it already exists.""" + return linux_net.ensure_vlan(vlan_num, bridge_interface) + + +class QuantumDriver(L2Driver): + """L2 driver based on Quantum network service.""" + + def ensure_bridge(bridge, interface, net_attrs=None): + """Do nothing.""" + pass + + def ensure_vlan(vlan_num, bridge_interface): + """Return None.""" + return None + diff --git a/nova/network/manager.py b/nova/network/manager.py index d42bc8c4e..3d6388259 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -111,6 +111,8 @@ flags.DEFINE_string('network_host', socket.gethostname(), 'Network host to use for ip allocation in flat modes') flags.DEFINE_bool('fake_call', False, 'If True, skip using the queue and make local calls') +flags.DEFINE_string('l2_driver', 'nova.network.l2_drivers.LinuxBridgeDriver', + 'L2 network connectivity driver.') class AddressAlreadyAllocated(exception.Error): @@ -294,6 +296,7 @@ class NetworkManager(manager.SchedulerDependentManager): if not network_driver: network_driver = FLAGS.network_driver self.driver = utils.import_object(network_driver) + self.l2_driver = utils.import_object(FLAGS.l2_driver) self.network_api = network_api.API() super(NetworkManager, self).__init__(service_name='network', *args, **kwargs) @@ -738,8 +741,8 @@ class FlatDHCPManager(FloatingIP, RPCAllocateFixedIP, NetworkManager): """ networks = db.network_get_all_by_instance(context, instance_id) for network in networks: - self.driver.ensure_bridge(network['bridge'], - network['bridge_interface']) + self.l2_driver.ensure_bridge(network['bridge'], + network['bridge_interface']) def allocate_fixed_ip(self, context, instance_id, network): """Allocate flat_network fixed_ip, then setup dhcp for this network.""" @@ -755,9 +758,9 @@ class FlatDHCPManager(FloatingIP, RPCAllocateFixedIP, NetworkManager): net['dhcp_start'] = FLAGS.flat_network_dhcp_start self.db.network_update(context, network_id, net) network = db.network_get(context, network_id) - self.driver.ensure_bridge(network['bridge'], - network['bridge_interface'], - network) + self.l2_driver.ensure_bridge(network['bridge'], + network['bridge_interface'], + network) if not FLAGS.fake_network: self.driver.update_dhcp(context, network_id) if(FLAGS.use_ipv6): @@ -822,9 +825,11 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager): """ networks = self.db.network_get_all_by_instance(context, instance_id) for network in networks: - self.driver.ensure_vlan_bridge(network['vlan'], - network['bridge'], - network['bridge_interface']) + interface = self.l2_driver.ensure_vlan(network['vlan'], + network['bridge_interface']) + if interface: + self.l2_driver.ensure_bridge(network['bridge'], interface, + network['bridge_interface']) def _get_networks_for_instance(self, context, instance_id, project_id): """Determine which networks an instance should connect to.""" @@ -861,10 +866,13 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager): db.network_update(context, network_id, net) else: address = network['vpn_public_address'] - self.driver.ensure_vlan_bridge(network['vlan'], - network['bridge'], - network['bridge_interface'], - network) + + interface = self.l2_driver.ensure_vlan(network['vlan'], + network['bridge_interface']) + if interface: + self.l2_driver.ensure_bridge(network['bridge'], interface, + network['bridge_interface'], + network) # NOTE(vish): only ensure this forward if the address hasn't been set # manually. -- cgit From 2b553a89b34d7a3691c0952c5debda6b5ea1bb79 Mon Sep 17 00:00:00 2001 From: Ryu Ishimoto Date: Thu, 7 Jul 2011 01:04:56 +0900 Subject: Added net_attrs argument for ensure_bridge/vlan methods --- nova/network/l2_drivers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nova/network/l2_drivers.py b/nova/network/l2_drivers.py index 1e66dcd26..e1de5cc5b 100644 --- a/nova/network/l2_drivers.py +++ b/nova/network/l2_drivers.py @@ -26,7 +26,7 @@ class L2Driver(object): """Create a bridge unless it already exists.""" raise NotImplementedError() - def ensure_vlan(vlan_num, bridge_interface): + def ensure_vlan(vlan_num, bridge_interface, net_attrs=None): """Create a vlan unless it already exists.""" raise NotImplementedError() @@ -38,9 +38,9 @@ class LinuxBridgeDriver(L2Driver): """Create a Linux bridge unless it already eixsts.""" linux_net.ensure_bridge(bridge, interface, net_attrs) - def ensure_vlan(vlan_num, bridge_interface): + def ensure_vlan(vlan_num, bridge_interface, net_attrs=None): """Create a vlan unless it already exists.""" - return linux_net.ensure_vlan(vlan_num, bridge_interface) + return linux_net.ensure_vlan(vlan_num, bridge_interface, net_attrs) class QuantumDriver(L2Driver): @@ -50,7 +50,7 @@ class QuantumDriver(L2Driver): """Do nothing.""" pass - def ensure_vlan(vlan_num, bridge_interface): + def ensure_vlan(vlan_num, bridge_interface, net_attrs=None): """Return None.""" return None -- cgit From 23a5775d6dbd5f11ff0adb67dd6b5bceb96b8030 Mon Sep 17 00:00:00 2001 From: Ryu Ishimoto Date: Thu, 7 Jul 2011 02:12:03 +0900 Subject: Added the missing 'self' parameter --- nova/network/l2_drivers.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/nova/network/l2_drivers.py b/nova/network/l2_drivers.py index e1de5cc5b..23d05cda4 100644 --- a/nova/network/l2_drivers.py +++ b/nova/network/l2_drivers.py @@ -22,11 +22,11 @@ from nova.network import linux_net class L2Driver(object): """Base class that defines interfaces for L2 drivers.""" - def ensure_bridge(bridge, interface, net_attrs=None): + def ensure_bridge(self, bridge, interface, net_attrs=None): """Create a bridge unless it already exists.""" raise NotImplementedError() - def ensure_vlan(vlan_num, bridge_interface, net_attrs=None): + def ensure_vlan(self, vlan_num, bridge_interface, net_attrs=None): """Create a vlan unless it already exists.""" raise NotImplementedError() @@ -34,11 +34,11 @@ class L2Driver(object): class LinuxBridgeDriver(L2Driver): """L2 driver based on Linux Bridge.""" - def ensure_bridge(bridge, interface, net_attrs=None): + def ensure_bridge(self, bridge, interface, net_attrs=None): """Create a Linux bridge unless it already eixsts.""" linux_net.ensure_bridge(bridge, interface, net_attrs) - def ensure_vlan(vlan_num, bridge_interface, net_attrs=None): + def ensure_vlan(self, vlan_num, bridge_interface, net_attrs=None): """Create a vlan unless it already exists.""" return linux_net.ensure_vlan(vlan_num, bridge_interface, net_attrs) @@ -46,11 +46,11 @@ class LinuxBridgeDriver(L2Driver): class QuantumDriver(L2Driver): """L2 driver based on Quantum network service.""" - def ensure_bridge(bridge, interface, net_attrs=None): + def ensure_bridge(self, bridge, interface, net_attrs=None): """Do nothing.""" pass - def ensure_vlan(vlan_num, bridge_interface, net_attrs=None): + def ensure_vlan(self, vlan_num, bridge_interface, net_attrs=None): """Return None.""" return None -- cgit From a05b0325a76dea16a2d5f7d1931a5cbc922e0364 Mon Sep 17 00:00:00 2001 From: Ryu Ishimoto Date: Thu, 7 Jul 2011 02:13:18 +0900 Subject: Added VIF driver concept --- nova/virt/libvirt.xml.template | 18 ++++++++++ nova/virt/libvirt/connection.py | 48 +++++-------------------- nova/virt/libvirt/vif_drivers.py | 76 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 39 deletions(-) create mode 100644 nova/virt/libvirt/vif_drivers.py diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index e1a683da8..ea27e5fd7 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -92,6 +92,22 @@ #end if #for $nic in $nics + #if $vif_type='ethernet' + + + +