~ubuntu-cloud-archive/ubuntu/precise/nova/trunk

« back to all changes in this revision

Viewing changes to .pc/nova-manage_flagfile_location.patch/bin/nova-manage

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandleman
  • Date: 2012-01-13 09:51:10 UTC
  • mfrom: (1.1.40)
  • Revision ID: package-import@ubuntu.com-20120113095110-ffd6163drcg77wez
Tags: 2012.1~e3~20120113.12049-0ubuntu1
[Chuck Short]
* New upstream version.
* debian/nova_sudoers, debian/nova-common.install, 
  Switch out to nova-rootwrap. (LP: #681774)
* Add "get-origsource-git" which allows developers to 
  generate a tarball from github, by doing:
  fakeroot debian/rules get-orig-source-git
* debian/debian/nova-objectstore.logrotate: Dont determine
  if we are running Debian or Ubuntu. (LP: #91379)

[Adam Gandleman]
* Removed python-nova.postinst, let dh_python2 generate instead since
  python-support is not a dependency. (LP: #907543)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
3
 
 
4
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
4
5
# Copyright 2010 United States Government as represented by the
5
6
# Administrator of the National Aeronautics and Space Administration.
6
7
# All Rights Reserved.
88
89
from nova import utils
89
90
from nova import version
90
91
from nova import vsa
 
92
from nova.api.ec2 import admin
91
93
from nova.api.ec2 import ec2utils
92
94
from nova.auth import manager
93
95
from nova.cloudpipe import pipelib
96
98
from nova.volume import volume_types
97
99
 
98
100
FLAGS = flags.FLAGS
99
 
flags.DECLARE('fixed_range', 'nova.network.manager')
 
101
flags.DECLARE('flat_network_bridge', 'nova.network.manager')
100
102
flags.DECLARE('num_networks', 'nova.network.manager')
 
103
flags.DECLARE('multi_host', 'nova.network.manager')
101
104
flags.DECLARE('network_size', 'nova.network.manager')
102
105
flags.DECLARE('vlan_start', 'nova.network.manager')
103
106
flags.DECLARE('vpn_start', 'nova.network.manager')
104
 
flags.DECLARE('fixed_range_v6', 'nova.network.manager')
105
 
flags.DECLARE('gateway_v6', 'nova.network.manager')
 
107
flags.DECLARE('default_floating_pool', 'nova.network.manager')
 
108
flags.DECLARE('public_interface', 'nova.network.linux_net')
106
109
flags.DECLARE('libvirt_type', 'nova.virt.libvirt.connection')
107
110
flags.DEFINE_flag(flags.HelpFlag())
108
111
flags.DEFINE_flag(flags.HelpshortFlag())
175
178
    def spawn(self):
176
179
        """Run all VPNs."""
177
180
        print "WARNING: This method only works with deprecated auth"
 
181
        ctxt = context.get_admin_context()
178
182
        for p in reversed(self.manager.get_projects()):
179
 
            if not self._vpn_for(p.id):
 
183
            if self._vpn_for(ctxt, p.id):
180
184
                print 'spawning %s' % p.id
181
185
                self.pipe.launch_vpn_instance(p.id, p.project_manager_id)
182
186
                time.sleep(10)
212
216
                              {'vpn_public_address': ip,
213
217
                               'vpn_public_port': int(port)})
214
218
 
 
219
    def _vpn_for(self, context, project_id):
 
220
        return admin.AdminController()._vpn_for(context, project_id)
 
221
 
215
222
 
216
223
class ShellCommands(object):
217
224
    def bpython(self):
680
687
class FloatingIpCommands(object):
681
688
    """Class for managing floating ip."""
682
689
 
683
 
    @args('--ip_range', dest="range", metavar='<range>', help='IP range')
684
 
    def create(self, range):
 
690
    @args('--ip_range', dest="ip_range", metavar='<range>', help='IP range')
 
691
    @args('--pool', dest="pool", metavar='<pool>', help='Optional pool')
 
692
    @args('--interface', dest="interface", metavar='<interface>',
 
693
          help='Optional interface')
 
694
    def create(self, ip_range, pool=None, interface=None):
685
695
        """Creates floating ips for zone by range"""
686
 
        for address in netaddr.IPNetwork(range):
687
 
            db.floating_ip_create(context.get_admin_context(),
688
 
                                  {'address': str(address)})
 
696
        addresses = netaddr.IPNetwork(ip_range)
 
697
        admin_context = context.get_admin_context()
 
698
        if not pool:
 
699
            pool = FLAGS.default_floating_pool
 
700
        if not interface:
 
701
            interface = FLAGS.public_interface
 
702
        for address in addresses.iter_hosts():
 
703
            db.floating_ip_create(admin_context,
 
704
                                  {'address': str(address),
 
705
                                   'pool': pool,
 
706
                                   'interface': interface})
689
707
 
690
708
    @args('--ip_range', dest="ip_range", metavar='<range>', help='IP range')
691
709
    def delete(self, ip_range):
692
710
        """Deletes floating ips by range"""
693
 
        for address in netaddr.IPNetwork(ip_range):
 
711
        for address in netaddr.IPNetwork(ip_range).iter_hosts():
694
712
            db.floating_ip_destroy(context.get_admin_context(),
695
713
                                   str(address))
696
714
 
706
724
        for floating_ip in floating_ips:
707
725
            instance = None
708
726
            if floating_ip['fixed_ip']:
709
 
                instance = floating_ip['fixed_ip']['instance']['hostname']
710
 
            print "%s\t%s\t%s" % (floating_ip['host'],
711
 
                                  floating_ip['address'],
712
 
                                  instance)
 
727
                instance = floating_ip['fixed_ip']['instance']['uuid']
 
728
            print "%s\t%s\t%s\t%s\t%s" % (floating_ip['project_id'],
 
729
                                          floating_ip['address'],
 
730
                                          instance,
 
731
                                          floating_ip['pool'],
 
732
                                          floating_ip['interface'])
713
733
 
714
734
 
715
735
class NetworkCommands(object):
960
980
                instance['availability_zone'],
961
981
                instance['launch_index'])
962
982
 
963
 
    def _migration(self, ec2_id, dest, block_migration=False):
 
983
    def _migration(self, ec2_id, dest, block_migration=False,
 
984
                                       disk_over_commit=False):
964
985
        """Migrates a running instance to a new machine.
965
986
         :param ec2_id: instance id which comes from euca-describe-instance.
966
987
         :param dest: destination host name.
987
1008
                  "args": {"instance_id": instance_id,
988
1009
                           "dest": dest,
989
1010
                           "topic": FLAGS.compute_topic,
990
 
                           "block_migration": block_migration}})
 
1011
                           "block_migration": block_migration,
 
1012
                           "disk_over_commit": disk_over_commit}})
991
1013
 
992
1014
        print _('Migration of %s initiated.'
993
1015
               'Check its progress using euca-describe-instances.') % ec2_id
1002
1024
 
1003
1025
    @args('--ec2_id', dest='ec2_id', metavar='<ec2 id>', help='EC2 ID')
1004
1026
    @args('--dest', dest='dest', metavar='<Destanation>',
1005
 
            help='destanation node')
1006
 
    def block_migration(self, ec2_id, dest):
 
1027
                           help='destanation node')
 
1028
    @args('--disk_over_commit', dest='disk_over_commit',
 
1029
                           metavar='<overcommit flag>',
 
1030
                           help='Allow overcommit (default Flase)')
 
1031
    def block_migration(self, ec2_id, dest, disk_over_commit=False):
1007
1032
        """Migrates a running instance to a new machine with storage data."""
1008
1033
 
1009
 
        self._migration(ec2_id, dest, True)
 
1034
        self._migration(ec2_id, dest, True, disk_over_commit)
1010
1035
 
1011
1036
 
1012
1037
class ServiceCommands(object):
1071
1096
 
1072
1097
    @args('--host', dest='host', metavar='<host>', help='Host')
1073
1098
    def describe_resource(self, host):
1074
 
        """Describes cpu/memory/hdd info for host."""
1075
 
 
 
1099
        """Describes cpu/memory/hdd info for host.
 
1100
 
 
1101
        :param host: hostname.
 
1102
 
 
1103
        """
1076
1104
        result = rpc.call(context.get_admin_context(),
1077
1105
                     FLAGS.scheduler_topic,
1078
1106
                     {"method": "show_host_resources",
1079
1107
                      "args": {"host": host}})
1080
1108
 
1081
 
        if type(result) != dict:
 
1109
        if not isinstance(result, dict):
1082
1110
            print _('An unexpected error has occurred.')
1083
1111
            print _('[Result]'), result
1084
1112
        else:
1085
 
            cpu = result['resource']['vcpus']
1086
 
            mem = result['resource']['memory_mb']
1087
 
            hdd = result['resource']['local_gb']
1088
 
            cpu_u = result['resource']['vcpus_used']
1089
 
            mem_u = result['resource']['memory_mb_used']
1090
 
            hdd_u = result['resource']['local_gb_used']
1091
 
 
 
1113
            # Printing a total and used_now
 
1114
            # (NOTE)The host name width 16 characters
 
1115
            print '%(a)-25s%(b)16s%(c)8s%(d)8s%(e)8s' % {"a": _('HOST'),
 
1116
                                                         "b": _('PROJECT'),
 
1117
                                                         "c": _('cpu'),
 
1118
                                                         "d": _('mem(mb)'),
 
1119
                                                         "e": _('hdd')}
 
1120
            print '%(a)-16s(total)%(b)26s%(c)8s%(d)8s' %\
 
1121
                              {"a": host,
 
1122
                               "b": result['resource']['vcpus'],
 
1123
                               "c": result['resource']['memory_mb'],
 
1124
                               "d": result['resource']['local_gb']}
 
1125
 
 
1126
            print '%(a)-16s(used_now)%(b)23s%(c)8s%(d)8s' %\
 
1127
                              {"a": host,
 
1128
                               "b": result['resource']['vcpus_used'],
 
1129
                               "c": result['resource']['memory_mb_used'],
 
1130
                               "d": result['resource']['local_gb_used']}
 
1131
 
 
1132
            # Printing a used_max
1092
1133
            cpu_sum = 0
1093
1134
            mem_sum = 0
1094
1135
            hdd_sum = 0
1095
 
            print 'HOST\t\t\tPROJECT\t\tcpu\tmem(mb)\tdisk(gb)'
1096
 
            print '%s(total)\t\t\t%s\t%s\t%s' % (host, cpu, mem, hdd)
1097
 
            print '%s(used_now)\t\t\t%s\t%s\t%s' % (host, cpu_u, mem_u, hdd_u)
1098
 
            for p_id, val in result['usage'].items():
 
1136
            ctxt = context.get_admin_context()
 
1137
            instance_refs = db.instance_get_all_by_host(ctxt, host)
 
1138
 
 
1139
            project_ids = [i['project_id'] for i in instance_refs]
 
1140
            project_ids = list(set(project_ids))
 
1141
            usage = dict()
 
1142
            for project_id in project_ids:
 
1143
                vcpus = [i['vcpus'] for i in instance_refs \
 
1144
                    if i['project_id'] == project_id]
 
1145
 
 
1146
                mem = [i['memory_mb']  for i in instance_refs \
 
1147
                    if i['project_id'] == project_id]
 
1148
 
 
1149
                disk = [i['local_gb']  for i in instance_refs \
 
1150
                    if i['project_id'] == project_id]
 
1151
 
 
1152
                usage[project_id] = {
 
1153
                                 'vcpus': reduce(lambda x, y: x + y, vcpus),
 
1154
                                 'memory_mb': reduce(lambda x, y: x + y, mem),
 
1155
                                 'local_gb': reduce(lambda x, y: x + y, disk)}
 
1156
 
 
1157
            for p_id, val in usage.items():
1099
1158
                cpu_sum += val['vcpus']
1100
1159
                mem_sum += val['memory_mb']
1101
1160
                hdd_sum += val['local_gb']
1102
 
            print '%s(used_max)\t\t\t%s\t%s\t%s' % (host, cpu_sum,
1103
 
                                                    mem_sum, hdd_sum)
1104
 
 
1105
 
            for p_id, val in result['usage'].items():
1106
 
                print '%s\t\t%s\t\t%s\t%s\t%s' % (host,
1107
 
                                                  p_id,
1108
 
                                                  val['vcpus'],
1109
 
                                                  val['memory_mb'],
1110
 
                                                  val['local_gb'])
1111
 
 
1112
 
    @args('--host', dest='host', metavar='<host>', help='Host')
1113
 
    def update_resource(self, host):
1114
 
        """Updates available vcpu/memory/disk info for host."""
1115
 
 
1116
 
        ctxt = context.get_admin_context()
1117
 
        service_refs = db.service_get_all_by_host(ctxt, host)
1118
 
        if len(service_refs) <= 0:
1119
 
            raise exception.Invalid(_('%s does not exist.') % host)
1120
 
 
1121
 
        service_refs = [s for s in service_refs if s['topic'] == 'compute']
1122
 
        if len(service_refs) <= 0:
1123
 
            raise exception.Invalid(_('%s is not compute node.') % host)
1124
 
 
1125
 
        rpc.call(ctxt,
1126
 
                 db.queue_get_for(ctxt, FLAGS.compute_topic, host),
1127
 
                 {"method": "update_available_resource"})
 
1161
            print '%(a)-16s(used_max)%(b)23s%(c)8s%(d)8s' % {"a": host,
 
1162
                                                             "b": cpu_sum,
 
1163
                                                             "c": mem_sum,
 
1164
                                                             "d": hdd_sum}
 
1165
 
 
1166
            for p_id, val in usage.items():
 
1167
                print '%(a)-25s%(b)16s%(c)8s%(d)8s%(e)8s' %\
 
1168
                                                     {"a": host,
 
1169
                                                      "b": p_id,
 
1170
                                                      "c": val['vcpus'],
 
1171
                                                      "d": val['memory_mb'],
 
1172
                                                      "e": val['local_gb']}
1128
1173
 
1129
1174
 
1130
1175
class HostCommands(object):
1392
1437
        if storage is not None:
1393
1438
            try:
1394
1439
                storage_list = ast.literal_eval(storage)
1395
 
            except:
 
1440
            except Exception:
1396
1441
                print _("Invalid string format %s") % storage
1397
1442
                raise
1398
1443
 
1581
1626
        except exception.DBError, e:
1582
1627
            print "DB Error: %s" % e
1583
1628
            sys.exit(2)
1584
 
        except:
 
1629
        except Exception:
1585
1630
            sys.exit(3)
1586
1631
        else:
1587
1632
            print "%s %s" % (name, verb)
1599
1644
        if name is not None:
1600
1645
            search_opts['extra_specs']['name'] = name
1601
1646
 
1602
 
        if all == False:
 
1647
        if not all:
1603
1648
            search_opts['extra_specs']['visible'] = '1'
1604
1649
 
1605
1650
        drives = volume_types.get_all_types(self.context,
1741
1786
            print "Currently defined instance_type names and flavorids:"
1742
1787
            self.list("--all")
1743
1788
            sys.exit(2)
1744
 
        except:
 
1789
        except Exception:
1745
1790
            print "Unknown error"
1746
1791
            sys.exit(3)
1747
1792
        else:
1766
1811
        except exception.DBError, e:
1767
1812
            print "DB Error: %s" % e
1768
1813
            sys.exit(2)
1769
 
        except:
 
1814
        except Exception:
1770
1815
            sys.exit(3)
1771
1816
        else:
1772
1817
            print "%s %s" % (name, verb)
1967
2012
        ctxt = context.get_admin_context()
1968
2013
 
1969
2014
        try:
1970
 
            if flavor == None:
 
2015
            if flavor is None:
1971
2016
                flavors = db.sm_flavor_get_all(ctxt)
1972
2017
            else:
1973
2018
                flavors = db.sm_flavor_get(ctxt, flavor)
2009
2054
        ctxt = context.get_admin_context()
2010
2055
 
2011
2056
        try:
2012
 
            if backend_conf_id == None:
 
2057
            if backend_conf_id is None:
2013
2058
                backends = db.sm_backend_conf_get_all(ctxt)
2014
2059
            else:
2015
2060
                backends = db.sm_backend_conf_get(ctxt, backend_conf_id)
2069
2114
        print '(WARNING: Creating will destroy all data on backend!!!)'
2070
2115
        c = raw_input('Proceed? (y/n) ')
2071
2116
        if c == 'y' or c == 'Y':
2072
 
            if flavor_label == None:
 
2117
            if flavor_label is None:
2073
2118
                print "error: backend needs to be associated with flavor"
2074
2119
                sys.exit(2)
2075
2120