本文整理汇总了Python中nailgun.task.helpers.TaskHelper.make_slave_fqdn方法的典型用法代码示例。如果您正苦于以下问题:Python TaskHelper.make_slave_fqdn方法的具体用法?Python TaskHelper.make_slave_fqdn怎么用?Python TaskHelper.make_slave_fqdn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.task.helpers.TaskHelper
的用法示例。
在下文中一共展示了TaskHelper.make_slave_fqdn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from nailgun.task.helpers import TaskHelper [as 别名]
# 或者: from nailgun.task.helpers.TaskHelper import make_slave_fqdn [as 别名]
def execute(self, task, respond_to='remove_nodes_resp'):
logger.debug("DeletionTask.execute(task=%s)" % task.uuid)
task_uuid = task.uuid
logger.debug("Nodes deletion task is running")
nodes_to_delete = []
nodes_to_delete_constant = []
nodes_to_restore = []
USE_FAKE = settings.FAKE_TASKS or settings.FAKE_TASKS_AMQP
# no need to call naily if there are no nodes in cluster
if respond_to == 'remove_cluster_resp' and \
not list(task.cluster.nodes):
rcvr = rpc.receiver.NailgunReceiver()
rcvr.remove_cluster_resp(
task_uuid=task_uuid,
status='ready',
progress=100
)
return
for node in task.cluster.nodes:
if node.pending_deletion:
nodes_to_delete.append({
'id': node.id,
'uid': node.id,
'roles': node.roles
})
if USE_FAKE:
# only fake tasks
new_node = {}
keep_attrs = (
'id',
'cluster_id',
'roles',
'pending_deletion',
'pending_addition'
)
for prop in object_mapper(node).iterate_properties:
if isinstance(
prop, ColumnProperty
) and prop.key not in keep_attrs:
new_node[prop.key] = getattr(node, prop.key)
nodes_to_restore.append(new_node)
# /only fake tasks
# this variable is used to iterate over it
# and be able to delete node from nodes_to_delete safely
nodes_to_delete_constant = list(nodes_to_delete)
for node in nodes_to_delete_constant:
node_db = db().query(Node).get(node['id'])
slave_name = TaskHelper.make_slave_name(node['id'])
logger.debug("Removing node from database and pending it "
"to clean its MBR: %s", slave_name)
if not node_db.online:
logger.info(
"Node is offline, can't MBR clean: %s", slave_name)
db().delete(node_db)
db().commit()
nodes_to_delete.remove(node)
# only real tasks
engine_nodes = []
if not USE_FAKE:
for node in nodes_to_delete_constant:
slave_name = TaskHelper.make_slave_name(node['id'])
logger.debug("Pending node to be removed from cobbler %s",
slave_name)
engine_nodes.append(slave_name)
try:
node_db = db().query(Node).get(node['id'])
if node_db and node_db.fqdn:
node_hostname = node_db.fqdn
else:
node_hostname = TaskHelper.make_slave_fqdn(node['id'])
logger.info("Removing node cert from puppet: %s",
node_hostname)
cmd = "puppet cert clean {0}".format(node_hostname)
proc = subprocess.Popen(
shlex.split(cmd),
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
p_stdout, p_stderr = proc.communicate()
logger.info(
"'{0}' executed, STDOUT: '{1}',"
" STDERR: '{2}'".format(
cmd,
p_stdout,
p_stderr
)
)
except OSError:
logger.warning(
"'{0}' returned non-zero exit code".format(
#.........这里部分代码省略.........