本文整理汇总了Python中trove.taskmanager.models.FreshInstanceTasks类的典型用法代码示例。如果您正苦于以下问题:Python FreshInstanceTasks类的具体用法?Python FreshInstanceTasks怎么用?Python FreshInstanceTasks使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FreshInstanceTasks类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_instance
def create_instance(self, context, instance_id, name, flavor,
image_id, databases, users, datastore_manager,
packages, volume_size, backup_id, availability_zone,
root_password, nics, overrides, slave_of_id,
cluster_config):
if slave_of_id:
self._create_replication_slave(context, instance_id, name,
flavor, image_id, databases, users,
datastore_manager, packages,
volume_size,
availability_zone, root_password,
nics, overrides, slave_of_id,
backup_id)
else:
if type(instance_id) in [list]:
raise AttributeError(_(
"Cannot create multiple non-replica instances."))
instance_tasks = FreshInstanceTasks.load(context, instance_id)
instance_tasks.create_instance(flavor, image_id, databases, users,
datastore_manager, packages,
volume_size, backup_id,
availability_zone, root_password,
nics, overrides, cluster_config)
timeout = (CONF.restore_usage_timeout if backup_id
else CONF.usage_timeout)
instance_tasks.wait_for_instance(timeout, flavor)
示例2: create_instance
def create_instance(self, context, instance_id, name, flavor,
image_id, databases, users, service_type,
volume_size, backup_id, availability_zone,
root_password):
instance_tasks = FreshInstanceTasks.load(context, instance_id)
instance_tasks.create_instance(flavor, image_id, databases, users,
service_type, volume_size, backup_id,
availability_zone, root_password)
示例3: create_instance
def create_instance(self, context, instance_id, name, flavor_id,
flavor_ram, image_id, databases, users, service_type,
volume_size, security_groups, backup_id):
instance_tasks = FreshInstanceTasks.load(context, instance_id)
instance_tasks.create_instance(flavor_id, flavor_ram, image_id,
databases, users, service_type,
volume_size, security_groups,
backup_id)
示例4: _create_replication_slave
def _create_replication_slave(self, context, instance_id, name, flavor,
image_id, databases, users,
datastore_manager, packages, volume_size,
availability_zone, root_password, nics,
overrides, slave_of_id, backup_id,
volume_type, modules):
if type(instance_id) in [list]:
ids = instance_id
root_passwords = root_password
else:
ids = [instance_id]
root_passwords = [root_password]
replica_number = 0
replica_backup_id = backup_id
replica_backup_created = False
replicas = []
master_instance_tasks = BuiltInstanceTasks.load(context, slave_of_id)
server_group = master_instance_tasks.server_group
scheduler_hints = srv_grp.ServerGroup.convert_to_hint(server_group)
LOG.debug("Using scheduler hints for locality: %s" % scheduler_hints)
try:
for replica_index in range(0, len(ids)):
try:
replica_number += 1
LOG.debug("Creating replica %d of %d."
% (replica_number, len(ids)))
instance_tasks = FreshInstanceTasks.load(
context, ids[replica_index])
snapshot = instance_tasks.get_replication_master_snapshot(
context, slave_of_id, flavor, replica_backup_id,
replica_number=replica_number)
replica_backup_id = snapshot['dataset']['snapshot_id']
replica_backup_created = (replica_backup_id is not None)
instance_tasks.create_instance(
flavor, image_id, databases, users, datastore_manager,
packages, volume_size, replica_backup_id,
availability_zone, root_passwords[replica_index],
nics, overrides, None, snapshot, volume_type,
modules, scheduler_hints)
replicas.append(instance_tasks)
except Exception:
# if it's the first replica, then we shouldn't continue
LOG.exception(_(
"Could not create replica %(num)d of %(count)d.")
% {'num': replica_number, 'count': len(ids)})
if replica_number == 1:
raise
for replica in replicas:
replica.wait_for_instance(CONF.restore_usage_timeout, flavor)
finally:
if replica_backup_created:
Backup.delete(context, replica_backup_id)
示例5: create_instance
def create_instance(self, context, instance_id, name, flavor,
image_id, databases, users, datastore_manager,
packages, volume_size, backup_id, availability_zone,
root_password, nics, overrides):
instance_tasks = FreshInstanceTasks.load(context, instance_id)
instance_tasks.create_instance(flavor, image_id, databases, users,
datastore_manager, packages,
volume_size, backup_id,
availability_zone, root_password, nics,
overrides)
示例6: _create_replication_slave
def _create_replication_slave(self, context, instance_id, name, flavor,
image_id, databases, users,
datastore_manager, packages, volume_size,
availability_zone, root_password, nics,
overrides, slave_of_id, backup_id):
if type(instance_id) in [list]:
ids = instance_id
root_passwords = root_password
else:
ids = [instance_id]
root_passwords = [root_password]
replica_number = 0
replica_backup_id = backup_id
replica_backup_created = False
replicas = []
try:
for replica_index in range(0, len(ids)):
try:
replica_number += 1
LOG.debug("Creating replica %d of %d."
% (replica_number, len(ids)))
instance_tasks = FreshInstanceTasks.load(
context, ids[replica_index])
snapshot = instance_tasks.get_replication_master_snapshot(
context, slave_of_id, flavor, replica_backup_id,
replica_number=replica_number)
replica_backup_id = snapshot['dataset']['snapshot_id']
replica_backup_created = True
instance_tasks.create_instance(
flavor, image_id, databases, users, datastore_manager,
packages, volume_size, replica_backup_id,
availability_zone, root_passwords[replica_index],
nics, overrides, None, snapshot)
replicas.append(instance_tasks)
except Exception:
# if it's the first replica, then we shouldn't continue
LOG.exception(_(
"Could not create replica %(num)d of %(count)d.")
% {'num': replica_number, 'count': len(instance_id)})
if replica_number == 1:
raise
for replica in replicas:
replica.wait_for_instance(CONF.restore_usage_timeout, flavor)
#rds-start
replica.create_monitor()
#rds-end
finally:
if replica_backup_created:
Backup.delete(context, replica_backup_id)
示例7: _relocate_master
def _relocate_master(self, master_id, slave_id,backup_id=None):
'''
Fore. 2014/9/29 desperated method. don't use it.
:param master_id:
:param slave_id:
:param backup_id:
'''
master_group_item = InstanceGroupItem.get_by_instance_id(self.context, master_id)
def __show_master_status(inst_id):
_instance = self.load(self.context, inst_id)
_guest = _instance.get_guest()
mStatus = _guest.ksc_show_master_status()
log_path, log_pos = mStatus['file'], mStatus['position']
return log_path, log_pos
if backup_id is None:
log_path, log_pos = __show_master_status(master_id)
else:
bk_info = Backup.get_by_id(self.context, backup_id)
if master_group_item.group_id == bk_info.group_id:
log_path, log_pos = Backup.get_binlog_info(self.context, backup_id)
else:
log_path, log_pos = __show_master_status(master_id)
LOG.debug("relocate master instance %s get binlog_path:%s binlog_pos:%s" \
%(master_id, log_path, log_pos))
group_item = master_group_item
master_host = self._get_instance_ip(master_id)
master_guest = FreshInstanceTasks.load(self.context, master_id).guest
master_port = int(master_guest.ksc_list_variables(["port"])["port"])
repl_user = CONF.rds_rpl_user
repl_password = self._gen_rpl_user_password(group_item.group_id)
master_log_file = log_path
master_log_pos = log_pos
slave_instance = self.load(self.context, slave_id)
slave_guest = slave_instance.get_guest()
slave_guest.ksc_relocate_master(master_host=master_host, master_port = master_port, repl_user=repl_user,
repl_password=repl_password, master_log_file=master_log_file,
master_log_pos=master_log_pos)
示例8: _create_replication_slave
def _create_replication_slave(self, context, instance_id, name, flavor,
image_id, databases, users,
datastore_manager, packages, volume_size,
availability_zone,
root_password, nics, overrides, slave_of_id):
instance_tasks = FreshInstanceTasks.load(context, instance_id)
snapshot = instance_tasks.get_replication_master_snapshot(context,
slave_of_id)
instance_tasks.create_instance(flavor, image_id, databases, users,
datastore_manager, packages,
volume_size,
snapshot['dataset']['snapshot_id'],
availability_zone, root_password,
nics, overrides, None)
instance_tasks.attach_replication_slave(snapshot)
示例9: create_instance
def create_instance(self, context, instance_id, name, flavor,
image_id, databases, users, datastore_manager,
packages, volume_size, backup_id, availability_zone,
root_password, nics, overrides, slave_of_id,
cluster_config):
if slave_of_id:
self._create_replication_slave(context, instance_id, name,
flavor, image_id, databases, users,
datastore_manager, packages,
volume_size,
availability_zone, root_password,
nics, overrides, slave_of_id)
else:
instance_tasks = FreshInstanceTasks.load(context, instance_id)
instance_tasks.create_instance(flavor, image_id, databases, users,
datastore_manager, packages,
volume_size, backup_id,
availability_zone, root_password,
nics, overrides, cluster_config)
示例10: _create_instance
def _create_instance(self, context, instance_id, name, flavor,
image_id, databases, users, datastore_manager,
packages, volume_size, backup_id, availability_zone,
root_password, nics, overrides, slave_of_id,
cluster_config, volume_type, locality):
if slave_of_id:
self._create_replication_slave(context, instance_id, name,
flavor, image_id, databases, users,
datastore_manager, packages,
volume_size,
availability_zone, root_password,
nics, overrides, slave_of_id,
backup_id, volume_type)
else:
if type(instance_id) in [list]:
raise AttributeError(_(
"Cannot create multiple non-replica instances."))
instance_tasks = FreshInstanceTasks.load(context, instance_id)
scheduler_hints = None
if locality:
try:
server_group = instance_tasks.create_server_group(locality)
scheduler_hints = self._convert_server_group_to_hint(
server_group)
except Exception as e:
msg = (_("Error creating '%(locality)s' server group for "
"instance %(id)s: $(error)s") %
{'locality': locality, 'id': instance_id,
'error': e.message})
LOG.exception(msg)
raise
instance_tasks.create_instance(flavor, image_id, databases, users,
datastore_manager, packages,
volume_size, backup_id,
availability_zone, root_password,
nics, overrides, cluster_config,
None, volume_type, scheduler_hints)
timeout = (CONF.restore_usage_timeout if backup_id
else CONF.usage_timeout)
instance_tasks.wait_for_instance(timeout, flavor)
示例11: restore_instance
def restore_instance(self, context, packages, flavor, datastore_manager,
instance_id, image_id, backup_id):
instance_tasks = models.BuiltInstanceTasks.load(context, instance_id)
new_tasks = FreshInstanceTasks.load(context, instance_id)
volume_info = new_tasks._build_volume_info(datastore_manager, instance_tasks.volume_size)
instance_tasks.reattach_volume(volume_info['volumes'][0]['id'])
files = new_tasks._get_injected_files(datastore_manager)
instance_tasks.rebuild(image_id, files)
backup_info = None
if backup_id is not None:
backup = models.bkup_models.Backup.get_by_id(context, backup_id)
backup_info = {'id': backup_id,
'location': backup.location,
'type': backup.backup_type,
'checksum': backup.checksum,
}
'''
device_path = instance_tasks.device_path
mount_point = CONF.get(datastore_manager).mount_point
volume_info = {'block_device': None,
'device_path': device_path,
'mount_point': mount_point,
'volumes': None,
}
'''
config = new_tasks._render_config(flavor)
LOG.info(_("config is %s") % config)
LOG.info(_("volume info is %s") % volume_info )
new_tasks._guest_prepare(flavor['ram'],
volume_info,
packages=packages,
databases=None,
users=None,
backup_info=backup_info,
config_contents=config.config_contents)
timeout = CONF.restore_usage_timeout
new_tasks.wait_for_restore(timeout, flavor, backup_id)
示例12: _delete_resources
def _delete_resources(self, fake):
group_item = InstanceGroupItem.get_by_instance_id(self.context, self.id)
group_id = group_item.group_id
inst_type = group_item.type
instance_id = self.db_info.id
if self.server and self.db_info.server_status == "ACTIVE":
# set instance to read only model
LOG.info("Set readonly for instance %s" % self.id)
self._set_instance_readonly(instance_id=self.id)
else:
LOG.info("vm_status is not ACTIVE for %s" % self.id)
if inst_type == DBInstanceType.MASTER:
rrinsts = []
try:
standby = InstanceGroupItem.get_by_gid_type(self.context, group_id, DBInstanceType.STANDBY)
rrinsts = InstanceGroupItem.get_by_gid_type(self.context, group_id, DBInstanceType.READ_REPLI)
standby_inst_id = standby.instance_id
LOG.info("MASTER %s,it hava STANDBY %s,RRS %s",
(self.id, standby_inst_id, [_inst.instance_id for _inst in rrinsts]))
InstanceGroupItem.delete(self.context, standby_inst_id)
except Exception as e:
LOG.error(utils.get_traceback_stack())
# waite replication group db sysnc
if len(rrinsts) > 0:
self.guest.ksc_set_read_only(True)
for _inst in rrinsts:
try:
rr_instance = self.load(self.context, _inst.instance_id)
rr_instance.waite_rpl_synchronize(time_out=CONF.delete_waite_rplg_sync)
except Exception as e:
LOG.error(utils.get_traceback_stack())
# delete standby instance
try:
try:
standby_instance = self.load(self.context, standby_inst_id)
except exception.UnprocessableEntity:
standby_instance = FreshInstanceTasks.load(self.context, standby_inst_id)
standby_instance.update_db(deleted=True, deleted_at=utils.utcnow(), task_status=InstanceTasks.NONE)
standby_instance.set_servicestatus_deleted()
standby_instance._delete_instance_config()
if standby_instance.server:
LOG.info("Delete STANDBY compute server %s" % standby_instance.server.id)
standby_instance.get_guest().delete_queue()
standby_instance.server.delete()
poll_until(standby_instance.server_is_finished, sleep_time=1, time_out=CONF.server_delete_time_out)
else:
LOG.info("standby instance vm_status is not ACTIVE for %s" % standby_inst_id)
except Exception as e:
LOG.error(utils.get_traceback_stack())
if fake is True and self.type == DBInstanceType.MASTER:
try:
LOG.debug("fake is True, %s is MASTER, stop mysqld", self.id)
self.guest.ksc_stop_db(do_not_start_on_reboot=True)
except Exception as e:
msg = "fake_delete, instance: %s, stop mysqld error, exception: %s " % (self.id, str(e))
LOG.error("%s, %s", msg, utils.get_traceback_stack())
AlarmRpc(self.context).alarm(self.tenant_id, level=AlarmRpc.LEVEL_ERROR,
_type=AlarmRpc.TYPE_TASKMANAGER, message=msg)
if self.server:
if fake is True and self.type == DBInstanceType.MASTER:
LOG.debug("fake is True, %s is MASTER, skip delete server", self.id)
else:
try:
LOG.info("Delete compute server %s" % self.server.id)
guest = self.get_guest()
guest.delete_queue()
self.server.delete()
poll_until(self.server_is_finished, sleep_time=1, time_out=CONF.server_delete_time_out)
except Exception as e:
LOG.error(utils.get_traceback_stack())
# delete group_item/autobackup_setting/group
if self.type in [DBInstanceType.MASTER, DBInstanceType.SINGLE]:
try:
LOG.info("Delete autobackup_setting of group_id %s" % group_id)
AutoBackup.delete(self.context, group_id)
except:
LOG.error(utils.get_traceback_stack())
# remove vip.
if CONF.trove_vip_support and \
self.type in [DBInstanceType.MASTER, DBInstanceType.SINGLE, DBInstanceType.READ_REPLI]:
if fake is True and self.type == DBInstanceType.MASTER:
LOG.debug("fake is True, %s is MASTER, skip release vip", self.id)
else:
try:
self.update_db(task_status=InstanceTasks.RELEASE_VIP)
LOG.info("release vip for instance %s" % instance_id)
if inst_type in [DBInstanceType.MASTER, DBInstanceType.SINGLE]:
cur_vip = vipService.InstanceVip.get_by_instance_id(self.context, instance_id)
vipService.InstanceVip.release_vip(self.context, cur_vip)
#.........这里部分代码省略.........
示例13: _create_replication_slave
def _create_replication_slave(self, context, instance_id, name, flavor,
image_id, databases, users,
datastore_manager, packages, volume_size,
availability_zone, root_password, nics,
overrides, slave_of_id, backup_id,
volume_type, modules):
if type(instance_id) in [list]:
ids = instance_id
root_passwords = root_password
else:
ids = [instance_id]
root_passwords = [root_password]
replica_number = 0
replica_backup_id = backup_id
replica_backup_created = False
replicas = []
master_instance_tasks = BuiltInstanceTasks.load(context, slave_of_id)
server_group = master_instance_tasks.server_group
scheduler_hints = srv_grp.ServerGroup.convert_to_hint(server_group)
LOG.debug("Using scheduler hints for locality: %s" % scheduler_hints)
try:
for replica_index in range(0, len(ids)):
try:
replica_number += 1
LOG.debug("Creating replica %d of %d."
% (replica_number, len(ids)))
instance_tasks = FreshInstanceTasks.load(
context, ids[replica_index])
snapshot = instance_tasks.get_replication_master_snapshot(
context, slave_of_id, flavor, replica_backup_id,
replica_number=replica_number)
replica_backup_id = snapshot['dataset']['snapshot_id']
replica_backup_created = (replica_backup_id is not None)
instance_tasks.create_instance(
flavor, image_id, databases, users, datastore_manager,
packages, volume_size, replica_backup_id,
availability_zone, root_passwords[replica_index],
nics, overrides, None, snapshot, volume_type,
modules, scheduler_hints)
replicas.append(instance_tasks)
except Exception:
# if it's the first replica, then we shouldn't continue
LOG.exception(_(
"Could not create replica %(num)d of %(count)d.")
% {'num': replica_number, 'count': len(ids)})
if replica_number == 1:
raise
for replica in replicas:
replica.wait_for_instance(CONF.restore_usage_timeout, flavor)
# Some datastores requires completing configuration of replication
# nodes with information that is only available after all the
# instances has been started.
if (master_instance_tasks
.post_processing_required_for_replication()):
slave_instances = [BuiltInstanceTasks.load(context, slave.id)
for slave in master_instance_tasks.slaves]
# Collect info from each slave post instance launch
slave_detail = [slave_instance.get_replication_detail()
for slave_instance in slave_instances]
# Pass info of all replication nodes to the master for
# replication setup completion
master_detail = master_instance_tasks.get_replication_detail()
master_instance_tasks.complete_master_setup(slave_detail)
# Pass info of all replication nodes to each slave for
# replication setup completion
for slave_instance in slave_instances:
slave_instance.complete_slave_setup(master_detail,
slave_detail)
# Push pending data/transactions from master to slaves
master_instance_tasks.sync_data_to_slaves()
# Set the status of all slave nodes to ACTIVE
for slave_instance in slave_instances:
slave_guest = remote.create_guest_client(
slave_instance.context, slave_instance.db_info.id,
slave_instance.datastore_version.manager)
slave_guest.cluster_complete()
finally:
if replica_backup_created:
Backup.delete(context, replica_backup_id)