本文整理汇总了Python中chef.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chef_instance
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
示例2: handle
def handle(event, _context):
"""Lambda Handler"""
log_event(event)
with ChefAPI(CHEF_SERVER_URL, get_pem(), USERNAME):
instance_id = get_instance_id(event)
try:
search = Search('node', 'ec2_instance_id:' + instance_id)
except ChefServerNotFoundError as err:
LOGGER.error(err)
return False
if len(search) != 0:
for instance in search:
node = Node(instance.object.name)
client = Client(instance.object.name)
try:
node.delete()
LOGGER.info('===Node Delete: SUCCESS===')
client.delete()
LOGGER.info('===Client Delete: SUCCESS===')
return True
except ChefServerNotFoundError as err:
LOGGER.error(err)
return False
else:
LOGGER.info('=Instance does not appear to be Chef Server managed.=')
return True
示例3: create_nodes
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
示例4: _is_node_busy_and_reserve_it
def _is_node_busy_and_reserve_it(node_id, api, controller_requestor='gcc'):
settings = get_current_registry().settings
seconds_block_is_busy = int(settings.get('chef.seconds_block_is_busy'))
time_to_exp = datetime.timedelta(seconds=seconds_block_is_busy)
node = ChefNode(node_id, api)
current_use_node = node.attributes.get(USE_NODE, {})
current_use_node_control = current_use_node.get('control', None)
current_use_node_exp_date = current_use_node.get('exp_date', None)
if current_use_node_exp_date:
current_use_node_exp_date = json.loads(current_use_node_exp_date, object_hook=json_util.object_hook)
current_use_node_exp_date = current_use_node_exp_date.astimezone(pytz.utc).replace(tzinfo=None)
now = datetime.datetime.now()
if now - current_use_node_exp_date > time_to_exp:
current_use_node_control = None
if current_use_node_control == controller_requestor:
return (node, False)
elif current_use_node_control is None:
exp_date = datetime.datetime.utcnow() + time_to_exp
node.attributes.set_dotted(USE_NODE, {'control': controller_requestor,
'exp_date': json.dumps(exp_date, default=json_util.default)})
node.save()
node2 = ChefNode(node.name, api) # second check
current_use_node2 = node2.attributes.get(USE_NODE, {})
current_use_control2 = current_use_node2.get('control', None)
if current_use_control2 == controller_requestor:
return (node2, False)
return (node, True)
示例5: post
def post(self):
node_id = self.request.POST.get('node_id')
if node_id is None:
return {'ok': False, 'message': 'Missing node ID'}
settings = get_current_registry().settings
api = get_chef_api(settings, self.request.user)
# create chef client
chef_client = ChefClient(node_id, api)
if chef_client.exists:
return {'ok': False, 'message': 'This client already exists'}
chef_client = ChefClient.create(node_id, api)
# Prepare the API for this client
chef_url = settings.get('chef.url')
chef_version = settings.get('chef.version')
chef_ssl_verify = settings.get('chef.ssl.verify')
if chef_ssl_verify == 'False' or chef_ssl_verify == 'True':
chef_ssl_verify = bool(chef_ssl_verify)
api = ChefAPI(chef_url, str(chef_client.private_key), node_id, chef_version, ssl_verify = False)
# create chef node
chef_node = ChefNode(node_id, api)
if chef_node.exists:
return {'ok': False, 'message': 'This node already exists'}
chef_node.save()
return {'ok': True, 'message': 'Node and client have been added',
'client_private_key': chef_client.private_key}
示例6: build_computes
def build_computes(computes):
# Run computes
print "Making the compute nodes..."
for compute in computes:
compute_node = Node(compute)
compute_node['in_use'] = "compute"
compute_node.run_list = ["role[qa-single-compute]"]
compute_node.save()
print "Updating server...this may take some time"
update_node(compute_node)
if compute_node['platform_family'] == 'rhel':
print "Platform is RHEL family, disabling iptables"
disable_iptables(compute_node)
# Run chef client twice
print "Running chef-client on compute node: %s, this may take some time..." % compute
run1 = run_chef_client(compute_node)
if run1['success']:
print "First chef-client run successful...starting second run..."
run2 = run_chef_client(compute_node)
if run2['success']:
print "Second chef-client run successful..."
else:
print "Error running chef-client for compute %s" % compute
print run2
sys.exit(1)
else:
print "Error running chef-client for compute %s" % compute
print run1
sys.exit(1)
示例7: build_dir_server
def build_dir_server(dir_server):
# We dont support 389 yet, so exit if it is not ldap
if results.dir_version != 'openldap':
print "%s as a directory service is not yet supported...exiting" % results.dir_version
sys.exit(1)
# Build directory service node
dir_node = Node(dir_server)
ip = dir_node['ipaddress']
root_pass = razor.get_active_model_pass(dir_node['razor_metadata'].to_dict()['razor_active_model_uuid'])['password']
dir_node['in_use'] = 'directory-server'
dir_node.run_list = ["role[qa-%s-%s]" % (results.dir_version, results.os)]
dir_node.save()
print "Updating server...this may take some time"
update_node(dir_node)
# if redhat platform, disable iptables
if dir_node['platform_family'] == 'rhel':
print "Platform is RHEL family, disabling iptables"
disable_iptables(dir_node)
# Run chef-client twice
print "Running chef-client for directory service node...this may take some time..."
run1 = run_chef_client(dir_node)
if run1['success']:
print "First chef-client run successful...starting second run..."
run2 = run_chef_client(dir_node)
if run2['success']:
print "Second chef-client run successful..."
else:
print "Error running chef-client for directory node %s" % dir_node
print run2
sys.exit(1)
else:
print "Error running chef-client for directory node %s" % dir_node
print run1
sys.exit(1)
# Directory service is set up, need to import config
if run1['success'] and run2['success']:
if results.dir_version == 'openldap':
scp_run = run_remote_scp_cmd(ip, 'root', root_pass, '/var/lib/jenkins/source_files/ldif/*.ldif')
if scp_run['success']:
ssh_run = run_remote_ssh_cmd(ip, 'root', root_pass, 'ldapadd -x -D \"cn=admin,dc=dev,dc=rcbops,dc=me\" -f base.ldif [email protected]')
elif results.dir_version == '389':
# Once we support 389, code here to import needed config files
print "389 is not yet supported..."
sys.exit(1)
else:
print "%s is not supported...exiting" % results.dir_version
sys.exit(1)
if scp_run['success'] and ssh_run['success']:
print "Directory Service: %s successfully set up..." % results.dir_version
else:
print "Failed to set-up Directory Service: %s..." % results.dir_version
sys.exit(1)
示例8: computer_deleted
def computer_deleted(self, user, obj, computers=None):
node_chef_id = obj.get('node_chef_id', None)
if node_chef_id:
api = get_chef_api(self.app.conf, user)
node = Node(node_chef_id, api)
node.delete()
client = Client(node_chef_id, api=api)
client.delete()
self.log_action('deleted', 'Computer', obj)
示例9: add_run_list_item
def add_run_list_item(self, items):
"""
Adds list of items to run_list
"""
util.logger.debug("run_list:{0} add:{1}".format(self.run_list, items))
self.run_list.extend(items)
cnode = ChefNode(self.name, api=self.environment.local_api)
cnode.run_list = self.run_list
self.save(cnode)
示例10: remove_run_list_item
def remove_run_list_item(self, item):
"""
Adds list of items to run_list
"""
util.logger.debug("run_list:{0} remove:{1}".format(self.run_list,
item))
self.run_list.pop(self.run_list.index(item))
cnode = ChefNode(self.name, api=self.environment.local_api)
cnode.run_list = self.run_list
self.save(cnode)
示例11: build
def build(self):
""" Builds the node
"""
# clear run_list
self.run_list = []
node = ChefNode(self.name, self.environment.local_api)
node.run_list = []
node.save()
super(Chef, self).build()
示例12: clear_pool
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()
示例13: hosts
def hosts(env=None, name=None):
api = autoconfigure()
if name:
nodes = (node for node in Node.list() if name in Node(node).name)
else:
nodes = (node for node in Node.list() if Node(node).chef_environment == env)
file = open("hosts", "w")
file.write("[hosts]\n")
map(lambda n: file.write("{0}\n".format(Node(n)['ipaddress'])), nodes)
示例14: destroy_node
def destroy_node(self, node):
"""
Destroys chef node from openstack
:param node: node to destroy
:type node: ChefNode
"""
cnode = Node(node.name, node.environment.local_api)
if cnode.exists:
self.compute_client.servers.get(node['uuid']).delete()
cnode.delete()
client = Client(node.name, node.environment.local_api)
if client.exists:
client.delete()
示例15: test_create_crosslink
def test_create_crosslink(self):
node = Node.create(self.random())
self.register(node)
node.normal['foo'] = 'bar'
self.assertEqual(node['foo'], 'bar')
node.attributes['foo'] = 'baz'
self.assertEqual(node.normal['foo'], 'baz')