Example #1
0
 def setUp(self):
     super(NovaLoggerTestCase, self).setUp()
     levels = FLAGS.default_log_levels
     levels.append("nova-test=AUDIT")
     self.flags(default_log_levels=levels,
                verbose=True)
     self.log = log.getLogger('nova-test')
Example #2
0
File: wsgi.py Project: A7Zulu/nova
    def __init__(self, name, app, host='0.0.0.0', port=0, pool_size=None,
                       protocol=eventlet.wsgi.HttpProtocol, backlog=128):
        """Initialize, but do not start, a WSGI server.

        :param name: Pretty name for logging.
        :param app: The WSGI application to serve.
        :param host: IP address to serve the application.
        :param port: Port number to server the application.
        :param pool_size: Maximum number of eventlets to spawn concurrently.
        :param backlog: Maximum number of queued connections.
        :returns: None
        :raises: nova.exception.InvalidInput
        """
        self.name = name
        self.app = app
        self._server = None
        self._protocol = protocol
        self._pool = eventlet.GreenPool(pool_size or self.default_pool_size)
        self._logger = logging.getLogger("nova.%s.wsgi.server" % self.name)
        self._wsgi_logger = logging.WritableLogger(self._logger)

        if backlog < 1:
            raise exception.InvalidInput(
                    reason='The backlog must be more than 1')

        self._socket = eventlet.listen((host, port), backlog=backlog)
        (self.host, self.port) = self._socket.getsockname()
        LOG.info(_("%(name)s listening on %(host)s:%(port)s") % self.__dict__)
Example #3
0
 def _intercept_log_messages(self):
     mylog = log.getLogger()
     stream = cStringIO.StringIO()
     handler = logging.StreamHandler(stream)
     handler.setFormatter(log.LegacyNovaFormatter())
     mylog.logger.addHandler(handler)
     return mylog, handler, stream
    def setUp(self):
        super(NotifierListTestCase, self).setUp()
        list_notifier._reset_drivers()
        self.stubs = stubout.StubOutForTesting()
        # Mock log to add one to exception_count when log.exception is called

        def mock_exception(cls, *args):
            self.exception_count += 1

        self.exception_count = 0
        list_notifier_log = logging.getLogger('nova.notifier.list_notifier')
        self.stubs.Set(list_notifier_log, "exception", mock_exception)
        # Mock no_op notifier to add one to notify_count when called.

        def mock_notify(cls, *args):
            self.notify_count += 1

        self.notify_count = 0
        self.stubs.Set(nova.notifier.no_op_notifier, 'notify', mock_notify)
        # Mock log_notifier to raise RuntimeError when called.

        def mock_notify2(cls, *args):
            raise RuntimeError("Bad notifier.")

        self.stubs.Set(nova.notifier.log_notifier, 'notify', mock_notify2)
Example #5
0
 def setUp(self):
     super(JSONFormatterTestCase, self).setUp()
     self.log = log.getLogger('test-json')
     self.stream = cStringIO.StringIO()
     handler = logging.StreamHandler(self.stream)
     handler.setFormatter(log.JSONFormatter())
     self.log.logger.addHandler(handler)
     self.log.logger.setLevel(logging.DEBUG)
Example #6
0
def notify(_context, message):
    """Notifies the recipient of the desired event given the model.
    Log notifications using nova's default logging system"""

    priority = message.get('priority',
                           FLAGS.default_notification_level)
    priority = priority.lower()
    logger = logging.getLogger(
            'nova.notification.%s' % message['event_type'])
    getattr(logger, priority)(json.dumps(message))
Example #7
0
 def _intercept_log_messages(self):
     try:
         mylog = log.getLogger()
         stream = cStringIO.StringIO()
         handler = logging.StreamHandler(stream)
         handler.setFormatter(log.LegacyNovaFormatter())
         mylog.logger.addHandler(handler)
         yield stream
     finally:
         mylog.logger.removeHandler(handler)
Example #8
0
 def setUp(self):
     super(NovaFormatterTestCase, self).setUp()
     self.flags(logging_context_format_string="HAS CONTEXT "
                                              "[%(request_id)s]: "
                                              "%(message)s",
                logging_default_format_string="NOCTXT: %(message)s",
                logging_debug_format_suffix="--DBG")
     self.log = log.getLogger()
     self.stream = cStringIO.StringIO()
     self.handler = logging.StreamHandler(self.stream)
     self.handler.setFormatter(log.LegacyNovaFormatter())
     self.log.logger.addHandler(self.handler)
     self.level = self.log.logger.getEffectiveLevel()
     self.log.logger.setLevel(logging.DEBUG)
Example #9
0
    def test_error_notification(self):
        self.stubs.Set(nova.flags.FLAGS, "notification_driver", "nova.notifier.rabbit_notifier")
        self.stubs.Set(nova.flags.FLAGS, "publish_errors", True)
        LOG = log.getLogger("nova")
        LOG.setup_from_flags()
        msgs = []

        def mock_cast(context, topic, data):
            msgs.append(data)

        self.stubs.Set(nova.rpc, "cast", mock_cast)
        LOG.error("foo")
        self.assertEqual(1, len(msgs))
        msg = msgs[0]
        self.assertEqual(msg["event_type"], "error_notification")
        self.assertEqual(msg["priority"], "ERROR")
        self.assertEqual(msg["payload"]["error"], "foo")
Example #10
0
    def test_error_notification(self):
        self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
            'nova.notifier.rabbit_notifier')
        self.stubs.Set(nova.flags.FLAGS, 'publish_errors', True)
        LOG = log.getLogger('nova')
        log.setup()
        msgs = []

        def mock_notify(context, topic, data):
            msgs.append(data)

        self.stubs.Set(nova.rpc, 'notify', mock_notify)
        LOG.error('foo')
        self.assertEqual(1, len(msgs))
        msg = msgs[0]
        self.assertEqual(msg['event_type'], 'error_notification')
        self.assertEqual(msg['priority'], 'ERROR')
        self.assertEqual(msg['payload']['error'], 'foo')
Example #11
0
    def setUp(self):
        super(DriverTestCase, self).setUp()
        self.flags(volume_driver=self.driver_name,
                   logging_default_format_string="%(message)s")
        self.volume = utils.import_object(FLAGS.volume_manager)
        self.context = context.get_admin_context()
        self.output = ""

        def _fake_execute(_command, *_args, **_kwargs):
            """Fake _execute."""
            return self.output, None
        self.volume.driver.set_execute(_fake_execute)

        log = logging.getLogger()
        self.stream = cStringIO.StringIO()
        log.addHandler(logging.StreamHandler(self.stream))

        inst = {}
        self.instance_id = db.instance_create(self.context, inst)['id']
Example #12
0
    def __init__(self, name, app, host=None, port=None, pool_size=None):
        """Initialize, but do not start, a WSGI server.

        :param name: Pretty name for logging.
        :param app: The WSGI application to serve.
        :param host: IP address to serve the application.
        :param port: Port number to server the application.
        :param pool_size: Maximum number of eventlets to spawn concurrently.
        :returns: None

        """
        self.name = name
        self.app = app
        self.host = host or "0.0.0.0"
        self.port = port or 0
        self._server = None
        self._tcp_server = None
        self._socket = None
        self._pool = eventlet.GreenPool(pool_size or self.default_pool_size)
        self._logger = logging.getLogger("eventlet.wsgi.server")
        self._wsgi_logger = logging.WritableLogger(self._logger)
Example #13
0
used must be present or the host will be excluded. The hosts
returned are then weighed by the Weighted Scheduler. Weights
can take the more esoteric factors into consideration (such as
server affinity and customer separation).
"""

import json

from nova import exception
from nova import flags
from nova import log as logging
from nova.scheduler import zone_aware_scheduler
from nova import utils
from nova.scheduler import zone_aware_scheduler

LOG = logging.getLogger('nova.scheduler.host_filter')

FLAGS = flags.FLAGS
flags.DEFINE_string('default_host_filter',
                    'nova.scheduler.host_filter.AllHostsFilter',
                    'Which filter to use for filtering hosts.')


class HostFilter(object):
    """Base class for host filters."""

    def instance_type_to_filter(self, instance_type):
        """Convert instance_type into a filter for most common use-case."""
        raise NotImplementedError()

    def filter_hosts(self, zone_manager, query):
Example #14
0
import webob.dec
import webob.exc

from nova import context
from nova import exception
from nova import flags
from nova import log as logging
from nova import utils
from nova import wsgi
from nova.api.ec2 import apirequest
from nova.api.ec2 import ec2utils
from nova.auth import manager


FLAGS = flags.FLAGS
LOG = logging.getLogger("nova.api")
flags.DEFINE_boolean('use_forwarded_for', False,
                     'Treat X-Forwarded-For as the canonical remote address. '
                     'Only enable this if you have a sanitizing proxy.')
flags.DEFINE_integer('lockout_attempts', 5,
                     'Number of failed auths before lockout.')
flags.DEFINE_integer('lockout_minutes', 15,
                     'Number of minutes to lockout if triggered.')
flags.DEFINE_integer('lockout_window', 15,
                     'Number of minutes for lockout window.')


class RequestLogging(wsgi.Middleware):
    """Access-Log akin logging for all EC2 API requests."""

    @webob.dec.wsgify(RequestClass=wsgi.Request)
Example #15
0
                `nova-volumes`)
:aoe_eth_dev:  Device name the volumes will be exported on (default: `eth0`).
:num_shell_tries:  Number of times to attempt to run AoE commands (default: 3)

"""

import datetime

from nova import context
from nova import exception
from nova import flags
from nova import log as logging
from nova import manager
from nova import utils

LOG = logging.getLogger('nova.volume.manager')
FLAGS = flags.FLAGS
flags.DEFINE_string('storage_availability_zone', 'nova',
                    'availability zone of this service')
flags.DEFINE_string('volume_driver', 'nova.volume.driver.ISCSIDriver',
                    'Driver to use for volume creation')
flags.DEFINE_boolean('use_local_volumes', True,
                     'if True, will not discover local volumes')


class VolumeManager(manager.SchedulerDependentManager):
    """Manages attachable block storage devices."""
    def __init__(self, volume_driver=None, *args, **kwargs):
        """Load the driver from the one specified in args, or from flags."""
        if not volume_driver:
            volume_driver = FLAGS.volume_driver
Example #16
0
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License

import urllib

import webob

from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova.api.openstack import extensions
from nova import exception
from nova import log as logging
from nova import network

LOG = logging.getLogger('nova.api.openstack.compute.contrib.floating_ip_dns')


def make_dns_entry(elem):
    elem.set('id')
    elem.set('ip')
    elem.set('type')
    elem.set('zone')
    elem.set('name')


def make_zone_entry(elem):
    elem.set('zone')


class FloatingIPDNSTemplate(xmlutil.TemplateBuilder):
Example #17
0
flags.DEFINE_string('ldap_cloudadmin',
                    'cn=cloudadmins,ou=Groups,dc=example,dc=com',
                    'cn for Cloud Admins')
flags.DEFINE_string('ldap_itsec', 'cn=itsec,ou=Groups,dc=example,dc=com',
                    'cn for ItSec')
flags.DEFINE_string('ldap_sysadmin',
                    'cn=sysadmins,ou=Groups,dc=example,dc=com',
                    'cn for Sysadmins')
flags.DEFINE_string('ldap_netadmin',
                    'cn=netadmins,ou=Groups,dc=example,dc=com',
                    'cn for NetAdmins')
flags.DEFINE_string('ldap_developer',
                    'cn=developers,ou=Groups,dc=example,dc=com',
                    'cn for Developers')

LOG = logging.getLogger("nova.ldapdriver")

if FLAGS.memcached_servers:
    import memcache
else:
    from nova.testing.fake import memcache

# TODO(vish): make an abstract base class with the same public methods
#             to define a set interface for AuthDrivers. I'm delaying
#             creating this now because I'm expecting an auth refactor
#             in which we may want to change the interface a bit more.


def _clean(attr):
    """Clean attr for insertion into ldap"""
    if attr is None:
Example #18
0
"""Nova base exception handling.

Includes decorator for re-raising Nova-type exceptions.

SHOULD include dedicated exception logging.

"""

from functools import wraps
import sys

from novaclient import exceptions as novaclient_exceptions

from nova import log as logging

LOG = logging.getLogger('nova.exception')


def novaclient_converter(f):
    """Convert novaclient ClientException HTTP codes to webob exceptions.
    Has to be the outer-most decorator.
    """
    def new_f(*args, **kwargs):
        try:
            ret = f(*args, **kwargs)
            return ret
        except novaclient_exceptions.ClientException, e:
            raise ConvertedException(e.code, e.message, e.details)

    return new_f
Example #19
0
"""

import functools

from nova.compute import vm_states
from nova import db
from nova import exception
from nova import flags
from nova import log as logging
from nova import manager
from nova.openstack.common import cfg
from nova import rpc
from nova import utils


LOG = logging.getLogger('nova.scheduler.manager')

scheduler_driver_opt = cfg.StrOpt('scheduler_driver',
        default='nova.scheduler.multi.MultiScheduler',
        help='Default driver to use for the scheduler')

FLAGS = flags.FLAGS
FLAGS.add_option(scheduler_driver_opt)


class SchedulerManager(manager.Manager):
    """Chooses a host to run instances on."""

    def __init__(self, scheduler_driver=None, *args, **kwargs):
        if not scheduler_driver:
            scheduler_driver = FLAGS.scheduler_driver
Example #20
0
#
# @author: Sumit Naiksatam, Cisco Systems, Inc.
#
"""VIF drivers for interface type direct."""

from nova import exception as excp
from nova import flags
from nova import log as logging
from nova.network import linux_net
from nova.virt.libvirt import netutils
from nova import utils
from nova.virt.vif import VIFDriver
from quantum.client import Client
from quantum.common.wsgi import Serializer

LOG = logging.getLogger('quantum.plugins.cisco.nova.vifdirect')

FLAGS = flags.FLAGS
flags.DEFINE_string('quantum_host', "127.0.0.1",
                    'IP address of the quantum network service.')
flags.DEFINE_integer('quantum_port', 9696,
                     'Listening port for Quantum network service')

HOST = FLAGS.quantum_host
PORT = FLAGS.quantum_port
USE_SSL = False
TENANT_ID = 'nova'
ACTION_PREFIX_EXT = '/v1.0'
ACTION_PREFIX_CSCO = ACTION_PREFIX_EXT + \
        '/extensions/csco/tenants/{tenant_id}'
TENANT_ID = 'nova'
#    License for the specific language governing permissions and limitations
#    under the License.
"""Implements vlans, bridges, and iptables rules using linux utilities."""

import calendar
import inspect
import netaddr
import os

from nova import db
from nova import exception
from nova import flags
from nova import log as logging
from nova import utils

LOG = logging.getLogger("nova.linux_net")


def _bin_file(script):
    """Return the absolute path to scipt in the bin directory."""
    return os.path.abspath(os.path.join(__file__, '../../../bin', script))


FLAGS = flags.FLAGS
flags.DEFINE_string('dhcpbridge_flagfile', '/etc/nova/nova-dhcpbridge.conf',
                    'location of flagfile for dhcpbridge')
flags.DEFINE_string('dhcp_domain', 'novalocal',
                    'domain to use for building the hostnames')
flags.DEFINE_string('networks_path', '$state_path/networks',
                    'Location to keep network config files')
flags.DEFINE_string('public_interface', 'eth0',
Example #22
0
"""
Handles all requests to the DNS Manager.
"""


import numbers
import types

from nova import flags
from nova import log as logging
from nova import rpc
from nova.db import base
from nova.db.sqlalchemy.models import NovaBase

FLAGS = flags.FLAGS
LOG = logging.getLogger('nova.dns.api')


class API(base.Base):
    """API for interacting with the DNS manager."""

    def __init__(self, **kwargs):
        super(API, self).__init__(**kwargs)

    def convert_instance(self, instance):
        if isinstance(instance, NovaBase):
            new_instance = {}
            for k, v in instance:
                if isinstance(v, (types.BooleanType, numbers.Number,
                                  types.StringTypes)):
                    new_instance[k] = v
Example #23
0
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 rpc
from nova import test
from nova import utils
from nova.auth import manager
from nova.compute import instance_types
from nova.compute import manager as compute_manager
from nova.compute import power_state
from nova.db.sqlalchemy import models
from nova.image import local

LOG = logging.getLogger('nova.tests.compute')
FLAGS = flags.FLAGS
flags.DECLARE('stub_network', 'nova.compute.manager')
flags.DECLARE('live_migration_retry_count', 'nova.compute.manager')


class ComputeTestCase(test.TestCase):
    """Test case for compute"""
    def setUp(self):
        super(ComputeTestCase, self).setUp()
        self.flags(connection_type='fake',
                   stub_network=True,
                   network_manager='nova.network.manager.FlatManager')
        self.compute = utils.import_object(FLAGS.compute_manager)
        self.compute_api = compute.API()
        self.manager = manager.AuthManager()
Example #24
0
#    License for the specific language governing permissions and limitations
#    under the License.
"""
Drivers for volumes.

"""

import time
import os

from nova import exception
from nova import flags
from nova import log as logging
from nova import utils

LOG = logging.getLogger("nova.volume.driver")
FLAGS = flags.FLAGS
flags.DEFINE_string('volume_group', 'nova-volumes',
                    'Name for the VG that will contain exported volumes')
flags.DEFINE_string('aoe_eth_dev', 'eth0',
                    'Which device to export the volumes on')
flags.DEFINE_string('num_shell_tries', 3,
                    'number of times to attempt to run flakey shell commands')
flags.DEFINE_string('num_iscsi_scan_tries', 3,
                    'number of times to rescan iSCSI target to find volume')
flags.DEFINE_integer('num_shelves', 100, 'Number of vblade shelves')
flags.DEFINE_integer('blades_per_shelf', 16,
                     'Number of vblade blades per shelf')
flags.DEFINE_integer('iscsi_num_targets', 100,
                     'Number of iscsi target ids per host')
flags.DEFINE_string('iscsi_target_prefix', 'iqn.2010-10.org.openstack:',
Example #25
0
                    utils.abspath('cloudpipe/client.ovpn.template'),
                    'Template for creating users vpn file')
flags.DEFINE_string('credential_vpn_file', 'nova-vpn.conf',
                    'Filename of certificate in credentials zip')
flags.DEFINE_string('credential_key_file', 'pk.pem',
                    'Filename of private key in credentials zip')
flags.DEFINE_string('credential_cert_file', 'cert.pem',
                    'Filename of certificate in credentials zip')
flags.DEFINE_string(
    'credential_rc_file', '%src',
    'Filename of rc in credentials zip, %s will be '
    'replaced by name of the region (nova by default)')
flags.DEFINE_string('auth_driver', 'nova.auth.dbdriver.DbDriver',
                    'Driver that auth manager uses')

LOG = logging.getLogger('nova.auth.manager')

if FLAGS.memcached_servers:
    import memcache
else:
    from nova.testing.fake import memcache


class AuthBase(object):
    """Base class for objects relating to auth

    Objects derived from this class should be stupid data objects with
    an id member. They may optionally contain methods that delegate to
    AuthManager, but should not implement logic themselves.
    """
    @classmethod
Example #26
0
from nova import context
from nova import db
from nova import dns
from nova import exception
from nova import flags
from nova import ipv6
from nova import log as logging
from nova import manager
from nova import quota
from nova import utils
from nova import rpc
from nova.network import api as network_api
import random


LOG = logging.getLogger("nova.network.manager")


FLAGS = flags.FLAGS
flags.DEFINE_string('flat_network_bridge', None,
                    'Bridge for simple network instances')
flags.DEFINE_string('flat_network_dns', '8.8.4.4',
                    'Dns for simple network')
flags.DEFINE_bool('flat_injected', True,
                  'Whether to attempt to inject network setup into guest')
flags.DEFINE_string('flat_interface', None,
                    'FlatDhcp will bridge into this interface if set')
flags.DEFINE_integer('vlan_start', 100, 'First VLAN for private networks')
flags.DEFINE_string('vlan_interface', None,
                    'vlans will bridge into this interface if set')
flags.DEFINE_integer('num_networks', 1, 'Number of networks to support')
Example #27
0
from nova import exception
from nova import flags
from nova import log as logging
from nova import utils
from nova.compute import power_state
from nova.virt.vmwareapi import vim_util
from nova.virt.vmwareapi import vm_util
from nova.virt.vmwareapi import vmware_images
from nova.virt.vmwareapi import network_utils

FLAGS = flags.FLAGS
flags.DEFINE_string('vmware_vif_driver',
                    'nova.virt.vmwareapi.vif.VMWareVlanBridgeDriver',
                    'The VMWare VIF driver to configure the VIFs.')

LOG = logging.getLogger("nova.virt.vmwareapi.vmops")

VMWARE_POWER_STATES = {
                   'poweredOff': power_state.SHUTDOWN,
                    'poweredOn': power_state.RUNNING,
                    'suspended': power_state.PAUSED}


class VMWareVMOps(object):
    """Management class for VM-related tasks."""

    def __init__(self, session):
        """Initializer."""
        self._session = session
        self._vif_driver = utils.import_object(FLAGS.vmware_vif_driver)
Example #28
0
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Tests For RPC AMQP.
"""

from nova import context
from nova import log as logging
from nova import rpc
from nova.rpc import amqp
from nova import test


LOG = logging.getLogger('nova.tests.rpc')


class RpcAMQPTestCase(test.TestCase):
    def setUp(self):
        super(RpcAMQPTestCase, self).setUp()
        self.conn = rpc.create_connection(True)
        self.receiver = TestReceiver()
        self.consumer = rpc.create_consumer(self.conn,
                                            'test',
                                            self.receiver,
                                            False)
        self.consumer.attach_to_eventlet()
        self.context = context.get_admin_context()

    def test_connectionpool_single(self):
Example #29
0
#    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.

"""Volume drivers for libvirt."""

import os
import time

from nova import exception
from nova import flags
from nova import log as logging
from nova import utils

LOG = logging.getLogger(__name__)
FLAGS = flags.FLAGS
flags.DECLARE('num_iscsi_scan_tries', 'nova.volume.driver')


class LibvirtVolumeDriver(object):
    """Base class for volume drivers."""
    def __init__(self, connection):
        self.connection = connection

    def _pick_volume_driver(self):
        hypervisor_type = self.connection.get_hypervisor_type().lower()
        return "phy" if hypervisor_type == "xen" else "qemu"

    def connect_volume(self, connection_info, mount_device):
        """Connect the volume. Returns xml for libvirt."""
Example #30
0
import webob.exc
from xml.dom import minidom
from xml.parsers import expat

from nova.api.openstack import common
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova.api.openstack.v2 import extensions
from nova import compute
from nova import exception
from nova import flags
from nova import log as logging
from nova.scheduler import api as scheduler_api

LOG = logging.getLogger("nova.api.openstack.v2.contrib.hosts")
FLAGS = flags.FLAGS


def _list_hosts(req, service=None):
    """Returns a summary list of hosts, optionally filtering
    by service type.
    """
    context = req.environ['nova.context']
    hosts = scheduler_api.get_host_list(context)
    if service:
        hosts = [host for host in hosts if host["service"] == service]
    return hosts


def check_host(fn):
Example #31
0
#    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.

from nova.api.openstack import extensions as base_extensions
from nova import flags
from nova import log as logging

LOG = logging.getLogger('nova.api.openstack.volume.extensions')
FLAGS = flags.FLAGS


class ExtensionManager(base_extensions.ExtensionManager):
    def __new__(cls):
        if cls._ext_mgr is None:
            LOG.audit(_('Initializing extension manager.'))

            cls._ext_mgr = super(ExtensionManager, cls).__new__(cls)

            cls.cls_list = FLAGS.osapi_volume_extension
            cls._ext_mgr.extensions = {}
            cls._ext_mgr._load_extensions()

        return cls._ext_mgr
Example #32
0
File: utils.py Project: emonty/nova
import time
import uuid
import pyclbr
from xml.sax import saxutils

from eventlet import event
from eventlet import greenthread
from eventlet import semaphore
from eventlet.green import subprocess
import netaddr

from nova import exception
from nova import flags
from nova import log as logging

LOG = logging.getLogger("nova.utils")
ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f"
FLAGS = flags.FLAGS


def import_class(import_str):
    """Returns a class from a string including module and class."""
    mod_str, _sep, class_str = import_str.rpartition('.')
    try:
        __import__(mod_str)
        return getattr(sys.modules[mod_str], class_str)
    except (ImportError, ValueError, AttributeError), exc:
        LOG.debug(_('Inner Exception: %s'), exc)
        raise exception.ClassNotFound(class_name=class_str, exception=exc)
Example #33
0
#         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.

from netaddr import IPNetwork, IPAddress
from nova import db
from nova import exception
from nova import flags
from nova import log as logging
from nova.network.quantum import melange_connection

LOG = logging.getLogger("nova.network.quantum.melange_ipam_lib")

FLAGS = flags.FLAGS


def get_ipam_lib(net_man):
    return QuantumMelangeIPAMLib()


class QuantumMelangeIPAMLib(object):
    """Implements Quantum IP Address Management (IPAM) interface
       using the Melange service, which is access using the Melange
       web services API.
    """
    def __init__(self):
        """Initialize class used to connect to Melange server"""
Example #34
0
:num_shell_tries:  Number of times to attempt to run commands (default: 3)

"""

from nova import context
from nova import exception
from nova import flags
from nova import log as logging
from nova import manager
from nova.openstack.common import cfg
from nova import rpc
from nova import utils
from nova.volume import volume_types


LOG = logging.getLogger('nova.volume.manager')

volume_manager_opts = [
    cfg.StrOpt('storage_availability_zone',
               default='nova',
               help='availability zone of this service'),
    cfg.StrOpt('volume_driver',
               default='nova.volume.driver.ISCSIDriver',
               help='Driver to use for volume creation'),
    cfg.BoolOpt('use_local_volumes',
                default=True,
                help='if True, will not discover local volumes'),
    cfg.BoolOpt('volume_force_update_capabilities',
                default=False,
                help='if True will force update capabilities on each check'),
    ]
Example #35
0
#    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.

from nova.api.openstack import extensions as base_extensions
from nova import flags
from nova import log as logging

LOG = logging.getLogger('nova.api.openstack.compute.extensions')
FLAGS = flags.FLAGS


class ExtensionManager(base_extensions.ExtensionManager):
    def __new__(cls):
        if cls._ext_mgr is None:
            LOG.audit(_('Initializing extension manager.'))

            cls._ext_mgr = super(ExtensionManager, cls).__new__(cls)

            cls.cls_list = FLAGS.osapi_compute_extension
            cls._ext_mgr.extensions = {}
            cls._ext_mgr._load_extensions()

        return cls._ext_mgr
Example #36
0
# 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.

from nova import db
from nova import exception
from nova import log as logging
from nova import test
from nova.network import manager as network_manager


import mox


LOG = logging.getLogger('nova.tests.network')


HOST = "testhost"


class FakeModel(dict):
    """Represent a model from the db"""
    def __init__(self, *args, **kwargs):
        self.update(kwargs)

        def __getattr__(self, name):
            return self[name]


networks = [{'id': 0,
Example #37
0
#    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.

from webob import exc

from nova import exception
from nova import flags
from nova import log as logging
from nova.api.openstack import common
from nova.api.openstack import faults
from nova.auth import manager

FLAGS = flags.FLAGS
LOG = logging.getLogger('nova.api.openstack')


def _translate_keys(user):
    return dict(id=user.id,
                name=user.name,
                access=user.access,
                secret=user.secret,
                admin=user.admin)


class Controller(common.OpenstackController):

    _serialization_metadata = {
        'application/xml': {
            "attributes": {
Example #38
0
from xml.dom import minidom

from webob import exc
import webob

from nova.api.openstack import common
from nova.api.openstack.v2 import extensions
from nova.api.openstack import wsgi
from nova import compute
from nova import db
from nova import exception
from nova import flags
from nova import log as logging
from nova import utils

LOG = logging.getLogger("nova.api.openstack.v2.contrib.security_groups")
FLAGS = flags.FLAGS


class SecurityGroupController(object):
    """The Security group API controller for the OpenStack API."""
    def __init__(self):
        self.compute_api = compute.API()
        super(SecurityGroupController, self).__init__()

    def _format_security_group_rule(self, context, rule):
        sg_rule = {}
        sg_rule['id'] = rule.id
        sg_rule['parent_group_id'] = rule.parent_group_id
        sg_rule['ip_protocol'] = rule.protocol
        sg_rule['from_port'] = rule.from_port
Example #39
0
#    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.

from nova.api.openstack import extensions as base_extensions
from nova import flags
from nova import log as logging


LOG = logging.getLogger('nova.api.openstack.compute.extensions')
FLAGS = flags.FLAGS


class ExtensionManager(base_extensions.ExtensionManager):
    def __new__(cls):
        if cls._ext_mgr is None:
            LOG.audit(_('Initializing extension manager.'))

            cls._ext_mgr = super(ExtensionManager, cls).__new__(cls)

            cls.cls_list = FLAGS.osapi_compute_extension
            cls._ext_mgr.extensions = {}
            cls._ext_mgr._load_extensions()

        return cls._ext_mgr
Example #40
0
"""
Utility classes for defining the time saving transfer of data from the reader
to the write using a LightQueue as a Pipe between the reader and the writer.
"""

from eventlet import event
from eventlet import greenthread
from eventlet.queue import LightQueue

from glance import client

from nova import exception
from nova import log as logging

LOG = logging.getLogger("nova.virt.vmwareapi.io_util")

IO_THREAD_SLEEP_TIME = 0.01
GLANCE_POLL_INTERVAL = 5


class ThreadSafePipe(LightQueue):
    """The pipe to hold the data which the reader writes to and the writer
    reads from."""

    def __init__(self, maxsize, transfer_size):
        LightQueue.__init__(self, maxsize)
        self.transfer_size = transfer_size
        self.transferred = 0

    def read(self, chunk_size):
Example #41
0
#    License for the specific language governing permissions and limitations
#    under the License

import webob

from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova.api.openstack.v2 import extensions
from nova import compute
from nova import exception
from nova import log as logging
from nova import network
from nova import rpc


LOG = logging.getLogger('nova.api.openstack.v2.contrib.floating_ips')


def make_float_ip(elem):
    elem.set('id')
    elem.set('ip')
    elem.set('fixed_ip')
    elem.set('instance_id')


class FloatingIPTemplate(xmlutil.TemplateBuilder):
    def construct(self):
        root = xmlutil.TemplateElement('floating_ip',
                                       selector='floating_ip')
        make_float_ip(root)
        return xmlutil.MasterTemplate(root, 1)
Example #42
0
#    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.

from nova import exception
from nova import flags
from nova import log as logging

LOG = logging.getLogger('nova.rpc')

flags.DEFINE_integer('rpc_thread_pool_size', 1024, 'Size of RPC thread pool')
flags.DEFINE_integer('rpc_conn_pool_size', 30, 'Size of RPC connection pool')


class RemoteError(exception.NovaException):
    """Signifies that a remote class has raised an exception.

    Contains a string representation of the type of the original exception,
    the value of the original exception, and the traceback.  These are
    sent to the parent as a joined string so printing the exception
    contains all of the relevant info.

    """
    message = _("Remote error: %(exc_type)s %(value)s\n%(traceback)s.")
Example #43
0
import random
import uuid

from pprint import pformat

from nova import exception
from nova import log as logging
from nova import utils


_CLASSES = ['host', 'network', 'session', 'SR', 'VBD',
            'PBD', 'VDI', 'VIF', 'PIF', 'VM', 'VLAN', 'task']

_db_content = {}

LOG = logging.getLogger("nova.virt.xenapi.fake")


def log_db_contents(msg=None):
    text = msg or ""
    content = pformat(_db_content)
    LOG.debug(_("%(text)s: _db_content => %(content)s") % locals())


def reset():
    for c in _CLASSES:
        _db_content[c] = {}
    create_host('fake')
    create_vm('fake',
              'Running',
              is_a_template=False,
Example #44
0
"""
Scheduler Service
"""

import functools

from nova import db
from nova import flags
from nova import log as logging
from nova import manager
from nova import rpc
from nova import utils
from nova.scheduler import zone_manager

LOG = logging.getLogger('nova.scheduler.manager')
FLAGS = flags.FLAGS
flags.DEFINE_string('scheduler_driver',
                    'nova.scheduler.chance.ChanceScheduler',
                    'Driver to use for the scheduler')


class SchedulerManager(manager.Manager):
    """Chooses a host to run instances on."""
    def __init__(self, scheduler_driver=None, *args, **kwargs):
        if not scheduler_driver:
            scheduler_driver = FLAGS.scheduler_driver
        self.driver = utils.import_object(scheduler_driver)
        self.zone_manager = zone_manager.ZoneManager()
        super(SchedulerManager, self).__init__(*args, **kwargs)
Example #45
0
"""The volumes extension."""

from webob import exc

from nova import compute
from nova import exception
from nova import flags
from nova import log as logging
from nova import volume
from nova.api.openstack import common
from nova.api.openstack import extensions
from nova.api.openstack import faults


LOG = logging.getLogger("nova.api.volumes")


FLAGS = flags.FLAGS


def _translate_volume_detail_view(context, vol):
    """Maps keys for volumes details view."""

    d = _translate_volume_summary_view(context, vol)

    # No additional data / lookups at the moment

    return d

Example #46
0
#   under the License.
"""The Extended Server Attributes API extension."""

from webob import exc

from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova import compute
from nova import db
from nova import exception
from nova import flags
from nova import log as logging

FLAGS = flags.FLAGS
LOG = logging.getLogger("nova.api.openstack.compute.contrib."
                        "extended_server_attributes")
authorize = extensions.soft_extension_authorizer('compute',
                                                 'extended_server_attributes')


class ExtendedServerAttributesController(wsgi.Controller):
    def __init__(self, *args, **kwargs):
        super(ExtendedServerAttributesController,
              self).__init__(*args, **kwargs)
        self.compute_api = compute.API()

    def _get_instances(self, context, instance_uuids):
        filters = {'uuid': instance_uuids}
        instances = self.compute_api.get_all(context, filters)
        return dict((instance['uuid'], instance) for instance in instances)
Example #47
0
import base64
import netaddr
import sys
import traceback

from nova import exception
from nova import flags
from nova import image
from nova import log as logging
from nova import test
from nova.tests import utils as test_utils

libvirt = None
FLAGS = flags.FLAGS

LOG = logging.getLogger('nova.tests.test_virt_drivers')


def catch_notimplementederror(f):
    """Decorator to simplify catching drivers raising NotImplementedError

    If a particular call makes a driver raise NotImplementedError, we
    log it so that we can extract this information afterwards to
    automatically generate a hypervisor/feature support matrix."""
    def wrapped_func(self, *args, **kwargs):
        try:
            return f(self, *args, **kwargs)
        except NotImplementedError:
            frame = traceback.extract_tb(sys.exc_info()[2])[-1]
            LOG.error('%(driver)s does not implement %(method)s' % {
                                               'driver': type(self.connection),
Example #48
0
"""
import time

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 test
from nova import utils
from nova.volume import volume_types
from nova.db.sqlalchemy.session import get_session
from nova.db.sqlalchemy import models

FLAGS = flags.FLAGS
LOG = logging.getLogger('nova.tests.test_volume_types')


class VolumeTypeTestCase(test.TestCase):
    """Test cases for volume type code"""
    def setUp(self):
        super(VolumeTypeTestCase, self).setUp()

        self.ctxt = context.get_admin_context()
        self.vol_type1_name = str(int(time.time()))
        self.vol_type1_specs = dict(type="physical drive",
                                    drive_type="SAS",
                                    size="300",
                                    rpm="7200",
                                    visible="True")
        self.vol_type1 = dict(name=self.vol_type1_name,
Example #49
0
from nova import log as logging
from nova import rpc

from ceilometer import meter
from ceilometer import counter

from ceilometer.publish import PublisherBase

LOG = logging.getLogger('nova.' + __name__)

class QueuePublisher(PublisherBase):

    QUEUE_TOPIC_ARG = 'topic'

    def __init__(self, context, **kwargs):
        self.context = context
        if kwargs.has_key(self.QUEUE_TOPIC_ARG):
            self.topic = kwargs[self.QUEUE_TOPIC_ARG]
        else:
            self.topic = None

    def publish_data(self, data):

        if isinstance(data, counter.Counter):
            self._publish_counter(self.context, data)
        else:
            LOG.debug('Bad argument passed. Expected ceilometer.counter:Counter, received ' + str(type(data)))

    def message_from_data(self, raw_data):

        msg = {
Example #50
0
from nova import context
from nova import db
from nova.db.sqlalchemy import models
from nova.db.sqlalchemy.session import get_session
from nova import exception
from nova import ipv6
from nova import log as logging
from nova.network.quantum import manager as quantum_manager
from nova.network.quantum import melange_connection
from nova import test
from nova import utils
from nova.network import manager

import mox

LOG = logging.getLogger('nova.tests.quantum_network')


# this class can be used for unit functional/testing on nova,
# as it does not actually make remote calls to the Quantum service
class FakeQuantumClientConnection(object):
    def __init__(self):
        self.nets = {}

    def get_networks_for_tenant(self, tenant_id):
        net_ids = []
        for net_id, n in self.nets.items():
            if n['tenant-id'] == tenant_id:
                net_ids.append(net_id)
        return {'networks': net_ids}
Example #51
0
from nova import log as logging
from nova.scheduler import api
from nova.scheduler import driver
from nova.scheduler import least_cost
from nova.scheduler import scheduler_options
from nova import utils


FLAGS = flags.FLAGS
flags.DEFINE_list(
    "default_host_filters",
    ["InstanceTypeFilter"],
    "Which filters to use for filtering hosts when not specified " "in the request.",
)

LOG = logging.getLogger("nova.scheduler.distributed_scheduler")


class InvalidBlob(exception.NovaException):
    message = _("Ill-formed or incorrectly routed 'blob' data sent " "to instance create request.")


class DistributedScheduler(driver.Scheduler):
    """Scheduler that can work across any nova deployment, from simple
    deployments to multiple nested zones.
    """

    def __init__(self, *args, **kwargs):
        super(DistributedScheduler, self).__init__(*args, **kwargs)
        self.cost_function_cache = {}
        self.options = scheduler_options.SchedulerOptions()
Example #52
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.
"""Built-in instance properties."""

from nova import context
from nova import db
from nova import exception
from nova import flags
from nova import log as logging

FLAGS = flags.FLAGS
LOG = logging.getLogger('nova.instance_types')


def create(name,
           memory,
           vcpus,
           root_gb,
           ephemeral_gb,
           flavorid,
           swap=None,
           rxtx_factor=None):
    """Creates instance types."""

    if swap is None:
        swap = 0
    if rxtx_factor is None:
Example #53
0
#    License for the specific language governing permissions and limitations
#    under the License.

import webob.exc

from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova.auth import manager
from nova import exception
from nova import flags
from nova import log as logging


FLAGS = flags.FLAGS
LOG = logging.getLogger('nova.api.openstack.compute.contrib.accounts')


class AccountTemplate(xmlutil.TemplateBuilder):
    def construct(self):
        root = xmlutil.TemplateElement('account', selector='account')
        root.set('id', 'id')
        root.set('name', 'name')
        root.set('description', 'description')
        root.set('manager', 'manager')

        return xmlutil.MasterTemplate(root, 1)


def _translate_keys(account):
    return dict(id=account.id,
Example #54
0
from nova.api.openstack import common
from nova.api.openstack.compute import ips
from nova.api.openstack.compute.views import servers as views_servers
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova import compute
from nova.compute import instance_types
from nova import exception
from nova import flags
from nova import log as logging
from nova.rpc import common as rpc_common
from nova.scheduler import api as scheduler_api
from nova import utils

LOG = logging.getLogger('nova.api.openstack.compute.servers')
FLAGS = flags.FLAGS


class SecurityGroupsTemplateElement(xmlutil.TemplateElement):
    def will_render(self, datum):
        return 'security_groups' in datum


def make_fault(elem):
    fault = xmlutil.SubTemplateElement(elem, 'fault', selector='fault')
    fault.set('code')
    fault.set('created')
    msg = xmlutil.SubTemplateElement(fault, 'message')
    msg.text = 'message'
    det = xmlutil.SubTemplateElement(fault, 'details')
Example #55
0
File: vif.py Project: ipbabble/nova
#    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.

"""VIF drivers for libvirt."""

from nova import exception
from nova import flags
from nova import log as logging
from nova.network import linux_net
from nova import utils
from nova.virt.libvirt import netutils
from nova.virt.vif import VIFDriver

LOG = logging.getLogger('nova.virt.libvirt.vif')

FLAGS = flags.FLAGS

flags.DEFINE_string('libvirt_ovs_bridge', 'br-int',
                    'Name of Integration Bridge used by Open vSwitch')


class LibvirtBridgeDriver(VIFDriver):
    """VIF driver for Linux bridge."""

    def _get_configurations(self, network, mapping):
        """Get a dictionary of VIF configurations for bridge type."""
        # Assume that the gateway also acts as the dhcp server.
        gateway_v6 = mapping.get('gateway_v6')
        mac_id = mapping['mac'].replace(':', '')
Example #56
0
"""The volumes api."""

from webob import exc
import webob

from nova.api.openstack import common
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova import exception
from nova import flags
from nova import log as logging
from nova import volume
from nova.volume import volume_types


LOG = logging.getLogger("nova.api.openstack.volume.volumes")


FLAGS = flags.FLAGS


def _translate_attachment_detail_view(_context, vol):
    """Maps keys for attachment details view."""

    d = _translate_attachment_summary_view(_context, vol)

    # No additional data / lookups at the moment

    return d

Example #57
0
import json
import os
import tempfile

from nova import exception
from nova import flags
from nova import log as logging
from nova.openstack.common import cfg
from nova import utils
from nova.virt.disk import guestfs
from nova.virt.disk import loop
from nova.virt.disk import nbd


LOG = logging.getLogger('nova.compute.disk')

disk_opts = [
    cfg.StrOpt('injected_network_template',
               default=utils.abspath('virt/interfaces.template'),
               help='Template file for injected network'),
    cfg.ListOpt('img_handlers',
                default=['loop', 'nbd', 'guestfs'],
                help='Order of methods used to mount disk images'),

    # NOTE(yamahata): ListOpt won't work because the command may include a
    #                 comma. For example:
    #
    #                 mkfs.ext3 -O dir_index,extent -E stride=8,stripe-width=16
    #                           --label %(fs_label)s %(target)s
    #
Example #58
0
"""
A fake (in-memory) hypervisor+api.

Allows nova testing w/o a hypervisor.  This module also documents the
semantics of real hypervisor connections.

"""

from nova import db
from nova import exception
from nova import log as logging
from nova import utils
from nova.compute import power_state
from nova.virt import driver

LOG = logging.getLogger('nova.compute.disk')


def get_connection(_=None):
    # The read_only parameter is ignored.
    return FakeConnection.instance()


class FakeInstance(object):
    def __init__(self, name, state):
        self.name = name
        self.state = state


class FakeConnection(driver.ComputeDriver):
    """Fake hypervisor driver"""
Example #59
0
"""
Least Cost is an algorithm for choosing which host machines to
provision a set of resources to. The input is a WeightedHost object which
is decided upon by a set of objective-functions, called the 'cost-functions'.
The WeightedHost contains a combined weight for each cost-function.

The cost-function and weights are tabulated, and the host with the least cost
is then selected for provisioning.
"""

from nova.common import cfg
from nova import flags
from nova import log as logging


LOG = logging.getLogger('nova.scheduler.least_cost')

least_cost_opts = [
    cfg.ListOpt('least_cost_functions',
                default=[
                  'nova.scheduler.least_cost.compute_fill_first_cost_fn'
                  ],
                help='Which cost functions the LeastCostScheduler should use'),
    cfg.FloatOpt('noop_cost_fn_weight',
             default=1.0,
               help='How much weight to give the noop cost function'),
    cfg.FloatOpt('compute_fill_first_cost_fn_weight',
             default=1.0,
               help='How much weight to give the fill-first cost function'),
    ]
Example #60
0
File: api.py Project: justinsb/nova
#    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.

from nova.db import base
from nova import exception
from nova import flags
from nova import log as logging
from nova.network import model as network_model
from nova import rpc
from nova.rpc import common as rpc_common

FLAGS = flags.FLAGS
LOG = logging.getLogger(__name__)


class API(base.Base):
    """API for interacting with the network manager."""
    def get_all(self, context):
        return rpc.call(context, FLAGS.network_topic,
                        {'method': 'get_all_networks'})

    def get(self, context, network_uuid):
        return rpc.call(context, FLAGS.network_topic, {
            'method': 'get_network',
            'args': {
                'network_uuid': network_uuid
            }
        })