def _run(self, application, socket): """Start a WSGI server in a new green thread.""" logger = logging.getLogger('eventlet.wsgi.server') eventlet.wsgi.server(socket, application, custom_pool=self.pool, log=logging.WritableLogger(logger))
def _run(self, application, socket): """Start a WSGI service in a new green thread.""" logger = logging.getLogger('eventlet.wsgi.server') eventlet.wsgi.server(socket, application, custom_pool=self.pool, protocol=UnixDomainHttpProtocol, log=logging.WritableLogger(logger))
class ProbeCommand(QuantumCommand): log = logging.getLogger(__name__ + '.ProbeCommand') def get_debug_agent(self): return self.app.debug_agent def run(self, parsed_args): self.log.debug('run(%s)' % parsed_args) self.app.stdout.write(_('Unimplemented commands') + '\n')
def notify(_context, message): """Notifies the recipient of the desired event given the model. Log notifications using openstack's default logging system""" priority = message.get('priority', CONF.default_notification_level) priority = priority.lower() logger = logging.getLogger('quantum.openstack.common.notification.%s' % message['event_type']) getattr(logger, priority)(jsonutils.dumps(message))
class ClearProbe(ProbeCommand): """Clear All probes """ log = logging.getLogger(__name__ + '.ClearProbe') def run(self, parsed_args): self.log.debug('run(%s)' % parsed_args) debug_agent = self.get_debug_agent() debug_agent.clear_probe() self.app.stdout.write(_('All Probes deleted ') + '\n')
def setup_logging(conf): """ Sets up the logging options for a log with supplied name :param conf: a cfg.ConfOpts object """ product_name = "quantum" logging.setup(product_name) log_root = logging.getLogger(product_name).logger LOG.info(_("Logging enabled!"))
def notify(_context, message): """Notifies the recipient of the desired event given the model. Log notifications using openstack's default logging system""" priority = message.get('priority', CONF.default_notification_level) priority = priority.lower() logger = logging.getLogger( 'quantum.openstack.common.notification.%s' % message['event_type']) getattr(logger, priority)(jsonutils.dumps(message))
class DeleteProbe(ProbeCommand): """Delete probe - delete port then uplug """ log = logging.getLogger(__name__ + '.DeleteProbe') def get_parser(self, prog_name): parser = super(DeleteProbe, self).get_parser(prog_name) parser.add_argument('id', metavar='port_id', help=_('ID of probe port to delete')) return parser def run(self, parsed_args): self.log.debug('run(%s)' % parsed_args) debug_agent = self.get_debug_agent() debug_agent.delete_probe(parsed_args.id) self.app.stdout.write(_('Probe %s deleted') % parsed_args.id + '\n')
class ExecProbe(ProbeCommand): """Exec commands on the namespace of the probe """ log = logging.getLogger(__name__ + '.ExecProbe') def get_parser(self, prog_name): parser = super(ExecProbe, self).get_parser(prog_name) parser.add_argument('id', metavar='port_id', help=_('ID of probe port to execute command')) parser.add_argument('command', metavar='command', nargs='?', default=None, help=_('Command to execute')) return parser def run(self, parsed_args): self.log.debug('run(%s)' % parsed_args) debug_agent = self.get_debug_agent() result = debug_agent.exec_command(parsed_args.id, parsed_args.command) self.app.stdout.write(result + '\n')
class CreateProbe(ProbeCommand): """Create probe port and interface, then plug it in.""" log = logging.getLogger(__name__ + '.CreateProbe') def get_parser(self, prog_name): parser = super(CreateProbe, self).get_parser(prog_name) parser.add_argument('id', metavar='network_id', help=_('ID of network to probe')) parser.add_argument( '--device-owner', default='network', choices=['network', 'compute'], help=_('owner type of the device: network/compute')) return parser def run(self, parsed_args): self.log.debug('run(%s)' % parsed_args) debug_agent = self.get_debug_agent() port = debug_agent.create_probe(parsed_args.id, parsed_args.device_owner) self.app.stdout.write(_('Probe created : %s ') % port.id + '\n')
class PingAll(ProbeCommand): """Ping all fixed_ip """ log = logging.getLogger(__name__ + '.ExecProbe') def get_parser(self, prog_name): parser = super(PingAll, self).get_parser(prog_name) parser.add_argument('--timeout', metavar='<timeout>', default=10, help=_('Ping timeout')) parser.add_argument('--id', metavar='network_id', default=None, help=_('ID of network')) return parser def run(self, parsed_args): self.log.debug('run(%s)' % parsed_args) debug_agent = self.get_debug_agent() result = debug_agent.ping_all(parsed_args.id, timeout=parsed_args.timeout) self.app.stdout.write(result + '\n')
class ListProbe(QuantumCommand, lister.Lister): """ List probes """ log = logging.getLogger(__name__ + '.ListProbe') _formatters = { 'fixed_ips': _format_fixed_ips, } def get_debug_agent(self): return self.app.debug_agent def get_data(self, parsed_args): debug_agent = self.get_debug_agent() info = debug_agent.list_probes() columns = len(info) > 0 and sorted(info[0].keys()) or [] return ( columns, (utils.get_item_properties( s, columns, formatters=self._formatters, ) for s in info), )
import os import routes import webob.dec import webob.exc from quantum.common import exceptions import quantum.extensions from quantum.manager import QuantumManager from quantum.openstack.common import cfg from quantum.openstack.common import importutils from quantum.openstack.common import log as logging from quantum import wsgi LOG = logging.getLogger("quantum.api.extensions") # Besides the supported_extension_aliases in plugin class, # we also support register enabled extensions here so that we # can load some mandatory files (such as db models) before initialize plugin ENABLED_EXTS = { "quantum.plugins.linuxbridge.lb_quantum_plugin.LinuxBridgePluginV2": { "ext_alias": ["quotas"], "ext_db_models": ["quantum.extensions._quotav2_model.Quota"], }, "quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2": { "ext_alias": ["quotas"], "ext_db_models": ["quantum.extensions._quotav2_model.Quota"], }, "quantum.plugins.nicira.nicira_nvp_plugin.QuantumPlugin.NvpPluginV2": { "ext_alias": ["quotas"],
def _run(self, application, socket): """Start a WSGI server in a new green thread.""" logger = logging.getLogger("eventlet.wsgi.server") eventlet.wsgi.server(socket, application, custom_pool=self.pool, log=logging.WritableLogger(logger))
from quantum import manager from quantum.openstack.common import log as logging from quantum import wsgi RESOURCE_NAME = 'ip_address' RESOURCE_COLLECTION = RESOURCE_NAME + "es" EXTENDED_ATTRIBUTES_2_0 = { RESOURCE_COLLECTION: {} } attr_dict = EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION] attr_dict[RESOURCE_NAME] = {'allow_post': True, 'allow_put': True, 'is_visible': True} LOG = logging.getLogger("quantum.quark.api.extensions.ip_addresses") def ip_dict(address): return dict(subnet_id=address["subnet_id"], network_id=address["network_id"], id=address["id"], address=address["address"], port_id=address["port_id"]) class IpAddressesController(wsgi.Controller): def __init__(self, plugin): self._resource_name = RESOURCE_NAME self._plugin = plugin
from quantum import manager from quantum.openstack.common import log as logging from quantum import wsgi RESOURCE_NAME = 'route' RESOURCE_COLLECTION = RESOURCE_NAME + "s" EXTENDED_ATTRIBUTES_2_0 = { RESOURCE_COLLECTION: {} } attr_dict = EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION] attr_dict[RESOURCE_NAME] = {'allow_post': True, 'allow_put': True, 'is_visible': True} LOG = logging.getLogger("quantum.quark.api.extensions.routes") def route_dict(route): return dict(cidr=route["cidr"], gateway=route["gateway"], id=route["id"], subnet_id=route["subnet_id"]) class RoutesController(wsgi.Controller): def __init__(self, plugin): self._resource_name = RESOURCE_NAME self._plugin = plugin
from sqlalchemy import orm from sqlalchemy.ext import associationproxy from sqlalchemy.ext import declarative from sqlalchemy.ext import hybrid import quantum.db.model_base from quantum.db import models_v2 as models from quantum.openstack.common import log as logging from quantum.openstack.common import timeutils from quark.db import custom_types HasId = models.HasId LOG = logging.getLogger("quantum.quark.db.models") def _default_list_getset(collection_class, proxy): attr = proxy.value_attr def getter(obj): if obj: return getattr(obj, attr, None) return [] if collection_class is dict: setter = lambda o, k, v: setattr(o, attr, v) else: setter = lambda o, v: setattr(o, attr, v) return getter, setter
from quantum import manager from quantum.openstack.common import log as logging from quantum import wsgi RESOURCE_NAME = 'mac_address_range' RESOURCE_COLLECTION = RESOURCE_NAME + "s" EXTENDED_ATTRIBUTES_2_0 = { RESOURCE_COLLECTION: {} } attr_dict = EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION] attr_dict[RESOURCE_NAME] = {'allow_post': True, 'allow_put': False, 'is_visible': True} LOG = logging.getLogger("quantum.quark.api.extensions.mac_address_ranges") def mac_range_dict(mac_range): return dict(address=mac_range["cidr"], id=mac_range["id"]) class MacAddressRangesController(wsgi.Controller): def __init__(self, plugin): self._resource_name = RESOURCE_NAME self._plugin = plugin def create(self, request, body=None): body = self._deserialize(request.body, request.get_content_type())
# under the License. """ Quark Pluggable IPAM """ import netaddr from quantum.common import exceptions from quantum.openstack.common import log as logging from quantum.openstack.common import timeutils from quark.db import api as db_api LOG = logging.getLogger("quantum") class QuarkIpam(object): def _choose_available_subnet(self, context, net_id, version=None, ip_address=None): filters = {} if version: filters["version"] = version subnets = db_api.subnet_find_allocation_counts(context, net_id, scope=db_api.ALL, **filters) for subnet, ips_in_subnet in subnets: ipnet = netaddr.IPNetwork(subnet["cidr"]) if ip_address and ip_address not in ipnet: continue
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """Context: context for security/db session.""" import copy from datetime import datetime from quantum.db import api as db_api from quantum.openstack.common import context as common_context from quantum.openstack.common import log as logging LOG = logging.getLogger(__name__) class ContextBase(common_context.RequestContext): """Security context and request information. Represents the user taking a given action within the system. """ def __init__(self, user_id, tenant_id, is_admin=None, read_deleted="no", roles=None, timestamp=None, **kwargs): """ :param read_deleted: 'no' indicates deleted records are hidden, 'yes' indicates deleted records are visible, 'only' indicates that *only* deleted records are visible.
import os from oslo.config import cfg import routes import webob.dec import webob.exc from quantum.api.v2 import attributes from quantum.common import exceptions import quantum.extensions from quantum.manager import QuantumManager from quantum.openstack.common import log as logging from quantum import wsgi LOG = logging.getLogger('quantum.api.extensions') class PluginInterface(object): __metaclass__ = ABCMeta @classmethod def __subclasshook__(cls, klass): """Checking plugin class. The __subclasshook__ method is a class method that will be called everytime a class is tested using issubclass(klass, PluginInterface). In that case, it will check that every method marked with the abstractmethod decorator is provided by the plugin class.
# under the License. import datetime from quantum.openstack.common import log as logging from quantum.openstack.common import timeutils from sqlalchemy import func as sql_func from sqlalchemy import orm, or_ from quark.db import models from quark import exceptions as quark_exc from quark import network_strategy STRATEGY = network_strategy.STRATEGY LOG = logging.getLogger("quantum.quark.db.api") ONE = "one" ALL = "all" def _listify(filters): for key in ["name", "network_id", "id", "device_id", "tenant_id", "mac_address", "shared"]: if key in filters: if not filters[key]: continue listified = filters[key] if not isinstance(listified, list): listified = [listified] filters[key] = listified
NVP client driver for Quark """ from oslo.config import cfg import sqlalchemy as sa from sqlalchemy import orm import aiclib from quantum.openstack.common import log as logging from quark.db import models from quark.drivers import base LOG = logging.getLogger("quantum.quark.nvplib") CONF = cfg.CONF nvp_opts = [ cfg.IntOpt('max_ports_per_switch', default=0, help=_('Maximum amount of NVP ports on an NVP lswitch')), cfg.StrOpt('default_tz', help=_('The default transport zone UUID')), cfg.MultiStrOpt('controller_connection', default=[], help=_('NVP Controller connection string')), ] CONF.register_opts(nvp_opts, "NVP")
import os from oslo.config import cfg import routes import webob.dec import webob.exc from quantum.api.v2 import attributes from quantum.common import constants from quantum.common import exceptions import quantum.extensions from quantum.manager import QuantumManager from quantum.openstack.common import log as logging from quantum import wsgi LOG = logging.getLogger('quantum.api.extensions') class PluginInterface(object): __metaclass__ = ABCMeta @classmethod def __subclasshook__(cls, klass): """ The __subclasshook__ method is a class method that will be called everytime a class is tested using issubclass(klass, PluginInterface). In that case, it will check that every method marked with the abstractmethod decorator is provided by the plugin class. """
# # 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 # from quantum.openstack.common import log as logging LOG = logging.getLogger("quantum.quark.base") class BaseDriver(object): """Base interface for all Quark drivers. Usable as a replacement for the sample plugin. """ def load_config(self, path): LOG.info("load_config %s" % path) def get_connection(self): LOG.info("get_connection") def create_network(self, tenant_id, network_name, tags=None, network_id=None, **kwargs):
import abc import netaddr from oslo.config import cfg from quantum.agent.common import config from quantum.agent.linux import ip_lib from quantum.agent.linux import ovs_lib from quantum.agent.linux import utils from quantum.common import exceptions from quantum.extensions.flavor import (FLAVOR_NETWORK) from quantum.openstack.common import importutils from quantum.openstack.common import log as logging LOG = logging.getLogger(__name__) OPTS = [ cfg.StrOpt('ovs_integration_bridge', default='br-int', help=_('Name of Open vSwitch bridge to use')), cfg.BoolOpt('ovs_use_veth', default=False, help=_('Uses veth for an interface or not')), cfg.StrOpt('network_device_mtu', help=_('MTU setting for device.')), cfg.StrOpt('meta_flavor_driver_mappings', help=_('Mapping between flavor and LinuxInterfaceDriver')), cfg.StrOpt('admin_user', help=_("Admin username")), cfg.StrOpt('admin_password',
import json from oslo.config import cfg from quantum.common import exceptions from quantum.openstack.common import log as logging LOG = logging.getLogger("quantum.quark") CONF = cfg.CONF quark_opts = [ cfg.StrOpt('default_net_strategy', default='{}', help=_("Default network assignment strategy")) ] CONF.register_opts(quark_opts, "QUARK") class JSONStrategy(object): def __init__(self): self.reverse_strategy = {} self.strategy = {} self._compile_strategy(CONF.QUARK.default_net_strategy) def _compile_strategy(self, strategy): strategy = json.loads(strategy) for network, definition in strategy.iteritems(): for _, child_net in definition["children"].iteritems(): self.reverse_strategy[child_net] = network self.strategy = strategy def split_network_ids(self, context, net_ids): assignable = []