summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2010-08-18 22:14:24 +0100
committerJustin Santa Barbara <justin@fathomdb.com>2010-08-18 22:14:24 +0100
commitd8f8d121a00173cb3f5fb5e496cc010dc179cf19 (patch)
tree79ae8953421d065a13309ae5052a0faaee94b485 /bin
parent993563b6cc9db9f24480678cf8b2d0750aee7a92 (diff)
parent2af3bad97be40c135fb73f2e595e7fda86f17900 (diff)
downloadnova-d8f8d121a00173cb3f5fb5e496cc010dc179cf19.tar.gz
nova-d8f8d121a00173cb3f5fb5e496cc010dc179cf19.tar.xz
nova-d8f8d121a00173cb3f5fb5e496cc010dc179cf19.zip
Merged with trunk
Diffstat (limited to 'bin')
-rwxr-xr-xbin/nova-api6
-rwxr-xr-xbin/nova-api-new34
-rwxr-xr-xbin/nova-dhcpbridge43
-rwxr-xr-xbin/nova-import-canonical-imagestore33
-rwxr-xr-xbin/nova-instancemonitor18
-rwxr-xr-xbin/nova-manage141
-rwxr-xr-xbin/nova-objectstore8
-rwxr-xr-xbin/nova-rsapi58
8 files changed, 161 insertions, 180 deletions
diff --git a/bin/nova-api b/bin/nova-api
index 1f2009c30..13baf22a7 100755
--- a/bin/nova-api
+++ b/bin/nova-api
@@ -29,8 +29,6 @@ from nova import flags
from nova import rpc
from nova import server
from nova import utils
-from nova.auth import manager
-from nova.compute import model
from nova.endpoint import admin
from nova.endpoint import api
from nova.endpoint import cloud
@@ -39,10 +37,10 @@ FLAGS = flags.FLAGS
def main(_argv):
+ """Load the controllers and start the tornado I/O loop."""
controllers = {
'Cloud': cloud.CloudController(),
- 'Admin': admin.AdminController()
- }
+ 'Admin': admin.AdminController()}
_app = api.APIServerApplication(controllers)
conn = rpc.Connection.instance()
diff --git a/bin/nova-api-new b/bin/nova-api-new
new file mode 100755
index 000000000..fda42339c
--- /dev/null
+++ b/bin/nova-api-new
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# pylint: disable-msg=C0103
+# 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.
+"""
+Nova API daemon.
+"""
+
+from nova import api
+from nova import flags
+from nova import utils
+from nova import wsgi
+
+FLAGS = flags.FLAGS
+flags.DEFINE_integer('api_port', 8773, 'API port')
+
+if __name__ == '__main__':
+ utils.default_flagfile()
+ wsgi.run_server(api.API(), FLAGS.api_port)
diff --git a/bin/nova-dhcpbridge b/bin/nova-dhcpbridge
index b3e7d456a..f70a4482c 100755
--- a/bin/nova-dhcpbridge
+++ b/bin/nova-dhcpbridge
@@ -18,8 +18,6 @@
# under the License.
"""
-nova-dhcpbridge
-
Handle lease database updates from DHCP servers.
"""
@@ -42,34 +40,42 @@ from nova.network import service
FLAGS = flags.FLAGS
-def add_lease(mac, ip, hostname, interface):
+def add_lease(_mac, ip, _hostname, _interface):
+ """Set the IP that was assigned by the DHCP server."""
if FLAGS.fake_rabbit:
service.VlanNetworkService().lease_ip(ip)
else:
- rpc.cast("%s.%s" (FLAGS.network_topic, FLAGS.node_name),
+ rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name),
{"method": "lease_ip",
- "args" : {"fixed_ip": ip}})
+ "args": {"fixed_ip": ip}})
+
-def old_lease(mac, ip, hostname, interface):
+def old_lease(_mac, _ip, _hostname, _interface):
+ """Do nothing, just an old lease update."""
logging.debug("Adopted old lease or got a change of mac/hostname")
-def del_lease(mac, ip, hostname, interface):
+
+def del_lease(_mac, ip, _hostname, _interface):
+ """Called when a lease expires."""
if FLAGS.fake_rabbit:
service.VlanNetworkService().release_ip(ip)
else:
- rpc.cast("%s.%s" (FLAGS.network_topic, FLAGS.node_name),
+ rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.node_name),
{"method": "release_ip",
- "args" : {"fixed_ip": ip}})
+ "args": {"fixed_ip": ip}})
+
def init_leases(interface):
+ """Get the list of hosts for an interface."""
net = model.get_network_by_interface(interface)
res = ""
- for host_name in net.hosts:
- res += "%s\n" % linux_net.hostDHCP(net, host_name, net.hosts[host_name])
+ for address in net.assigned_objs:
+ res += "%s\n" % linux_net.host_dhcp(address)
return res
def main():
+ """Parse environment and arguments and call the approproate action."""
flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile)
utils.default_flagfile(flagfile)
argv = FLAGS(sys.argv)
@@ -79,18 +85,19 @@ def main():
FLAGS.redis_db = 8
FLAGS.network_size = 32
FLAGS.connection_type = 'fake'
- FLAGS.fake_network=True
- FLAGS.auth_driver='nova.auth.ldapdriver.FakeLdapDriver'
+ FLAGS.fake_network = True
+ FLAGS.auth_driver = 'nova.auth.ldapdriver.FakeLdapDriver'
action = argv[1]
- if action in ['add','del','old']:
+ if action in ['add', 'del', 'old']:
mac = argv[2]
ip = argv[3]
hostname = argv[4]
- logging.debug("Called %s for mac %s with ip %s and hostname %s on interface %s" % (action, mac, ip, hostname, interface))
- globals()[action+'_lease'](mac, ip, hostname, interface)
+ logging.debug("Called %s for mac %s with ip %s and "
+ "hostname %s on interface %s",
+ action, mac, ip, hostname, interface)
+ globals()[action + '_lease'](mac, ip, hostname, interface)
else:
print init_leases(interface)
- exit(0)
if __name__ == "__main__":
- sys.exit(main())
+ main()
diff --git a/bin/nova-import-canonical-imagestore b/bin/nova-import-canonical-imagestore
index 8106cc5ca..44e65191d 100755
--- a/bin/nova-import-canonical-imagestore
+++ b/bin/nova-import-canonical-imagestore
@@ -37,20 +37,17 @@ FLAGS = flags.FLAGS
api_url = 'https://imagestore.canonical.com/api/dashboard'
-image_cache = None
-def images():
- global image_cache
- if not image_cache:
- try:
- images = json.load(urllib2.urlopen(api_url))['images']
- image_cache = [i for i in images if i['title'].find('amd64') > -1]
- except Exception:
- print 'unable to download canonical image list'
- sys.exit(1)
- return image_cache
-
-# FIXME(ja): add checksum/signature checks
+
+def get_images():
+ """Get a list of the images from the imagestore URL."""
+ images = json.load(urllib2.urlopen(api_url))['images']
+ images = [img for img in images if img['title'].find('amd64') > -1]
+ return images
+
+
def download(img):
+ """Download an image to the local filesystem."""
+ # FIXME(ja): add checksum/signature checks
tempdir = tempfile.mkdtemp(prefix='cis-')
kernel_id = None
@@ -79,20 +76,22 @@ def download(img):
shutil.rmtree(tempdir)
+
def main():
+ """Main entry point."""
utils.default_flagfile()
argv = FLAGS(sys.argv)
+ images = get_images()
if len(argv) == 2:
- for img in images():
+ for img in images:
if argv[1] == 'all' or argv[1] == img['title']:
download(img)
else:
print 'usage: %s (title|all)'
print 'available images:'
- for image in images():
- print image['title']
+ for img in images:
+ print img['title']
if __name__ == '__main__':
main()
-
diff --git a/bin/nova-instancemonitor b/bin/nova-instancemonitor
index b195089b7..911fb6f42 100755
--- a/bin/nova-instancemonitor
+++ b/bin/nova-instancemonitor
@@ -22,7 +22,6 @@
"""
import logging
-from twisted.internet import task
from twisted.application import service
from nova import twistd
@@ -30,7 +29,11 @@ from nova.compute import monitor
logging.getLogger('boto').setLevel(logging.WARN)
-def main():
+
+if __name__ == '__main__':
+ twistd.serve(__file__)
+
+if __name__ == '__builtin__':
logging.warn('Starting instance monitor')
m = monitor.InstanceMonitor()
@@ -38,14 +41,3 @@ def main():
# parses this file, return it so that we can get it into globals below
application = service.Application('nova-instancemonitor')
m.setServiceParent(application)
- return application
-
-if __name__ == '__main__':
- twistd.serve(__file__)
-
-if __name__ == '__builtin__':
- application = main()
-
-
-
-
diff --git a/bin/nova-manage b/bin/nova-manage
index c1fe2a823..2b1651c00 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -37,12 +37,15 @@ FLAGS = flags.FLAGS
class VpnCommands(object):
+ """Class for managing VPNs."""
+
def __init__(self):
self.manager = manager.AuthManager()
self.instdir = model.InstanceDirectory()
self.pipe = pipelib.CloudPipe(cloud.CloudController())
def list(self):
+ """Print a listing of the VPNs for all projects."""
print "%-12s\t" % 'project',
print "%-12s\t" % 'ip:port',
print "%s" % 'state'
@@ -50,11 +53,11 @@ class VpnCommands(object):
print "%-12s\t" % project.name,
print "%s:%s\t" % (project.vpn_ip, project.vpn_port),
- vpn = self.__vpn_for(project.id)
+ vpn = self._vpn_for(project.id)
if vpn:
- out, err = utils.execute(
- "ping -c1 -w1 %s > /dev/null; echo $?"
- % vpn['private_dns_name'], check_exit_code=False)
+ command = "ping -c1 -w1 %s > /dev/null; echo $?"
+ out, _err = utils.execute( command % vpn['private_dns_name'],
+ check_exit_code=False)
if out.strip() == '0':
net = 'up'
else:
@@ -68,25 +71,32 @@ class VpnCommands(object):
else:
print None
- def __vpn_for(self, project_id):
+ def _vpn_for(self, project_id):
+ """Get the VPN instance for a project ID."""
for instance in self.instdir.all:
- if (instance.state.has_key('image_id')
+ if ('image_id' in instance.state
and instance['image_id'] == FLAGS.vpn_image_id
- and not instance['state_description'] in ['shutting_down', 'shutdown']
+ and not instance['state_description'] in
+ ['shutting_down', 'shutdown']
and instance['project_id'] == project_id):
return instance
def spawn(self):
+ """Run all VPNs."""
for p in reversed(self.manager.get_projects()):
- if not self.__vpn_for(p.id):
- print 'spawning %s' % p.id
- self.pipe.launch_vpn_instance(p.id)
- time.sleep(10)
+ if not self._vpn_for(p.id):
+ print 'spawning %s' % p.id
+ self.pipe.launch_vpn_instance(p.id)
+ time.sleep(10)
def run(self, project_id):
+ """Start the VPN for a given project."""
self.pipe.launch_vpn_instance(project_id)
+
class RoleCommands(object):
+ """Class for managing roles."""
+
def __init__(self):
self.manager = manager.AuthManager()
@@ -109,25 +119,24 @@ class RoleCommands(object):
arguments: user, role [project]"""
self.manager.remove_role(user, role, project)
+
class UserCommands(object):
+ """Class for managing users."""
+
def __init__(self):
self.manager = manager.AuthManager()
- def __print_export(self, user):
- print 'export EC2_ACCESS_KEY=%s' % user.access
- print 'export EC2_SECRET_KEY=%s' % user.secret
-
def admin(self, name, access=None, secret=None):
"""creates a new admin and prints exports
arguments: name [access] [secret]"""
user = self.manager.create_user(name, access, secret, True)
- self.__print_export(user)
+ 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)
- self.__print_export(user)
+ print_export(user)
def delete(self, name):
"""deletes an existing user
@@ -139,7 +148,7 @@ class UserCommands(object):
arguments: name"""
user = self.manager.get_user(name)
if user:
- self.__print_export(user)
+ print_export(user)
else:
print "User %s doesn't exist" % name
@@ -149,53 +158,58 @@ class UserCommands(object):
for user in self.manager.get_users():
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."""
+
def __init__(self):
self.manager = manager.AuthManager()
def add(self, project, user):
- """adds user to project
+ """Adds user to project
arguments: project user"""
self.manager.add_to_project(user, project)
def create(self, name, project_manager, description=None):
- """creates a new project
+ """Creates a new project
arguments: name project_manager [description]"""
- user = self.manager.create_project(name, project_manager, description)
+ self.manager.create_project(name, project_manager, description)
def delete(self, name):
- """deletes an existing project
+ """Deletes an existing project
arguments: name"""
self.manager.delete_project(name)
def environment(self, project_id, user_id, filename='novarc'):
- """exports environment variables to an sourcable file
+ """Exports environment variables to an sourcable file
arguments: project_id user_id [filename='novarc]"""
rc = self.manager.get_environment_rc(project_id, user_id)
with open(filename, 'w') as f:
f.write(rc)
def list(self):
- """lists all projects
+ """Lists all projects
arguments: <none>"""
for project in self.manager.get_projects():
print project.name
def remove(self, project, user):
- """removes user from project
+ """Removes user from project
arguments: project user"""
self.manager.remove_from_project(user, project)
- def zip(self, project_id, user_id, filename='nova.zip'):
- """exports credentials for project to a zip file
+ 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]"""
- zip = self.manager.get_credentials(project_id, user_id)
+ zip_file = self.manager.get_credentials(user_id, project_id)
with open(filename, 'w') as f:
- f.write(zip)
-
-
-def usage(script_name):
- print script_name + " category action [<args>]"
+ f.write(zip_file)
categories = [
@@ -207,62 +221,61 @@ categories = [
def lazy_match(name, key_value_tuples):
- """finds all objects that have a key that case insensitively contains [name]
- key_value_tuples is a list of tuples of the form (key, value)
+ """Finds all objects that have a key that case insensitively contains
+ [name] key_value_tuples is a list of tuples of the form (key, value)
returns a list of tuples of the form (key, value)"""
- return [(k, v) for (k, v) in key_value_tuples if k.lower().find(name.lower()) == 0]
+ result = []
+ for (k, v) in key_value_tuples:
+ if k.lower().find(name.lower()) == 0:
+ result.append((k, v))
+ if len(result) == 0:
+ print "%s does not match any options:" % name
+ for k, _v in key_value_tuples:
+ print "\t%s" % k
+ sys.exit(2)
+ if len(result) > 1:
+ print "%s matched multiple options:" % name
+ for k, _v in result:
+ print "\t%s" % k
+ sys.exit(2)
+ return result
def methods_of(obj):
- """get all callable methods of an object that don't start with underscore
+ """Get all callable methods of an object that don't start with underscore
returns a list of tuples of the form (method_name, method)"""
- return [(i, getattr(obj, i)) for i in dir(obj) if callable(getattr(obj, i)) and not i.startswith('_')]
+ result = []
+ for i in dir(obj):
+ if callable(getattr(obj, i)) and not i.startswith('_'):
+ result.append((i, getattr(obj, i)))
+ return result
-if __name__ == '__main__':
+def main():
+ """Parse options and call the appropriate class/method."""
utils.default_flagfile('/etc/nova/nova-manage.conf')
argv = FLAGS(sys.argv)
script_name = argv.pop(0)
if len(argv) < 1:
- usage(script_name)
+ print script_name + " category action [<args>]"
print "Available categories:"
- for k, v in categories:
+ for k, _ in categories:
print "\t%s" % k
sys.exit(2)
category = argv.pop(0)
matches = lazy_match(category, categories)
- if len(matches) == 0:
- print "%s does not match any categories:" % category
- for k, v in categories:
- print "\t%s" % k
- sys.exit(2)
- if len(matches) > 1:
- print "%s matched multiple categories:" % category
- for k, v in matches:
- print "\t%s" % k
- sys.exit(2)
# instantiate the command group object
category, fn = matches[0]
command_object = fn()
actions = methods_of(command_object)
if len(argv) < 1:
- usage(script_name)
+ print script_name + " category action [<args>]"
print "Available actions for %s category:" % category
- for k, v in actions:
+ for k, _v in actions:
print "\t%s" % k
sys.exit(2)
action = argv.pop(0)
matches = lazy_match(action, actions)
- if len(matches) == 0:
- print "%s does not match any actions" % action
- for k, v in actions:
- print "\t%s" % k
- sys.exit(2)
- if len(matches) > 1:
- print "%s matched multiple actions:" % action
- for k, v in matches:
- print "\t%s" % k
- sys.exit(2)
action, fn = matches[0]
# call the action with the remaining arguments
try:
@@ -273,3 +286,5 @@ if __name__ == '__main__':
print "%s %s: %s" % (category, action, fn.__doc__)
sys.exit(2)
+if __name__ == '__main__':
+ main()
diff --git a/bin/nova-objectstore b/bin/nova-objectstore
index c0fa815c0..02f2bcb48 100755
--- a/bin/nova-objectstore
+++ b/bin/nova-objectstore
@@ -30,15 +30,9 @@ from nova.objectstore import handler
FLAGS = flags.FLAGS
-def main():
- app = handler.get_application()
- print app
- return app
-
-# NOTE(soren): Stolen from nova-compute
if __name__ == '__main__':
twistd.serve(__file__)
if __name__ == '__builtin__':
utils.default_flagfile()
- application = main()
+ application = handler.get_application()
diff --git a/bin/nova-rsapi b/bin/nova-rsapi
deleted file mode 100755
index 306a1fc60..000000000
--- a/bin/nova-rsapi
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/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.
-"""
- WSGI daemon for the main API endpoint.
-"""
-
-import logging
-from tornado import ioloop
-from wsgiref import simple_server
-
-from nova import flags
-from nova import rpc
-from nova import server
-from nova import utils
-from nova.auth import manager
-from nova.endpoint import rackspace
-
-FLAGS = flags.FLAGS
-flags.DEFINE_integer('cc_port', 8773, 'cloud controller port')
-
-def main(_argv):
- user_manager = manager.AuthManager()
- api_instance = rackspace.Api(user_manager)
- conn = rpc.Connection.instance()
- rpc_consumer = rpc.AdapterConsumer(connection=conn,
- topic=FLAGS.cloud_topic,
- proxy=api_instance)
-
-# TODO: fire rpc response listener (without attach to tornado)
-# io_inst = ioloop.IOLoop.instance()
-# _injected = consumer.attach_to_tornado(io_inst)
-
- http_server = simple_server.WSGIServer(('0.0.0.0', FLAGS.cc_port), simple_server.WSGIRequestHandler)
- http_server.set_app(api_instance.handler)
- logging.debug('Started HTTP server on port %i' % FLAGS.cc_port)
- while True:
- http_server.handle_request()
-# io_inst.start()
-
-if __name__ == '__main__':
- utils.default_flagfile()
- server.serve('nova-rsapi', main)