Пример #1
0
    def create(cls, context, name, flavor_ref, image_id,
               databases, service_type, volume_size):
        db_info = DBInstance.create(name=name,
            task_status=InstanceTasks.NONE)
        LOG.debug(_("Created new Reddwarf instance %s...") % db_info.id)
        volume, volume_info = cls._create_volume(context,
                                                     db_info,
                                                     volume_size)
        client = create_nova_client(context)
        files = {"/etc/guest_info": "guest_id=%s\nservice_type=%s\n" %
                 (db_info.id, service_type)}
        server = client.servers.create(name, image_id, flavor_ref,
                     files=files,
                     block_device_mapping=volume_info['block_device'])
        LOG.debug(_("Created new compute instance %s.") % server.id)

        db_info.compute_instance_id = server.id
        db_info.save()
        service_status = InstanceServiceStatus.create(instance_id=db_info.id,
            status=ServiceStatuses.NEW)
        # Now wait for the response from the create to do additional work

        guest = create_guest_client(context, db_info.id)

        # populate the databases
        model_schemas = populate_databases(databases)
        guest.prepare(512, model_schemas, users=[],
                      device_path=volume_info['device_path'],
                      mount_point=volume_info['mount_point'])
        return Instance(context, db_info, server, service_status, volume)
Пример #2
0
 def create(cls, context, instance_id, user):
     load_and_verify(context, instance_id)
     root = create_guest_client(context, instance_id).enable_root()
     root_user = guest_models.RootUser()
     root_user.deserialize(root)
     root_history = RootHistory.create(context, instance_id, user)
     return root_user
Пример #3
0
 def create(cls, context, instance_id, user):
     load_and_verify(context, instance_id)
     root = create_guest_client(context, instance_id).enable_root()
     root_user = guest_models.RootUser()
     root_user.deserialize(root)
     root_history = RootHistory.create(context, instance_id, user)
     return root_user
Пример #4
0
def load_via_context(cls, context, instance_id):
    """Creates guest and fetches pagination arguments from the context."""
    load_and_verify(context, instance_id)
    limit = int(context.limit or cls.DEFAULT_LIMIT)
    limit = cls.DEFAULT_LIMIT if limit > cls.DEFAULT_LIMIT else limit
    client = create_guest_client(context, instance_id)
    # The REST API standard dictates that we *NEVER* include the marker.
    return cls.load_with_client(client=client, limit=limit, marker=context.marker, include_marker=False)
Пример #5
0
def load_guest_info(instance, context, id):
    if instance.status not in AGENT_INVALID_STATUSES:
        guest = create_guest_client(context, id)
        try:
            instance.volume_used = guest.get_volume_info()['used']
        except Exception as e:
            LOG.error(e)
    return instance
Пример #6
0
 def change_password(cls, context, instance_id, users):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     change_users = []
     for user in users:
         change_user = {"name": user.name, "host": user.host, "password": user.password}
         change_users.append(change_user)
     client.change_passwords(change_users)
Пример #7
0
def load_guest_info(instance, context, id):
    if instance.status not in AGENT_INVALID_STATUSES:
        guest = create_guest_client(context, id)
        try:
            instance.volume_used = guest.get_volume_info()['used']
        except Exception as e:
            LOG.error(e)
    return instance
Пример #8
0
 def access(cls, context, instance_id, username, hostname):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     databases = client.list_access(username, hostname)
     dbs = []
     for db in databases:
         dbs.append(Schema(name=db["_name"], collate=db["_collate"], character_set=db["_character_set"]))
     return UserAccess(dbs)
Пример #9
0
 def load(cls, context, instance_id, username, hostname):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     found_user = client.get_user(username=username, hostname=hostname)
     if not found_user:
         return None
     database_names = [{"name": db["_name"]} for db in found_user["_databases"]]
     return cls(found_user["_name"], found_user["_host"], found_user["_password"], database_names)
Пример #10
0
    def resize_flavor_async(self, new_flavor_id, old_memory_size,
                            updated_memory_size):
        def resize_status_msg():
            return "instance_id=%s, status=%s, flavor_id=%s, " \
                   "dest. flavor id=%s)" % (self.id, self.server.status, \
                    str(self.flavor['id']), str(new_flavor_id))
        try:
            LOG.debug("Instance %s calling stop_mysql..." % self.id)
            guest = create_guest_client(self.context, self.db_info.id)
            guest.stop_mysql()
            try:
                LOG.debug("Instance %s calling Compute resize..." % self.id)
                self.server.resize(new_flavor_id)
                #TODO(tim.simpson): Figure out some way to message the
                #                   following exceptions:
                # nova_exceptions.NotFound (for the flavor)
                # nova_exceptions.OverLimit

                self._refresh_compute_server_info()
                # Do initial check and confirm the status is appropriate.
                if self.server.status != "RESIZE" and \
                    self.server.status != "VERIFY_RESIZE":
                    raise ReddwarfError("Unexpected status after call to "
                        "resize! : %s" % resize_status_msg())

                # Wait for the flavor to change.
                #TODO(tim.simpson): Bring back our good friend poll_until.
                while(self.server.status == "RESIZE"):
                    LOG.debug("Resizing... currently, %s" % resize_status_msg())
                    time.sleep(1)
                    self._refresh_compute_server_info()

                # Do check to make sure the status and flavor id are correct.
                if (str(self.flavor['id']) != str(new_flavor_id) or
                    self.server.status != "VERIFY_RESIZE"):
                    raise ReddwarfError("Assertion failed! flavor_id=%s "
                        "and not %s"
                        % (self.server.status, str(self.flavor['id'])))

                # Confirm the resize with Nova.
                LOG.debug("Instance %s calling Compute confirm resize..."
                          % self.id)
                self.server.confirm_resize()
            except Exception as ex:
                updated_memory_size = old_memory_size
                LOG.error("Error during resize compute! Aborting action.")
                LOG.error(ex)
                raise
            finally:
                # Tell the guest to restart MySQL with the new RAM size.
                # This is in the finally because we have to call this, or
                # else MySQL could stay turned off on an otherwise usable
                # instance.
                LOG.debug("Instance %s starting mysql..." % self.id)
                guest.start_mysql_with_conf_changes(updated_memory_size)
        finally:
            self.db_info.task_status = InstanceTasks.NONE
            self.db_info.save()
Пример #11
0
def load_via_context(cls, context, instance_id):
    """Creates guest and fetches pagination arguments from the context."""
    load_and_verify(context, instance_id)
    limit = int(context.limit or cls.DEFAULT_LIMIT)
    limit = cls.DEFAULT_LIMIT if limit > cls.DEFAULT_LIMIT else limit
    client = create_guest_client(context, instance_id)
    # The REST API standard dictates that we *NEVER* include the marker.
    return cls.load_with_client(client=client, limit=limit,
                                marker=context.marker, include_marker=False)
Пример #12
0
 def create(cls, context, instance_id, schemas):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     for schema in schemas:
         schema_name = schema["_name"]
         existing_schema, _nadda = Schemas.load_with_client(client, limit=1, marker=schema_name, include_marker=True)
         if len(existing_schema) > 0 and str(existing_schema[0].name) == str(schema_name):
             raise exception.DatabaseAlreadyExists(name=schema_name)
     return client.create_database(schemas)
Пример #13
0
 def access(cls, context, instance_id, username, hostname):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     databases = client.list_access(username, hostname)
     dbs = []
     for db in databases:
         dbs.append(Schema(name=db['_name'],
                           collate=db['_collate'],
                           character_set=db['_character_set']))
     return UserAccess(dbs)
Пример #14
0
 def change_password(cls, context, instance_id, users):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     change_users = []
     for user in users:
         change_user = {'name': user.name,
                        'host': user.host,
                        'password': user.password,
                        }
         change_users.append(change_user)
     client.change_passwords(change_users)
Пример #15
0
 def change_password(cls, context, instance_id, users):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     change_users = []
     for user in users:
         change_user = {'name': user.name,
                        'host': user.host,
                        'password': user.password,
                        }
         change_users.append(change_user)
     client.change_passwords(change_users)
Пример #16
0
 def load(cls, context, instance_id):
     load_and_verify(context, instance_id)
     schemas = create_guest_client(context, instance_id).list_databases()
     model_schemas = []
     for schema in schemas:
         mysql_schema = guest_models.MySQLDatabase()
         mysql_schema.deserialize(schema)
         model_schemas.append(Schema(mysql_schema.name,
                                     mysql_schema.collate,
                                     mysql_schema.character_set))
     return model_schemas
Пример #17
0
 def create(cls, context, instance_id, schemas):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     for schema in schemas:
         schema_name = schema['_name']
         existing_schema, _nadda = Schemas.load_with_client(
             client, limit=1, marker=schema_name, include_marker=True)
         if (len(existing_schema) > 0
                 and str(existing_schema[0].name) == str(schema_name)):
             raise exception.DatabaseAlreadyExists(name=schema_name)
     return client.create_database(schemas)
Пример #18
0
 def load(cls, context, instance_id, username, hostname):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     found_user = client.get_user(username=username, hostname=hostname)
     if not found_user:
         return None
     database_names = [{
         'name': db['_name']
     } for db in found_user['_databases']]
     return cls(found_user['_name'], found_user['_host'],
                found_user['_password'], database_names)
Пример #19
0
 def create(cls, context, instance_id, users):
     # Load InstanceServiceStatus to verify if it's running
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     for user in users:
         user_name = user['_name']
         existing_users, _nadda = Users.load_with_client(
             client, limit=1, marker=user_name, include_marker=True)
         if (len(existing_users) > 0
                 and str(existing_users[0].name) == str(user_name)):
             raise exception.UserAlreadyExists(name=user_name)
     return client.create_user(users)
Пример #20
0
 def create(cls, context, instance_id, users):
     # Load InstanceServiceStatus to verify if it's running
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     for user in users:
         user_name = user['_name']
         existing_users, _nadda = Users.load_with_client(client, limit=1,
             marker=user_name, include_marker=True)
         if len(existing_users) > 0 and \
            str(existing_users[0].name) == str(user_name):
             raise exception.UserAlreadyExists(name=user_name)
     return client.create_user(users)
Пример #21
0
def load_instance_with_guest(cls, context, id):
    db_info = get_db_info(context, id)
    load_simple_instance_server_status(context, db_info)
    service_status = InstanceServiceStatus.find_by(instance_id=id)
    LOG.info("service status=%s" % service_status)
    instance = cls(context, db_info, service_status)
    if instance.status not in AGENT_INVALID_STATUSES:
        guest = create_guest_client(context, id)
        try:
            instance.volume_used = guest.get_volume_info()['used']
        except Exception as e:
            LOG.error(e)
    return instance
Пример #22
0
def load_instance_with_guest(cls, context, id):
    db_info = get_db_info(context, id)
    load_simple_instance_server_status(context, db_info)
    service_status = InstanceServiceStatus.find_by(instance_id=id)
    LOG.info("service status=%s" % service_status)
    instance = cls(context, db_info, service_status)
    if instance.status not in AGENT_INVALID_STATUSES:
        guest = create_guest_client(context, id)
        try:
            instance.volume_used = guest.get_volume_info()['used']
        except Exception as e:
            LOG.error(e)
    return instance
Пример #23
0
 def load(cls, context, instance_id, username, hostname):
     load_and_verify(context, instance_id)
     validate = guest_models.MySQLUser()
     validate.name = username
     validate.host = hostname
     client = create_guest_client(context, instance_id)
     found_user = client.get_user(username=username, hostname=hostname)
     if not found_user:
         return None
     database_names = [{'name': db['_name']}
                       for db in found_user['_databases']]
     return cls(found_user['_name'],
                found_user['_host'],
                found_user['_password'],
                database_names)
Пример #24
0
 def update_all(self, context):
     num_i = len(self.instances)
     LOG.debug("Host %s has %s instances to update" % (self.name, num_i))
     failed_instances = []
     for instance in self.instances:
         client = create_guest_client(context, instance['id'])
         try:
             client.update_guest()
         except exception.ReddwarfError as re:
             LOG.error(re)
             LOG.error("Unable to update instance: %s" % instance['id'])
             failed_instances.append(instance['id'])
     if len(failed_instances) > 0:
         msg = "Failed to update instances: %s" % failed_instances
         raise exception.UpdateGuestError(msg)
Пример #25
0
 def update_all(self, context):
     num_i = len(self.instances)
     LOG.debug("Host %s has %s instances to update" % (self.name, num_i))
     failed_instances = []
     for instance in self.instances:
         client = create_guest_client(context, instance['id'])
         try:
             client.update_guest()
         except exception.ReddwarfError as re:
             LOG.error(re)
             LOG.error("Unable to update instance: %s" % instance['id'])
             failed_instances.append(instance['id'])
     if len(failed_instances) > 0:
         msg = "Failed to update instances: %s" % failed_instances
         raise exception.UpdateGuestError(msg)
Пример #26
0
 def load(cls, context, instance_id):
     load_and_verify(context, instance_id)
     user_list = create_guest_client(context, instance_id).list_users()
     model_users = []
     for user in user_list:
         mysql_user = guest_models.MySQLUser()
         mysql_user.deserialize(user)
         # TODO(hub-cap): databases are not being returned in the
         # reference agent
         dbs = []
         for db in mysql_user.databases:
             dbs.append({'name': db['_name']})
         model_users.append(User(mysql_user.name,
                                 mysql_user.password,
                                 dbs))
     return model_users
Пример #27
0
 def load(cls, context, instance_id):
     load_and_verify(context, instance_id)
     limit = int(context.limit or Schemas.DEFAULT_LIMIT)
     if limit > Schemas.DEFAULT_LIMIT:
         limit = Schemas.DEFAULT_LIMIT
     client = create_guest_client(context, instance_id)
     schemas, next_marker = client.list_databases(limit=limit,
                                                  marker=context.marker)
     model_schemas = []
     for schema in schemas:
         mysql_schema = guest_models.MySQLDatabase()
         mysql_schema.deserialize(schema)
         model_schemas.append(Schema(mysql_schema.name,
                                     mysql_schema.collate,
                                     mysql_schema.character_set))
     return model_schemas, next_marker
Пример #28
0
 def load(context, id):
     if context is None:
         raise TypeError("Argument context not defined.")
     elif id is None:
         raise TypeError("Argument id not defined.")
     try:
         db_info = inst_models.DBInstance.find_by(id=id)
     except exception.NotFound:
         raise exception.NotFound(uuid=id)
     server, volumes = inst_models.load_server_with_volumes(context,
                                             db_info.id,
                                             db_info.compute_instance_id)
     nova_client = remote.create_nova_client(context)
     volume_client = remote.create_nova_volume_client(context)
     guest = remote.create_guest_client(context, id)
     return InstanceTasks(context, db_info, server, volumes,
                          nova_client=nova_client,
                          volume_client=volume_client, guest=guest)
Пример #29
0
def load_instance_with_guest(cls, context, id):
    db_info = get_db_info(context, id)
    load_simple_instance_server_status(context, db_info)
    service_status = InstanceServiceStatus.find_by(instance_id=id)
    LOG.info("service status=%s" % service_status)
    instance = cls(context, db_info, service_status)
    try:
        agent = agent_models.AgentHeartBeat.find_by(instance_id=id)
    except exception.ModelNotFoundError as mnfe:
        LOG.warn(mnfe)
        return instance

    if instance.status not in AGENT_INVALID_STATUSES and \
       agent_models.AgentHeartBeat.is_active(agent):
        guest = create_guest_client(context, id)
        try:
            instance.volume_used = guest.get_volume_info()['used']
        except Exception as e:
            LOG.error(e)
    return instance
Пример #30
0
 def load(cls, context, instance_id):
     load_and_verify(context, instance_id)
     limit = int(context.limit or Users.DEFAULT_LIMIT)
     limit = Users.DEFAULT_LIMIT if limit > Users.DEFAULT_LIMIT else limit
     client = create_guest_client(context, instance_id)
     user_list, next_marker = client.list_users(limit=limit,
         marker=context.marker)
     model_users = []
     for user in user_list:
         mysql_user = guest_models.MySQLUser()
         mysql_user.deserialize(user)
         # TODO(hub-cap): databases are not being returned in the
         # reference agent
         dbs = []
         for db in mysql_user.databases:
             dbs.append({'name': db['_name']})
         model_users.append(User(mysql_user.name,
                                 mysql_user.password,
                                 dbs))
     return model_users, next_marker
Пример #31
0
 def create(cls, context, instance_id, users):
     # Load InstanceServiceStatus to verify if it's running
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     for user in users:
         user_name = user['_name']
         host_name = user['_host']
         if host_name is None:
             host_name = '%'
         userhost = "%s@%s" % (user_name, host_name)
         existing_users, _nadda = Users.load_with_client(
             client,
             limit=1,
             marker=userhost,
             include_marker=True)
         if (len(existing_users) > 0 and
                 str(existing_users[0].name) == str(user_name) and
                 str(existing_users[0].host) == str(host_name)):
             raise exception.UserAlreadyExists(name=user_name,
                                               host=host_name)
     return client.create_user(users)
Пример #32
0
 def delete(cls, context, instance_id, schema):
     load_and_verify(context, instance_id)
     create_guest_client(context, instance_id).delete_database(schema)
Пример #33
0
 def delete(cls, context, instance_id, username):
     load_and_verify(context, instance_id)
     create_guest_client(context, instance_id).delete_user(username)
Пример #34
0
 def delete(cls, context, instance_id, schema):
     load_and_verify(context, instance_id)
     create_guest_client(context, instance_id).delete_database(schema)
Пример #35
0
 def get_guest(self):
     return create_guest_client(self.context, self.db_info.id)
Пример #36
0
 def grant(cls, context, instance_id, username, hostname, databases):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     client.grant_access(username, hostname, databases)
Пример #37
0
 def revoke(cls, context, instance_id, username, hostname, database):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     client.revoke_access(username, hostname, database)
Пример #38
0
 def get_guest(self):
     return create_guest_client(self.context, self.db_info.id)
Пример #39
0
    def create(cls, context, name, flavor_ref, image_id,
               databases, service_type, volume_size):
        db_info = DBInstance.create(name=name,
            task_status=InstanceTasks.NONE)
        LOG.debug(_("Created new Reddwarf instance %s...") % db_info.id)

        if volume_size:
            volume_info = cls._create_volume(context, db_info, volume_size)
            block_device_mapping = volume_info['block_device']
            device_path = volume_info['device_path']
            mount_point = volume_info['mount_point']
            volumes = volume_info['volumes']
        else:
            block_device_mapping = None
            device_path = None
            mount_point = None
            volumes = []

        client = create_nova_client(context)
        files = {"/etc/guest_info": "guest_id=%s\nservice_type=%s\n" %
                 (db_info.id, service_type)}
        server = client.servers.create(name, image_id, flavor_ref,
                     files=files,
                     block_device_mapping=block_device_mapping)
        LOG.debug(_("Created new compute instance %s.") % server.id)

        db_info.compute_instance_id = server.id
        db_info.save()
        service_status = InstanceServiceStatus.create(instance_id=db_info.id,
            status=ServiceStatuses.NEW)
        # Now wait for the response from the create to do additional work

        guest = create_guest_client(context, db_info.id)

        # populate the databases
        model_schemas = populate_databases(databases)
        guest.prepare(512, model_schemas, users=[],
                      device_path=device_path,
                      mount_point=mount_point)

        dns_support = config.Config.get("reddwarf_dns_support", 'False')
        LOG.debug(_("reddwarf dns support = %s") % dns_support)
        dns_client = create_dns_client(context)
        # Default the hostname to instance name if no dns support
        dns_client.update_hostname(db_info)
        if utils.bool_from_string(dns_support):

            def get_server():
                return client.servers.get(server.id)

            def ip_is_available(server):
                if server.addresses != {}:
                    return True
                elif server.addresses == {} and\
                     server.status != InstanceStatus.ERROR:
                    return False
                elif server.addresses == {} and\
                     server.status == InstanceStatus.ERROR:
                    LOG.error(_("Instance IP not available, instance (%s): server had "
                                " status (%s).") % (db_info['id'], server.status))
                    raise rd_exceptions.ReddwarfError(
                        status=server.status)
            poll_until(get_server, ip_is_available, sleep_time=1, time_out=60*2)

            dns_client.create_instance_entry(db_info['id'],
                          get_ip_address(server.addresses))

        return Instance(context, db_info, server, service_status, volumes)
Пример #40
0
 def delete(cls, context, instance_id, user):
     load_and_verify(context, instance_id)
     create_guest_client(context, instance_id).delete_user(user)
Пример #41
0
 def load(cls, context, instance_id):
     load_and_verify(context, instance_id)
     return create_guest_client(context, instance_id).is_root_enabled()
Пример #42
0
 def revoke(cls, context, instance_id, username, hostname, database):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     client.revoke_access(username, hostname, database)
Пример #43
0
 def grant(cls, context, instance_id, username, hostname, databases):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     client.grant_access(username, hostname, databases)
Пример #44
0
 def create(cls, context, instance_id, users):
     # Load InstanceServiceStatus to verify if it's running
     load_and_verify(context, instance_id)
     create_guest_client(context, instance_id).create_user(users)