def _validate_and_set_cloud_provider(self): all_errs = [] if self.cloud_provider not in Cloud.VALID_TARGET_CLOUD_INPUT: all_errs.append( "Cloud provider {} not supported. Please choose from {}". format(self.cloud_provider, Cloud.VALID_TARGET_CLOUD_INPUT)) else: try: # Validate placement only for AWS c = Cloud(target_cloud=self.cloud_provider) if c.target_cloud_aws(): ec2 = EC2(profile=self.cloud_profile, region=self.cloud_region) zones = ec2.get_availability_zones() if self.cloud_placement: if self.cloud_placement not in zones: all_errs.append( "Invalid cloud placement {}. Please choose from {}" .format(self.cloud_placement, zones)) else: self.cloud_placement = random.choice(zones) logger.info( "Cloud placement not provided, setting it to %s from currently available zones %s", self.cloud_placement, zones) except Exception as e: all_errs.append( "Cloud provider validation error: {}".format(e)) return all_errs
def validate(self): all_errs = [] all_errs += self._validate_critical_directories() # Because we have strict validation during installation, so we can assume # cluster has a valid name and cluster config if not self.cluster_name: all_errs.append("Please provide cluster name to pause the cluster") if self.cloud_provider not in Cloud.VALID_TARGET_CLOUD_INPUT: all_errs.append( "Cloud provider {} not supported. Please choose from {}". format(self.cloud_provider, Cloud.VALID_TARGET_CLOUD_INPUT)) else: # Cloud singleton should be instantiated during validation stage so # we can ensure customer ID Cloud(target_cloud=self.cloud_provider) if self.force_uninstall and self.cloud_region and self.cloud_placement: try: # Validate placement only for AWS c = Cloud(target_cloud=self.cloud_provider) if c.target_cloud_aws(): ec2 = EC2(profile=self.cloud_profile, region=self.cloud_region) zones = ec2.get_availability_zones() if self.cloud_placement not in zones: all_errs.append( "Invalid cloud placement {}. Please choose from {}" .format(self.cloud_placement, zones)) except Exception as e: all_errs.append( "Cloud provider validation error: {}".format(e)) return all_errs