예제 #1
0
 def __init__(self, flavor=None, context=None, flavor_id=None):
     if flavor:
         self.flavor = flavor
         return
     if flavor_id and context:
         try:
             client = create_nova_client(context)
             self.flavor = client.flavors.get(flavor_id)
         except nova_exceptions.NotFound as e:
             raise exception.NotFound(uuid=flavor_id)
         except nova_exceptions.ClientException as e:
             raise exception.TroveError(str(e))
         return
     msg = ("Flavor is not defined, and"
            " context and flavor_id were not specified.")
     raise exception.InvalidModelError(errors=msg)
예제 #2
0
파일: models.py 프로젝트: vdialani/trove
 def find_server(instance_id, server_id):
     matches = [server for server in server_list if server.id == server_id]
     if len(matches) == 1:
         return matches[0]
     elif len(matches) < 1:
         # The instance was not found in the list and
         # this can happen if the instance is deleted from
         # nova but still in trove database
         raise exception.ComputeInstanceNotFound(
             instance_id=instance_id, server_id=server_id)
     else:
         # Should never happen, but never say never.
         LOG.error(_("Server %(server)s for instance %(instance)s was "
                     "found twice!") % {'server': server_id,
                                        'instance': instance_id})
         raise exception.TroveError(uuid=instance_id)
예제 #3
0
파일: postgresql.py 프로젝트: crowdy/trove
    def detach_slave(self, service, for_failover):
        """Promote replica and wait for its running.

        Running on replica, detach from the primary.
        """
        service.adm.query("select pg_promote()")

        def _wait_for_failover():
            """Wait until slave has switched out of recovery mode"""
            return not service.is_replica()

        try:
            utils.poll_until(_wait_for_failover, time_out=60)
        except exception.PollTimeOut:
            raise exception.TroveError(
                "Timeout occurred waiting for replica to exit standby mode")
예제 #4
0
파일: api.py 프로젝트: ISCAS-VDI/trove-base
    def _parse_grow_item(self, item):
        used_keys = []

        def _check_option(key, required=False, valid_values=None):
            if required and key not in item:
                raise exception.TroveError(
                    _('An instance with the options %(given)s is missing '
                      'the MongoDB required option %(expected)s.')
                    % {'given': item.keys(), 'expected': key}
                )
            value = item.get(key, None)
            if valid_values and value not in valid_values:
                raise exception.TroveError(
                    _('The value %(value)s for key %(key)s is invalid. '
                      'Allowed values are %(valid)s.')
                    % {'value': value, 'key': key, 'valid': valid_values}
                )
            used_keys.append(key)
            return value

        flavor_id = utils.get_id_from_href(_check_option('flavorRef',
                                                         required=True))
        volume_size = int(_check_option('volume', required=True)['size'])
        instance_type = _check_option('type', required=True,
                                      valid_values=['replica',
                                                    'query_router'])
        name = _check_option('name')
        related_to = _check_option('related_to')

        unused_keys = list(set(item.keys()).difference(set(used_keys)))
        if unused_keys:
            raise exception.TroveError(
                _('The arguments %s are not supported by MongoDB.')
                % unused_keys
            )

        instance = {'flavor_id': flavor_id,
                    'volume_size': volume_size,
                    'instance_type': instance_type}
        if name:
            instance['name'] = name
        if related_to:
            instance['related_to'] = related_to
        return instance
예제 #5
0
    def perform_restore(self, context, restore_location, backup_info):
        LOG.info(
            "Starting to restore database from backup %s, "
            "backup_info: %s", backup_info['id'], backup_info)

        if (backup_info["location"].endswith('.enc')
                and not CONF.backup_aes_cbc_key):
            self.status.set_status(service_status.ServiceStatuses.FAILED)
            raise exception.TroveError('Decryption key not configured for '
                                       'encrypted backup.')

        try:
            self.app.restore_backup(context, backup_info, restore_location)
        except Exception:
            LOG.error("Failed to restore from backup %s.", backup_info['id'])
            self.status.set_status(service_status.ServiceStatuses.FAILED)
            raise

        LOG.info("Finished restore data from backup %s", backup_info['id'])
예제 #6
0
 def _get_subnets(self):
     public_subnet_name = rac_utils.make_object_name(
         self.ds_conf, ['public', 'subnet'], self.id)
     interconnect_subnet_name = rac_utils.make_object_name(
         self.ds_conf, ['interconnect', 'subnet'], self.id)
     subnets = self.network_driver.list_subnets()
     self.pub_subnet = None
     self.int_subnet = None
     for subnet in subnets:
         if subnet['name'] == public_subnet_name:
             self.pub_subnet = subnet
         elif subnet['name'] == interconnect_subnet_name:
             self.int_subnet = subnet
     if not self.pub_subnet and self.int_subnet:
         raise exception.TroveError(
             _("Could not find cluster's public and interconnect subnets."))
     LOG.debug("Cluster {clu} is using public subnet {pubsub} and "
               "interconnect subnet {intsub}".format(
                   clu=self.id,
                   pubsub=self.pub_subnet['cidr'],
                   intsub=self.int_subnet['cidr']))
예제 #7
0
    def __init__(self, volume_type=None, context=None, volume_type_id=None):
        """
        Initialize the volume type either from the volume_type parameter, or
        by querying cinder using the context provided.
        """

        if volume_type and not (volume_type_id or context):
            self.volume_type = volume_type
        elif volume_type_id and context:
            try:
                client = create_cinder_client(context)
                self.volume_type = client.volume_types.get(volume_type_id)
            except cinder_exception.NotFound:
                raise trove_exception.NotFound(uuid=volume_type_id)
            except cinder_exception.ClientException as ce:
                raise trove_exception.TroveError(str(ce))

            return
        else:
            raise trove_exception.InvalidModelError(
                errors="An invalid set of arguments were provided.")
예제 #8
0
파일: models.py 프로젝트: flg77/trove
def load_server(context, instance_id, server_id):
    """
    Loads a server or raises an exception.
    :param context: request context used to access nova
    :param instance_id: the trove instance id corresponding to the nova server
    (informational only)
    :param server_id: the compute instance id which will be retrieved from nova
    :type context: trove.common.context.TroveContext
    :type instance_id: unicode
    :type server_id: unicode
    :rtype: novaclient.v1_1.servers.Server
    """
    client = create_nova_client(context)
    try:
        server = client.servers.get(server_id)
    except nova_exceptions.NotFound:
        LOG.error(_LE("Could not find nova server_id(%s)."), server_id)
        raise exception.ComputeInstanceNotFound(instance_id=instance_id,
                                                server_id=server_id)
    except nova_exceptions.ClientException as e:
        raise exception.TroveError(str(e))
    return server
예제 #9
0
 def enable_root(self, root_password=None):
     """Enable the sys user global access and/or
        reset the sys password.
     """
     LOG.debug("Enabling root.")
     if self.database_open_mode.startswith('READ ONLY'):
         raise exception.TroveError(
             _("Cannot root enable a read only database."))
     if not root_password:
         root_password = new_oracle_password()
     with self.cursor(self.database_name) as cursor:
         cursor.execute(
             str(
                 sql_query.AlterUser.change_password(
                     self.root_user_name, root_password)))
     self.ora_config.enable_root()
     self.ora_config.root_password = root_password
     user = models.RootUser()
     user.name = self.root_user_name
     user.host = '%'
     user.password = root_password
     LOG.debug("Successfully enabled root.")
     return user.serialize()
예제 #10
0
 def action(self, req, body, tenant_id, id):
     LOG.debug("Committing Action Against Cluster for "
               "Tenant '%s'" % tenant_id)
     LOG.info(_("req : '%s'\n\n") % req)
     LOG.info(_("id : '%s'\n\n") % id)
     if not body:
         raise exception.BadRequest(_("Invalid request body."))
     context = req.environ[wsgi.CONTEXT_KEY]
     cluster = models.Cluster.load(context, id)
     manager = cluster.datastore_version.manager
     api_strategy = strategy.load_api_strategy(manager)
     _actions = api_strategy.cluster_controller_actions
     selected_action = None
     for key in body:
         if key in _actions:
             selected_action = _actions[key]
             break
     else:
         message = _("No action '%(action)s' supplied "
                     "by strategy for manager '%(manager)s'") % (
                         {'action': key, 'manager': manager})
         raise exception.TroveError(message)
     return selected_action(cluster, body)
예제 #11
0
파일: service.py 프로젝트: wffeige/trove
    def _instance_root_delete(self, req, instance_id, slave_instances=None):
        LOG.info("Disabling authentication for instance '%s'.", instance_id)
        LOG.info("req : '%s'\n\n", req)
        context = req.environ[wsgi.CONTEXT_KEY]

        is_root_enabled = RedisRoot.load(context, instance_id)
        if not is_root_enabled:
            raise exception.RootHistoryNotFound()

        original_auth_password = self._get_original_auth_password(
            context, instance_id)

        # Do root-disable and roll back once if operation fails.
        try:
            RedisRoot.delete(context, instance_id)
        except exception.TroveError:
            self._rollback_once(req, instance_id, original_auth_password)
            raise exception.TroveError(
                _("Failed to do root-disable for instance "
                  "'%(instance_id)s'.") % {'instance_id': instance_id})

        failed_slaves = []
        for slave_id in slave_instances:
            try:
                LOG.info(
                    "Disabling authentication for slave instance "
                    "'%s'.", slave_id)
                RedisRoot.delete(context, slave_id)
            except exception.TroveError:
                failed_slaves.append(slave_id)

        if len(failed_slaves) > 0:
            result = {'failed_slaves': failed_slaves}
            return wsgi.Result(result, 200)

        return wsgi.Result(None, 204)
예제 #12
0
파일: manager.py 프로젝트: tattabbum/trove
 def apply_overrides(self, context, overrides):
     raise exception.TroveError(ERROR_MSG)
예제 #13
0
파일: manager.py 프로젝트: tattabbum/trove
 def update_overrides(self, context, overrides, remove=False):
     raise exception.TroveError(ERROR_MSG)
예제 #14
0
파일: manager.py 프로젝트: tattabbum/trove
 def create_backup(self, context, backup_info):
     raise exception.TroveError(ERROR_MSG)
예제 #15
0
파일: manager.py 프로젝트: tattabbum/trove
 def _perform_restore(self, backup_info, context, restore_location, app):
     raise exception.TroveError(ERROR_MSG)
예제 #16
0
파일: manager.py 프로젝트: tattabbum/trove
 def is_root_enabled(self, context):
     raise exception.TroveError(ERROR_MSG)
예제 #17
0
파일: manager.py 프로젝트: tattabbum/trove
 def enable_root(self, context):
     raise exception.TroveError(ERROR_MSG)
예제 #18
0
파일: manager.py 프로젝트: tattabbum/trove
 def list_users(self,
                context,
                limit=None,
                marker=None,
                include_marker=False):
     raise exception.TroveError(ERROR_MSG)
예제 #19
0
파일: manager.py 프로젝트: tattabbum/trove
 def list_access(self, context, username, hostname):
     raise exception.TroveError(ERROR_MSG)
예제 #20
0
파일: manager.py 프로젝트: tattabbum/trove
 def change_passwords(self, context, users):
     raise exception.TroveError(ERROR_MSG)
예제 #21
0
 def _get_node_details(self):
     for node_details in self._get_node_info():
         if 'myself' in node_details[2]:
             return node_details
     raise exception.TroveError(_("Unable to determine node details"))
예제 #22
0
파일: manager.py 프로젝트: tattabbum/trove
 def delete_user(self, context, user):
     raise exception.TroveError(ERROR_MSG)
예제 #23
0
파일: manager.py 프로젝트: tattabbum/trove
 def delete_database(self, context, database):
     raise exception.TroveError(ERROR_MSG)
예제 #24
0
파일: manager.py 프로젝트: tattabbum/trove
 def create_user(self, context, users):
     raise exception.TroveError(ERROR_MSG)
예제 #25
0
파일: manager.py 프로젝트: tattabbum/trove
 def create_database(self, context, databases):
     raise exception.TroveError(ERROR_MSG)
예제 #26
0
파일: api.py 프로젝트: xgoeforever/trove
    def shrink(self, instance_ids):
        """Removes instances from a cluster.
        Currently only supports removing entire replica sets from the cluster.
        """
        if not len(instance_ids) > 0:
            raise exception.TroveError(
                _('No instances specified for shrink operation.'))

        self._prep_resize()

        all_member_ids = set([member.id for member in self.members])
        all_query_router_ids = set(
            [query_router.id for query_router in self.query_routers])
        target_ids = set(instance_ids)
        target_member_ids = target_ids.intersection(all_member_ids)
        target_query_router_ids = target_ids.intersection(all_query_router_ids)
        target_configsvr_ids = target_ids.difference(
            target_member_ids.union(target_query_router_ids))
        if target_configsvr_ids:
            raise exception.ClusterShrinkInstanceInUse(
                id=list(target_configsvr_ids),
                reason="Cannot remove config servers.")

        remaining_query_router_ids = all_query_router_ids.difference(
            target_query_router_ids)
        if len(remaining_query_router_ids) < 1:
            raise exception.ClusterShrinkInstanceInUse(
                id=list(target_query_router_ids),
                reason="Cannot remove all remaining query routers. At least "
                "one query router must be available in the cluster.")

        if target_member_ids:
            target_members = [
                member for member in self.members
                if member.id in target_member_ids
            ]
            target_shards = {}
            for member in target_members:
                if member.shard_id in target_shards:
                    target_shards[member.shard_id].append(member.id)
                else:
                    target_shards[member.shard_id] = [member.id]
            for target_shard_id in target_shards.keys():
                # check the whole shard is being deleted
                target_shard_member_ids = [
                    member.id for member in target_members
                    if member.shard_id == target_shard_id
                ]
                all_shard_member_ids = [
                    member.id for member in self.members
                    if member.shard_id == target_shard_id
                ]
                if set(target_shard_member_ids) != set(all_shard_member_ids):
                    raise exception.TroveError(
                        _('MongoDB cluster shrink only supports removing an '
                          'entire shard. Shard %(shard)s has members: '
                          '%(instances)s') % {
                              'shard': target_shard_id,
                              'instances': all_shard_member_ids
                          })
                self._check_shard_status(target_shard_member_ids[0])

        # all checks are done by now
        self.update_db(task_status=ClusterTasks.SHRINKING_CLUSTER)
        for instance_id in instance_ids:
            instance = inst_models.load_any_instance(self.context, instance_id)
            instance.delete()
        self.manager.shrink_cluster(self.id, instance_ids)
예제 #27
0
파일: manager.py 프로젝트: tattabbum/trove
 def update_attributes(self, context, username, hostname, user_attrs):
     raise exception.TroveError(ERROR_MSG)
예제 #28
0
파일: manager.py 프로젝트: tattabbum/trove
 def grant_access(self, context, username, hostname, databases):
     raise exception.TroveError(ERROR_MSG)
예제 #29
0
파일: manager.py 프로젝트: tattabbum/trove
 def get_user(self, context, username, hostname):
     raise exception.TroveError(ERROR_MSG)
예제 #30
0
파일: manager.py 프로젝트: tattabbum/trove
 def revoke_access(self, context, username, hostname, database):
     raise exception.TroveError(ERROR_MSG)