summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorRyu Ishimoto <ryu@midokura.jp>2011-08-16 14:20:09 +0900
committerRyu Ishimoto <ryu@midokura.jp>2011-08-16 14:20:09 +0900
commit9d6b9c01a5652cea1aa51aa56eafada92fa82f7a (patch)
tree82e2f37e43dcc3c2eeca0da24326fa3116eae5ea /bin
parent7407a1a86c4039bdc541e9a26cc68c9c93f49bc3 (diff)
parentea53d0f37a4f478ffbe18516f99ca26192117e80 (diff)
Merged trunk
Diffstat (limited to 'bin')
-rwxr-xr-xbin/clear_rabbit_queues73
-rwxr-xr-xbin/nova-dhcpbridge17
-rwxr-xr-xbin/nova-import-canonical-imagestore110
-rwxr-xr-xbin/nova-manage96
4 files changed, 161 insertions, 135 deletions
diff --git a/bin/clear_rabbit_queues b/bin/clear_rabbit_queues
new file mode 100755
index 000000000..7a000e5d8
--- /dev/null
+++ b/bin/clear_rabbit_queues
@@ -0,0 +1,73 @@
+#!/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.
+
+"""Admin/debug script to wipe rabbitMQ (AMQP) queues nova uses.
+ This can be used if you need to change durable options on queues,
+ or to wipe all messages in the queue system if things are in a
+ serious bad way.
+
+"""
+
+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 exception
+from nova import flags
+from nova import log as logging
+from nova import rpc
+from nova import utils
+
+
+FLAGS = flags.FLAGS
+flags.DEFINE_boolean('delete_exchange', False, 'delete nova exchange too.')
+
+
+def delete_exchange(exch):
+ conn = rpc.create_connection()
+ x = conn.get_channel()
+ x.exchange_delete(exch)
+
+
+def delete_queues(queues):
+ conn = rpc.create_connection()
+ x = conn.get_channel()
+ for q in queues:
+ x.queue_delete(q)
+
+if __name__ == '__main__':
+ utils.default_flagfile()
+ args = flags.FLAGS(sys.argv)
+ logging.setup()
+ delete_queues(args[1:])
+ if FLAGS.delete_exchange:
+ delete_exchange(FLAGS.control_exchange)
diff --git a/bin/nova-dhcpbridge b/bin/nova-dhcpbridge
index 325642d52..621222d8f 100755
--- a/bin/nova-dhcpbridge
+++ b/bin/nova-dhcpbridge
@@ -53,7 +53,7 @@ flags.DEFINE_string('dnsmasq_interface', 'br0', 'Default Dnsmasq interface')
LOG = logging.getLogger('nova.dhcpbridge')
-def add_lease(mac, ip_address, _hostname, _interface):
+def add_lease(mac, ip_address, _interface):
"""Set the IP that was assigned by the DHCP server."""
if FLAGS.fake_rabbit:
LOG.debug(_("leasing ip"))
@@ -67,13 +67,13 @@ def add_lease(mac, ip_address, _hostname, _interface):
"args": {"address": ip_address}})
-def old_lease(mac, ip_address, hostname, interface):
+def old_lease(mac, ip_address, interface):
"""Update just as add lease."""
- LOG.debug(_("Adopted old lease or got a change of mac/hostname"))
- add_lease(mac, ip_address, hostname, interface)
+ LOG.debug(_("Adopted old lease or got a change of mac"))
+ add_lease(mac, ip_address, interface)
-def del_lease(mac, ip_address, _hostname, _interface):
+def del_lease(mac, ip_address, _interface):
"""Called when a lease expires."""
if FLAGS.fake_rabbit:
LOG.debug(_("releasing ip"))
@@ -115,11 +115,10 @@ def main():
if action in ['add', 'del', 'old']:
mac = argv[2]
ip = argv[3]
- hostname = argv[4]
- msg = _("Called %(action)s for mac %(mac)s with ip %(ip)s and"
- " hostname %(hostname)s on interface %(interface)s") % locals()
+ msg = _("Called %(action)s for mac %(mac)s with ip %(ip)s"
+ " on interface %(interface)s") % locals()
LOG.debug(msg)
- globals()[action + '_lease'](mac, ip, hostname, interface)
+ globals()[action + '_lease'](mac, ip, interface)
else:
print init_leases(interface)
diff --git a/bin/nova-import-canonical-imagestore b/bin/nova-import-canonical-imagestore
deleted file mode 100755
index 404ae37f4..000000000
--- a/bin/nova-import-canonical-imagestore
+++ /dev/null
@@ -1,110 +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.
-
-"""
- Download images from Canonical Image Store
-"""
-
-import gettext
-import json
-import os
-import tempfile
-import shutil
-import subprocess
-import sys
-import urllib2
-
-# 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 log as logging
-from nova import utils
-from nova.objectstore import image
-
-FLAGS = flags.FLAGS
-
-API_URL = 'https://imagestore.canonical.com/api/dashboard'
-
-
-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
- ramdisk_id = None
-
- for f in img['files']:
- if f['kind'] == 'kernel':
- dest = os.path.join(tempdir, 'kernel')
- subprocess.call(['curl', '--fail', f['url'], '-o', dest])
- kernel_id = image.Image.add(dest,
- description='kernel/' + img['title'], kernel=True)
-
- for f in img['files']:
- if f['kind'] == 'ramdisk':
- dest = os.path.join(tempdir, 'ramdisk')
- subprocess.call(['curl', '--fail', f['url'], '-o', dest])
- ramdisk_id = image.Image.add(dest,
- description='ramdisk/' + img['title'], ramdisk=True)
-
- for f in img['files']:
- if f['kind'] == 'image':
- dest = os.path.join(tempdir, 'image')
- subprocess.call(['curl', '--fail', f['url'], '-o', dest])
- ramdisk_id = image.Image.add(dest,
- description=img['title'], kernel=kernel_id, ramdisk=ramdisk_id)
-
- shutil.rmtree(tempdir)
-
-
-def main():
- """Main entry point."""
- utils.default_flagfile()
- argv = FLAGS(sys.argv)
- logging.setup()
- images = get_images()
-
- if len(argv) == 2:
- 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 img in images:
- print img['title']
-
-if __name__ == '__main__':
- main()
diff --git a/bin/nova-manage b/bin/nova-manage
index f272351c2..3959a236e 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -592,6 +592,31 @@ class FixedIpCommands(object):
fixed_ip['address'],
mac_address, hostname, host)
+ @args('--address', dest="address", metavar='<ip address>',
+ help='IP address')
+ def reserve(self, address):
+ """Mark fixed ip as reserved
+ arguments: address"""
+ self._set_reserved(address, True)
+
+ @args('--address', dest="address", metavar='<ip address>',
+ help='IP address')
+ def unreserve(self, address):
+ """Mark fixed ip as free to use
+ arguments: address"""
+ self._set_reserved(address, False)
+
+ def _set_reserved(self, address, reserved):
+ ctxt = context.get_admin_context()
+
+ try:
+ fixed_ip = db.fixed_ip_get_by_address(ctxt, address)
+ db.fixed_ip_update(ctxt, fixed_ip['address'],
+ {'reserved': reserved})
+ except exception.NotFound as ex:
+ print "error: %s" % ex
+ sys.exit(2)
+
class FloatingIpCommands(object):
"""Class for managing floating ip."""
@@ -701,8 +726,7 @@ class NetworkCommands(object):
network_size = FLAGS.network_size
subnet = 32 - int(math.log(network_size, 2))
oversize_msg = _('Subnet(s) too large, defaulting to /%s.'
- ' To override, specify network_size flag.'
- ) % subnet
+ ' To override, specify network_size flag.') % subnet
print oversize_msg
else:
network_size = fixnet.size
@@ -810,11 +834,13 @@ class VmCommands(object):
instance['availability_zone'],
instance['launch_index'])
- @args('--ec2_id', dest='ec2_id', metavar='<ec2 id>', help='EC2 ID')
- @args('--dest', dest='dest', metavar='<Destanation>',
- help='destanation node')
- def live_migration(self, ec2_id, dest):
- """Migrates a running instance to a new machine."""
+ def _migration(self, ec2_id, dest, block_migration=False):
+ """Migrates a running instance to a new machine.
+ :param ec2_id: instance id which comes from euca-describe-instance.
+ :param dest: destination host name.
+ :param block_migration: if True, do block_migration.
+
+ """
ctxt = context.get_admin_context()
instance_id = ec2utils.ec2_id_to_id(ec2_id)
@@ -835,11 +861,28 @@ class VmCommands(object):
{"method": "live_migration",
"args": {"instance_id": instance_id,
"dest": dest,
- "topic": FLAGS.compute_topic}})
+ "topic": FLAGS.compute_topic,
+ "block_migration": block_migration}})
print _('Migration of %s initiated.'
'Check its progress using euca-describe-instances.') % ec2_id
+ @args('--ec2_id', dest='ec2_id', metavar='<ec2 id>', help='EC2 ID')
+ @args('--dest', dest='dest', metavar='<Destanation>',
+ help='destanation node')
+ def live_migration(self, ec2_id, dest):
+ """Migrates a running instance to a new machine."""
+
+ self._migration(ec2_id, dest)
+
+ @args('--ec2_id', dest='ec2_id', metavar='<ec2 id>', help='EC2 ID')
+ @args('--dest', dest='dest', metavar='<Destanation>',
+ help='destanation node')
+ def block_migration(self, ec2_id, dest):
+ """Migrates a running instance to a new machine with storage data."""
+
+ self._migration(ec2_id, dest, True)
+
class ServiceCommands(object):
"""Enable and disable running services"""
@@ -858,6 +901,14 @@ class ServiceCommands(object):
services = [s for s in services if s['host'] == host]
if service:
services = [s for s in services if s['binary'] == service]
+ print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
+ print print_format % (
+ _('Binary'),
+ _('Host'),
+ _('Zone'),
+ _('Status'),
+ _('State'),
+ _('Updated_At'))
for svc in services:
delta = now - (svc['updated_at'] or svc['created_at'])
alive = (delta.seconds <= 15)
@@ -865,9 +916,9 @@ class ServiceCommands(object):
active = 'enabled'
if svc['disabled']:
active = 'disabled'
- print "%-10s %-10s %-8s %s %s" % (svc['host'], svc['binary'],
- active, art,
- svc['updated_at'])
+ print print_format % (svc['binary'], svc['host'],
+ svc['availability_zone'], active, art,
+ svc['updated_at'])
@args('--host', dest='host', metavar='<host>', help='Host')
@args('--service', dest='service', metavar='<service>',
@@ -913,9 +964,19 @@ class ServiceCommands(object):
mem_u = result['resource']['memory_mb_used']
hdd_u = result['resource']['local_gb_used']
+ cpu_sum = 0
+ mem_sum = 0
+ hdd_sum = 0
print 'HOST\t\t\tPROJECT\t\tcpu\tmem(mb)\tdisk(gb)'
print '%s(total)\t\t\t%s\t%s\t%s' % (host, cpu, mem, hdd)
- print '%s(used)\t\t\t%s\t%s\t%s' % (host, cpu_u, mem_u, hdd_u)
+ print '%s(used_now)\t\t\t%s\t%s\t%s' % (host, cpu_u, mem_u, hdd_u)
+ for p_id, val in result['usage'].items():
+ cpu_sum += val['vcpus']
+ mem_sum += val['memory_mb']
+ hdd_sum += val['local_gb']
+ print '%s(used_max)\t\t\t%s\t%s\t%s' % (host, cpu_sum,
+ mem_sum, hdd_sum)
+
for p_id, val in result['usage'].items():
print '%s\t\t%s\t\t%s\t%s\t%s' % (host,
p_id,
@@ -1095,10 +1156,12 @@ class InstanceTypeCommands(object):
@args('--name', dest='name', metavar='<name>',
help='Name of instance type/flavor')
- def delete(self, name, purge=None):
+ @args('--purge', action="store_true", dest='purge', default=False,
+ help='purge record from database')
+ def delete(self, name, purge):
"""Marks instance types / flavors as deleted"""
try:
- if purge == "--purge":
+ if purge:
instance_types.purge(name)
verb = "purged"
else:
@@ -1235,11 +1298,12 @@ class ImageCommands(object):
is_public, architecture)
def _lookup(self, old_image_id):
+ elevated = context.get_admin_context()
try:
internal_id = ec2utils.ec2_id_to_id(old_image_id)
- image = self.image_service.show(context, internal_id)
+ image = self.image_service.show(elevated, internal_id)
except (exception.InvalidEc2Id, exception.ImageNotFound):
- image = self.image_service.show_by_name(context, old_image_id)
+ image = self.image_service.show_by_name(elevated, old_image_id)
return image['id']
def _old_to_new(self, old):