summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorIsaku Yamahata <yamahata@valinux.co.jp>2011-07-08 12:07:58 +0900
committerIsaku Yamahata <yamahata@valinux.co.jp>2011-07-08 12:07:58 +0900
commita02895b6bb353a468ce7c58e60bc2dbd152c5ec9 (patch)
tree605c2efa569a42fd6f059299da1316edb597fec1 /bin
parent02c0bf3b242395e63baf582b1f9c279eef4282d6 (diff)
parentbc8f009f8ac6393301dd857339918d40b93be63d (diff)
downloadnova-a02895b6bb353a468ce7c58e60bc2dbd152c5ec9.tar.gz
nova-a02895b6bb353a468ce7c58e60bc2dbd152c5ec9.tar.xz
nova-a02895b6bb353a468ce7c58e60bc2dbd152c5ec9.zip
merge with trunk
Diffstat (limited to 'bin')
-rwxr-xr-xbin/instance-usage-audit116
-rwxr-xr-xbin/nova-ajax-console-proxy5
-rwxr-xr-xbin/nova-api55
-rwxr-xr-xbin/nova-dhcpbridge8
-rwxr-xr-xbin/nova-direct-api7
-rwxr-xr-xbin/nova-manage83
-rwxr-xr-xbin/nova-objectstore7
-rwxr-xr-xbin/nova-vncproxy22
8 files changed, 231 insertions, 72 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..fff67251f 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,40 @@
# 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')):
+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)
+import nova.service
+import nova.utils
+
+
+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-dhcpbridge b/bin/nova-dhcpbridge
index 5926b97de..6d9d85896 100755
--- a/bin/nova-dhcpbridge
+++ b/bin/nova-dhcpbridge
@@ -59,14 +59,12 @@ def add_lease(mac, ip_address, _hostname, _interface):
LOG.debug(_("leasing ip"))
network_manager = utils.import_object(FLAGS.network_manager)
network_manager.lease_fixed_ip(context.get_admin_context(),
- mac,
ip_address)
else:
rpc.cast(context.get_admin_context(),
"%s.%s" % (FLAGS.network_topic, FLAGS.host),
{"method": "lease_fixed_ip",
- "args": {"mac": mac,
- "address": ip_address}})
+ "args": {"address": ip_address}})
def old_lease(mac, ip_address, hostname, interface):
@@ -81,14 +79,12 @@ def del_lease(mac, ip_address, _hostname, _interface):
LOG.debug(_("releasing ip"))
network_manager = utils.import_object(FLAGS.network_manager)
network_manager.release_fixed_ip(context.get_admin_context(),
- mac,
ip_address)
else:
rpc.cast(context.get_admin_context(),
"%s.%s" % (FLAGS.network_topic, FLAGS.host),
{"method": "release_fixed_ip",
- "args": {"mac": mac,
- "address": ip_address}})
+ "args": {"address": ip_address}})
def init_leases(interface):
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 02f20347d..7dfe91698 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -172,17 +172,23 @@ class VpnCommands(object):
def change(self, project_id, ip, port):
"""Change the ip and port for a vpn.
+ this will update all networks associated with a project
+ not sure if that's the desired behavior or not, patches accepted
+
args: project, ip, port"""
+ # TODO(tr3buchet): perhaps this shouldn't update all networks
+ # associated with a project in the future
project = self.manager.get_project(project_id)
if not project:
print 'No project %s' % (project_id)
return
- admin = context.get_admin_context()
- network_ref = db.project_get_network(admin, project_id)
- db.network_update(admin,
- network_ref['id'],
- {'vpn_public_address': ip,
- 'vpn_public_port': int(port)})
+ admin_context = context.get_admin_context()
+ networks = db.project_get_networks(admin_context, project_id)
+ for network in networks:
+ db.network_update(admin_context,
+ network['id'],
+ {'vpn_public_address': ip,
+ 'vpn_public_port': int(port)})
class ShellCommands(object):
@@ -446,12 +452,13 @@ class ProjectCommands(object):
def scrub(self, project_id):
"""Deletes data associated with project
arguments: project_id"""
- ctxt = context.get_admin_context()
- network_ref = db.project_get_network(ctxt, project_id)
- db.network_disassociate(ctxt, network_ref['id'])
- groups = db.security_group_get_by_project(ctxt, project_id)
+ admin_context = context.get_admin_context()
+ networks = db.project_get_networks(admin_context, project_id)
+ for network in networks:
+ db.network_disassociate(admin_context, network['id'])
+ groups = db.security_group_get_by_project(admin_context, project_id)
for group in groups:
- db.security_group_destroy(ctxt, group['id'])
+ db.security_group_destroy(admin_context, group['id'])
def zipfile(self, project_id, user_id, filename='nova.zip'):
"""Exports credentials for project to a zip file
@@ -505,7 +512,7 @@ class FixedIpCommands(object):
instance = fixed_ip['instance']
hostname = instance['hostname']
host = instance['host']
- mac_address = instance['mac_address']
+ mac_address = fixed_ip['mac_address']['address']
print "%-18s\t%-15s\t%-17s\t%-15s\t%s" % (
fixed_ip['network']['cidr'],
fixed_ip['address'],
@@ -515,13 +522,12 @@ class FixedIpCommands(object):
class FloatingIpCommands(object):
"""Class for managing floating ip."""
- def create(self, host, range):
- """Creates floating ips for host by range
- arguments: host ip_range"""
+ def create(self, range):
+ """Creates floating ips for zone by range
+ arguments: ip_range"""
for address in netaddr.IPNetwork(range):
db.floating_ip_create(context.get_admin_context(),
- {'address': str(address),
- 'host': host})
+ {'address': str(address)})
def delete(self, ip_range):
"""Deletes floating ips by range
@@ -532,7 +538,8 @@ class FloatingIpCommands(object):
def list(self, host=None):
"""Lists all floating ips (optionally by host)
- arguments: [host]"""
+ arguments: [host]
+ Note: if host is given, only active floating IPs are returned"""
ctxt = context.get_admin_context()
if host is None:
floating_ips = db.floating_ip_get_all(ctxt)
@@ -550,10 +557,23 @@ class FloatingIpCommands(object):
class NetworkCommands(object):
"""Class for managing networks."""
- 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'):
- """Creates fixed ips for host by range"""
+ def create(self, label=None, fixed_range=None, num_networks=None,
+ network_size=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],
+ [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
+ Ex: network create private 10.0.0.0/8 1 15 0 0 0 0 xenbr1 eth1
+ network create private 10.0.0.0/8 1 15
+ """
+ if not label:
+ msg = _('a label (ex: public) is required to create networks.')
+ print msg
+ raise TypeError(msg)
if not fixed_range:
msg = _('Fixed range in the form of 10.0.0.0/8 is '
'required to create networks.')
@@ -569,11 +589,17 @@ class NetworkCommands(object):
vpn_start = FLAGS.vpn_start
if not fixed_range_v6:
fixed_range_v6 = FLAGS.fixed_range_v6
+ if not flat_network_bridge:
+ flat_network_bridge = FLAGS.flat_network_bridge
+ if not bridge_interface:
+ bridge_interface = FLAGS.flat_interface or FLAGS.vlan_interface
if not gateway_v6:
gateway_v6 = FLAGS.gateway_v6
net_manager = utils.import_object(FLAGS.network_manager)
+
try:
net_manager.create_networks(context.get_admin_context(),
+ label=label,
cidr=fixed_range,
num_networks=int(num_networks),
network_size=int(network_size),
@@ -581,7 +607,8 @@ class NetworkCommands(object):
vpn_start=int(vpn_start),
cidr_v6=fixed_range_v6,
gateway_v6=gateway_v6,
- label=label)
+ bridge=flat_network_bridge,
+ bridge_interface=bridge_interface)
except ValueError, e:
print e
raise e
@@ -617,7 +644,7 @@ class VmCommands(object):
:param host: show all instance on specified host.
:param instance: show specificed instance.
"""
- print "%-10s %-15s %-10s %-10s %-19s %-12s %-12s %-12s" \
+ print "%-10s %-15s %-10s %-10s %-26s %-9s %-9s %-9s" \
" %-10s %-10s %-10s %-5s" % (
_('instance'),
_('node'),
@@ -639,14 +666,14 @@ class VmCommands(object):
context.get_admin_context(), host)
for instance in instances:
- print "%-10s %-15s %-10s %-10s %-19s %-12s %-12s %-12s" \
+ print "%-10s %-15s %-10s %-10s %-26s %-9s %-9s %-9s" \
" %-10s %-10s %-10s %-5d" % (
instance['hostname'],
instance['host'],
- instance['instance_type'],
+ instance['instance_type'].name,
instance['state_description'],
instance['launched_at'],
- instance['image_id'],
+ instance['image_ref'],
instance['kernel_id'],
instance['ramdisk_id'],
instance['project_id'],
@@ -878,7 +905,7 @@ class InstanceTypeCommands(object):
try:
instance_types.create(name, memory, vcpus, local_gb,
flavorid, swap, rxtx_quota, rxtx_cap)
- except exception.InvalidInput:
+ except exception.InvalidInput, e:
print "Must supply valid parameters to create instance_type"
print e
sys.exit(1)
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..bdbb30a7f 100755
--- a/bin/nova-vncproxy
+++ b/bin/nova-vncproxy
@@ -63,6 +63,19 @@ flags.DEFINE_flag(flags.HelpshortFlag())
flags.DEFINE_flag(flags.HelpXMLFlag())
+def handle_flash_socket_policy(socket):
+ LOG.info(_("Received connection on flash socket policy port"))
+
+ fd = socket.makefile('rw')
+ expected_command = "<policy-file-request/>"
+ if expected_command in fd.read(len(expected_command) + 1):
+ LOG.info(_("Received valid flash socket policy request"))
+ fd.write('<?xml version="1.0"?><cross-domain-policy><allow-'
+ 'access-from domain="*" to-ports="%d" /></cross-'
+ 'domain-policy>' % (FLAGS.vncproxy_port))
+ fd.flush()
+ socket.close()
+
if __name__ == "__main__":
utils.default_flagfile()
FLAGS(sys.argv)
@@ -96,6 +109,11 @@ 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.start_tcp(handle_flash_socket_policy, 843, host=FLAGS.vncproxy_host)
+
server.wait()