def setUp(self): super(EngineLoggerTestCase, self).setUp() levels = FLAGS.default_log_levels levels.append("engine-test=AUDIT") self.flags(default_log_levels=levels, verbose=True) self.log = log.getLogger('engine-test')
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('engine.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(engine.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(engine.notifier.log_notifier, 'notify', mock_notify2)
def notify(message): """Notifies the recipient of the desired event given the model. Log notifications using engine's default logging system""" priority = message.get('priority', FLAGS.default_notification_level) priority = priority.lower() logger = logging.getLogger( 'engine.notification.%s' % message['event_type']) getattr(logger, priority)(json.dumps(message))
def test_error_notification(self): self.stubs.Set(engine.flags.FLAGS, 'notification_driver', 'engine.notifier.rabbit_notifier') self.stubs.Set(engine.flags.FLAGS, 'publish_errors', True) LOG = log.getLogger('engine') LOG.setup_from_flags() msgs = [] def mock_notify(context, topic, data): msgs.append(data) self.stubs.Set(engine.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')
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']
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)
import base64 import netaddr import sys import traceback from engine import exception from engine import flags from engine import image from engine import log as logging from engine import test from engine.tests import utils as test_utils libvirt = None FLAGS = flags.FLAGS LOG = logging.getLogger("engine.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(
# 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. """VIF drivers for libvirt.""" from engine import exception from engine import flags from engine import log as logging from engine.network import linux_net from engine import utils from engine.virt.libvirt import netutils from engine.virt.vif import VIFDriver LOG = logging.getLogger('engine.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(':', '')
import struct import tempfile import time import utils import M2Crypto gettext.install('engine', unicode=1) from engine import context from engine import db from engine import flags from engine import log as logging LOG = logging.getLogger("engine.crypto") FLAGS = flags.FLAGS flags.DEFINE_string('ca_file', 'cacert.pem', _('Filename of root CA')) flags.DEFINE_string('key_file', os.path.join('private', 'cakey.pem'), _('Filename of private key')) flags.DEFINE_string('crl_file', 'crl.pem', _('Filename of root Certificate Revocation List')) flags.DEFINE_string('keys_path', '$state_path/keys', _('Where we keep our keys')) flags.DEFINE_string('ca_path', '$state_path/CA', _('Where we keep our root CA')) flags.DEFINE_boolean('use_project_ca', False, _('Should we use a CA for each project?'))
# License for the specific language governing permissions and limitations # under the License """Disk Config extension.""" from xml.dom import minidom from webob import exc from engine.api.x7.v2 import extensions from engine.api.x7 import xmlutil from engine import compute from engine import db from engine import log as logging from engine import utils LOG = logging.getLogger('engine.api.x7.contrib.disk_config') ALIAS = 'RAX-DCF' XMLNS_DCF = "http://docs.rackspacecloud.com/servers/api/ext/diskConfig/v1.0" class ServerDiskConfigTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('server') root.set('{%s}diskConfig' % XMLNS_DCF, '%s:diskConfig' % ALIAS) return xmlutil.SlaveTemplate(root, 1, nsmap={ALIAS: XMLNS_DCF}) class ServersDiskConfigTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('servers')
# 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. import sqlalchemy from sqlalchemy import select, Column, ForeignKey, Integer, String from migrate import ForeignKeyConstraint from engine import log as logging LOG = logging.getLogger('engine.db.sqlalchemy.migrate_repo.versions') meta = sqlalchemy.MetaData() def _get_table(name): return sqlalchemy.Table(name, meta, autoload=True) def upgrade(migrate_engine): meta.bind = migrate_engine instance_actions = _get_table('instance_actions') instances = _get_table('instances') uuid_column = Column('instance_uuid', String(36), ForeignKey('instances.uuid')) uuid_column = Column('instance_uuid', String(36)) uuid_column.create(instance_actions)
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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. """ Unit Tests for remote procedure calls using fake_impl """ from engine import log as logging from engine.rpc import impl_fake from engine.tests.rpc import common LOG = logging.getLogger('engine.tests.rpc') class RpcFakeTestCase(common._BaseRpcTestCase): def setUp(self): self.rpc = impl_fake super(RpcFakeTestCase, self).setUp() def tearDown(self): super(RpcFakeTestCase, self).tearDown()
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 engine import exception from engine import flags from engine import log as logging LOG = logging.getLogger("engine.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)
# under the License. import routes import webob.dec import webob.exc import engine.api.x7.v2 from engine.api.x7 import wsgi from engine.api.x7 import xmlutil 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.extensions') FLAGS = flags.FLAGS class ExtensionDescriptor(object): """Base class that defines the contract for extensions. Note that you don't have to derive from this class to have a valid extension; it is purely a convenience. """ # The name of the extension, e.g., 'Fox In Socks' name = None
# 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 eventlet import tpool from engine import context from engine import db from engine import flags from engine import log as logging from engine import utils from engine.virt.libvirt import netutils LOG = logging.getLogger("engine.virt.libvirt.firewall") FLAGS = flags.FLAGS try: import libvirt except ImportError: LOG.warn( _("Libvirt module could not be loaded. NWFilterFirewall will " "not work correctly.")) class FirewallDriver(object): def prepare_instance_filter(self, instance, network_info): """Prepare filters for the instance. At this point, the instance isn't running yet."""
from engine import context from engine import db from engine.db.sqlalchemy import models from engine.db.sqlalchemy.session import get_session from engine import exception from engine import ipv6 from engine import log as logging from engine.network.quantum import manager as quantum_manager from engine.network.quantum import melange_connection from engine import test from engine import utils from engine.network import manager import mox LOG = logging.getLogger('engine.tests.quantum_network') # this class can be used for unit functional/testing on engine, # 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}
import time 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
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """The Extended Status Admin API extension.""" from webob import exc from engine.api.x7.v2 import extensions from engine.api.x7 import xmlutil from engine import compute from engine import exception from engine import flags from engine import log as logging FLAGS = flags.FLAGS LOG = logging.getLogger("engine.api.x7.v2.contrib.extendedstatus") class Extended_status(extensions.ExtensionDescriptor): """Extended Status support""" name = "ExtendedStatus" alias = "OS-EXT-STS" namespace = "http://docs.x7.org/compute/ext/" \ "extended_status/api/v1.1" updated = "2011-11-03T00:00:00+00:00" admin_only = True def get_request_extensions(self): request_extensions = []
# License for the specific language governing permissions and limitations # under the License. from lxml import etree import webob.exc from engine import context from engine import exception from engine import flags from engine import log as logging from engine import test from engine.api.x7.v2.contrib import hosts as os_hosts from engine.scheduler import api as scheduler_api FLAGS = flags.FLAGS LOG = logging.getLogger('engine.tests.hosts') # Simulate the hosts returned by the zone manager. HOST_LIST = [{ "host_name": "host_c1", "service": "compute" }, { "host_name": "host_c2", "service": "compute" }, { "host_name": "host_v1", "service": "volume" }, { "host_name": "host_v2", "service": "volume" }]
from eventlet import queue from eventlet import tpool from eventlet import timeout from engine import context from engine import db from engine import exception from engine import utils from engine import flags from engine import log as logging from engine.virt import driver from engine.virt.xenapi import vm_utils from engine.virt.xenapi.vmops import VMOps from engine.virt.xenapi.volumeops import VolumeOps LOG = logging.getLogger("engine.virt.xenapi") FLAGS = flags.FLAGS flags.DEFINE_string( 'xenapi_connection_url', None, 'URL for connection to XenServer/Xen Cloud Platform.' ' Required if connection_type=xenapi.') flags.DEFINE_string( 'xenapi_connection_username', 'root', 'Username for connection to XenServer/Xen Cloud Platform.' ' Used only if connection_type=xenapi.') flags.DEFINE_string( 'xenapi_connection_password', None, 'Password for connection to XenServer/Xen Cloud Platform.' ' Used only if connection_type=xenapi.')
from engine.api.x7 import common from engine.api.x7.v2 import ips from engine.api.x7.v2.views import servers as views_servers from engine.api.x7 import wsgi from engine.api.x7 import xmlutil from engine import compute from engine.compute import instance_types from engine import network from engine import exception from engine import flags from engine import log as logging from engine.rpc import common as rpc_common from engine.scheduler import api as scheduler_api from engine import utils LOG = logging.getLogger('engine.api.x7.v2.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')
from xml.parsers import expat from lxml import etree import webob from engine import exception from engine import log as logging from engine import utils from engine import wsgi XMLNS_V10 = 'http://docs.rackspacecloud.com/servers/api/v1.0' XMLNS_V11 = 'http://docs.x7.org/compute/api/v1.1' XMLNS_ATOM = 'http://www.w3.org/2005/Atom' LOG = logging.getLogger('engine.api.x7.wsgi') # The vendor content types should serialize identically to the non-vendor # content types. So to avoid littering the code with both options, we # map the vendor to the other when looking up the type _CONTENT_TYPE_MAP = { 'application/vnd.x7.compute+json': 'application/json', 'application/vnd.x7.compute+xml': 'application/xml', } SUPPORTED_CONTENT_TYPES = ( 'application/json', 'application/vnd.x7.compute+json', 'application/xml', 'application/vnd.x7.compute+xml', )
# 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 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."""
# 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 exception from engine import flags from engine import log as logging LOG = logging.getLogger('engine.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.EngineException): """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.
# 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. """Auth Components for VNC Console.""" import os import sys from engine import flags from engine import log as logging from engine import version from engine import wsgi from engine.vnc import auth from engine.vnc import proxy LOG = logging.getLogger('engine.vncproxy') FLAGS = flags.FLAGS flags.DEFINE_string('vncproxy_wwwroot', '/var/lib/engine/noVNC/', 'Full path to noVNC directory') flags.DEFINE_boolean('vnc_debug', False, 'Enable debugging features, like token bypassing') flags.DEFINE_integer('vncproxy_port', 6080, 'Port that the VNC proxy should bind to') flags.DEFINE_string('vncproxy_host', '0.0.0.0', 'Address that the VNC proxy should bind to') flags.DEFINE_integer('vncproxy_flash_socket_policy_port', 843, 'Port that the socket policy listener should bind to') flags.DEFINE_string('vncproxy_flash_socket_policy_host', '0.0.0.0', 'Address that the socket policy listener should bind to') flags.DEFINE_integer('vnc_token_ttl', 300, 'How many seconds before deleting tokens')
from lxml import etree import webob from engine.api.x7.v2.contrib import volumes from engine import context from engine import exception from engine import flags from engine import log as logging from engine import test from engine import volume from engine.tests.api.x7 import fakes FLAGS = flags.FLAGS LOG = logging.getLogger('engine.tests.api.x7.snapshot') _last_param = {} def _get_default_snapshot_param(): return { 'id': 123, 'volume_id': 12, 'status': 'available', 'volume_size': 100, 'created_at': None, 'display_name': 'Default name', 'display_description': 'Default description', }
# 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. # # @author: Sumit Naiksatam, Cisco Systems, Inc. # from engine import exception as excp from engine import flags from engine import log as logging from engine.scheduler import driver from quantum.client import Client from quantum.common.wsgi import Serializer LOG = logging.getLogger('quantum.plugins.cisco.engine.quantum_aware_scheduler') 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 ACTION_PREFIX_EXT = '/v1.0' ACTION_PREFIX_CSCO = ACTION_PREFIX_EXT + \ '/extensions/csco/tenants/{tenant_id}' TENANT_ID = 'engine' CSCO_EXT_NAME = 'Cisco Engine Tenant'
""" import json import os import tempfile from engine import exception from engine import flags from engine import log as logging from engine import utils from engine.virt.disk import guestfs from engine.virt.disk import loop from engine.virt.disk import nbd LOG = logging.getLogger('engine.compute.disk') FLAGS = flags.FLAGS flags.DEFINE_integer('minimum_root_size', 1024 * 1024 * 1024 * 10, 'minimum size in bytes of root partition') flags.DEFINE_string('injected_network_template', utils.abspath('virt/interfaces.template'), 'Template file for injected network') flags.DEFINE_list('img_handlers', ['loop', 'nbd', 'guestfs'], 'Order of methods used to mount disk images') # NOTE(yamahata): DEFINE_list() doesn't work because the command may # include ','. For example, # mkfs.ext3 -O dir_index,extent -E stride=8,stripe-width=16 # --label %(fs_label)s %(target)s #
Drivers for volumes. """ import os import time from xml.etree import ElementTree from engine import exception from engine import flags from engine import log as logging from engine import utils from engine.volume import iscsi from engine.volume import volume_types LOG = logging.getLogger("engine.volume.driver") FLAGS = flags.FLAGS flags.DEFINE_string('volume_group', 'engine-volumes', 'Name for the VG that will contain exported volumes') 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('iscsi_num_targets', 100, 'Number of iscsi target ids per host') flags.DEFINE_string('iscsi_target_prefix', 'iqn.2010-10.org.x7:', 'prefix for iscsi volumes') flags.DEFINE_string('iscsi_ip_address', '$my_ip', 'use this ip for iscsi') flags.DEFINE_integer('iscsi_port', 3260, 'The port that the iSCSI daemon is listening on') flags.DEFINE_string('rbd_pool', 'rbd',
""" 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 engine import flags from engine import log as logging from engine import exception LOG = logging.getLogger('engine.scheduler.least_cost') FLAGS = flags.FLAGS flags.DEFINE_list('least_cost_functions', ['engine.scheduler.least_cost.compute_fill_first_cost_fn'], 'Which cost functions the LeastCostScheduler should use.') # TODO(sirp): Once we have enough of these rules, we can break them out into a # cost_functions.py file (perhaps in a least_cost_scheduler directory) flags.DEFINE_float('noop_cost_fn_weight', 1.0, 'How much weight to give the noop cost function') flags.DEFINE_float('compute_fill_first_cost_fn_weight', 1.0, 'How much weight to give the fill-first cost function')
# under the License. import stubout from engine import exception from engine import flags from engine import vsa from engine import volume from engine import db from engine import context from engine import test from engine import log as logging import engine.image.fake FLAGS = flags.FLAGS LOG = logging.getLogger('engine.tests.vsa.volumes') class VsaVolumesTestCase(test.TestCase): def setUp(self): super(VsaVolumesTestCase, self).setUp() self.stubs = stubout.StubOutForTesting() self.vsa_api = vsa.API() self.volume_api = volume.API() self.context = context.get_admin_context() self.default_vol_type = self.vsa_api.get_vsa_volume_type(self.context) def fake_show_by_name(meh, context, name): return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}}
import os import time from engine.compute import power_state from engine import exception from engine import flags from engine import log as logging from engine.virt import driver from engine.virt import images wmi = None FLAGS = flags.FLAGS LOG = logging.getLogger('engine.virt.hyperv') HYPERV_POWER_STATE = { 3: power_state.SHUTDOWN, 2: power_state.RUNNING, 32768: power_state.PAUSED, } REQ_POWER_STATE = { 'Enabled': 2, 'Disabled': 3, 'Reboot': 10, 'Reset': 11, 'Paused': 32768, 'Suspended': 32769, }
# under the License. import webob.exc from engine.api.x7 import common from engine.api.x7.v2.views import images as views_images from engine.api.x7 import wsgi from engine.api.x7 import xmlutil from engine import compute from engine import exception from engine import flags import engine.image from engine import log LOG = log.getLogger('engine.api.x7.v2.images') FLAGS = flags.FLAGS SUPPORTED_FILTERS = { 'name': 'name', 'status': 'status', 'changes-since': 'changes-since', 'server': 'property-instance_ref', 'type': 'property-image_type', 'minRam': 'min_ram', 'minDisk': 'min_disk', } def make_image(elem, detailed=False): elem.set('name')
# limitations under the License. """Auth Components for VNC Console.""" import os import sys from engine import flags from engine import log as logging from engine import version from engine import wsgi from engine.vnc import auth from engine.vnc import proxy LOG = logging.getLogger('engine.vncproxy') FLAGS = flags.FLAGS flags.DEFINE_string('vncproxy_wwwroot', '/var/lib/engine/noVNC/', 'Full path to noVNC directory') flags.DEFINE_boolean('vnc_debug', False, 'Enable debugging features, like token bypassing') flags.DEFINE_integer('vncproxy_port', 6080, 'Port that the VNC proxy should bind to') flags.DEFINE_string('vncproxy_host', '0.0.0.0', 'Address that the VNC proxy should bind to') flags.DEFINE_integer('vncproxy_flash_socket_policy_port', 843, 'Port that the socket policy listener should bind to') flags.DEFINE_string('vncproxy_flash_socket_policy_host', '0.0.0.0', 'Address that the socket policy listener should bind to') flags.DEFINE_integer('vnc_token_ttl', 300, 'How many seconds before deleting tokens')
VSA Simple Scheduler """ from engine import context from engine import db from engine import flags from engine import log as logging from engine import rpc from engine import utils from engine import exception from engine.scheduler import driver from engine.scheduler import simple from engine.vsa.api import VsaState from engine.volume import volume_types LOG = logging.getLogger('engine.scheduler.vsa') FLAGS = flags.FLAGS flags.DEFINE_integer('drive_type_approx_capacity_percent', 10, 'The percentage range for capacity comparison') flags.DEFINE_integer('vsa_unique_hosts_per_alloc', 10, 'The number of unique hosts per storage allocation') flags.DEFINE_boolean('vsa_select_unique_drives', True, 'Allow selection of same host for multiple drives') def BYTES_TO_GB(bytes): return bytes >> 30 def GB_TO_BYTES(gb):
""" import time 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 test from engine import utils from engine.compute import instance_types from engine.db.sqlalchemy.session import get_session from engine.db.sqlalchemy import models FLAGS = flags.FLAGS LOG = logging.getLogger('engine.tests.compute') class InstanceTypeTestCase(test.TestCase): """Test cases for instance type code""" def setUp(self): super(InstanceTypeTestCase, self).setUp() session = get_session() def _generate_name(self): """return a name not in the DB""" nonexistent_flavor = str(int(time.time())) flavors = instance_types.get_all_types() while nonexistent_flavor in flavors: nonexistent_flavor += "z" else:
import copy import datetime import json import random import time from urlparse import urlparse from tank.common import exception as tank_exception from engine import exception from engine import flags from engine import log as logging from engine import utils LOG = logging.getLogger('engine.image.tank') FLAGS = flags.FLAGS TankClient = utils.import_class('tank.client.Client') def _parse_image_ref(image_href): """Parse an image href into composite parts. :param image_href: href of an image :returns: a tuple of the form (image_id, host, port) :raises ValueError """ o = urlparse(image_href)
# 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 engine import exception from engine import flags from engine import log as logging from engine.network import linux_net from engine import utils from engine.virt.libvirt import netutils from engine.virt.vif import VIFDriver LOG = logging.getLogger('engine.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(':', '')
"""The hosts admin extension.""" import webob.exc from xml.dom import minidom from xml.parsers import expat from engine.api.x7 import wsgi from engine.api.x7 import xmlutil from engine.api.x7.v2 import extensions from engine import compute from engine import exception from engine import flags from engine import log as logging from engine.scheduler import api as scheduler_api LOG = logging.getLogger("engine.api.x7.v2.contrib.hosts") FLAGS = flags.FLAGS class HostIndexTemplate(xmlutil.TemplateBuilder): def construct(self): def shimmer(obj, do_raise=False): # A bare list is passed in; we need to wrap it in a dict return dict(hosts=obj) root = xmlutil.TemplateElement('hosts', selector=shimmer) elem = xmlutil.SubTemplateElement(root, 'host', selector='hosts') elem.set('host_name') elem.set('service') return xmlutil.MasterTemplate(root, 1)
""" import os import time from xml.etree import ElementTree from engine import exception from engine import flags from engine import log as logging from engine import utils from engine.volume import iscsi from engine.volume import volume_types LOG = logging.getLogger("engine.volume.driver") FLAGS = flags.FLAGS flags.DEFINE_string('volume_group', 'engine-volumes', 'Name for the VG that will contain exported volumes') 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('iscsi_num_targets', 100, 'Number of iscsi target ids per host') flags.DEFINE_string('iscsi_target_prefix', 'iqn.2010-10.org.x7:', 'prefix for iscsi volumes') flags.DEFINE_string('iscsi_ip_address', '$my_ip', 'use this ip for iscsi') flags.DEFINE_integer('iscsi_port', 3260,
# License for the specific language governing permissions and limitations # under the License. from M2Crypto import X509 import unittest from engine import crypto from engine import flags from engine import log as logging from engine import test from engine.auth import manager from engine.api.ec2 import cloud from engine.auth import fakeldap FLAGS = flags.FLAGS LOG = logging.getLogger('engine.tests.auth_unittest') class user_generator(object): def __init__(self, manager, **user_state): if 'name' not in user_state: user_state['name'] = 'test1' self.manager = manager self.user = manager.create_user(**user_state) def __enter__(self): return self.user def __exit__(self, value, type, trace): self.manager.delete_user(self.user)
# 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. import hashlib from engine.api.x7 import common from engine.api.x7.v2.views import addresses as views_addresses from engine.api.x7.v2.views import flavors as views_flavors from engine.api.x7.v2.views import images as views_images from engine import log as logging from engine import utils LOG = logging.getLogger('engine.api.x7.v2.views.servers') class ViewBuilder(common.ViewBuilder): """Model a server API response as a python dictionary.""" _collection_name = "servers" _progress_statuses = ( "ACTIVE", "BUILD", "REBUILD", "RESIZE", "VERIFY_RESIZE", )
# # Licensed under the Apache License, Version 2.0 (the "License"); you may # 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. """ Unit Tests for remote procedure calls using fake_impl """ from engine import log as logging from engine.rpc import impl_fake from engine.tests.rpc import common LOG = logging.getLogger('engine.tests.rpc') class RpcFakeTestCase(common._BaseRpcTestCase): def setUp(self): self.rpc = impl_fake super(RpcFakeTestCase, self).setUp() def tearDown(self): super(RpcFakeTestCase, self).tearDown()
Scheduler base class that all Schedulers should inherit from """ 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
# under the License. """Contrib contains extensions that are shipped with engine. It can't be called 'extensions' because that causes namespacing problems. """ import os from engine import exception from engine import log as logging from engine import utils LOG = logging.getLogger("engine.api.x7.v2.contrib") def standard_extensions(ext_mgr): """Registers all standard API extensions.""" # Walk through all the modules in our directory... our_dir = __path__[0] for dirpath, dirnames, filenames in os.walk(our_dir): # Compute the relative package name from the dirpath relpath = os.path.relpath(dirpath, our_dir) if relpath == ".": relpkg = "" else: relpkg = ".%s" % ".".join(relpath.split(os.sep))
# 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 engine import context from engine import db from engine import exception from engine import flags from engine import log as logging FLAGS = flags.FLAGS LOG = logging.getLogger("engine.instance_types") def create(name, memory, vcpus, local_gb, flavorid, swap=0, rxtx_factor=1): """Creates instance types.""" kwargs = {"memory_mb": memory, "vcpus": vcpus, "local_gb": local_gb, "swap": swap, "rxtx_factor": rxtx_factor} # ensure some attributes are integers and greater than or equal to 0 for option in kwargs: try: kwargs[option] = int(kwargs[option]) assert kwargs[option] >= 0 except (ValueError, AssertionError): msg = _("create arguments must be positive integers") raise exception.InvalidInput(reason=msg)
# 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 engine import db from engine import exception from engine import flags from engine import log as logging from engine.network.quantum import melange_connection LOG = logging.getLogger("engine.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"""
# # 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. """The deferred instance delete extension.""" import webob from engine.api.x7.v2 import extensions from engine.api.x7.v2 import servers from engine import compute from engine import log as logging LOG = logging.getLogger("engine.api.x7.v2.contrib.deferred-delete") class Deferred_delete(extensions.ExtensionDescriptor): """Instance deferred delete""" name = "DeferredDelete" alias = "os-deferred-delete" namespace = "http://docs.x7.org/compute/ext/" \ "deferred-delete/api/v1.1" updated = "2011-09-01T00:00:00+00:00" def __init__(self, ext_mgr): super(Deferred_delete, self).__init__(ext_mgr) self.compute_api = compute.API()
# 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 volume type properties.""" from engine import context from engine import db from engine import exception from engine import flags from engine import log as logging FLAGS = flags.FLAGS LOG = logging.getLogger('engine.volume.volume_types') def create(context, name, extra_specs={}): """Creates volume types.""" try: db.volume_type_create(context, dict(name=name, extra_specs=extra_specs)) except exception.DBError, e: LOG.exception(_('DB error: %s') % e) raise exception.ApiError(_("Cannot create volume_type with " "name %(name)s and specs %(extra_specs)s") % locals())
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """VMRC Console Manager.""" from engine import exception from engine import flags from engine import log as logging from engine import manager from engine import rpc from engine import utils from engine.virt import vmwareapi_conn LOG = logging.getLogger("engine.console.vmrc_manager") FLAGS = flags.FLAGS flags.DEFINE_string('console_public_hostname', '', 'Publicly visible name for this console host') flags.DEFINE_string('console_driver', 'engine.console.vmrc.VMRCConsole', 'Driver to use for the console') class ConsoleVMRCManager(manager.Manager): """Manager to handle VMRC connections for accessing instance consoles.""" def __init__(self, console_driver=None, *args, **kwargs): self.driver = utils.import_object(FLAGS.console_driver) super(ConsoleVMRCManager, self).__init__(*args, **kwargs)
import netaddr from engine.api.ec2 import ec2utils from engine.auth import manager from engine import compute from engine.compute import instance_types from engine.compute import vm_states from engine import db from engine import exception from engine import flags from engine import log as logging from engine import utils FLAGS = flags.FLAGS LOG = logging.getLogger('engine.api.ec2.admin') def user_dict(user, base64_file=None): """Convert the user object to a result dict""" if user: return { 'username': user.id, 'accesskey': user.access, 'secretkey': user.secret, 'file': base64_file} else: return {} def project_dict(project):