summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorChiradeep Vittal <chiradeep@chiradeep-lt2>2011-01-04 15:42:59 -0800
committerChiradeep Vittal <chiradeep@chiradeep-lt2>2011-01-04 15:42:59 -0800
commitc40e41f7fbfac12ce07bbd1ee6bf57d1897e6009 (patch)
tree9cc9a299117fcee66b7668725325beeb04f8cc90 /bin
parent91e44607d1454a9c2e258910f009a034fb9cff1c (diff)
parentdd1e36b9690a2c2de18c565c496b25295a13d0aa (diff)
downloadnova-c40e41f7fbfac12ce07bbd1ee6bf57d1897e6009.tar.gz
nova-c40e41f7fbfac12ce07bbd1ee6bf57d1897e6009.tar.xz
nova-c40e41f7fbfac12ce07bbd1ee6bf57d1897e6009.zip
Merge from trunk again
Diffstat (limited to 'bin')
-rwxr-xr-xbin/nova-api-paste109
-rwxr-xr-xbin/nova-manage50
2 files changed, 158 insertions, 1 deletions
diff --git a/bin/nova-api-paste b/bin/nova-api-paste
new file mode 100755
index 000000000..6ee833a18
--- /dev/null
+++ b/bin/nova-api-paste
@@ -0,0 +1,109 @@
+#!/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.
+
+"""Starter script for Nova API."""
+
+import gettext
+import logging
+import os
+import sys
+
+from paste import deploy
+
+# 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)
+
+gettext.install('nova', unicode=1)
+
+from nova import flags
+from nova import wsgi
+
+LOG = logging.getLogger('nova.api')
+LOG.setLevel(logging.DEBUG)
+LOG.addHandler(logging.StreamHandler())
+
+FLAGS = flags.FLAGS
+
+API_ENDPOINTS = ['ec2', 'openstack']
+
+
+def load_configuration(paste_config):
+ """Load the paste configuration from the config file and return it."""
+ config = None
+ # Try each known name to get the global DEFAULTS, which will give ports
+ for name in API_ENDPOINTS:
+ try:
+ config = deploy.appconfig("config:%s" % paste_config, name=name)
+ except LookupError:
+ pass
+ if config:
+ verbose = config.get('verbose', None)
+ if verbose:
+ FLAGS.verbose = int(verbose) == 1
+ if FLAGS.verbose:
+ logging.getLogger().setLevel(logging.DEBUG)
+ return config
+ LOG.debug(_("Paste config at %s has no secion for known apis"),
+ paste_config)
+ print _("Paste config at %s has no secion for any known apis") % \
+ paste_config
+ os.exit(1)
+
+
+def launch_api(paste_config_file, section, server, port, host):
+ """Launch an api server from the specified port and IP."""
+ LOG.debug(_("Launching %s api on %s:%s"), section, host, port)
+ app = deploy.loadapp('config:%s' % paste_config_file, name=section)
+ server.start(app, int(port), host)
+
+
+def run_app(paste_config_file):
+ LOG.debug(_("Using paste.deploy config at: %s"), configfile)
+ config = load_configuration(paste_config_file)
+ LOG.debug(_("Configuration: %r"), config)
+ server = wsgi.Server()
+ ip = config.get('host', '0.0.0.0')
+ for api in API_ENDPOINTS:
+ port = config.get("%s_port" % api, None)
+ if not port:
+ continue
+ host = config.get("%s_host" % api, ip)
+ launch_api(configfile, api, server, port, host)
+ LOG.debug(_("All api servers launched, now waiting"))
+ server.wait()
+
+
+if __name__ == '__main__':
+ FLAGS(sys.argv)
+ configfiles = ['/etc/nova/nova-api.conf']
+ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
+ configfiles.insert(0,
+ os.path.join(possible_topdir, 'etc', 'nova-api.conf'))
+ for configfile in configfiles:
+ if os.path.exists(configfile):
+ run_app(configfile)
+ break
+ else:
+ LOG.debug(_("Skipping missing configuration: %s"), configfile)
diff --git a/bin/nova-manage b/bin/nova-manage
index 599e02a7e..3416c1a52 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -53,6 +53,7 @@
CLI interface for nova management.
"""
+import datetime
import gettext
import logging
import os
@@ -452,6 +453,52 @@ class NetworkCommands(object):
int(network_size), int(vlan_start),
int(vpn_start))
+
+class ServiceCommands(object):
+ """Enable and disable running services"""
+
+ def list(self, host=None, service=None):
+ """Show a list of all running services. Filter by host & service name.
+ args: [host] [service]"""
+ ctxt = context.get_admin_context()
+ now = datetime.datetime.utcnow()
+ services = db.service_get_all(ctxt)
+ if host:
+ services = [s for s in services if s['host'] == host]
+ if service:
+ services = [s for s in services if s['binary'] == service]
+ for svc in services:
+ delta = now - (svc['updated_at'] or svc['created_at'])
+ alive = (delta.seconds <= 15)
+ art = (alive and ":-)") or "XXX"
+ active = 'enabled'
+ if svc['disabled']:
+ active = 'disabled'
+ print "%-10s %-10s %-8s %s %s" % (svc['host'], svc['binary'],
+ active, art,
+ svc['updated_at'])
+
+ def enable(self, host, service):
+ """Enable scheduling for a service
+ args: host service"""
+ ctxt = context.get_admin_context()
+ svc = db.service_get_by_args(ctxt, host, service)
+ if not svc:
+ print "Unable to find service"
+ return
+ db.service_update(ctxt, svc['id'], {'disabled': False})
+
+ def disable(self, host, service):
+ """Disable scheduling for a service
+ args: host service"""
+ ctxt = context.get_admin_context()
+ svc = db.service_get_by_args(ctxt, host, service)
+ if not svc:
+ print "Unable to find service"
+ return
+ db.service_update(ctxt, svc['id'], {'disabled': True})
+
+
CATEGORIES = [
('user', UserCommands),
('project', ProjectCommands),
@@ -459,7 +506,8 @@ CATEGORIES = [
('shell', ShellCommands),
('vpn', VpnCommands),
('floating', FloatingIpCommands),
- ('network', NetworkCommands)]
+ ('network', NetworkCommands),
+ ('service', ServiceCommands)]
def lazy_match(name, key_value_tuples):