diff options
| author | Vishvananda Ishaya <vishvananda@yahoo.com> | 2010-09-21 11:12:34 -0700 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@yahoo.com> | 2010-09-21 11:12:34 -0700 |
| commit | 2e258a97d73aa9c08e4d6d6be364b97d1d3f97c0 (patch) | |
| tree | 830d11118f755f27c4e8ac82d23c6aa61d086dd2 /bin | |
| parent | 6186634c0f8d6a44323fe1f7b2530528a539c64c (diff) | |
| parent | ce0a9b7b36ba816c347f10a1804aedf337ad35da (diff) | |
merged trunk
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/nova-compute | 4 | ||||
| -rwxr-xr-x | bin/nova-dhcpbridge | 51 | ||||
| -rwxr-xr-x | bin/nova-manage | 83 | ||||
| -rwxr-xr-x | bin/nova-network | 9 | ||||
| -rwxr-xr-x | bin/nova-objectstore | 2 | ||||
| -rwxr-xr-x | bin/nova-scheduler | 43 | ||||
| -rwxr-xr-x | bin/nova-volume | 4 |
7 files changed, 149 insertions, 47 deletions
diff --git a/bin/nova-compute b/bin/nova-compute index 631d2c85c..1724e9659 100755 --- a/bin/nova-compute +++ b/bin/nova-compute @@ -32,12 +32,12 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +from nova import service from nova import twistd -from nova.compute import service if __name__ == '__main__': twistd.serve(__file__) if __name__ == '__builtin__': - application = service.ComputeService.create() # pylint: disable-msg=C0103 + application = service.Service.create() # pylint: disable=C0103 diff --git a/bin/nova-dhcpbridge b/bin/nova-dhcpbridge index 0c3d987a7..a127ed03c 100755 --- a/bin/nova-dhcpbridge +++ b/bin/nova-dhcpbridge @@ -33,24 +33,32 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +from nova import db from nova import flags from nova import rpc from nova import utils from nova.network import linux_net -from nova.network import model -from nova.network import service FLAGS = flags.FLAGS +flags.DECLARE('auth_driver', 'nova.auth.manager') +flags.DECLARE('redis_db', 'nova.datastore') +flags.DECLARE('network_size', 'nova.network.manager') +flags.DECLARE('num_networks', 'nova.network.manager') +flags.DECLARE('update_dhcp_on_disassociate', 'nova.network.manager') -def add_lease(_mac, ip_address, _hostname, _interface): +def add_lease(mac, ip_address, _hostname, _interface): """Set the IP that was assigned by the DHCP server.""" if FLAGS.fake_rabbit: - service.VlanNetworkService().lease_ip(ip_address) + logging.debug("leasing ip") + network_manager = utils.import_object(FLAGS.network_manager) + network_manager.lease_fixed_ip(None, mac, ip_address) else: - rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name), - {"method": "lease_ip", - "args": {"fixed_ip": ip_address}}) + rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.host), + {"method": "lease_fixed_ip", + "args": {"context": None, + "mac": mac, + "address": ip_address}}) def old_lease(_mac, _ip_address, _hostname, _interface): @@ -58,23 +66,24 @@ def old_lease(_mac, _ip_address, _hostname, _interface): logging.debug("Adopted old lease or got a change of mac/hostname") -def del_lease(_mac, ip_address, _hostname, _interface): +def del_lease(mac, ip_address, _hostname, _interface): """Called when a lease expires.""" if FLAGS.fake_rabbit: - service.VlanNetworkService().release_ip(ip_address) + logging.debug("releasing ip") + network_manager = utils.import_object(FLAGS.network_manager) + network_manager.release_fixed_ip(None, mac, ip_address) else: - rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name), - {"method": "release_ip", - "args": {"fixed_ip": ip_address}}) + rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.host), + {"method": "release_fixed_ip", + "args": {"context": None, + "mac": mac, + "address": ip_address}}) def init_leases(interface): """Get the list of hosts for an interface.""" - net = model.get_network_by_interface(interface) - res = "" - for address in net.assigned_objs: - res += "%s\n" % linux_net.host_dhcp(address) - return res + network_ref = db.network_get_by_bridge(None, interface) + return linux_net.get_dhcp_hosts(None, network_ref['id']) def main(): @@ -86,10 +95,16 @@ def main(): if int(os.environ.get('TESTING', '0')): FLAGS.fake_rabbit = True FLAGS.redis_db = 8 - FLAGS.network_size = 32 + FLAGS.network_size = 16 FLAGS.connection_type = 'fake' FLAGS.fake_network = True FLAGS.auth_driver = 'nova.auth.ldapdriver.FakeLdapDriver' + FLAGS.num_networks = 5 + path = os.path.abspath(os.path.join(os.path.dirname(__file__), + '..', + '_trial_temp', + 'nova.sqlite')) + FLAGS.sql_connection = 'sqlite:///%s' % path action = argv[1] if action in ['add', 'del', 'old']: mac = argv[2] diff --git a/bin/nova-manage b/bin/nova-manage index d23818348..4ae2f20dc 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -50,13 +50,14 @@ """ CLI interface for nova management. - Connects to the running ADMIN api in the api daemon. """ import os import sys import time +import IPy + # 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... possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), @@ -65,10 +66,12 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +from nova import db +from nova import exception from nova import flags +from nova import quota from nova import utils from nova.auth import manager -from nova.compute import model from nova.cloudpipe import pipelib from nova.endpoint import cloud @@ -81,7 +84,6 @@ class VpnCommands(object): def __init__(self): self.manager = manager.AuthManager() - self.instdir = model.InstanceDirectory() self.pipe = pipelib.CloudPipe(cloud.CloudController()) def list(self): @@ -96,8 +98,8 @@ class VpnCommands(object): vpn = self._vpn_for(project.id) if vpn: command = "ping -c1 -w1 %s > /dev/null; echo $?" - out, _err = utils.execute( command % vpn['private_dns_name'], - check_exit_code=False) + out, _err = utils.execute(command % vpn['private_dns_name'], + check_exit_code=False) if out.strip() == '0': net = 'up' else: @@ -113,9 +115,8 @@ class VpnCommands(object): def _vpn_for(self, project_id): """Get the VPN instance for a project ID.""" - for instance in self.instdir.all: - if ('image_id' in instance.state - and instance['image_id'] == FLAGS.vpn_image_id + for instance in db.instance_get_all(): + if (instance['image_id'] == FLAGS.vpn_image_id and not instance['state_description'] in ['shutting_down', 'shutdown'] and instance['project_id'] == project_id): @@ -224,6 +225,13 @@ class RoleCommands(object): class UserCommands(object): """Class for managing users.""" + @staticmethod + def _print_export(user): + """Print export variables to use with API.""" + print 'export EC2_ACCESS_KEY=%s' % user.access + print 'export EC2_SECRET_KEY=%s' % user.secret + + def __init__(self): self.manager = manager.AuthManager() @@ -231,13 +239,13 @@ class UserCommands(object): """creates a new admin and prints exports arguments: name [access] [secret]""" user = self.manager.create_user(name, access, secret, True) - print_export(user) + self._print_export(user) def create(self, name, access=None, secret=None): """creates a new user and prints exports arguments: name [access] [secret]""" user = self.manager.create_user(name, access, secret, False) - print_export(user) + self._print_export(user) def delete(self, name): """deletes an existing user @@ -249,7 +257,7 @@ class UserCommands(object): arguments: name""" user = self.manager.get_user(name) if user: - print_export(user) + self._print_export(user) else: print "User %s doesn't exist" % name @@ -260,12 +268,6 @@ class UserCommands(object): print user.name -def print_export(user): - """Print export variables to use with API.""" - print 'export EC2_ACCESS_KEY=%s' % user.access - print 'export EC2_SECRET_KEY=%s' % user.secret - - class ProjectCommands(object): """Class for managing projects.""" @@ -300,6 +302,19 @@ class ProjectCommands(object): for project in self.manager.get_projects(): print project.name + def quota(self, project_id, key=None, value=None): + """Set or display quotas for project + arguments: project_id [key] [value]""" + if key: + quo = {'project_id': project_id, key: value} + try: + db.quota_update(None, project_id, quo) + except exception.NotFound: + db.quota_create(None, quo) + project_quota = quota.get_quota(None, project_id) + for key, value in project_quota.iteritems(): + print '%s: %s' % (key, value) + def remove(self, project, user): """Removes user from project arguments: project user""" @@ -313,12 +328,46 @@ class ProjectCommands(object): f.write(zip_file) +class FloatingIpCommands(object): + """Class for managing floating ip.""" + + def create(self, host, range): + """Creates floating ips for host by range + arguments: host ip_range""" + for address in IPy.IP(range): + db.floating_ip_create(None, {'address': str(address), + 'host': host}) + + def delete(self, ip_range): + """Deletes floating ips by range + arguments: range""" + for address in IPy.IP(ip_range): + db.floating_ip_destroy(None, str(address)) + + + def list(self, host=None): + """Lists all floating ips (optionally by host) + arguments: [host]""" + if host == None: + floating_ips = db.floating_ip_get_all(None) + else: + floating_ips = db.floating_ip_get_all_by_host(None, host) + for floating_ip in floating_ips: + instance = None + if floating_ip['fixed_ip']: + instance = floating_ip['fixed_ip']['instance']['str_id'] + print "%s\t%s\t%s" % (floating_ip['host'], + floating_ip['address'], + instance) + + CATEGORIES = [ ('user', UserCommands), ('project', ProjectCommands), ('role', RoleCommands), ('shell', ShellCommands), ('vpn', VpnCommands), + ('floating', FloatingIpCommands) ] diff --git a/bin/nova-network b/bin/nova-network index 307795d7b..fa88aeb47 100755 --- a/bin/nova-network +++ b/bin/nova-network @@ -32,17 +32,12 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) -from nova import flags +from nova import service from nova import twistd -from nova.network import service - -FLAGS = flags.FLAGS - if __name__ == '__main__': twistd.serve(__file__) if __name__ == '__builtin__': - # pylint: disable-msg=C0103 - application = service.type_to_class(FLAGS.network_type).create() + application = service.Service.create() # pylint: disable-msg=C0103 diff --git a/bin/nova-objectstore b/bin/nova-objectstore index 447ef9055..728f2ee5b 100755 --- a/bin/nova-objectstore +++ b/bin/nova-objectstore @@ -46,4 +46,4 @@ if __name__ == '__main__': if __name__ == '__builtin__': utils.default_flagfile() - application = handler.get_application() # pylint: disable-msg=C0103 + application = handler.get_application() # pylint: disable-msg=C0103 diff --git a/bin/nova-scheduler b/bin/nova-scheduler new file mode 100755 index 000000000..38a8f213f --- /dev/null +++ b/bin/nova-scheduler @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# 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. + +""" + Twistd daemon for the nova scheduler nodes. +""" + +import os +import sys + +# 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... +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): + sys.path.insert(0, possible_topdir) + +from nova import service +from nova import twistd + + +if __name__ == '__main__': + twistd.serve(__file__) + +if __name__ == '__builtin__': + application = service.Service.create() diff --git a/bin/nova-volume b/bin/nova-volume index f8e2e1744..b9e235717 100755 --- a/bin/nova-volume +++ b/bin/nova-volume @@ -32,12 +32,12 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +from nova import service from nova import twistd -from nova.volume import service if __name__ == '__main__': twistd.serve(__file__) if __name__ == '__builtin__': - application = service.VolumeService.create() # pylint: disable-msg=C0103 + application = service.Service.create() # pylint: disable-msg=C0103 |
