コード例 #1
0
 def bind_infra_env(self, name, cluster, force=False):
     infra_env_id = self.get_infra_env_id(name)
     cluster_id = self.get_cluster_id(cluster)
     for host in self.client.v2_list_hosts(infra_env_id=infra_env_id):
         host_id = host['id']
         host_name = host['requested_hostname']
         host_cluster_id = host.get('cluster_id')
         if host_cluster_id is not None:
             if host_cluster_id == cluster_id:
                 info(f"Host {host_name} already bound to Cluster {cluster}")
                 continue
             elif not force:
                 info(f"Host {host_name} already bound another cluster")
                 continue
             else:
                 host_cluster = self.get_cluster_name(host_cluster_id)
                 info(f"Unbinding Host {host_name} from Cluster {host_cluster}")
                 self.client.unbind_host(infra_env_id=infra_env_id, host_id=host_id)
                 while True:
                     currenthost = self.client.v2_get_host(infra_env_id=infra_env_id, host_id=host_id)
                     currentstatus = currenthost.status
                     if currentstatus == 'known-unbound':
                         break
                     else:
                         info(f"Waiting 5s for host {host_name} to get unbound")
                         sleep(5)
         info(f"Binding Host {host_name} to Cluster {cluster}")
         bind_host_params = {'cluster_id': cluster_id}
         bind_host_params = models.BindHostParams(**bind_host_params)
         self.client.bind_host(infra_env_id, host_id, bind_host_params)
コード例 #2
0
 def bind_host(self, infra_env_id: str, host_id: str,
               cluster_id: str) -> None:
     log.info(
         f"Enabling host: {host_id}, from infra_env {infra_env_id}, in cluster id: {cluster_id}"
     )
     bind_host_params = models.BindHostParams(cluster_id=cluster_id)
     self.client.bind_host(infra_env_id=infra_env_id,
                           host_id=host_id,
                           bind_host_params=bind_host_params)
コード例 #3
0
 def update_host(self, hostname, overrides):
     infra_envs = {}
     if 'infraenv' in overrides:
         infra_env = overrides['infraenv']
         infra_env_id = self.get_infra_env_id(infra_env)
         hosts = self.client.v2_list_hosts(infra_env_id=infra_env_id)
         matchingids = [host['id'] for host in hosts
                        if host['requested_hostname'] == hostname or host['id'] == hostname]
     else:
         for infra_env in self.client.list_infra_envs():
             infra_env_id = infra_env['id']
             hosts = self.client.v2_list_hosts(infra_env_id=infra_env_id)
             matchingids = [host['id'] for host in hosts
                            if host['requested_hostname'] == hostname or host['id'] == hostname]
             if matchingids:
                 infra_envs[infra_env_id] = matchingids
     if not infra_envs:
         error(f"No Matching Host with name {hostname} found")
     for infra_env_id in infra_envs:
         host_ids = infra_envs[infra_env_id]
         for index, host_id in enumerate(host_ids):
             role = None
             bind_updated = False
             host_update_params = {}
             if 'cluster' in overrides:
                 cluster = overrides['cluster']
                 if cluster is None or cluster == '':
                     self.client.unbind_host(infra_env_id=infra_env_id, host_id=host_id)
                 else:
                     cluster_id = self.get_cluster_id(cluster)
                     bind_host_params = {'cluster_id': cluster_id}
                     bind_host_params = models.BindHostParams(**bind_host_params)
                     self.client.bind_host(infra_env_id, host_id, bind_host_params)
                 bind_updated = True
             if 'role' in overrides:
                 role = overrides['role']
                 host_update_params['host_role'] = role
             if 'name' in overrides or 'requested_hostname' in overrides:
                 newname = overrides.get('name', overrides.get('requested_hostname'))
                 if len(host_ids) > 1:
                     newname = f"{newname}-{index}"
                 host_update_params['host_name'] = newname
             if 'ignition' in overrides:
                 ignition_path = overrides['ignition']
                 if not os.path.exists(ignition_path):
                     warning(f"Ignition {ignition_path} not found. Ignoring")
                 else:
                     ignition_data = open(ignition_path).read()
                     host_ignition_params = models.HostIgnitionParams(config=ignition_data)
                     self.client.v2_update_host_ignition(infra_env_id, host_id, host_ignition_params)
             if 'extra_args' in overrides and cluster_id is not None:
                 extra_args = overrides['extra_args']
                 installer_args_params = models.InstallerArgsParams(args=extra_args)
                 self.client.v2_update_host_installer_args(cluster_id, host_id, installer_args_params)
             if 'mcp' in overrides:
                 valid_status = ["discovering", "known", "disconnected", "insufficient", "pending-for-input"]
                 currenthost = self.client.v2_get_host(infra_env_id=infra_env_id, host_id=host_id)
                 currentstatus = currenthost.status
                 if currentstatus not in valid_status:
                     error(f"Mcp can't be set for host {hostname} because of incorrect status {currentstatus}")
                 else:
                     mcp = overrides['mcp']
                     host_update_params['machine_config_pool_name'] = mcp
             if host_update_params:
                 info(f"Updating host with id {host_id}")
                 host_update_params = models.HostUpdateParams(**host_update_params)
                 self.client.v2_update_host(infra_env_id=infra_env_id, host_id=host_id,
                                            host_update_params=host_update_params)
             elif not bind_updated:
                 warning("Nothing updated for this host")