Exemplo n.º 1
0
    def test_declare(self):
        self.assert_('answer' not in self.global_FLAGS)
        flags.DECLARE('answer', 'engine.tests.declare_flags')
        self.assert_('answer' in self.global_FLAGS)
        self.assertEqual(self.global_FLAGS.answer, 42)

        # Make sure we don't overwrite anything
        self.global_FLAGS.answer = 256
        self.assertEqual(self.global_FLAGS.answer, 256)
        flags.DECLARE('answer', 'engine.tests.declare_flags')
        self.assertEqual(self.global_FLAGS.answer, 256)
Exemplo n.º 2
0
from engine import db
from engine import exception
from engine import flags
from engine import log as logging
from engine import rpc
from engine import utils
from engine.compute import api as compute_api
from engine.compute import power_state
from engine.compute import vm_states
from engine.api.ec2 import ec2utils

FLAGS = flags.FLAGS
LOG = logging.getLogger('engine.scheduler.driver')
flags.DEFINE_integer('service_down_time', 60,
                     'maximum time since last check-in for up service')
flags.DECLARE('instances_path', 'engine.compute.manager')


def cast_to_volume_host(context, host, method, update_db=True, **kwargs):
    """Cast request to a volume host queue"""

    if update_db:
        volume_id = kwargs.get('volume_id', None)
        if volume_id is not None:
            now = utils.utcnow()
            db.volume_update(context, volume_id, {
                'host': host,
                'scheduled_at': now
            })
    rpc.cast(context, db.queue_get_for(context, 'volume', host), {
        "method": method,
Exemplo n.º 3
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.
"""Database setup and migration commands."""

from engine import flags
from engine import utils

FLAGS = flags.FLAGS
flags.DECLARE('db_backend', 'engine.db')

IMPL = utils.LazyPluggable(FLAGS['db_backend'],
                           sqlalchemy='engine.db.sqlalchemy.migration')


def db_sync(version=None):
    """Migrate the database to `version` or the most recent version."""
    return IMPL.db_sync(version=version)


def db_version():
    """Display the current database version."""
    return IMPL.db_version()
Exemplo n.º 4
0
import webob.dec
import webob.exc

from engine.api.x7 import common
from engine.api.x7 import wsgi
from engine import auth
from engine import context
from engine import exception
from engine import flags
from engine import log as logging
from engine import utils
from engine import wsgi as base_wsgi

LOG = logging.getLogger('engine.api.x7.v2.auth')
FLAGS = flags.FLAGS
flags.DECLARE('use_forwarded_for', 'engine.api.auth')


class NoAuthMiddleware(base_wsgi.Middleware):
    """Return a fake token if one isn't specified."""
    @webob.dec.wsgify(RequestClass=wsgi.Request)
    def __call__(self, req):
        if 'X-Auth-Token' not in req.headers:
            user_id = req.headers.get('X-Auth-User', 'admin')
            project_id = req.headers.get('X-Auth-Project-Id', 'admin')
            os_url = os.path.join(req.url, project_id)
            res = webob.Response()
            # NOTE(vish): This is expecting and returning Auth(1.1), whereas
            #             keystone uses 2.0 auth.  We should probably allow
            #             2.0 auth here as well.
            res.headers['X-Auth-Token'] = '%s:%s' % (user_id, project_id)
Exemplo n.º 5
0
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Tests For Console proxy.
"""

from engine import context
from engine import db
from engine import exception
from engine import flags
from engine import test
from engine import utils

FLAGS = flags.FLAGS
flags.DECLARE('console_driver', 'engine.console.manager')


class ConsoleTestCase(test.TestCase):
    """Test case for console proxy"""
    def setUp(self):
        super(ConsoleTestCase, self).setUp()
        self.flags(console_driver='engine.console.fake.FakeConsoleProxy',
                   stub_compute=True)
        self.console = utils.import_object(FLAGS.console_manager)
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id, self.project_id)
        self.host = 'test_compute_host'

    def _create_instance(self):
Exemplo n.º 6
0
"""

from engine import db
from engine import flags
from engine import context
from engine import test
from engine import log as logging
from engine import utils
import engine.image.fake
from engine.compute import utils as compute_utils
from engine.compute import instance_types
from engine.notifier import test_notifier

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


class UsageInfoTestCase(test.TestCase):
    def setUp(self):
        super(UsageInfoTestCase, self).setUp()
        self.flags(connection_type='fake',
                   stub_network=True,
                   notification_driver='engine.notifier.test_notifier',
                   network_manager='engine.network.manager.FlatManager')
        self.compute = utils.import_object(FLAGS.compute_manager)
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id, self.project_id)
        test_notifier.NOTIFICATIONS = []
Exemplo n.º 7
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.
"""Volume drivers for libvirt."""

import os
import time

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

LOG = logging.getLogger('engine.virt.libvirt.volume')
FLAGS = flags.FLAGS
flags.DECLARE('num_iscsi_scan_tries', 'engine.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."""
        driver = self._pick_volume_driver()
        device_path = connection_info['data']['device_path']
Exemplo n.º 8
0
from engine.api.ec2 import ec2utils
from engine import block_device
from engine import compute
from engine import context
from engine import db
from engine import exception
from engine import flags
from engine import log as logging
from engine import network
from engine import volume
from engine import wsgi

LOG = logging.getLogger('engine.api.metadata')
FLAGS = flags.FLAGS
flags.DECLARE('use_forwarded_for', 'engine.api.auth')
flags.DECLARE('dhcp_domain', 'engine.network.manager')

_DEFAULT_MAPPINGS = {
    'ami': 'sda1',
    'ephemeral0': 'sda2',
    'root': block_device.DEFAULT_ROOT_DEV_NAME,
    'swap': 'sda3'
}


class Versions(wsgi.Application):
    @webob.dec.wsgify(RequestClass=wsgi.Request)
    def __call__(self, req):
        """Respond to a request for all versions."""
        # available api versions
Exemplo n.º 9
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 engine import flags

FLAGS = flags.FLAGS

flags.DECLARE('volume_driver', 'engine.volume.manager')
FLAGS['volume_driver'].SetDefault('engine.volume.driver.FakeISCSIDriver')
FLAGS['connection_type'].SetDefault('fake')
FLAGS['fake_rabbit'].SetDefault(True)
FLAGS['rpc_backend'].SetDefault('engine.rpc.impl_fake')
flags.DECLARE('auth_driver', 'engine.auth.manager')
FLAGS['auth_driver'].SetDefault('engine.auth.dbdriver.DbDriver')
flags.DECLARE('network_size', 'engine.network.manager')
flags.DECLARE('num_networks', 'engine.network.manager')
flags.DECLARE('fake_network', 'engine.network.manager')
FLAGS['network_size'].SetDefault(8)
FLAGS['num_networks'].SetDefault(2)
FLAGS['fake_network'].SetDefault(True)
FLAGS['image_service'].SetDefault('engine.image.fake.FakeImageService')
flags.DECLARE('iscsi_num_targets', 'engine.volume.driver')
FLAGS['iscsi_num_targets'].SetDefault(8)
Exemplo n.º 10
0
from engine.db.sqlalchemy.session import get_session
from engine.db.sqlalchemy import models
from engine.db.sqlalchemy import api as sqlalchemy_api

from engine.api.x7 import wsgi
import engine.api.x7.v2 as x7_api
from engine.api.x7.v2 import extensions
from engine.api.x7.v2 import views

from engine.compute import instance_types
from engine.scheduler import api as scheduler_api

from sqlalchemy.orm import joinedload

FLAGS = flags.FLAGS
flags.DECLARE('max_gigabytes', 'engine.scheduler.simple')
flags.DECLARE('max_cores', 'engine.scheduler.simple')

LOG = logging.getLogger('engine.api.x7.admin')


class AdminQuotasController(object):
    def _format_quota_set(self, project_id, quota_set):
        """Convert the quota object to a result dict"""
        if quota_set:
            return {
                'id':
                project_id,
                'metadata_items':
                quota_set['metadata_items'],
                'injected_file_content_bytes':
Exemplo n.º 11
0
"""vm_vdi_cleaner.py - List or clean orphaned VDIs/instances on XenServer."""

import doctest
import optparse
import sys
import XenAPI

from engine import context
from engine import db
from engine import exception
from engine import flags
from engine import utils

from engine.virt import xenapi_conn

flags.DECLARE("resize_confirm_window", "engine.compute.manager")
flags.DECLARE("xenapi_connection_url", "engine.virt.xenapi_conn")
flags.DECLARE("xenapi_connection_username", "engine.virt.xenapi_conn")
flags.DECLARE("xenapi_connection_password", "engine.virt.xenapi_conn")

FLAGS = flags.FLAGS
# NOTE(sirp): Engine 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"]
utils.default_flagfile(args=dummy)
FLAGS(dummy)


class UnrecognizedNameLabel(Exception):
    pass
Exemplo n.º 12
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 sqlalchemy import *

from sqlalchemy import Column, MetaData, Table, String

from engine import flags

flags.DECLARE('default_floating_pool', 'engine.network.manager')
flags.DECLARE('public_interface', 'engine.network.linux_net')
FLAGS = flags.FLAGS

meta = MetaData()

pool_column = Column('pool', String(255))
interface_column = Column('interface', String(255))


def upgrade(migrate_engine):
    meta.bind = migrate_engine
    table = Table('floating_ips', meta, autoload=True)
    table.create_column(pool_column)
    table.create_column(interface_column)
    table.update().values(pool=FLAGS.default_floating_pool,
Exemplo n.º 13
0
"""
Handles all requests relating to volumes.
"""

from eventlet import greenthread

from engine import exception
from engine import flags
from engine import log as logging
from engine import quota
from engine import rpc
from engine import utils
from engine.db import base

FLAGS = flags.FLAGS
flags.DECLARE('storage_availability_zone', 'engine.volume.manager')

LOG = logging.getLogger('engine.volume')


class API(base.Base):
    """API for interacting with the volume manager."""
    def create(self,
               context,
               size,
               snapshot_id,
               name,
               description,
               volume_type=None,
               metadata=None,
               availability_zone=None):