def get_terraform_configuration(tf_var_file):

    print("\nCluster configuration")
    print("=====================")

    print(
        "  The cluster configuration will be derived from the terraform configuration:\n"
        + f"  {tf_var_file}\n")

    tf_config = {}
    tf_config['replica_count'] = {}
    tf_config['instance_type'] = {}
    instance_type_count = {}

    tf_config_json = AWSGenericHelper.get_terraform_config_json(tf_var_file)

    tf_config['region'] = tf_config_json['variable']['region']['default']
    tf_config['deploy_type'] = tf_config_json['variable']['azlist']['default']
    tf_config['storage-type'] = tf_config_json['variable']['storage-type'][
        'default']
    tf_config['replica_count']['master'] = tf_config_json['variable'][
        'master_replica_count']['default']
    tf_config['replica_count']['worker'] = tf_config_json['variable'][
        'worker_replica_count']['default']
    tf_config['replica_count']['bootnode'] = 1
    tf_config['instance_type']['master'] = tf_config_json['variable'][
        'master-instance-type']['default']
    tf_config['instance_type']['worker'] = tf_config_json['variable'][
        'worker-instance-type']['default']
    if tf_config['storage-type'] == 'ocs':
        tf_config['instance_type']['worker'] = tf_config_json['variable'][
            'worker-ocs-instance-type']['default']
    tf_config['instance_type']['bootnode'] = tf_config_json['variable'][
        'bootnode-instance-type']['default']

    # storage-type dependend adaptions
    ## storage-type == 'ocs' --> 3 additional OCS worker nodes are deployed
    if tf_config['storage-type'] == 'ocs':
        tf_config['replica_count'][
            'worker'] = tf_config['replica_count']['worker'] + 3
    ## storage-type == 'portworx' --> 1 additional worker node added by cluster auto-scaler
    if tf_config['storage-type'] == 'portworx':
        tf_config['replica_count'][
            'worker'] = tf_config['replica_count']['worker'] + 1

    # Summing up the number of required number of instance types
    for node_type in tf_config['instance_type']:
        instance_type = tf_config['instance_type'][node_type]
        if instance_type not in instance_type_count:
            instance_type_count[instance_type] = tf_config['replica_count'][
                node_type]
        else:
            instance_type_count[instance_type] += tf_config['replica_count'][
                node_type]

    tf_config['instances'] = instance_type_count

    # pprint(tf_config)

    return tf_config
Exemple #2
0
def get_terraform_configuration():
    print("\nCluster configuration")
    print("=====================")

    tf_var_file = os.path.dirname(os.path.abspath(__file__)) + '/../variables.tf'
    print("  The cluster configuration will be derived from terraform " +
          f"configuration: '{tf_var_file}'\n")

    tf_config = {}

    tf_config_json = AWSGenericHelper.get_terraform_config_json(tf_var_file)

    tf_config['region'] = tf_config_json['variable']['region']['default']
    pprint(tf_config)

    return tf_config
Exemple #3
0
    def validate_aws_instance_types(self, terraform_var_file):

        tf_config = {}
        tf_config['node_type'] = {}
        tf_config['node_type']['master'] = {}
        tf_config['node_type']['worker'] = {}
        tf_config['node_type']['bootnode'] = {}

        tf_config_json = AWSGenericHelper.get_terraform_config_json(
            terraform_var_file)

        # get specified instance types from terraform config
        tf_config['region'] = tf_config_json['variable']['region']['default']
        tf_config['storage-type'] = tf_config_json['variable']['storage-type'][
            'default']
        tf_config['node_type']['master']['instance_type'] = tf_config_json[
            'variable']['master-instance-type']['default']
        tf_config['node_type']['worker']['instance_type'] = tf_config_json[
            'variable']['worker-instance-type']['default']
        # if tf_config['storage-type'] == 'ocs':
        #     tf_config['node_type']['worker']['instance_type'] = tf_config_json['variable']['worker-ocs-instance-type']['default']
        tf_config['node_type']['bootnode']['instance_type'] = tf_config_json[
            'variable']['bootnode-instance-type']['default']

        # pprint(tf_config)

        # get available instance types
        not_supported_instance_types = False
        instance_type_list = []
        instance_types = self.get_instance_types()
        for instance_type in instance_types:
            instance_type_list.append(instance_type['InstanceType'])

        # print(f"InstanceType: {instance_type_list}")

        # validate availability of selected instance types
        for node_type in tf_config['node_type']:
            tf_config['node_type'][node_type]['availability'] = "PASSED"
            if tf_config['node_type'][node_type][
                    'instance_type'] not in instance_type_list:
                tf_config['node_type'][node_type]['availability'] = "FAILED"
                not_supported_instance_types = True

        if not_supported_instance_types:
            EC2Helper.print_out_instance_types(tf_config)
            exit(1)