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)
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
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')
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'])
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 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
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')
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)
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)
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')
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)
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 = []
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
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)
def init_nova(): flags.parse_args([])
# 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()
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
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")
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")
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')
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,
def setUp(self): super(FlagsFixture, self).setUp() fake_flags.set_defaults(FLAGS) flags.parse_args([], default_config_files=[]) self.addCleanup(FLAGS.reset)