本文整理汇总了Python中trove.common.remote.create_dns_client函数的典型用法代码示例。如果您正苦于以下问题:Python create_dns_client函数的具体用法?Python create_dns_client怎么用?Python create_dns_client使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_dns_client函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_resources
def _create_resources():
db_info = DBInstance.create(name=name, flavor_id=flavor_id,
tenant_id=context.tenant,
volume_size=volume_size,
service_type=service_type,
task_status=InstanceTasks.BUILDING)
LOG.debug(_("Tenant %(tenant)s created new "
"Trove instance %(db)s...") %
{'tenant': context.tenant, 'db': db_info.id})
service_status = InstanceServiceStatus.create(
instance_id=db_info.id,
status=rd_instance.ServiceStatuses.NEW)
if CONF.trove_dns_support:
dns_client = create_dns_client(context)
hostname = dns_client.determine_hostname(db_info.id)
db_info.hostname = hostname
db_info.save()
root_password = None
if CONF.root_on_create and not backup_id:
root_password = uuidutils.generate_uuid()
task_api.API(context).create_instance(db_info.id, name, flavor,
image_id, databases, users,
service_type, volume_size,
backup_id,
availability_zone,
root_password)
return SimpleInstance(context, db_info, service_status,
root_password)
示例2: _create_dns_entry
def _create_dns_entry(self):
LOG.debug("%s: Creating dns entry for instance: %s" % (greenthread.getcurrent(), self.id))
dns_support = CONF.trove_dns_support
LOG.debug(_("trove dns support = %s") % dns_support)
if dns_support:
dns_client = create_dns_client(self.context)
def get_server():
c_id = self.db_info.compute_instance_id
return self.nova_client.servers.get(c_id)
def ip_is_available(server):
LOG.info("Polling for ip addresses: $%s " % server.addresses)
if server.addresses != {}:
return True
elif server.addresses == {} and server.status != InstanceStatus.ERROR:
return False
elif server.addresses == {} and server.status == InstanceStatus.ERROR:
msg = _("Instance IP not available, instance (%s): " "server had status (%s).")
LOG.error(msg % (self.id, server.status))
raise TroveError(status=server.status)
poll_until(get_server, ip_is_available, sleep_time=1, time_out=DNS_TIME_OUT)
server = self.nova_client.servers.get(self.db_info.compute_instance_id)
LOG.info("Creating dns entry...")
dns_client.create_instance_entry(self.id, get_ip_address(server.addresses))
else:
LOG.debug("%s: DNS not enabled for instance: %s" % (greenthread.getcurrent(), self.id))
示例3: _create_resources
def _create_resources():
if cluster_config:
cluster_id = cluster_config.get("id", None)
shard_id = cluster_config.get("shard_id", None)
instance_type = cluster_config.get("instance_type", None)
else:
cluster_id = shard_id = instance_type = None
db_info = DBInstance.create(name=name, flavor_id=flavor_id,
tenant_id=context.tenant,
volume_size=volume_size,
datastore_version_id=
datastore_version.id,
task_status=InstanceTasks.BUILDING,
configuration_id=configuration_id,
slave_of_id=slave_of_id,
cluster_id=cluster_id,
shard_id=shard_id,
type=instance_type)
LOG.debug("Tenant %(tenant)s created new Trove instance %(db)s."
% {'tenant': context.tenant, 'db': db_info.id})
# if a configuration group is associated with an instance,
# generate an overrides dict to pass into the instance creation
# method
config = Configuration(context, configuration_id)
overrides = config.get_configuration_overrides()
service_status = InstanceServiceStatus.create(
instance_id=db_info.id,
status=tr_instance.ServiceStatuses.NEW)
if CONF.trove_dns_support:
dns_client = create_dns_client(context)
hostname = dns_client.determine_hostname(db_info.id)
db_info.hostname = hostname
db_info.save()
root_password = None
if cls.get_root_on_create(
datastore_version.manager) and not backup_id:
root_password = utils.generate_random_password()
task_api.API(context).create_instance(db_info.id, name, flavor,
image_id, databases, users,
datastore_version.manager,
datastore_version.packages,
volume_size, backup_id,
availability_zone,
root_password, nics,
overrides, slave_of_id,
cluster_config)
return SimpleInstance(context, db_info, service_status,
root_password)
示例4: _create_resources
def _create_resources():
security_groups = None
if backup_id is not None:
backup_info = Backup.get_by_id(context, backup_id)
if backup_info.is_running:
raise exception.BackupNotCompleteError(backup_id=backup_id)
location = backup_info.location
LOG.info(_("Checking if backup exist in '%s'") % location)
if not Backup.check_object_exist(context, location):
raise exception.BackupFileNotFound(location=location)
db_info = DBInstance.create(name=name, flavor_id=flavor_id,
tenant_id=context.tenant,
volume_size=volume_size,
service_type=service_type,
task_status=InstanceTasks.BUILDING)
LOG.debug(_("Tenant %(tenant)s created new "
"Trove instance %(db)s...") %
{'tenant': context.tenant, 'db': db_info.id})
service_status = InstanceServiceStatus.create(
instance_id=db_info.id,
status=rd_instance.ServiceStatuses.NEW)
if CONF.trove_dns_support:
dns_client = create_dns_client(context)
hostname = dns_client.determine_hostname(db_info.id)
db_info.hostname = hostname
db_info.save()
if CONF.trove_security_groups_support:
security_group = SecurityGroup.create_for_instance(
db_info.id,
context)
if CONF.trove_security_groups_rules_support:
SecurityGroupRule.create_sec_group_rule(
security_group,
CONF.trove_security_group_rule_protocol,
CONF.trove_security_group_rule_port,
CONF.trove_security_group_rule_port,
CONF.trove_security_group_rule_cidr,
context
)
security_groups = [security_group["name"]]
task_api.API(context).create_instance(db_info.id, name, flavor,
image_id, databases, users,
service_type, volume_size,
security_groups, backup_id,
availability_zone)
return SimpleInstance(context, db_info, service_status)
示例5: _delete_resources
def _delete_resources(self, deleted_at):
LOG.debug(_("begin _delete_resources for id: %s") % self.id)
server_id = self.db_info.compute_instance_id
old_server = self.nova_client.servers.get(server_id)
try:
if use_heat:
# Delete the server via heat
heatclient = create_heat_client(self.context)
name = 'trove-%s' % self.id
heatclient.stacks.delete(name)
else:
self.server.delete()
except Exception as ex:
LOG.exception(_("Error during delete compute server %s")
% self.server.id)
try:
dns_support = CONF.trove_dns_support
LOG.debug(_("trove dns support = %s") % dns_support)
if dns_support:
dns_api = create_dns_client(self.context)
dns_api.delete_instance_entry(instance_id=self.db_info.id)
except Exception as ex:
LOG.exception(_("Error during dns entry of instance %(id)s: %(ex)")
% {'id': self.db_info.id, 'ex': ex})
# Poll until the server is gone.
def server_is_finished():
try:
server = self.nova_client.servers.get(server_id)
if server.status not in ['SHUTDOWN', 'ACTIVE']:
LOG.error(_("Server %(server_id)s got into ERROR status "
"during delete of instance %(instance_id)s!") %
{'server_id': server.id, 'instance_id': self.id})
return False
except nova_exceptions.NotFound:
return True
try:
utils.poll_until(server_is_finished, sleep_time=2,
time_out=CONF.server_delete_time_out)
except PollTimeOut:
LOG.exception(_("Timout during nova server delete of server: %s") %
server_id)
self.send_usage_event('delete',
deleted_at=timeutils.isotime(deleted_at),
server=old_server)
LOG.debug(_("end _delete_resources for id: %s") % self.id)
示例6: _delete_resources
def _delete_resources(self, deleted_at):
server_id = self.db_info.compute_instance_id
old_server = self.nova_client.servers.get(server_id)
try:
if use_heat:
# Delete the server via heat
heatclient = create_heat_client(self.context)
name = "trove-%s" % self.id
heatclient.stacks.delete(name)
else:
self.server.delete()
except Exception as ex:
LOG.error("Error during delete compute server %s " % self.server.id)
LOG.error(ex)
try:
dns_support = CONF.trove_dns_support
LOG.debug(_("trove dns support = %s") % dns_support)
if dns_support:
dns_api = create_dns_client(self.context)
dns_api.delete_instance_entry(instance_id=self.db_info.id)
except Exception as ex:
LOG.error("Error during dns entry for instance %s " % self.db_info.id)
LOG.error(ex)
# Poll until the server is gone.
def server_is_finished():
try:
server = self.nova_client.servers.get(server_id)
if server.status not in ["SHUTDOWN", "ACTIVE"]:
msg = "Server %s got into %s status during delete " "of instance %s!" % (
server.id,
server.status,
self.id,
)
LOG.error(msg)
return False
except nova_exceptions.NotFound:
return True
try:
poll_until(server_is_finished, sleep_time=2, time_out=CONF.server_delete_time_out)
except PollTimeOut as e:
LOG.error("Timout during nova server delete", e)
self.send_usage_event("delete", deleted_at=timeutils.isotime(deleted_at), server=old_server)
示例7: _create_dns_entry
def _create_dns_entry(self):
LOG.debug(_("%(gt)s: Creating dns entry for instance: %(id)s") %
{'gt': greenthread.getcurrent(), 'id': self.id})
dns_support = CONF.trove_dns_support
LOG.debug(_("trove dns support = %s") % dns_support)
if dns_support:
dns_client = create_dns_client(self.context)
def get_server():
c_id = self.db_info.compute_instance_id
return self.nova_client.servers.get(c_id)
def ip_is_available(server):
LOG.info(_("Polling for ip addresses: $%s ") %
server.addresses)
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 (%(instance)s): "
"server had status (%(status)s).") %
{'instance': self.id, 'status': server.status})
raise TroveError(status=server.status)
utils.poll_until(get_server, ip_is_available,
sleep_time=1, time_out=DNS_TIME_OUT)
server = self.nova_client.servers.get(
self.db_info.compute_instance_id)
LOG.info(_("Creating dns entry..."))
ip = get_ip_address(server.addresses)
if not ip:
raise TroveError('Error creating DNS. No IP available.')
dns_client.create_instance_entry(self.id, ip.pop)
else:
LOG.debug(_("%(gt)s: DNS not enabled for instance: %(id)s") %
{'gt': greenthread.getcurrent(), 'id': self.id})
示例8: _delete_resources
def _delete_resources(self):
server_id = self.db_info.compute_instance_id
old_server = self.nova_client.servers.get(server_id)
try:
self.server.delete()
except Exception as ex:
LOG.error("Error during delete compute server %s "
% self.server.id)
LOG.error(ex)
try:
dns_support = CONF.trove_dns_support
LOG.debug(_("trove dns support = %s") % dns_support)
if dns_support:
dns_api = create_dns_client(self.context)
dns_api.delete_instance_entry(instance_id=self.db_info.id)
except Exception as ex:
LOG.error("Error during dns entry for instance %s "
% self.db_info.id)
LOG.error(ex)
# Poll until the server is gone.
def server_is_finished():
try:
server = self.nova_client.servers.get(server_id)
if server.status not in ['SHUTDOWN', 'ACTIVE']:
msg = "Server %s got into ERROR status during delete " \
"of instance %s!" % (server.id, self.id)
LOG.error(msg)
return False
except nova_exceptions.NotFound:
return True
poll_until(server_is_finished, sleep_time=2,
time_out=CONF.server_delete_time_out)
self.send_usage_event('delete', deleted_at=timeutils.isotime(),
server=old_server)
示例9: _create_resources
def _create_resources():
if cluster_config:
cluster_id = cluster_config.get("id", None)
shard_id = cluster_config.get("shard_id", None)
instance_type = cluster_config.get("instance_type", None)
else:
cluster_id = shard_id = instance_type = None
ids = []
names = []
root_passwords = []
root_password = None
for instance_index in range(0, instance_count):
db_info = DBInstance.create(
name=name, flavor_id=flavor_id, tenant_id=context.tenant,
volume_size=volume_size,
datastore_version_id=datastore_version.id,
task_status=InstanceTasks.BUILDING,
configuration_id=configuration_id,
slave_of_id=slave_of_id, cluster_id=cluster_id,
shard_id=shard_id, type=instance_type)
LOG.debug("Tenant %(tenant)s created new Trove instance "
"%(db)s.",
{'tenant': context.tenant, 'db': db_info.id})
instance_id = db_info.id
instance_name = name
ids.append(instance_id)
names.append(instance_name)
root_passwords.append(None)
# change the name to be name + replica_number if more than one
if multi_replica:
replica_number = instance_index + 1
names[instance_index] += '-' + str(replica_number)
setattr(db_info, 'name', names[instance_index])
db_info.save()
# if a configuration group is associated with an instance,
# generate an overrides dict to pass into the instance creation
# method
config = Configuration(context, configuration_id)
overrides = config.get_configuration_overrides()
service_status = InstanceServiceStatus.create(
instance_id=instance_id,
status=tr_instance.ServiceStatuses.NEW)
if CONF.trove_dns_support:
dns_client = create_dns_client(context)
hostname = dns_client.determine_hostname(instance_id)
db_info.hostname = hostname
db_info.save()
if cls.get_root_on_create(
datastore_version.manager) and not backup_id:
root_password = utils.generate_random_password()
root_passwords[instance_index] = root_password
if instance_count > 1:
instance_id = ids
instance_name = names
root_password = root_passwords
task_api.API(context).create_instance(
instance_id, instance_name, flavor, image_id, databases, users,
datastore_version.manager, datastore_version.packages,
volume_size, backup_id, availability_zone, root_password,
nics, overrides, slave_of_id, cluster_config)
return SimpleInstance(context, db_info, service_status,
root_password)