Ejemplo n.º 1
0
 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.V2ClusterUpdateParams(http_proxy=http_proxy,
                                                  https_proxy=https_proxy,
                                                  no_proxy=no_proxy)
     return self.update_cluster(cluster_id=cluster_id,
                                update_params=update_params)
Ejemplo n.º 2
0
 def update_cluster(self, name, overrides):
     cluster_id = self.get_cluster_id(name)
     if 'api_ip' in overrides:
         overrides['api_vip'] = overrides['api_ip']
     if 'ingress_ip' in overrides:
         overrides['ingress_vip'] = overrides['ingress_ip']
     if 'pull_secret' in overrides:
         pull_secret = os.path.expanduser(overrides['pull_secret'])
         if os.path.exists(pull_secret):
             overrides['pull_secret'] = re.sub(r"\s", "", open(pull_secret).read())
         else:
             warning("Using pull_secret as string")
     if 'role' in overrides:
         role = overrides['role']
         hosts_roles = [{"id": host['id'], "role": role} for host in self.client.list_hosts(cluster_id=cluster_id)]
         overrides['hosts_roles'] = hosts_roles
     installconfig = {}
     if 'network_type' in overrides:
         installconfig['networking'] = {'networkType': overrides['network_type']}
         del overrides['network_type']
     if 'sno_disk' in overrides:
         sno_disk = overrides['sno_disk']
         if '/dev' not in sno_disk:
             sno_disk = f'/dev/{sno_disk}'
         installconfig['BootstrapInPlace'] = {'InstallationDisk': sno_disk}
     if 'tpm' in overrides and overrides['tpm']:
         if overrides.get('tpm_masters', False):
             enable_on = 'masters'
         elif overrides.get('tpm_workers', False):
             enable_on = 'masters'
         else:
             enable_on = 'all'
         installconfig['disk_encryption'] = {"enable_on": enable_on, "mode": "tpmv2"}
     if 'tang_servers' in overrides and isinstance(overrides['tang_servers'], list):
         if overrides.get('tpm_masters', False):
             enable_on = 'masters'
         elif overrides.get('tpm_workers', False):
             enable_on = 'masters'
         else:
             enable_on = 'all'
         tang_servers = overrides['tang_servers']
         installconfig['disk_encryption'] = {"enable_on": "all", "mode": "tpmv2", "tang_servers": tang_servers}
     if 'proxy' in overrides:
         proxy = overrides['proxy']
         if isinstance(proxy, str):
             httpProxy, httpsProxy = proxy, proxy
             noproxy = overrides.get('noproxy')
         elif isinstance(proxy, dict):
             httpProxy = proxy.get('http_proxy') or proxy.get('httpProxy')
             httpsProxy = proxy.get('https_proxy') or proxy.get('httpsProxy')
             noproxy = proxy.get('no_proxy') or proxy.get('noProxy')
         else:
             error(f"Invalid entry for proxy: {proxy}")
             sys.exit(1)
         if not httpProxy.startswith('http'):
             httpProxy = f'http://{httpProxy}'
         if not httpsProxy.startswith('http'):
             httpsProxy = f'http://{httpsProxy}'
         installconfig['proxy'] = {'httpProxy': httpProxy, 'httpsProxy': httpsProxy, 'noProxy': noproxy}
     if 'installconfig' in overrides:
         installconfig = overrides['installconfig']
     if installconfig:
         self.client.v2_update_cluster_install_config(cluster_id, json.dumps(installconfig))
     if 'olm_operators' in overrides:
         overrides['olm_operators'] = self.set_olm_operators(overrides['olm_operators'])
     if 'machine_networks' in overrides:
         overrides['machine_networks'] = self.set_machine_networks(cluster_id, overrides['machine_networks'])
     if 'service_networks' in overrides:
         overrides['service_networks'] = self.set_service_networks(cluster_id, overrides['service_networks'])
     if 'cluster_networks' in overrides:
         overrides['cluster_networks'] = self.set_cluster_networks(cluster_id, overrides['cluster_networks'])
     if overrides:
         cluster_update_params = overrides.copy()
         allowed_parameters = self._allowed_parameters(models.V2ClusterUpdateParams)
         for parameter in overrides:
             if parameter not in allowed_parameters:
                 del cluster_update_params[parameter]
         cluster_update_params = models.V2ClusterUpdateParams(**cluster_update_params)
         self.client.v2_update_cluster(cluster_id=cluster_id, cluster_update_params=cluster_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.V2ClusterUpdateParams(pull_secret=pull_secret)
     return self.update_cluster(cluster_id=cluster_id, update_params=update_params)