Esempio n. 1
0
 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'] = "******"
     node.save()
     return node
Esempio n. 2
0
 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)))
Esempio n. 3
0
 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)))
Esempio n. 4
0
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
Esempio n. 5
0
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()
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)