def set_pull_secret(self, cluster_id, pull_secret): log.info( "Setting pull secret for cluster %s", cluster_id ) update_params = models.ClusterUpdateParams(pull_secret=pull_secret) return self.client.update_cluster( cluster_id=cluster_id, cluster_update_params=update_params)
def update_hosts(self, cluster_id, hosts_with_roles, hosts_names=None): log.info("Setting roles for hosts %s in cluster %s", hosts_with_roles, cluster_id) hosts = models.ClusterUpdateParams(hosts_roles=hosts_with_roles, hosts_names=hosts_names) return self.client.update_cluster(cluster_id=cluster_id, cluster_update_params=hosts)
def update_hosts( self, cluster_id: str, hosts_with_roles, hosts_names: Optional[models.ClusterupdateparamsHostsNames] = None ) -> models.cluster.Cluster: warnings.warn("update_hosts is deprecated. Use update_host instead.", DeprecationWarning) log.info("Setting roles for hosts %s in cluster %s", hosts_with_roles, cluster_id) hosts = models.ClusterUpdateParams(hosts_roles=hosts_with_roles, hosts_names=hosts_names) return self.update_cluster(cluster_id=cluster_id, update_params=hosts)
def set_cluster_machine_cidr(client, cluster_id, machine_net, set_vip_dhcp_allocation=True): update_params = models.ClusterUpdateParams( vip_dhcp_allocation=set_vip_dhcp_allocation, machine_network_cidr=get_machine_cidr_from_machine_net(machine_net)) client.update_cluster(cluster_id, update_params)
def create_day2_cluster(self, name, overrides={}): cluster_name = name.replace('-day2', '') cluster_id = None existing_ids = [x['id'] for x in self.list_clusters() if x['name'] == cluster_name] api_ip = None if not existing_ids: warning(f"Base Cluster {cluster_name} not found. Populating with default values") if 'version' in overrides: openshift_version = overrides['version'] elif 'openshift_version' in overrides: openshift_version = overrides['openshift_version'] else: openshift_version = default_cluster_params["openshift_version"] warning(f"No openshift_version provided.Using {openshift_version}") if 'domain' in overrides: domain = overrides['domain'] del overrides['domain'] elif 'base_dns_domain' in overrides: domain = overrides['base_dns_domain'] else: domain = default_cluster_params["base_dns_domain"] warning(f"No base_dns_domain provided.Using {domain}") overrides['base_dns_domain'] = domain api_name = "api." + cluster_name + "." + domain self.set_default_values(overrides) pull_secret, ssh_public_key = overrides['pull_secret'], overrides['ssh_public_key'] else: cluster_id = self.get_cluster_id(cluster_name) cluster = self.client.v2_get_cluster(cluster_id=cluster_id) openshift_version = cluster.openshift_version ssh_public_key = cluster.image_info.ssh_public_key api_name = "api." + cluster_name + "." + cluster.base_dns_domain api_ip = cluster.api_vip response = self.client.v2_download_cluster_files(cluster_id=cluster_id, file_name="install-config.yaml", _preload_content=False) data = yaml.safe_load(response.read().decode("utf-8")) pull_secret = data.get('pullSecret') try: socket.gethostbyname(api_name) except: if api_ip is not None: warning(f"Forcing api_vip_dnsname to {api_ip}") api_name = api_ip else: warning(f"{api_name} doesn't resolve") warning(f"run aicli update cluster {name} -P api_vip_dnsname=$api_ip") if cluster_id is None: cluster_id = str(uuid1()) new_import_cluster_params = {"name": name, "openshift_version": str(openshift_version), "api_vip_dnsname": api_name, 'openshift_cluster_id': cluster_id} new_import_cluster_params = models.ImportClusterParams(**new_import_cluster_params) self.client.v2_import_cluster(new_import_cluster_params=new_import_cluster_params) cluster_update_params = {'pull_secret': pull_secret, 'ssh_public_key': ssh_public_key} cluster_update_params = models.ClusterUpdateParams(**cluster_update_params) new_cluster_id = self.get_cluster_id(name) self.client.v2_update_cluster(cluster_id=new_cluster_id, cluster_update_params=cluster_update_params)
def set_cluster_proxy(self, cluster_id, http_proxy, https_proxy='', no_proxy=''): log.info("Setting proxy for cluster %s", cluster_id) update_params = models.ClusterUpdateParams(http_proxy=http_proxy, https_proxy=https_proxy, no_proxy=no_proxy) return self.client.update_cluster(cluster_id=cluster_id, cluster_update_params=update_params)
def update_hosts( self, cluster_id: str, hosts_with_roles, hosts_names: Optional[models.ClusterupdateparamsHostsNames] = None ) -> models.cluster.Cluster: log.info("Setting roles for hosts %s in cluster %s", hosts_with_roles, cluster_id) hosts = models.ClusterUpdateParams(hosts_roles=hosts_with_roles, hosts_names=hosts_names) return self.update_cluster(cluster_id=cluster_id, update_params=hosts)
def select_installation_disk(self, cluster_id, hosts_with_diskpaths): log.info("Setting installation disk for hosts %s in cluster %s", hosts_with_diskpaths, cluster_id) def role_to_selected_disk_config(host_id, path, role): disk_config_params = models.DiskConfigParams(id=path, role=role) return models.ClusterupdateparamsDisksSelectedConfig(id=host_id, disks_config=[disk_config_params]) disks_selected_config = [role_to_selected_disk_config(h["id"], h["path"], h["role"]) for h in hosts_with_diskpaths] params = models.ClusterUpdateParams(disks_selected_config=disks_selected_config) return self.client.update_cluster( cluster_id=cluster_id, cluster_update_params=params )
def set_cluster_proxy( self, cluster_id: str, http_proxy: str, https_proxy: Optional[str] = "", no_proxy: Optional[str] = "") -> models.cluster.Cluster: log.info("Setting proxy for cluster %s", cluster_id) update_params = models.ClusterUpdateParams(http_proxy=http_proxy, https_proxy=https_proxy, no_proxy=no_proxy) return self.update_cluster(cluster_id=cluster_id, update_params=update_params)
def select_installation_disk( self, cluster_id: str, hosts_with_diskpaths: List[dict]) -> models.cluster.Cluster: log.info("Setting installation disk for hosts %s in cluster %s", hosts_with_diskpaths, cluster_id) def role_to_selected_disk_config( host_id: str, disk_id: str, role: models.DiskRole ) -> models.ClusterupdateparamsDisksSelectedConfig: disk_config_params = models.DiskConfigParams(id=disk_id, role=role) return models.ClusterupdateparamsDisksSelectedConfig( id=host_id, disks_config=[disk_config_params]) disks_selected_config = [ role_to_selected_disk_config( h["id"], h["disk_id"] if "disk_id" in h else h["path"], h["role"]) for h in hosts_with_diskpaths ] params = models.ClusterUpdateParams( disks_selected_config=disks_selected_config) return self.update_cluster(cluster_id=cluster_id, update_params=params)
def set_cluster_vips(client, cluster_id, machine_net): api_vip, ingress_vip = _get_vips_ips(machine_net) update_params = models.ClusterUpdateParams(vip_dhcp_allocation=False, api_vip=api_vip, ingress_vip=ingress_vip) client.update_cluster(cluster_id, update_params)
def set_pull_secret(self, cluster_id: str, pull_secret: str) -> models.cluster.Cluster: log.info("Setting pull secret for cluster %s", cluster_id) update_params = models.ClusterUpdateParams(pull_secret=pull_secret) return self.update_cluster(cluster_id=cluster_id, update_params=update_params)