本文整理匯總了Python中chef.Node.chef_environment方法的典型用法代碼示例。如果您正苦於以下問題:Python Node.chef_environment方法的具體用法?Python Node.chef_environment怎麽用?Python Node.chef_environment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類chef.Node
的用法示例。
在下文中一共展示了Node.chef_environment方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: destroy_node
# 需要導入模塊: from chef import Node [as 別名]
# 或者: from chef.Node import chef_environment [as 別名]
def destroy_node(self, node):
"""
Destroys a node provisioned by razor
:param node: Node to destroy
:type node: ChefNode
"""
cnode = Node(node.name, node.environment.local_api)
in_use = node['in_use']
if in_use == "provisioning" or in_use == 0:
# Return to pool if the node is clean
cnode['in_use'] = 0
cnode['archive'] = {}
cnode.chef_environment = "_default"
cnode.save()
else:
# Remove active model if the node is dirty
active_model = cnode['razor_metadata']['razor_active_model_uuid']
try:
if node.feature_in('controller'):
# rabbit can cause the node to not actually reboot
kill = ("for i in `ps -U rabbitmq | tail -n +2 | "
"awk '{print $1}' `; do kill -9 $i; done")
node.run_cmd(kill)
node.run_cmd("shutdown -r now")
self.api.remove_active_model(active_model)
Client(node.name).delete()
cnode.delete()
sleep(15)
except:
util.logger.error("Node unreachable. "
"Manual restart required:{0}".
format(str(node)))
示例2: create_nodes
# 需要導入模塊: from chef import Node [as 別名]
# 或者: from chef.Node import chef_environment [as 別名]
def create_nodes(cluster, facet):
"""Initialize Chef nodes"""
instances = create_instances(cluster, facet)
for nodename, ipaddress in instances:
node = Node(nodename)
if node.exists:
node_ipaddress = node.get('ipaddress')
if ipaddress is None and node_ipaddress:
ipaddress = node_ipaddress
elif node_ipaddress and node_ipaddress != ipaddress:
raise Exception('The remote IP address is different: %s' % node_ipaddress)
if ipaddress is None:
raise Exception('Can not determine the IP address for %s' % nodename)
node['ipaddress'] = ipaddress
# update environment and run_list
node.chef_environment = cluster.environment
run_list = list(cluster.run_list)
run_list.extend(facet.run_list)
# tagging the cluster
run_list.append(u'role[%s_cluster]' % cluster.name)
run_list.append(u'role[%s_%s]'% (cluster.name, facet.name))
for role in run_list:
if role not in node.run_list:
node.run_list.append(role)
facet.nodes[ipaddress] = node
示例3: chef_instance
# 需要導入模塊: from chef import Node [as 別名]
# 或者: from chef.Node import chef_environment [as 別名]
def chef_instance(self, deployment, name, flavor="2GBP"):
"""
Builds an instance with desired specs and inits it with chef
:param client: compute client object
:type client: novaclient.client.Client
:param deployment: deployement to add to
:type deployment: ChefDeployment
:param name: name for instance
:type name: string
:param flavor: desired flavor for node
:type flavor: string
:rtype: ChefNode
"""
image = deployment.os_name
server, password = self.build_instance(name=name, image=image,
flavor=flavor)
run_list = ",".join(util.config[str(self)]['run_list'])
run_list_arg = ""
if run_list:
run_list_arg = "-r {0}".format(run_list)
command = 'knife bootstrap {0} -u root -P {1} -N {2} {3}'.format(
server.accessIPv4, password, name, run_list_arg)
run_cmd(command)
node = Node(name, api=deployment.environment.local_api)
node.chef_environment = deployment.environment.name
node['in_use'] = "provisioning"
node['ipaddress'] = server.accessIPv4
node['password'] = password
node['uuid'] = server.id
node['current_user'] = "root"
node.save()
return node
示例4: clear_pool
# 需要導入模塊: from chef import Node [as 別名]
# 或者: from chef.Node import chef_environment [as 別名]
def clear_pool(chef_nodes, environment):
for n in chef_nodes:
name = n['name']
node = Node(name)
if node.chef_environment == environment:
if "recipe[network-interfaces]" not in node.run_list:
erase_node(name)
else:
node.chef_environment = "_default"
node.save()
示例5: destroy
# 需要導入模塊: from chef import Node [as 別名]
# 或者: from chef.Node import chef_environment [as 別名]
def destroy(self):
cnode = CNode(self.name)
if self['in_use'] == "provisioned":
# Return to pool if the node is clean
cnode.chef_environment = "_default"
cnode.save()
else:
# Remove active model if the node is dirty
active_model = cnode['razor_metadata']['razor_active_model_uuid']
self.razor.remove_active_model(active_model)
self.run_cmd("reboot 0")
CClient(self.name).delete()
cnode.delete()
sleep(15)