def list_vms(host=None):
    """
      make a list of vms and expand out their fixed_ip and floating ips sensibly
    """
    flags.parse_args([])
    my_instances  = []
    if host is None:
        instances = db.instance_get_all(context.get_admin_context())
    else:
        instances = db.instance_get_all_by_host(
                      context.get_admin_context(), host)

    for instance in instances:
        my_inst = {}
        my_inst = dict(instance).copy()
        for (k,v) in my_inst.items():
            try:
                json.encoder(v)
            except TypeError, e:
                v = str(v)
                my_inst[k] = v

        ec2_id = db.get_ec2_instance_id_by_uuid(context.get_admin_context(), instance.uuid)
        ec2_id = 'i-' + hex(int(ec2_id)).replace('0x', '').zfill(8)
        my_inst['ec2_id'] = ec2_id
        try:
                fixed_ips = db.fixed_ip_get_by_instance(context.get_admin_context(), instance.uuid)
        except:
                pass
        my_inst['fixed_ips'] = [ ip.address for ip in fixed_ips ]
        my_inst['floating_ips'] = []
        for ip in fixed_ips:
            my_inst['floating_ips'].extend([ f_ip.address for f_ip in db.floating_ip_get_by_fixed_address(context.get_admin_context(), ip.address)])

        my_instances.append(my_inst)
示例#2
0
文件: views.py 项目: artofwar/stack
    def get_data(self):
        ctxt = nova_context.get_admin_context()
        FLAGS = nova_flags.FLAGS
        nova_flags.parse_args([])
        operation_logs = nova_db.operation_log_get_all(ctxt)

        return operation_logs 
示例#3
0
def prepare_service(argv=[]):
    cfg.CONF(argv[1:])
    # FIXME(dhellmann): We must set up the nova.flags module in order
    # to have the RPC and DB access work correctly because we are
    # still using the Service object out of nova directly. We need to
    # move that into openstack.common.
    flags.parse_args(_sanitize_cmd_line(argv))
    log.setup('ceilometer')
示例#4
0
 def test_spaces_in_list_opts(self):
     FLAGS.clear()
     FLAGS.register_cli_opt(cfg.ListOpt('enabled_apis_for_ut',
         default=['ec2', 'osapi_compute', 'metadata'],
         help='a list of APIs to enable by default'))
     argv = ['flags_test', '--enabled_apis_for_ut=metadata ,ec2']
     flags.parse_args(argv, default_config_files=[])
     self.assertEqual(FLAGS.enabled_apis_for_ut, ['metadata', 'ec2'])
示例#5
0
def initialize_nova_flags(config_file):
    from nova import flags
    from nova import log as logging
    from nova import service
    from nova import utils

    flags.parse_args(['int_tests'], default_config_files=[config_file])
    logging.setup()
    utils.monkey_patch()
def initialize_nova_flags(config_file):
    from nova import flags
    from nova import log as logging
    from nova import service
    from nova import utils

    flags.parse_args(['int_tests'], default_config_files=[config_file])
    logging.setup()
    utils.monkey_patch()
示例#7
0
文件: views.py 项目: artofwar/stack
    def get_usage_data(self):
        services = []
        ctxt = nova_context.get_admin_context()
        FLAGS = nova_flags.FLAGS
        nova_flags.parse_args([])
        db_compute_nodes=nova_db.compute_node_get_all(ctxt)
       
        for i, service in enumerate(db_compute_nodes):
            service['id'] = i
            service['mem'] = str(service['memory_mb_used'])+"/"+str(service['memory_mb'])
            service['disk'] = str(service['local_gb_used'])+"/"+str(service['local_gb'])
            service['cpu'] = str(service['vcpus_used'])+"/"+str(service['vcpus'])
            services.append(service)

        return services
示例#8
0
    def test_long_vs_short_flags(self):
        FLAGS.clear()
        FLAGS.register_cli_opt(
            cfg.StrOpt('duplicate_answer_long', default='val', help='desc'))
        argv = ['flags_test', '--duplicate_answer=60', 'extra_arg']
        args = flags.parse_args(argv, default_config_files=[])

        self.assert_('duplicate_answer' not in FLAGS)
        self.assert_(FLAGS.duplicate_answer_long, 60)

        FLAGS.clear()
        FLAGS.register_cli_opt(
            cfg.IntOpt('duplicate_answer', default=60, help='desc'))
        args = flags.parse_args(argv, default_config_files=[])
        self.assertEqual(FLAGS.duplicate_answer, 60)
        self.assertEqual(FLAGS.duplicate_answer_long, 'val')
示例#9
0
    def test_getopt_non_interspersed_args(self):
        self.assert_('runtime_answer' not in FLAGS)

        argv = ['flags_test', 'extra_arg', '--runtime_answer=60']
        args = flags.parse_args(argv, default_config_files=[])
        self.assertEqual(len(args), 3)
        self.assertEqual(argv, args)
示例#10
0
def main():
    flags.parse_args(sys.argv)
    utils.monkey_patch()

    xenapi = xenapi_driver.XenAPIDriver()
    session = xenapi._session

    sr_ref = vm_utils.safe_find_sr(session)
    destroyed = vm_utils.destroy_cached_images(
            session, sr_ref, all_cached=FLAGS.all_cached,
            dry_run=FLAGS.dry_run)

    if '--verbose' in sys.argv:
        print '\n'.join(destroyed)

    print "Destroyed %d cached VDIs" % len(destroyed)
示例#11
0
文件: test_flags.py 项目: A7Zulu/nova
    def test_long_vs_short_flags(self):
        FLAGS.clear()
        FLAGS.register_cli_opt(cfg.StrOpt('duplicate_answer_long',
                                          default='val',
                                          help='desc'))
        argv = ['flags_test', '--duplicate_answer=60', 'extra_arg']
        args = flags.parse_args(argv, default_config_files=[])

        self.assert_('duplicate_answer' not in FLAGS)
        self.assert_(FLAGS.duplicate_answer_long, 60)

        FLAGS.clear()
        FLAGS.register_cli_opt(cfg.IntOpt('duplicate_answer',
                                          default=60, help='desc'))
        args = flags.parse_args(argv, default_config_files=[])
        self.assertEqual(FLAGS.duplicate_answer, 60)
        self.assertEqual(FLAGS.duplicate_answer_long, 'val')
示例#12
0
def main():
    flags.parse_args(sys.argv)
    utils.monkey_patch()

    xenapi = xenapi_driver.XenAPIDriver()
    session = xenapi._session

    sr_ref = vm_utils.safe_find_sr(session)
    destroyed = vm_utils.destroy_cached_images(session,
                                               sr_ref,
                                               all_cached=FLAGS.all_cached,
                                               dry_run=FLAGS.dry_run)

    if '--verbose' in sys.argv:
        print '\n'.join(destroyed)

    print "Destroyed %d cached VDIs" % len(destroyed)
示例#13
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()

        fake_flags.set_defaults(FLAGS)
        flags.parse_args([], default_config_files=[])

        # NOTE(vish): We need a better method for creating fixtures for tests
        #             now that we have some required db setup for the system
        #             to work properly.
        self.start = timeutils.utcnow()
        tests.reset_db()

        # emulate some of the mox stuff, we can't use the metaclass
        # because it screws with our generators
        self.mox = mox.Mox()
        self.stubs = stubout.StubOutForTesting()
        self.injected = []
        self._services = []
示例#14
0
文件: views.py 项目: artofwar/stack
    def get_services_data(self):
        services = []

        ctxt = nova_context.get_admin_context()
        FLAGS = nova_flags.FLAGS
        nova_flags.parse_args([])
        db_nova_services=nova_db.service_get_all(ctxt)

        ctxt = cinder_context.get_admin_context()
        FLAGS=cinder_flags.FLAGS
        cinder_flags.parse_args([])
        db_cinder_services=cinder_db.service_get_all(ctxt)
        db_cinder_services.extend(db_nova_services)
        for i, service in enumerate(db_cinder_services):
            service['id'] = i
            services.append(service)

        services = sorted(services, key=lambda svc: (svc.host))#sort the list

        return services
示例#15
0
def list_vms(host=None):
    """
      make a list of vms and expand out their fixed_ip and floating ips sensibly
    """
    flags.parse_args([])
    my_instances = []
    if host is None:
        instances = db.instance_get_all(context.get_admin_context())
    else:
        instances = db.instance_get_all_by_host(context.get_admin_context(),
                                                host)

    for instance in instances:
        my_inst = {}
        my_inst = dict(instance).copy()
        for (k, v) in my_inst.items():
            try:
                json.encoder(v)
            except TypeError, e:
                v = str(v)
                my_inst[k] = v

        ec2_id = db.get_ec2_instance_id_by_uuid(context.get_admin_context(),
                                                instance.uuid)
        ec2_id = 'i-' + hex(int(ec2_id)).replace('0x', '').zfill(8)
        my_inst['ec2_id'] = ec2_id
        try:
            fixed_ips = db.fixed_ip_get_by_instance(
                context.get_admin_context(), instance.uuid)
        except:
            pass
        my_inst['fixed_ips'] = [ip.address for ip in fixed_ips]
        my_inst['floating_ips'] = []
        for ip in fixed_ips:
            my_inst['floating_ips'].extend([
                f_ip.address for f_ip in db.floating_ip_get_by_fixed_address(
                    context.get_admin_context(), ip.address)
            ])

        my_instances.append(my_inst)
示例#16
0
def init_nova():
    flags.parse_args([])
示例#17
0
def init_nova():
    flags.parse_args([])
示例#18
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 OCCI API."""

import eventlet
eventlet.monkey_patch(os=False)

import os
import sys

TOPDIR = os.path.normpath(
    os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir))
if os.path.exists(os.path.join(TOPDIR, "nova", "__init__.py")):
    sys.path.insert(0, TOPDIR)

from nova import flags
from nova import service
from nova import utils
from nova.openstack.common import log as logging

if __name__ == '__main__':
    flags.parse_args(sys.argv)
    logging.setup("nova")
    utils.monkey_patch()
    SERVER = service.WSGIService('occiapi')
    service.serve(SERVER)
    service.wait()
示例#19
0
import sys
sys.path.append(".")

import gettext
gettext.install(None)

from nova import context
from nova import db
from nova import flags
from nova.virt.xenapi import driver as xapi_driver
from nova.virt.xenapi import vm_utils

# hack a config file arg onto argv
sys.argv.insert(1, "--config-file=/etc/nova/nova.conf")
flags.parse_args(sys.argv)

instance_uuid = "2a4489d0-bce5-444f-a584-10b95c62a193"

# get full instance record:
ctx = context.get_admin_context()
instance = db.instance_get_by_uuid(ctx, instance_uuid)

# construct a xenapi driver:
driver = xapi_driver.XenAPIDriver()

# get xen opaque ref to vm:
vm_ref = driver._vmops._get_vm_opaque_ref(instance)

# get the root VDI for the instance:
session = driver._vmops._session
示例#20
0
from nova.openstack.common import timeutils

from nova.virt.xenapi import connection as xenapi_conn


flags.DECLARE("resize_confirm_window", "nova.compute.manager")
flags.DECLARE("xenapi_connection_url", "nova.virt.xenapi.connection")
flags.DECLARE("xenapi_connection_username", "nova.virt.xenapi.connection")
flags.DECLARE("xenapi_connection_password", "nova.virt.xenapi.connection")

FLAGS = flags.FLAGS
# NOTE(sirp): Nova futzs with the sys.argv in order to provide default
# flagfile. To isolate this awful practice, we're supplying a dummy
# argument list.
dummy = ["fakearg"]
flags.parse_args(dummy)


class UnrecognizedNameLabel(Exception):
    pass


def parse_options():
    """Generate command line options."""

    ALLOWED_COMMANDS = ["list-vdis", "clean-vdis", "list-instances",
                        "clean-instances", "test"]
    arg_str = "|".join(ALLOWED_COMMANDS)
    parser = optparse.OptionParser("%prog [options] [" + arg_str + "]")
    parser.add_option("--verbose", action="store_true")
示例#21
0
from nova import flags
from nova import utils

from nova.virt.xenapi import connection as xenapi_conn

flags.DECLARE("resize_confirm_window", "nova.compute.manager")
flags.DECLARE("xenapi_connection_url", "nova.virt.xenapi.connection")
flags.DECLARE("xenapi_connection_username", "nova.virt.xenapi.connection")
flags.DECLARE("xenapi_connection_password", "nova.virt.xenapi.connection")

FLAGS = flags.FLAGS
# NOTE(sirp): Nova futzs with the sys.argv in order to provide default
# flagfile. To isolate this awful practice, we're supplying a dummy
# argument list.
dummy = ["fakearg"]
flags.parse_args(dummy)


class UnrecognizedNameLabel(Exception):
    pass


def parse_options():
    """Generate command line options."""

    ALLOWED_COMMANDS = [
        "list-vdis", "clean-vdis", "list-instances", "clean-instances", "test"
    ]
    arg_str = "|".join(ALLOWED_COMMANDS)
    parser = optparse.OptionParser("%prog [options] [" + arg_str + "]")
    parser.add_option("--verbose", action="store_true")
示例#22
0
文件: nova.py 项目: gtt116/teststack
from nova import flags
flags.parse_args([])

from nova import context
c = context.get_admin_context()

from nova import quota
q = quota.QUOTAS
q.get_defaults(c)
q.get_project_quotas(c, '0cb025698166432c8acebe2b74860740')
示例#23
0
import glance.db.sqlalchemy.models as glance_model 

import functools
import nova.context as context
import nova.flags as nova_flags
import simplejson as json
import datetime
import sqlalchemy
import utils.logging_utils as logging


LOG = logging.getLogger(__name__, 'db_client.log')

#Force read configuration files
nova_flags.parse_args(['compute', '--config-file', '/etc/nova/nova.conf'], None)
glance_cfg.CONF(['glance', '--config-file', '/etc/glance/glance-api.conf'])

# setup database engine
glance_db.configure_db()

logging.setLevel('sqlalchemy.orm', "WARNING")
logging.setLevel('sqlalchemy.engine', "WARNING")
logging.setLevel(__name__, 'DEBUG')


def to_json(res, ignore_types=()):
    if not res:
        raise StandardError('res is empty')
    
    ignore_types += (datetime.datetime, 
示例#24
0
文件: test.py 项目: xww/nova-old
 def setUp(self):
     super(FlagsFixture, self).setUp()
     fake_flags.set_defaults(FLAGS)
     flags.parse_args([], default_config_files=[])
     self.addCleanup(FLAGS.reset)