summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2011-06-28 17:05:41 -0500
committerJosh Kearney <josh@jk0.org>2011-06-28 17:05:41 -0500
commitd59e576dfeccdbd7ee82ea2803b57e24dcba2c22 (patch)
treeea8c17a46c7fe9f354e48aa6b9aa754586d13875 /bin
parentd0ff8a737111e9155fd59816afa5c4fc2b34bb4c (diff)
parent9ae4fbdef0a5f4c925c7e3d546edea06e608e39b (diff)
downloadnova-d59e576dfeccdbd7ee82ea2803b57e24dcba2c22.tar.gz
nova-d59e576dfeccdbd7ee82ea2803b57e24dcba2c22.tar.xz
nova-d59e576dfeccdbd7ee82ea2803b57e24dcba2c22.zip
Merged trunk
Diffstat (limited to 'bin')
-rwxr-xr-xbin/instance-usage-audit116
-rwxr-xr-xbin/nova-ajax-console-proxy5
-rwxr-xr-xbin/nova-api53
-rwxr-xr-xbin/nova-direct-api7
-rwxr-xr-xbin/nova-manage6
-rwxr-xr-xbin/nova-objectstore7
-rwxr-xr-xbin/nova-vncproxy7
7 files changed, 158 insertions, 43 deletions
diff --git a/bin/instance-usage-audit b/bin/instance-usage-audit
new file mode 100755
index 000000000..a06c6b1b3
--- /dev/null
+++ b/bin/instance-usage-audit
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2011 Openstack, LLC.
+# 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.
+
+"""Cron script to generate usage notifications for instances neither created
+ nor destroyed in a given time period.
+
+ Together with the notifications generated by compute on instance
+ create/delete/resize, over that ime period, this allows an external
+ system consuming usage notification feeds to calculate instance usage
+ for each tenant.
+
+ Time periods are specified like so:
+ <number>[mdy]
+
+ 1m = previous month. If the script is run April 1, it will generate usages
+ for March 1 thry March 31.
+ 3m = 3 previous months.
+ 90d = previous 90 days.
+ 1y = previous year. If run on Jan 1, it generates usages for
+ Jan 1 thru Dec 31 of the previous year.
+"""
+
+import datetime
+import gettext
+import os
+import sys
+import time
+
+# 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 context
+from nova import db
+from nova import exception
+from nova import flags
+from nova import log as logging
+from nova import utils
+
+from nova.notifier import api as notifier_api
+
+FLAGS = flags.FLAGS
+flags.DEFINE_string('instance_usage_audit_period', '1m',
+ 'time period to generate instance usages for.')
+
+
+def time_period(period):
+ today = datetime.date.today()
+ unit = period[-1]
+ if unit not in 'mdy':
+ raise ValueError('Time period must be m, d, or y')
+ n = int(period[:-1])
+ if unit == 'm':
+ year = today.year - (n // 12)
+ n = n % 12
+ if n >= today.month:
+ year -= 1
+ month = 12 + (today.month - n)
+ else:
+ month = today.month - n
+ begin = datetime.datetime(day=1, month=month, year=year)
+ end = datetime.datetime(day=1, month=today.month, year=today.year)
+
+ elif unit == 'y':
+ begin = datetime.datetime(day=1, month=1, year=today.year - n)
+ end = datetime.datetime(day=1, month=1, year=today.year)
+
+ elif unit == 'd':
+ b = today - datetime.timedelta(days=n)
+ begin = datetime.datetime(day=b.day, month=b.month, year=b.year)
+ end = datetime.datetime(day=today.day,
+ month=today.month,
+ year=today.year)
+
+ return (begin, end)
+
+if __name__ == '__main__':
+ utils.default_flagfile()
+ flags.FLAGS(sys.argv)
+ logging.setup()
+ begin, end = time_period(FLAGS.instance_usage_audit_period)
+ print "Creating usages for %s until %s" % (str(begin), str(end))
+ instances = db.instance_get_active_by_window(context.get_admin_context(),
+ begin,
+ end)
+ print "%s instances" % len(instances)
+ for instance_ref in instances:
+ usage_info = utils.usage_from_instance(instance_ref,
+ audit_period_begining=str(begin),
+ audit_period_ending=str(end))
+ notifier_api.notify('compute.%s' % FLAGS.host,
+ 'compute.instance.exists',
+ notifier_api.INFO,
+ usage_info)
diff --git a/bin/nova-ajax-console-proxy b/bin/nova-ajax-console-proxy
index d88f59e40..21cf68007 100755
--- a/bin/nova-ajax-console-proxy
+++ b/bin/nova-ajax-console-proxy
@@ -137,8 +137,9 @@ if __name__ == '__main__':
utils.default_flagfile()
FLAGS(sys.argv)
logging.setup()
- server = wsgi.Server()
+ acp_port = FLAGS.ajax_console_proxy_port
acp = AjaxConsoleProxy()
acp.register_listeners()
- server.start(acp, FLAGS.ajax_console_proxy_port, host='0.0.0.0')
+ server = wsgi.Server("AJAX Console Proxy", acp, port=acp_port)
+ server.start()
server.wait()
diff --git a/bin/nova-api b/bin/nova-api
index a1088c23d..ea99a1b48 100755
--- a/bin/nova-api
+++ b/bin/nova-api
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-# pylint: disable=C0103
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 United States Government as represented by the
@@ -18,44 +17,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Starter script for Nova API."""
+"""Starter script for Nova API.
+
+Starts both the EC2 and OpenStack APIs in separate processes.
+
+"""
-import gettext
-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)
+import nova.service
+import nova.utils
+
-gettext.install('nova', unicode=1)
+def main():
+ """Launch EC2 and OSAPI services."""
+ nova.utils.Bootstrapper.bootstrap_binary(sys.argv)
-from nova import flags
-from nova import log as logging
-from nova import service
-from nova import utils
-from nova import version
-from nova import wsgi
+ ec2 = nova.service.WSGIService("ec2")
+ osapi = nova.service.WSGIService("osapi")
+ launcher = nova.service.Launcher()
+ launcher.launch_service(ec2)
+ launcher.launch_service(osapi)
-LOG = logging.getLogger('nova.api')
+ try:
+ launcher.wait()
+ except KeyboardInterrupt:
+ launcher.stop()
-FLAGS = flags.FLAGS
if __name__ == '__main__':
- utils.default_flagfile()
- FLAGS(sys.argv)
- logging.setup()
- LOG.audit(_("Starting nova-api node (version %s)"),
- version.version_string_with_vcs())
- LOG.debug(_("Full set of FLAGS:"))
- for flag in FLAGS:
- flag_get = FLAGS.get(flag, None)
- LOG.debug("%(flag)s : %(flag_get)s" % locals())
-
- service = service.serve_wsgi(service.ApiService)
- service.wait()
+ sys.exit(main())
diff --git a/bin/nova-direct-api b/bin/nova-direct-api
index 83ec72722..c6cf9b2ff 100755
--- a/bin/nova-direct-api
+++ b/bin/nova-direct-api
@@ -93,6 +93,9 @@ if __name__ == '__main__':
with_req = direct.PostParamsMiddleware(with_json)
with_auth = direct.DelegatedAuthMiddleware(with_req)
- server = wsgi.Server()
- server.start(with_auth, FLAGS.direct_port, host=FLAGS.direct_host)
+ server = wsgi.Server("Direct API",
+ with_auth,
+ host=FLAGS.direct_host,
+ port=FLAGS.direct_port)
+ server.start()
server.wait()
diff --git a/bin/nova-manage b/bin/nova-manage
index 0d9fbc69a..02f20347d 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -56,11 +56,11 @@
import gettext
import glob
import json
+import netaddr
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...
@@ -518,7 +518,7 @@ class FloatingIpCommands(object):
def create(self, host, range):
"""Creates floating ips for host by range
arguments: host ip_range"""
- for address in IPy.IP(range):
+ for address in netaddr.IPNetwork(range):
db.floating_ip_create(context.get_admin_context(),
{'address': str(address),
'host': host})
@@ -526,7 +526,7 @@ class FloatingIpCommands(object):
def delete(self, ip_range):
"""Deletes floating ips by range
arguments: range"""
- for address in IPy.IP(ip_range):
+ for address in netaddr.IPNetwork(ip_range):
db.floating_ip_destroy(context.get_admin_context(),
str(address))
diff --git a/bin/nova-objectstore b/bin/nova-objectstore
index 6ef841b85..1aef3a255 100755
--- a/bin/nova-objectstore
+++ b/bin/nova-objectstore
@@ -50,6 +50,9 @@ if __name__ == '__main__':
FLAGS(sys.argv)
logging.setup()
router = s3server.S3Application(FLAGS.buckets_path)
- server = wsgi.Server()
- server.start(router, FLAGS.s3_port, host=FLAGS.s3_host)
+ server = wsgi.Server("S3 Objectstore",
+ router,
+ port=FLAGS.s3_port,
+ host=FLAGS.s3_host)
+ server.start()
server.wait()
diff --git a/bin/nova-vncproxy b/bin/nova-vncproxy
index ccb97e3a3..72271df3a 100755
--- a/bin/nova-vncproxy
+++ b/bin/nova-vncproxy
@@ -96,6 +96,9 @@ if __name__ == "__main__":
service.serve()
- server = wsgi.Server()
- server.start(with_auth, FLAGS.vncproxy_port, host=FLAGS.vncproxy_host)
+ server = wsgi.Server("VNC Proxy",
+ with_auth,
+ host=FLAGS.vncproxy_host,
+ port=FLAGS.vncproxy_port)
+ server.start()
server.wait()