Exemplo n.º 1
0
    def delete(self, subcloud_ref):
        """Delete a subcloud.

        :param subcloud_ref: ID or name of subcloud to delete.
        """
        context = restcomm.extract_context_from_environ()
        subcloud = None

        if subcloud_ref.isdigit():
            # Look up subcloud as an ID
            try:
                subcloud = db_api.subcloud_get(context, subcloud_ref)
            except exceptions.SubcloudNotFound:
                pecan.abort(404, _('Subcloud not found'))
        else:
            # Look up subcloud by name
            try:
                subcloud = db_api.subcloud_get_by_name(context, subcloud_ref)
            except exceptions.SubcloudNameNotFound:
                pecan.abort(404, _('Subcloud not found'))

        subcloud_id = subcloud.id

        try:
            # Ask dcmanager-manager to delete the subcloud.
            # It will do all the real work...
            return self.rpc_client.delete_subcloud(context, subcloud_id)
        except RemoteError as e:
            pecan.abort(422, e.value)
        except Exception as e:
            LOG.exception(e)
            pecan.abort(500, _('Unable to delete subcloud'))
Exemplo n.º 2
0
    def get(self, subcloud_ref=None):
        """Get details about software update options.

        :param subcloud: name or id of subcloud (optional)
        """
        context = restcomm.extract_context_from_environ()

        if subcloud_ref is None:
            # List of all subcloud options requested.
            # Prepend the all clouds default options to the result.

            result = dict()
            result['sw-update-options'] = list()

            default_sw_update_opts_dict = utils.get_sw_update_opts(context)

            result['sw-update-options'].append(default_sw_update_opts_dict)

            subclouds = db_api.sw_update_opts_get_all_plus_subcloud_info(
                context)

            for subcloud, sw_update_opts in subclouds:
                if sw_update_opts:
                    result['sw-update-options'].append(
                        db_api.sw_update_opts_w_name_db_model_to_dict(
                            sw_update_opts, subcloud.name))

            return result

        elif subcloud_ref == consts.DEFAULT_REGION_NAME:
            # Default options requested, guaranteed to succeed

            return utils.get_sw_update_opts(context)

        else:
            # Specific subcloud options requested

            if subcloud_ref.isdigit():
                # Look up subcloud as an ID
                try:
                    subcloud = db_api.subcloud_get(context, subcloud_ref)
                except exceptions.SubcloudNotFound:
                    pecan.abort(404, _('Subcloud not found'))
            else:
                # Look up subcloud by name
                try:
                    subcloud = db_api.subcloud_get_by_name(
                        context, subcloud_ref)
                except exceptions.SubcloudNameNotFound:
                    pecan.abort(404, _('Subcloud not found'))

            try:
                return utils.get_sw_update_opts(context,
                                                subcloud_id=subcloud.id)
            except Exception as e:
                pecan.abort(404, _('%s') % e)
Exemplo n.º 3
0
    def get(self, steps=None, cloud_name=None):
        """Get details about software update strategy.

        :param steps: get the steps for this strategy (optional)
        :param cloud_name: name of cloud (optional)
        """
        context = restcomm.extract_context_from_environ()

        if steps is None:
            # Strategy requested
            strategy = None
            try:
                strategy = db_api.sw_update_strategy_get(context)
            except exceptions.NotFound:
                pecan.abort(404, _('Strategy not found'))

            strategy_dict = db_api.sw_update_strategy_db_model_to_dict(
                strategy)
            return strategy_dict

        elif steps == "steps":
            # Steps for the strategy requested
            if cloud_name is None:
                # List of steps requested
                result = dict()
                result['strategy-steps'] = list()
                strategy_steps = db_api.strategy_step_get_all(context)
                for strategy_step in strategy_steps:
                    result['strategy-steps'].append(
                        db_api.strategy_step_db_model_to_dict(strategy_step))

                return result
            else:
                # Single step requested
                strategy_step = None
                if cloud_name == consts.SYSTEM_CONTROLLER_NAME:
                    # The system controller step does not map to a subcloud,
                    # so has no name.
                    try:
                        strategy_step = db_api.strategy_step_get(context, None)
                    except exceptions.StrategyStepNotFound:
                        pecan.abort(404, _('Strategy step not found'))
                else:
                    try:
                        strategy_step = db_api.strategy_step_get_by_name(
                            context, cloud_name)
                    except exceptions.StrategyStepNameNotFound:
                        pecan.abort(404, _('Strategy step not found'))

                strategy_step_dict = db_api.strategy_step_db_model_to_dict(
                    strategy_step)
                return strategy_step_dict
Exemplo n.º 4
0
class DCManagerException(Exception):
    """Base DC Manager Exception.

    To correctly use this class, inherit from it and define
    a 'message' property. That message will get printf'd
    with the keyword arguments provided to the constructor.
    """

    message = _("An unknown exception occurred.")

    def __init__(self, **kwargs):
        try:
            super(DCManagerException, self).__init__(self.message % kwargs)
            self.msg = self.message % kwargs
        except Exception:
            with excutils.save_and_reraise_exception() as ctxt:
                if not self.use_fatal_exceptions():
                    ctxt.reraise = False
                    # at least get the core message out if something happened
                    super(DCManagerException, self).__init__(self.message)

    if six.PY2:
        def __unicode__(self):
            return unicode(self.msg)

    def use_fatal_exceptions(self):
        return False
Exemplo n.º 5
0
    def _get_subcloud_users(self):
        """Get the subcloud users and passwords from keyring"""
        DEFAULT_SERVICE_PROJECT_NAME = 'services'
        # First entry is openstack user name, second entry is the user stored
        # in keyring. Not sure why heat_admin uses a different keystone name.
        SUBCLOUD_USERS = [('nova', 'nova'), ('placement', 'placement'),
                          ('sysinv', 'sysinv'), ('patching', 'patching'),
                          ('heat', 'heat'), ('ceilometer', 'ceilometer'),
                          ('vim', 'vim'), ('aodh', 'aodh'), ('panko', 'panko'),
                          ('mtce', 'mtce'), ('cinder', 'cinder'),
                          ('glance', 'glance'), ('neutron', 'neutron'),
                          ('heat_admin', 'heat-domain')]

        user_list = list()
        for user in SUBCLOUD_USERS:
            password = keyring.get_password(user[1],
                                            DEFAULT_SERVICE_PROJECT_NAME)
            if password:
                user_dict = dict()
                user_dict['name'] = user[0]
                user_dict['password'] = password
                user_list.append(user_dict)
            else:
                LOG.error("User %s not found in keyring as %s" %
                          (user[0], user[1]))
                pecan.abort(500, _('System configuration error'))

        return user_list
Exemplo n.º 6
0
def is_admin_context(context):
    """Indicate if the request context is an administrator."""
    if not context:
        LOG.warning(_('Use of empty request context is deprecated'),
                    DeprecationWarning)
        raise Exception('die')
    return context.is_admin
Exemplo n.º 7
0
    def patch(self, subcloud_ref=None):
        """Update a subcloud.

        :param subcloud_ref: ID or name of subcloud to update
        """

        context = restcomm.extract_context_from_environ()
        subcloud = None

        if subcloud_ref is None:
            pecan.abort(400, _('Subcloud ID required'))

        payload = eval(request.body)
        if not payload:
            pecan.abort(400, _('Body required'))

        if subcloud_ref.isdigit():
            # Look up subcloud as an ID
            try:
                subcloud = db_api.subcloud_get(context, subcloud_ref)
            except exceptions.SubcloudNotFound:
                pecan.abort(404, _('Subcloud not found'))
        else:
            # Look up subcloud by name
            try:
                subcloud = db_api.subcloud_get_by_name(context, subcloud_ref)
            except exceptions.SubcloudNameNotFound:
                pecan.abort(404, _('Subcloud not found'))

        subcloud_id = subcloud.id

        management_state = payload.get('management-state')
        description = payload.get('description')
        location = payload.get('location')

        if not (management_state or description or location):
            pecan.abort(400, _('nothing to update'))

        # Syntax checking
        if management_state and \
                management_state not in [consts.MANAGEMENT_UNMANAGED,
                                         consts.MANAGEMENT_MANAGED]:
            pecan.abort(400, _('Invalid management-state'))

        try:
            # Inform dcmanager-manager that subcloud has been updated.
            # It will do all the real work...
            subcloud = self.rpc_client.update_subcloud(
                context,
                subcloud_id,
                management_state=management_state,
                description=description,
                location=location)
            return subcloud
        except RemoteError as e:
            pecan.abort(422, e.value)
        except Exception as e:
            # additional exceptions.
            LOG.exception(e)
            pecan.abort(500, _('Unable to update subcloud'))
Exemplo n.º 8
0
    def __init__(self, *args, **kwargs):
        LOG.debug(_('SubcloudAuditManager initialization...'))

        super(SubcloudAuditManager,
              self).__init__(service_name="subcloud_audit_manager")
        self.context = context.get_admin_context()
        self.dcorch_rpc_client = dcorch_rpc_client.EngineClient()
        self.fm_api = fm_api.FaultAPIs()
        self.subcloud_manager = kwargs['subcloud_manager']
Exemplo n.º 9
0
 def _stop_rpc_server(self):
     # Stop RPC connection to prevent new requests
     LOG.debug(_("Attempting to stop engine service..."))
     try:
         self._rpc_server.stop()
         self._rpc_server.wait()
         LOG.info('Engine service stopped successfully')
     except Exception as ex:
         LOG.error('Failed to stop engine service: %s', six.text_type(ex))
Exemplo n.º 10
0
    def __init__(self, *args, **kwargs):
        LOG.info(_('PatchAuditManager initialization...'))

        super(PatchAuditManager,
              self).__init__(service_name="patch_audit_manager")
        self.context = context.get_admin_context()
        self.subcloud_manager = kwargs['subcloud_manager']
        # Wait 20 seconds before doing the first audit
        self.wait_time_passed = DEFAULT_PATCH_AUDIT_DELAY_SECONDS - 25
Exemplo n.º 11
0
    def delete(self):
        """Delete the software update strategy."""
        context = restcomm.extract_context_from_environ()

        try:
            # Ask dcmanager-manager to delete the strategy.
            # It will do all the real work...
            return self.rpc_client.delete_sw_update_strategy(context)
        except RemoteError as e:
            pecan.abort(422, e.value)
        except Exception as e:
            LOG.exception(e)
            pecan.abort(500, _('Unable to delete strategy'))
Exemplo n.º 12
0
    def delete(self, subcloud_ref):
        """Delete the software update options."""

        context = restcomm.extract_context_from_environ()

        if subcloud_ref == consts.DEFAULT_REGION_NAME:
            # Delete defaults.
            # Note by deleting these, the next get will repopulate with
            # the global constants.

            try:
                db_api.sw_update_opts_default_destroy(context)
            except Exception:
                return
        else:

            if subcloud_ref.isdigit():
                # Look up subcloud as an ID
                try:
                    subcloud = db_api.subcloud_get(context, subcloud_ref)
                except exceptions.SubcloudNotFound:
                    pecan.abort(404, _('Subcloud not found'))

            else:
                # Look up subcloud by name
                try:
                    subcloud = db_api.subcloud_get_by_name(
                        context, subcloud_ref)
                except exceptions.SubcloudNameNotFound:
                    pecan.abort(404, _('Subcloud not found'))

            # Delete the subcloud specific options
            if db_api.sw_update_opts_get(context, subcloud.id):
                db_api.sw_update_opts_destroy(context, subcloud.id)
            else:
                pecan.abort(404, _('Subcloud patch options not found'))
Exemplo n.º 13
0
class SubcloudNotFound(NotFound):
    message = _("Subcloud with id %(subcloud_id)s doesn't exist.")
Exemplo n.º 14
0
class InvalidConfigurationOption(DCManagerException):
    message = _("An invalid value was provided for %(opt_name)s: "
                "%(opt_value)s")
Exemplo n.º 15
0
class InUse(DCManagerException):
    message = _("The resource is inuse")
Exemplo n.º 16
0
class AdminRequired(NotAuthorized):
    message = _("User does not have admin privileges: %(reason)s")
Exemplo n.º 17
0
class ServiceUnavailable(DCManagerException):
    message = _("The service is unavailable")
Exemplo n.º 18
0
class InternalError(DCManagerException):
    message = _("Error when performing operation")
Exemplo n.º 19
0
class NotFound(DCManagerException):
    message = _("Not found")
Exemplo n.º 20
0
class SubcloudPatchOptsNotFound(NotFound):
    message = _("No options found for Subcloud with id %(subcloud_id)s, "
                "defaults will be used.")
Exemplo n.º 21
0
class BadRequest(DCManagerException):
    message = _('Bad %(resource)s request: %(msg)s')
Exemplo n.º 22
0
class ConnectionRefused(DCManagerException):
    message = _("Connection to the service endpoint is refused")
Exemplo n.º 23
0
class StrategyStepNotFound(NotFound):
    message = _("StrategyStep with subcloud_id %(subcloud_id)s "
                "doesn't exist.")
Exemplo n.º 24
0
class InvalidInputError(DCManagerException):
    message = _("An invalid value was provided")
Exemplo n.º 25
0
class SubcloudNameNotFound(NotFound):
    message = _("Subcloud with name %(name)s doesn't exist.")
Exemplo n.º 26
0
class Conflict(DCManagerException):
    message = _('Conflict: %(msg)s')
Exemplo n.º 27
0
def serve(api_service, conf, workers=1):
    global _launcher
    if _launcher:
        raise RuntimeError(_('serve() can only be called once'))

    _launcher = service.launch(conf, api_service, workers=workers)
Exemplo n.º 28
0
class NotAuthorized(DCManagerException):
    message = _("Not authorized.")
Exemplo n.º 29
0
class StrategyStepNameNotFound(NotFound):
    message = _("StrategyStep with name %(name)s doesn't exist.")
Exemplo n.º 30
0
class TimeOut(DCManagerException):
    message = _("Timeout when connecting to OpenStack Service")