Example #1
0
def get_manager():
    global _global_manager

    if not _global_manager:
        LOG = log.getLogger()
        extension_manager = stevedore.ExtensionManager(
            namespace='ironic_python_agent.hardware_managers',
            invoke_on_load=True)

        # There will always be at least one extension available (the
        # GenericHardwareManager).
        if six.PY2:
            preferred_extension = sorted(extension_manager,
                                         _compare_extensions)[0]
        else:
            preferred_extension = sorted(
                extension_manager,
                key=functools.cmp_to_key(_compare_extensions))[0]

        preferred_manager = preferred_extension.obj

        if preferred_manager.evaluate_hardware_support() <= 0:
            raise RuntimeError('No suitable HardwareManager could be found')

        LOG.info('selected hardware manager {0}'.format(
            preferred_extension.entry_point_target))

        _global_manager = preferred_manager

    return _global_manager
Example #2
0
 def __init__(self, api_url, advertise_address, listen_address,
              ip_lookup_attempts, ip_lookup_sleep, network_interface,
              lookup_timeout, lookup_interval, driver_name):
     super(IronicPythonAgent, self).__init__()
     self.ext_mgr = extension.ExtensionManager(
         namespace='ironic_python_agent.extensions',
         invoke_on_load=True,
         propagate_map_exceptions=True,
         invoke_kwds={'agent': self},
     )
     self.api_url = api_url
     self.driver_name = driver_name
     self.api_client = ironic_api_client.APIClient(self.api_url,
                                                   self.driver_name)
     self.listen_address = listen_address
     self.advertise_address = advertise_address
     self.version = pkg_resources.get_distribution('ironic-python-agent')\
         .version
     self.api = app.VersionSelectorApplication(self)
     self.heartbeater = IronicPythonAgentHeartbeater(self)
     self.heartbeat_timeout = None
     self.hardware = hardware.get_manager()
     self.log = log.getLogger(__name__)
     self.started_at = None
     self.node = None
     # lookup timeout in seconds
     self.lookup_timeout = lookup_timeout
     self.lookup_interval = lookup_interval
     self.ip_lookup_attempts = ip_lookup_attempts
     self.ip_lookup_sleep = ip_lookup_sleep
     self.network_interface = network_interface
Example #3
0
 def __init__(self, api_url, advertise_address, listen_address,
              ip_lookup_attempts, ip_lookup_sleep, network_interface,
              lookup_timeout, lookup_interval, driver_name):
     super(IronicPythonAgent, self).__init__()
     self.ext_mgr = extension.ExtensionManager(
         namespace='ironic_python_agent.extensions',
         invoke_on_load=True,
         propagate_map_exceptions=True,
     )
     self.api_url = api_url
     self.driver_name = driver_name
     self.api_client = ironic_api_client.APIClient(self.api_url,
                                                   self.driver_name)
     self.listen_address = listen_address
     self.advertise_address = advertise_address
     self.version = pkg_resources.get_distribution('ironic-python-agent')\
         .version
     self.api = app.VersionSelectorApplication(self)
     self.heartbeater = IronicPythonAgentHeartbeater(self)
     self.heartbeat_timeout = None
     self.hardware = hardware.get_manager()
     self.log = log.getLogger(__name__)
     self.started_at = None
     self.node = None
     # lookup timeout in seconds
     self.lookup_timeout = lookup_timeout
     self.lookup_interval = lookup_interval
     self.ip_lookup_attempts = ip_lookup_attempts
     self.ip_lookup_sleep = ip_lookup_sleep
     self.network_interface = network_interface
def get_manager():
    global _global_manager

    if not _global_manager:
        LOG = log.getLogger()
        extension_manager = stevedore.ExtensionManager(
            namespace='ironic_python_agent.hardware_managers',
            invoke_on_load=True)

        # There will always be at least one extension available (the
        # GenericHardwareManager).
        if six.PY2:
            preferred_extension = sorted(
                    extension_manager,
                    _compare_extensions)[0]
        else:
            preferred_extension = sorted(
                    extension_manager,
                    key=functools.cmp_to_key(_compare_extensions))[0]

        preferred_manager = preferred_extension.obj

        if preferred_manager.evaluate_hardware_support() <= 0:
            raise RuntimeError('No suitable HardwareManager could be found')

        LOG.info('selected hardware manager {0}'.format(
                 preferred_extension.entry_point_target))

        _global_manager = preferred_manager

    return _global_manager
Example #5
0
 def __init__(self):
     super(BaseAgentExtension, self).__init__()
     self.log = log.getLogger(__name__)
     self.command_map = dict(
         (v.command_name, v)
         for k, v in inspect.getmembers(self)
         if hasattr(v, 'command_name')
     )
Example #6
0
 def __init__(self, agent):
     super(IronicPythonAgentHeartbeater, self).__init__()
     self.agent = agent
     self.hardware = hardware.get_manager()
     self.api = ironic_api_client.APIClient(agent.api_url)
     self.log = log.getLogger(__name__)
     self.stop_event = threading.Event()
     self.error_delay = self.initial_delay
 def __init__(self, agent):
     super(IronicPythonAgentHeartbeater, self).__init__()
     self.agent = agent
     self.hardware = hardware.get_manager()
     self.api = ironic_api_client.APIClient(agent.api_url,
                                            agent.driver_name)
     self.log = log.getLogger(__name__)
     self.stop_event = threading.Event()
     self.error_delay = self.initial_delay
    def __init__(self, api_url, driver_name):
        self.api_url = api_url.rstrip('/')
        self.driver_name = driver_name

        # Only keep alive a maximum of 2 connections to the API. More will be
        # opened if they are needed, but they will be closed immediately after
        # use.
        adapter = requests.adapters.HTTPAdapter(pool_connections=2,
                                                pool_maxsize=2)
        self.session = requests.Session()
        self.session.mount(self.api_url, adapter)

        self.encoder = encoding.RESTJSONEncoder()
        self.log = log.getLogger(__name__)
Example #9
0
    def __init__(self, api_url, driver_name):
        self.api_url = api_url.rstrip('/')
        self.driver_name = driver_name

        # Only keep alive a maximum of 2 connections to the API. More will be
        # opened if they are needed, but they will be closed immediately after
        # use.
        adapter = requests.adapters.HTTPAdapter(pool_connections=2,
                                                pool_maxsize=2)
        self.session = requests.Session()
        self.session.mount(self.api_url, adapter)

        self.encoder = encoding.RESTJSONEncoder()
        self.log = log.getLogger(__name__)
Example #10
0
    def __init__(self, agent):
        """Initialize the heartbeat thread.

        :param agent: an :class:`ironic_python_agent.agent.IronicPythonAgent`
                      instance.
        """
        super(IronicPythonAgentHeartbeater, self).__init__()
        self.agent = agent
        self.hardware = hardware.get_manager()
        self.api = ironic_api_client.APIClient(agent.api_url,
                                               agent.driver_name)
        self.log = log.getLogger(__name__)
        self.stop_event = threading.Event()
        self.error_delay = self.initial_delay
Example #11
0
    def __init__(self, agent):
        """Initialize the heartbeat thread.

        :param agent: an :class:`ironic_python_agent.agent.IronicPythonAgent`
                      instance.
        """
        super(IronicPythonAgentHeartbeater, self).__init__()
        self.agent = agent
        self.api = ironic_api_client.APIClient(agent.api_url,
                                               agent.driver_name)
        self.log = log.getLogger(__name__)
        self.error_delay = self.initial_delay
        self.reader = None
        self.writer = None
Example #12
0
    def __init__(self, agent):
        """Initialize the heartbeat thread.

        :param agent: an :class:`ironic_python_agent.agent.IronicPythonAgent`
                      instance.
        """
        super(IronicPythonAgentHeartbeater, self).__init__()
        self.agent = agent
        self.hardware = hardware.get_manager()
        self.api = ironic_api_client.APIClient(agent.api_url,
                                               agent.driver_name)
        self.log = log.getLogger(__name__)
        self.stop_event = threading.Event()
        self.error_delay = self.initial_delay
    def __init__(self, agent):
        """Initialize the heartbeat thread.

        :param agent: an :class:`ironic_python_agent.agent.IronicPythonAgent`
                      instance.
        """
        super(IronicPythonAgentHeartbeater, self).__init__()
        self.agent = agent
        self.api = ironic_api_client.APIClient(agent.api_url,
                                               agent.driver_name)
        self.log = log.getLogger(__name__)
        self.error_delay = self.initial_delay
        self.reader = None
        self.writer = None
Example #14
0
 def __init__(self, api_url, advertise_address, listen_address):
     self.api_url = api_url
     self.api_client = ironic_api_client.APIClient(self.api_url)
     self.listen_address = listen_address
     self.advertise_address = advertise_address
     self.mode_implementation = None
     self.version = pkg_resources.get_distribution('ironic-python-agent')\
         .version
     self.api = app.VersionSelectorApplication(self)
     self.command_results = utils.get_ordereddict()
     self.heartbeater = IronicPythonAgentHeartbeater(self)
     self.heartbeat_timeout = None
     self.hardware = hardware.get_manager()
     self.command_lock = threading.Lock()
     self.log = log.getLogger(__name__)
     self.started_at = None
     self.node = 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.

import sys
import time

from eventlet import event
from eventlet import greenthread

from ironic_python_agent.openstack.common.gettextutils import _LE, _LW
from ironic_python_agent.openstack.common import log as logging

LOG = logging.getLogger(__name__)

# NOTE(zyluo): This lambda function was declared to avoid mocking collisions
#              with time.time() called in the standard logging module
#              during unittests.
_ts = lambda: time.time()


class LoopingCallDone(Exception):
    """Exception to break out and stop a LoopingCallBase.

    The poll-function passed to LoopingCallBase can raise this exception to
    break out of the loop normally. This is somewhat analogous to
    StopIteration.

    An optional return-value can be included as the argument to the exception;
Example #16
0
 def __init__(self):
     super(BaseAgentExtension, self).__init__()
     self.log = log.getLogger(__name__)
     self.command_map = {}
Example #17
0
import functools
import os
import shlex

import netifaces
import psutil
import six
import stevedore

from ironic_python_agent import encoding
from ironic_python_agent import errors
from ironic_python_agent.openstack.common import log
from ironic_python_agent import utils

_global_managers = None
LOG = log.getLogger()


class HardwareSupport(object):
    """Example priorities for hardware managers.

    Priorities for HardwareManagers are integers, where largest means most
    specific and smallest means most generic. These values are guidelines
    that suggest values that might be returned by calls to
    `evaluate_hardware_support()`. No HardwareManager in mainline IPA will
    ever return a value greater than MAINLINE. Third party hardware managers
    should feel free to return values of SERVICE_PROVIDER or greater to
    distinguish between additional levels of hardware support.
    """
    NONE = 0
    GENERIC = 1
Example #18
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 random
import sys

from eventlet import event
from eventlet import greenthread

from ironic_python_agent.openstack.common import log
from ironic_python_agent.openstack.common import loopingcall

LOG = log.getLogger(__name__)


#TODO(JoshNang) move to oslo, i18n
class LoopingCallTimeOut(Exception):
    """Exception for a timed out LoopingCall.

    The LoopingCall will raise this exception when a timeout is provided
    and it is exceeded.
    """
    pass


class BackOffLoopingCall(loopingcall.LoopingCallBase):
    """The passed in function should return True (no error, return to
    initial_interval),
Example #19
0
 def __init__(self, name):
     super(BaseAgentMode, self).__init__()
     self.log = log.getLogger(__name__)
     self.name = name
     self.command_map = {}