Beispiel #1
0
 def check_update_deployed(undeployed_hosts, check_deployed_command, node_connection_params, vlan): #IGNORE:W0613
     logger.debug(style.emph("check which hosts are already deployed among:") + " %s", undeployed_hosts)
     deployment_hostnames_mapping = dict()
     if vlan:
         for host in undeployed_hosts:
             deployment_hostnames_mapping[get_kavlan_host_name(host, vlan)] = host
     else:
         for host in undeployed_hosts:
             deployment_hostnames_mapping[host] = host
     deployed_check = get_remote(check_deployed_command,
                                 list(deployment_hostnames_mapping),
                                 connection_params = node_connection_params)
     for p in deployed_check.processes:
             p.nolog_exit_code = True
             p.nolog_timeout = True
             p.nolog_error = True
             p.timeout = check_timeout
     deployed_check.run()
     newly_deployed = list()
     for process in deployed_check.processes:
         logger.debug(style.emph("check on %s:" % (process.host,))
                      + " %s\n" % (process,)
                      + style.emph("stdout:") + "\n%s\n" % (process.stdout)
                      + style.emph("stderr:") + "\n%s\n" % (process.stderr))
         if (process.ok):
             newly_deployed.append(deployment_hostnames_mapping[process.host.address])
             logger.debug("OK %s", deployment_hostnames_mapping[process.host.address])
         else:
             logger.debug("KO %s", deployment_hostnames_mapping[process.host.address])
     return newly_deployed
Beispiel #2
0
    def _launch_kadeploy(self, max_tries=1, check_deploy=True):
        """Create a execo_g5k.Deployment object, launch the deployment and
        return a tuple (deployed_hosts, undeployed_hosts)
        """
        logger.info('Deploying %s hosts \n%s', len(self.hosts),
                    hosts_list(self.hosts))
        deployment = Deployment(
            hosts=[Host(canonical_host_name(host)) for host in self.hosts],
            env_file=self.env_file,
            env_name=self.env_name,
            user=self.env_user,
            vlan=self.kavlan)
        # Activate kadeploy output log if log level is debug
        if logger.getEffectiveLevel() <= 10:
            stdout = [sys.stdout]
            stderr = [sys.stderr]
        else:
            stdout = None
            stderr = None

        deployed_hosts, undeployed_hosts = deploy(
            deployment,
            stdout_handlers=stdout,
            stderr_handlers=stderr,
            num_tries=max_tries,
            check_deployed_command=check_deploy)
        deployed_hosts = list(deployed_hosts)
        undeployed_hosts = list(undeployed_hosts)
        # Renaming hosts if a kavlan is used
        if self.kavlan:
            for i, host in enumerate(deployed_hosts):
                deployed_hosts[i] = get_kavlan_host_name(host, self.kavlan)
            for i, host in enumerate(undeployed_hosts):
                undeployed_hosts[i] = get_kavlan_host_name(host, self.kavlan)
        logger.info('Deployed %s hosts \n%s', len(deployed_hosts),
                    hosts_list(deployed_hosts))
        cr = '\n' if len(undeployed_hosts) > 0 else ''
        logger.info('Failed %s hosts %s%s', len(undeployed_hosts), cr,
                    hosts_list(undeployed_hosts))
        self._update_hosts_state(deployed_hosts, undeployed_hosts)
        return deployed_hosts, undeployed_hosts
Beispiel #3
0
    def _launch_kadeploy(self, max_tries=1, check_deploy=True):
        """Create a execo_g5k.Deployment object, launch the deployment and
        return a tuple (deployed_hosts, undeployed_hosts)
        """
        logger.info('Deploying %s hosts \n%s', len(self.hosts),
                    hosts_list(self.hosts))
        deployment = Deployment(hosts=[Host(canonical_host_name(host))
                                       for host in self.hosts],
                                env_file=self.env_file,
                                env_name=self.env_name,
                                user=self.env_user,
                                vlan=self.kavlan)
        # Activate kadeploy output log if log level is debug
        if logger.getEffectiveLevel() <= 10:
            stdout = [sys.stdout]
            stderr = [sys.stderr]
        else:
            stdout = None
            stderr = None

        deployed_hosts, undeployed_hosts = deploy(deployment,
                                                  stdout_handlers=stdout,
                                                  stderr_handlers=stderr,
                                                  num_tries=max_tries,
                                                  check_deployed_command=check_deploy)
        deployed_hosts = list(deployed_hosts)
        undeployed_hosts = list(undeployed_hosts)
        # Renaming hosts if a kavlan is used
        if self.kavlan:
            for i, host in enumerate(deployed_hosts):
                deployed_hosts[i] = get_kavlan_host_name(host, self.kavlan)
            for i, host in enumerate(undeployed_hosts):
                undeployed_hosts[i] = get_kavlan_host_name(host, self.kavlan)
        logger.info('Deployed %s hosts \n%s', len(deployed_hosts),
                    hosts_list(deployed_hosts))
        cr = '\n' if len(undeployed_hosts) > 0 else ''
        logger.info('Failed %s hosts %s%s', len(undeployed_hosts), cr,
                    hosts_list(undeployed_hosts))
        self._update_hosts_state(deployed_hosts, undeployed_hosts)
        return deployed_hosts, undeployed_hosts
Beispiel #4
0
    def _define_elements(self,
                         infile=None,
                         resources=None,
                         hosts=None,
                         vms=None,
                         ip_mac=None,
                         distribution=None):
        """Create the list of sites, clusters, hosts, vms and check
        correspondance between infile and resources"""

        if not ip_mac:
            self._get_ip_mac(resources)
        else:
            self.ip_mac = ip_mac

        if not hosts:
            self._get_resources_elements(resources)
        else:
            self.hosts = hosts if not self.kavlan else \
                map(lambda h: get_kavlan_host_name(h, self.kavlan),
                    hosts)
            self.sites = []
            self.clusters = []

        if not infile:
            self.vms = vms
            if len(filter(lambda v: v['host'] is None, self.vms)) > 0:
                self.distribution = distribution if distribution \
                    else 'round-robin'
            else:
                self.distribution = None
        else:
            xml = parse(infile)
            if self._check_xml_elements(xml, resources):
                self.vms = self._get_xml_vms(xml)
                self.distribution = None
            else:
                exit()

        self._add_xml_elements()

        if self.vms:
            if self.distribution:
                distribute_vms(self.vms, self.hosts, self.distribution)
            self._set_vms_ip_mac()
            self._add_xml_vms()
        else:
            self.vms = []

        self.backing_files = list(set([vm['backing_file'] for vm in self.vms]))
Beispiel #5
0
 def _get_resources_elements(self, resources=None):
     """ """
     self.sites = sorted([site for site in resources.keys()
                             if site != 'global'])
     self.hosts = []
     for site in self.sites:
         if self.kavlan:
             self.hosts += map(lambda host: get_kavlan_host_name(host,
                                 self.kavlan), resources[site]['hosts'])
         else:
             self.hosts += resources[site]['hosts']
     self.hosts.sort(key=lambda host: (host.split('.', 1)[0].split('-')[0],
                                 int(host.split('.', 1)[0].split('-')[1])))
     self.clusters = list(set([get_host_cluster(host)
                               for host in self.hosts]))
     self.clusters.sort()
Beispiel #6
0
    def _define_elements(self, infile=None, resources=None,
                         hosts=None, vms=None, ip_mac=None,
                         distribution=None):
        """Create the list of sites, clusters, hosts, vms and check
        correspondance between infile and resources"""

        if not ip_mac:
            self._get_ip_mac(resources)
        else:
            self.ip_mac = ip_mac

        if not hosts:
            self._get_resources_elements(resources)
        else:
            self.hosts = hosts if not self.kavlan else \
                map(lambda h: get_kavlan_host_name(h, self.kavlan),
                    hosts)
            self.sites = []
            self.clusters = []

        if not infile:
            self.vms = vms
            if len(filter(lambda v: v['host'] is None, self.vms)) > 0:
                self.distribution = distribution if distribution \
                    else 'round-robin'
            else: 
                self.distribution = None
        else:
            xml = parse(infile)
            if self._check_xml_elements(xml, resources):
                self.vms = self._get_xml_vms(xml)
                self.distribution = None
            else:
                exit()

        self._add_xml_elements()

        if self.vms:
            if self.distribution:
                distribute_vms(self.vms, self.hosts, self.distribution)
            self._set_vms_ip_mac()
            self._add_xml_vms()
        else:
            self.vms = []

        self.backing_files = list(set([vm['backing_file'] for vm in self.vms]))
Beispiel #7
0
 def _get_resources_elements(self, resources=None):
     """ """
     self.sites = sorted(
         [site for site in resources.keys() if site != 'global'])
     self.hosts = []
     for site in self.sites:
         if self.kavlan:
             self.hosts += map(
                 lambda host: get_kavlan_host_name(host, self.kavlan),
                 resources[site]['hosts'])
         else:
             self.hosts += resources[site]['hosts']
     self.hosts.sort(key=lambda host: (host.split('.', 1)[0].split('-')[
         0], int(host.split('.', 1)[0].split('-')[1])))
     self.clusters = list(
         set([get_host_cluster(host) for host in self.hosts]))
     self.clusters.sort()
Beispiel #8
0
 def check_update_deployed(undeployed_hosts, check_deployed_command,
                           node_connection_params, vlan):  #IGNORE:W0613
     logger.debug(
         style.emph("check which hosts are already deployed among:") +
         " %s", undeployed_hosts)
     deployment_hostnames_mapping = dict()
     if vlan:
         for host in undeployed_hosts:
             deployment_hostnames_mapping[get_kavlan_host_name(host,
                                                               vlan)] = host
     else:
         for host in undeployed_hosts:
             deployment_hostnames_mapping[host] = host
     deployed_check = get_remote(check_deployed_command,
                                 list(deployment_hostnames_mapping),
                                 connection_params=node_connection_params)
     for p in deployed_check.processes:
         p.nolog_exit_code = True
         p.nolog_timeout = True
         p.nolog_error = True
         p.timeout = check_timeout
     deployed_check.run()
     newly_deployed = list()
     for process in deployed_check.processes:
         logger.debug(
             style.emph("check on %s:" %
                        (process.host, )) + " %s\n" % (process, ) +
             style.emph("stdout:") + "\n%s\n" % (process.stdout) +
             style.emph("stderr:") + "\n%s\n" % (process.stderr))
         if (process.ok):
             newly_deployed.append(
                 deployment_hostnames_mapping[process.host.address])
             logger.debug(
                 "OK %s",
                 deployment_hostnames_mapping[process.host.address])
         else:
             logger.debug(
                 "KO %s",
                 deployment_hostnames_mapping[process.host.address])
     return newly_deployed