text:
<repo_name>eranchetz/gcpinstances.info<file_sep>/README.md
# gcpinstances.info
GCPinstances.info source code
<file_sep>/scraper.py
import csv
import json
import requests

def nice(number: float):
    return round(number, 5)

if __name__ == '__main__':
    output = {}
    n1_sud_discount = 0.7
    m1_sud_discount = 0.7
    m2_sud_discount = 0.7
    n2_sud_discount = 0.8
    n2d_sud_discount = 0.8
    c2_sud_discount = 0.8
    e2_sud_discount = 1
    a2_sud_discount = 1
    regions = ['us', 'us-central1', 'us-east1', 'us-east4', 'us-west4', 'us-west1', 'us-west2', 'us-west3', 'europe',
               'europe-central2', 'europe-west1', 'europe-west2', 'europe-west3', 'europe-west4', 'europe-west6', 'europe-north1',
               'northamerica-northeast1', 'northamerica-northeast2', 'asia', 'asia-east', 'asia-east1', 'asia-east2', 'asia-northeast',
               'asia-northeast1', 'asia-northeast2', 'asia-northeast3', 'asia-southeast', 'asia-southeast1',
               'australia-southeast1', 'australia-southeast2', 'australia', 'southamerica-east1', 'asia-south1', 'asia-southeast2', 'asia-south2']

    specs_params = ['cores', 'memory', 'local_ssd', 'gpu', 'sole_tenant', 'nested_virtualization', 'cpu']
    generations = ['f1', 'g1', 'n1', 'n2', 'n2d', 'e2', 'c2', 'm1', 'm2', 'a2']
    # the following variables scraped from https://cloud.google.com/compute/docs/machine-types
    instance_types = ['e2-highcpu-16', 'e2-highcpu-2', 'e2-highcpu-4', 'e2-highcpu-8', 'e2-highmem-16', 'e2-highmem-2',
                      'e2-highmem-4', 'e2-highmem-8', 'e2-medium', 'e2-micro', 'e2-small', 'e2-standard-16',
                      'e2-standard-2', 'e2-standard-4', 'e2-standard-8', 'f1-micro', 'g1-small', 'n1-highcpu-16',
                      'n1-highcpu-2', 'n1-highcpu-32', 'n1-highcpu-4', 'n1-highcpu-64', 'n1-highcpu-8', 'n1-highcpu-96',
                      'n1-highmem-16', 'n1-highmem-2', 'n1-highmem-32', 'n1-highmem-4', 'n1-highmem-64', 'n1-highmem-8',
                      'n1-highmem-96', 'n1-standard-1', 'n1-standard-16', 'n1-standard-2',
                      'n1-standard-32', 'n1-standard-4', 'n1-standard-64', 'n1-standard-8', 'n1-standard-96',
                      'c2-standard-4', 'c2-standard-8',
                      'c2-standard-16', 'm1-ultramem-40', 'm1-ultramem-80', 'm1-ultramem-160',
                      'm1-megamem-96', 'c2-standard-30', 'c2-standard-60', 'm2-ultramem-208', 'm2-ultramem-416',
                      'n2-standard-2', 'n2-standard-4', 'n2-standard-8', 'n2-standard-16', 'n2-standard-32',
                      'n2-standard-48', 'n2-standard-64', 'n2-standard-80', 'n2-highmem-2', 'n2-highmem-4',
                      'n2-highmem-8', 'n2-highmem-16', 'n2-highmem-32', 'n2-highmem-48', 'n2-highmem-64',
                      'n2-highmem-80', 'n2-highcpu-2', 'n2-highcpu-4', 'n2-highcpu-8', 'n2-highcpu-16', 'n2-highcpu-32',
                      'n2-highcpu-48', 'n2-highcpu-64', 'n2-highcpu-80', 'n2d-standard-2', 'n2d-standard-4',
                      'n2d-standard-8', 'n2d-standard-16', 'n2d-standard-32', 'n2d-standard-48', 'n2d-standard-64',
                      'n2d-standard-80', 'n2d-standard-96', 'n2d-standard-128', 'n2d-standard-224', 'n2d-highmem-2',
                      'n2d-highmem-4', 'n2d-highmem-8', 'n2d-highmem-16', 'n2d-highmem-32', 'n2d-highmem-48',
                      'n2d-highmem-64', 'n2d-highmem-80', 'n2d-highmem-96', 'n2d-highcpu-2', 'n2d-highcpu-4',
                      'n2d-highcpu-8', 'n2d-highcpu-16', 'n2d-highcpu-32', 'n2d-highcpu-48', 'n2d-highcpu-64',
                      'n2d-highcpu-80', 'n2d-highcpu-96', 'n2d-highcpu-128', 'n2d-highcpu-224', 'a2-highgpu-1g',
                      'a2-highgpu-2g', 'a2-highgpu-4g', 'a2-highgpu-8g', 'a2-megagpu-16g'
                      ]
    c2_instance_types = {"c2-standard-4": {"cpu": 4, "memory": 16, "local_ssd": 1, "network_egress": 10},
                         "c2-standard-8": {"cpu": 8, "memory": 32, "local_ssd": 1, "network_egress": 16},
                         "c2-standard-16": {"cpu": 16, "memory": 64, "local_ssd": 1, "network_egress": 32},
                         "c2-standard-30": {"cpu": 30, "memory": 120, "local_ssd": 1, "network_egress": 32},
                         "c2-standard-60": {"cpu": 60, "memory": 240, "local_ssd": 1, "network_egress": 32}}
    m1_instance_types = {"m1-ultramem-40": {"cpu": 40, "memory": 961, "local_ssd": 0, "network_egress": 32},
                         "m1-ultramem-80": {"cpu": 80, "memory": 1922, "local_ssd": 0, "network_egress": 32},
                         "m1-ultramem-160": {"cpu": 160, "memory": 3844, "local_ssd": 0, "network_egress": 32},
                         "m1-megamem-96": {"cpu": 96, "memory": 1433.6, "local_ssd": 1, "network_egress": 32}}
    m2_instance_types = {"m2-ultramem-208": {"cpu": 208, "memory": 5888, "local_ssd": 0, "network_egress": 32},
                         "m2-ultramem-416": {"cpu": 416, "memory": 11776, "local_ssd": 0, "network_egress": 32}}
    n2_instance_types = {"n2-standard-2": {"cpu": 2, "memory": 8, "local_ssd": 1, "network_egress": 10},
                         "n2-standard-4": {"cpu": 4, "memory": 16, "local_ssd": 1, "network_egress": 10},
                         "n2-standard-8": {"cpu": 8, "memory": 32, "local_ssd": 1, "network_egress": 16},
                         "n2-standard-16": {"cpu": 16, "memory": 64, "local_ssd": 1, "network_egress": 32},
                         "n2-standard-32": {"cpu": 32, "memory": 128, "local_ssd": 1, "network_egress": 32},
                         "n2-standard-48": {"cpu": 48, "memory": 192, "local_ssd": 1, "network_egress": 32},
                         "n2-standard-64": {"cpu": 64, "memory": 256, "local_ssd": 1, "network_egress": 32},
                         "n2-standard-80": {"cpu": 80, "memory": 320, "local_ssd": 1, "network_egress": 32},
                         "n2-highmem-2": {"cpu": 2, "memory": 16, "local_ssd": 1, "network_egress": 10},
                         "n2-highmem-4": {"cpu": 4, "memory": 32, "local_ssd": 1, "network_egress": 10},
                         "n2-highmem-8": {"cpu": 8, "memory": 64, "local_ssd": 1, "network_egress": 16},
                         "n2-highmem-16": {"cpu": 16, "memory": 128, "local_ssd": 1, "network_egress": 32},
                         "n2-highmem-32": {"cpu": 32, "memory": 256, "local_ssd": 1, "network_egress": 32},
                         "n2-highmem-48": {"cpu": 48, "memory": 384, "local_ssd": 1, "network_egress": 32},
                         "n2-highmem-64": {"cpu": 64, "memory": 512, "local_ssd": 1, "network_egress": 32},
                         "n2-highmem-80": {"cpu": 80, "memory": 640, "local_ssd": 1, "network_egress": 32},
                         "n2-highcpu-2": {"cpu": 2, "memory": 2, "local_ssd": 1, "network_egress": 10},
                         "n2-highcpu-4": {"cpu": 4, "memory": 4, "local_ssd": 1, "network_egress": 10},
                         "n2-highcpu-8": {"cpu": 8, "memory": 8, "local_ssd": 1, "network_egress": 16},
                         "n2-highcpu-16": {"cpu": 16, "memory": 16, "local_ssd": 1, "network_egress": 32},
                         "n2-highcpu-32": {"cpu": 32, "memory": 32, "local_ssd": 1, "network_egress": 32},
                         "n2-highcpu-48": {"cpu": 48, "memory": 48, "local_ssd": 1, "network_egress": 32},
                         "n2-highcpu-64": {"cpu": 64, "memory": 64, "local_ssd": 1, "network_egress": 32},
                         "n2-highcpu-80": {"cpu": 80, "memory": 80, "local_ssd": 1, "network_egress": 32}}
    e2_instance_types = {"e2-standard-2": {"cpu": 2, "memory": 8, "local_ssd": 0, "network_egress": 4},
                         "e2-standard-4": {"cpu": 4, "memory": 16, "local_ssd": 0, "network_egress": 8},
                         "e2-standard-8": {"cpu": 8, "memory": 32, "local_ssd": 0, "network_egress": 16},
                         "e2-standard-16": {"cpu": 16, "memory": 64, "local_ssd": 0, "network_egress": 16},
                         "e2-highmem-2": {"cpu": 2, "memory": 16, "local_ssd": 0, "network_egress": 4},
                         "e2-highmem-4": {"cpu": 4, "memory": 32, "local_ssd": 0, "network_egress": 8},
                         "e2-highmem-8": {"cpu": 8, "memory": 64, "local_ssd": 0, "network_egress": 16},
                         "e2-highmem-16": {"cpu": 16, "memory": 128, "local_ssd": 0, "network_egress": 16},
                         "e2-highcpu-2": {"cpu": 2, "memory": 2, "local_ssd": 0, "network_egress": 4},
                         "e2-highcpu-4": {"cpu": 4, "memory": 4, "local_ssd": 0, "network_egress": 8},
                         "e2-highcpu-8": {"cpu": 8, "memory": 8, "local_ssd": 0, "network_egress": 16},
                         "e2-highcpu-16": {"cpu": 16, "memory": 16, "local_ssd": 0, "network_egress": 16}}
    n2d_instance_types = {"n2d-standard-2": {"cpu": 2, "memory": 8, "local_ssd": 1, "network_egress": 10},
                          "n2d-standard-4": {"cpu": 4, "memory": 16, "local_ssd": 1, "network_egress": 10},
                          "n2d-standard-8": {"cpu": 8, "memory": 32, "local_ssd": 1, "network_egress": 10},
                          "n2d-standard-16": {"cpu": 16, "memory": 64, "local_ssd": 1, "network_egress": 32},
                          "n2d-standard-32": {"cpu": 32, "memory": 128, "local_ssd": 1, "network_egress": 32},
                          "n2d-standard-48": {"cpu": 48, "memory": 192, "local_ssd": 1, "network_egress": 32},
                          "n2d-standard-64": {"cpu": 64, "memory": 256, "local_ssd": 1, "network_egress": 32},
                          "n2d-standard-80": {"cpu": 80, "memory": 320, "local_ssd": 1, "network_egress": 32},
                          "n2d-standard-96": {"cpu": 96, "memory": 384, "local_ssd": 1, "network_egress": 32},
                          "n2d-standard-128": {"cpu": 128, "memory": 512, "local_ssd": 1, "network_egress": 32},
                          "n2d-standard-224": {"cpu": 224, "memory": 896, "local_ssd": 1, "network_egress": 32},
                          "n2d-highmem-2": {"cpu": 2, "memory": 16, "local_ssd": 1, "network_egress": 10},
                          "n2d-highmem-4": {"cpu": 4, "memory": 32, "local_ssd": 1, "network_egress": 10},
                          "n2d-highmem-8": {"cpu": 8, "memory": 64, "local_ssd": 1, "network_egress": 10},
                          "n2d-highmem-16": {"cpu": 16, "memory": 128, "local_ssd": 1, "network_egress": 32},
                          "n2d-highmem-32": {"cpu": 32, "memory": 256, "local_ssd": 1, "network_egress": 32},
                          "n2d-highmem-48": {"cpu": 48, "memory": 384, "local_ssd": 1, "network_egress": 32},
                          "n2d-highmem-64": {"cpu": 64, "memory": 512, "local_ssd": 1, "network_egress": 32},
                          "n2d-highmem-80": {"cpu": 80, "memory": 640, "local_ssd": 1, "network_egress": 32},
                          "n2d-highmem-96": {"cpu": 96, "memory": 768, "local_ssd": 1, "network_egress": 32},
                          "n2d-highcpu-2": {"cpu": 2, "memory": 2, "local_ssd": 1, "network_egress": 10},
                          "n2d-highcpu-4": {"cpu": 4, "memory": 4, "local_ssd": 1, "network_egress": 10},
                          "n2d-highcpu-8": {"cpu": 8, "memory": 8, "local_ssd": 1, "network_egress": 10},
                          "n2d-highcpu-16": {"cpu": 16, "memory": 16, "local_ssd": 1, "network_egress": 32},
                          "n2d-highcpu-32": {"cpu": 32, "memory": 32, "local_ssd": 1, "network_egress": 32},
                          "n2d-highcpu-48": {"cpu": 48, "memory": 48, "local_ssd": 1, "network_egress": 32},
                          "n2d-highcpu-64": {"cpu": 64, "memory": 64, "local_ssd": 1, "network_egress": 32},
                          "n2d-highcpu-80": {"cpu": 80, "memory": 80, "local_ssd": 1, "network_egress": 32},
                          "n2d-highcpu-96": {"cpu": 96, "memory": 96, "local_ssd": 1, "network_egress": 32},
                          "n2d-highcpu-128": {"cpu": 128, "memory": 128, "local_ssd": 1, "network_egress": 32},
                          "n2d-highcpu-224": {"cpu": 224, "memory": 224, "local_ssd": 1, "network_egress": 32}}
    n1_instance_types = {"n1-standard-1": {"cpu": 1, "memory": 3.75, "local_ssd": 1, "network_egress": 2},
                         "n1-standard-2": {"cpu": 2, "memory": 7.50, "local_ssd": 1, "network_egress": 10},
                         "n1-standard-4": {"cpu": 4, "memory": 15, "local_ssd": 1, "network_egress": 10},
                         "n1-standard-8": {"cpu": 8, "memory": 30, "local_ssd": 1, "network_egress": 16},
                         "n1-standard-16": {"cpu": 16, "memory": 60, "local_ssd": 1, "network_egress": 32},
                         "n1-standard-32": {"cpu": 32, "memory": 120, "local_ssd": 1, "network_egress": 32},
                         "n1-standard-64": {"cpu": 64, "memory": 240, "local_ssd": 1, "network_egress": 32},
                         "n1-standard-96": {"cpu": 96, "memory": 360, "local_ssd": 1, "network_egress": 32},
                         "n1-highmem-2": {"cpu": 2, "memory": 13, "local_ssd": 1, "network_egress": 10},
                         "n1-highmem-4": {"cpu": 4, "memory": 26, "local_ssd": 1, "network_egress": 10},
                         "n1-highmem-8": {"cpu": 8, "memory": 52, "local_ssd": 1, "network_egress": 16},
                         "n1-highmem-16": {"cpu": 16, "memory": 104, "local_ssd": 1, "network_egress": 32},
                         "n1-highmem-32": {"cpu": 32, "memory": 208, "local_ssd": 1, "network_egress": 32},
                         "n1-highmem-64": {"cpu": 64, "memory": 416, "local_ssd": 1, "network_egress": 32},
                         "n1-highmem-96": {"cpu": 96, "memory": 624, "local_ssd": 1, "network_egress": 32},
                         "n1-highcpu-2": {"cpu": 2, "memory": 1.80, "local_ssd": 1, "network_egress": 10},
                         "n1-highcpu-4": {"cpu": 4, "memory": 3.60, "local_ssd": 1, "network_egress": 10},
                         "n1-highcpu-8": {"cpu": 8, "memory": 7.20, "local_ssd": 1, "network_egress": 16},
                         "n1-highcpu-16": {"cpu": 16, "memory": 14.4, "local_ssd": 1, "network_egress": 32},
                         "n1-highcpu-32": {"cpu": 32, "memory": 28.8, "local_ssd": 1, "network_egress": 32},
                         "n1-highcpu-64": {"cpu": 64, "memory": 57.6, "local_ssd": 1, "network_egress": 32},
                         "n1-highcpu-96": {"cpu": 96, "memory": 86.4, "local_ssd": 1, "network_egress": 32}}
    a2_instance_types = {"a2-highgpu-1g": {"cpu": 12, "memory": 85, "local_ssd": 1, "network_egress": 24},
                         "a2-highgpu-2g": {"cpu": 24, "memory": 170, "local_ssd": 1, "network_egress": 32},
                         "a2-highgpu-4g": {"cpu": 48, "memory": 340, "local_ssd": 1, "network_egress": 50},
                         "a2-highgpu-8g": {"cpu": 96, "memory": 680, "local_ssd": 1, "network_egress": 100},
                         "a2-megagpu-16g": {"cpu": 96, "memory": 1360, "local_ssd": 1, "network_egress": 100}}

    for gen in generations:
        output[gen] = {}
        for instance_t in instance_types:
            instance_t_generation = instance_t.split('-')[0]
            if instance_t_generation == gen:
                output[gen][instance_t] = {'regions': {}, 'specs': {}}
                for region in regions:
                    output[gen][instance_t]['regions'][region] = {}
                for spec in specs_params:
                    output[gen][instance_t]['specs'][spec] = {}

    # OS License
    output['license'] = {}

    # Download GCP Calculator pricing, and reformat it to GCPinstances.info strcture
    data_json = requests.get('https://cloudpricingcalculator.appspot.com/static/data/pricelist.json').json()
    data = data_json['gcp_price_list']
    for k, v in data.items():
        if k == 'CP-COMPUTEENGINE-OS':
            for kk, vv in v.items():
                output['license'][kk] = vv
        if k == 'CP-COMPUTEENGINE-VMIMAGE-F1-MICRO':
            for kk, vv in v.items():
                if kk in regions:
                    output['f1']['f1-micro']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['f1']['f1-micro']['specs'].update(
                        {kk: vv, 'cpu': ['N/A'], 'gpu': 0, 'local_ssd': 0, 'nested_virtualization': 0,
                         'sole_tenant': 0})
        if k == 'CP-COMPUTEENGINE-VMIMAGE-G1-SMALL':
            for kk, vv in v.items():
                if kk in regions:
                    output['g1']['g1-small']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['g1']['g1-small']['specs'].update(
                        {kk: vv, 'cpu': ['N/A'], 'gpu': 0, 'local_ssd': 0, 'nested_virtualization': 0,
                         'sole_tenant': 0})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-1':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-1']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-standard-1']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-2':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-2']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-standard-2']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-4':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-4']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-standard-4']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-8':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-8']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-standard-8']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-16':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-16']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-standard-16']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-32':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-32']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-standard-32']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-64':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-64']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-standard-64']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-96':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-96']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-standard-96']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-2':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-2']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highmem-2']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-4':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-4']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highmem-4']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-8':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-8']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highmem-8']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-16':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-16']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highmem-16']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-32':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-32']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highmem-32']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-64':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-64']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highmem-64']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-96':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-96']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highmem-96']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-2':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-2']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highcpu-2']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-4':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-4']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highcpu-4']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-8':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-8']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highcpu-8']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-16':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-16']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highcpu-16']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-32':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-32']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highcpu-32']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-64':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-64']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highcpu-64']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-96':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-96']['regions'][kk] = {'ondemand': vv}
                    output['n1']['n1-highcpu-96']['regions'][kk].update({'sud': nice(vv * n1_sud_discount)})

        #### PREEMPTIBLE INSTANCES

        if k == 'CP-COMPUTEENGINE-VMIMAGE-F1-MICRO-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['f1']['f1-micro']['regions'][kk].update({'preemptible': vv})
        if k == 'CP-COMPUTEENGINE-VMIMAGE-G1-SMALL-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['g1']['g1-small']['regions'][kk].update({'preemptible': vv})
        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-1-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-1']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-2-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-2']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-4-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-4']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-8-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-8']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-16-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-16']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-32-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-32']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-64-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-64']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-96-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-96']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-2-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-2']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-4-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-4']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-8-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-8']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-16-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-16']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-32-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-32']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-64-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-64']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-96-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-96']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-2-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-2']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-4-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-4']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-8-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-8']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-16-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-16']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-32-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-32']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-64-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-64']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-96-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-96']['regions'][kk].update({'preemptible': vv})
        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-1-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-1']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-2-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-2']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-4-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-4']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-8-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-8']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-16-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-16']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-32-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-32']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-64-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-64']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-96-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-standard-96']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-2-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-2']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-4-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-4']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-8-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-8']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-16-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-16']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-32-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-32']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-64-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-64']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-96-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highmem-96']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-2-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-2']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-4-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-4']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-8-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-8']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-16-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-16']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-32-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-32']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-64-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-64']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-96-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['n1']['n1-highcpu-96']['regions'][kk].update({'preemptible': vv})
        ### E2
        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-2':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-2']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highcpu-2']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-2':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-2']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-standard-2']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-16':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-16']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-standard-16']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-16':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-16']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highmem-16']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-2':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-2']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-standard-2']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-4':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-4']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-standard-4']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-8':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-8']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-standard-8']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-SMALL':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-small']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-small']['specs'].update(
                        {kk: vv, 'cpu': ['N/A'], 'gpu': 0, 'local_ssd': 0, 'nested_virtualization': 0,
                         'sole_tenant': 0})
        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-8':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-8']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-standard-8']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-16':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-16']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-standard-16']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-16':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-16']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highmem-16']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-4':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-4']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-standard-4']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-8':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-8']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highmem-8']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-16':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-16']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highcpu-16']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-4':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-4']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highmem-4']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-16':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-16']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highcpu-16']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-8':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-8']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highmem-8']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-2':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-2']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highmem-2']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-MICRO':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-micro']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-micro']['specs'].update(
                        {kk: vv, 'cpu': ['N/A'], 'gpu': 0, 'local_ssd': 0, 'nested_virtualization': 0,
                         'sole_tenant': 0})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-4':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-4']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highcpu-4']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-2':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-2']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highmem-2']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-8':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-8']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highcpu-8']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-8':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-8']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highcpu-8']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-MEDIUM':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-medium']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-medium']['specs'].update(
                        {kk: vv, 'cpu': ['N/A'], 'gpu': 0, 'local_ssd': 0, 'nested_virtualization': 0,
                         'sole_tenant': 0})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-2':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-2']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highcpu-2']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-4':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-4']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highcpu-4']['specs'].update({kk: vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-4':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-4']['regions'][kk] = {'ondemand': vv}
                if kk in specs_params:
                    output['e2']['e2-highmem-4']['specs'].update({kk: vv})

        ### PREEMPTIBLE E2
        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-2-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-2']['regions'][kk].update({'preemptible': vv})
        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-2-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-2']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-16-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-16']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-8-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-8']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-16-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-16']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-MICRO-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-micro']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-MEDIUM-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-medium']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-SMALL-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-small']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-STANDARD-4-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-standard-4']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-16-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-16']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-8-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-8']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-4-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-4']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-2-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-2']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHCPU-8-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highcpu-8']['regions'][kk].update({'preemptible': vv})

        if k == 'CP-COMPUTEENGINE-VMIMAGE-E2-HIGHMEM-4-PREEMPTIBLE':
            for kk, vv in v.items():
                if kk in regions:
                    output['e2']['e2-highmem-4']['regions'][kk].update({'preemptible': vv})

    # N1
    # Update specs
    for k, v in n1_instance_types.items():
        output['n1'][k]['specs'].update({'cores': v['cpu'], 'memory': v['memory'], 'local_ssd': v['local_ssd'],
                                         'network_egress': v['network_egress'],
                                         'cpu': ['Skylake', 'Broadwell', 'Haswell', 'Sandy Bridge', 'Ivy Bridge'],
                                         'gpu': 1, 'nested_virtualization': 1, 'sole_tenant': 1, 'regional_disk': 1})
    # C2
    # On Demand, SUD and specs
    c2_ram = data['CP-COMPUTEENGINE-C2-PREDEFINED-VM-RAM']
    c2_cpu = data['CP-COMPUTEENGINE-C2-PREDEFINED-VM-CORE']
    for k, v in c2_instance_types.items():
        output['c2'][k]['specs'].update({'cores': v['cpu'], 'memory': v['memory'], 'local_ssd': v['local_ssd'],
                                         'network_egress': v['network_egress'], 'cpu': ['Cascade Lake'],
                                         'regional_disk': 0, 'gpu': 0, 'sole_tenant': -1,
                                         'nested_virtualization': -1})
        for reg, c2_cpu_region_cost in c2_cpu.items():
            for reg2, c2_ram_region_cost in c2_ram.items():
                if reg == reg2:
                    output['c2'][k]['regions'][reg]['ondemand'] = nice(v['cpu'] * c2_cpu_region_cost + v[
                    'memory'] * c2_ram_region_cost)
                    output['c2'][k]['regions'][reg]['sud'] = nice(
                        c2_sud_discount * (v['cpu'] * c2_cpu_region_cost + v[
                            'memory'] * c2_ram_region_cost))
    # Preemptible
    c2_ram = data['CP-COMPUTEENGINE-C2-PREDEFINED-VM-RAM-PREEMPTIBLE']
    c2_cpu = data['CP-COMPUTEENGINE-C2-PREDEFINED-VM-CORE-PREEMPTIBLE']
    for k, v in c2_instance_types.items():
        for reg, c2_cpu_region_cost in c2_cpu.items():
            for reg2, c2_ram_region_cost in c2_ram.items():
                if reg == reg2:
                    output['c2'][k]['regions'][reg]['preemptible'] = nice(v['cpu'] * c2_cpu_region_cost + v[
                        'memory'] * c2_ram_region_cost)
    # CUD - 1 year
    c2_ram = data['CP-COMPUTEENGINE-C2-CUD-1-YEAR-RAM']
    c2_cpu = data['CP-COMPUTEENGINE-C2-CUD-1-YEAR-CPU']
    for k, v in c2_instance_types.items():
        for reg, c2_cpu_region_cost in c2_cpu.items():
            for reg2, c2_ram_region_cost in c2_ram.items():
                if reg == reg2:
                    output['c2'][k]['regions'][reg]['cud-1y'] = nice(v['cpu'] * c2_cpu_region_cost + v[
                        'memory'] * c2_ram_region_cost)
    # CUD - 3 year
    c2_ram = data['CP-COMPUTEENGINE-C2-CUD-3-YEAR-RAM']
    c2_cpu = data['CP-COMPUTEENGINE-C2-CUD-3-YEAR-CPU']
    for k, v in c2_instance_types.items():
        for reg, c2_cpu_region_cost in c2_cpu.items():
            for reg2, c2_ram_region_cost in c2_ram.items():
                if reg == reg2:
                    output['c2'][k]['regions'][reg]['cud-3y'] = nice(v['cpu'] * c2_cpu_region_cost + v[
                        'memory'] * c2_ram_region_cost)

    # A2
    # On Demand, SUD and specs
    a2_ram = data['CP-COMPUTEENGINE-A2-PREDEFINED-VM-RAM']
    a2_cpu = data['CP-COMPUTEENGINE-A2-PREDEFINED-VM-CORE']
    for k, v in a2_instance_types.items():
        output['a2'][k]['specs'].update({'cores': v['cpu'], 'memory': v['memory'], 'local_ssd': v['local_ssd'],
                                         'network_egress': v['network_egress'], 'cpu': ['Cascade Lake'],
                                         'regional_disk': 1, 'gpu': 1, 'sole_tenant': -1,
                                         'nested_virtualization': -1})
        for reg, a2_cpu_region_cost in a2_cpu.items():
            for reg2, a2_ram_region_cost in a2_ram.items():
                if reg == reg2:
                    output['a2'][k]['regions'][reg]['ondemand'] = nice(v['cpu'] * a2_cpu_region_cost + v[
                    'memory'] * a2_ram_region_cost)
                    output['a2'][k]['regions'][reg]['sud'] = nice(
                        a2_sud_discount * (v['cpu'] * a2_cpu_region_cost + v[
                            'memory'] * a2_ram_region_cost))
    # Preemptible
    a2_ram = data['CP-COMPUTEENGINE-A2-PREDEFINED-VM-RAM-PREEMPTIBLE']
    a2_cpu = data['CP-COMPUTEENGINE-A2-PREDEFINED-VM-CORE-PREEMPTIBLE']
    for k, v in a2_instance_types.items():
        for reg, a2_cpu_region_cost in a2_cpu.items():
            for reg2, a2_ram_region_cost in a2_ram.items():
                if reg == reg2:
                    output['a2'][k]['regions'][reg]['preemptible'] = nice(v['cpu'] * a2_cpu_region_cost + v[
                        'memory'] * a2_ram_region_cost)
    # CUD - 1 year
    a2_ram = data['CP-COMPUTEENGINE-A2-CUD-1-YEAR-RAM']
    a2_cpu = data['CP-COMPUTEENGINE-A2-CUD-1-YEAR-CPU']
    for k, v in a2_instance_types.items():
        for reg, a2_cpu_region_cost in a2_cpu.items():
            for reg2, a2_ram_region_cost in a2_ram.items():
                if reg == reg2:
                    output['a2'][k]['regions'][reg]['cud-1y'] = nice(v['cpu'] * a2_cpu_region_cost + v[
                        'memory'] * a2_ram_region_cost)
    # CUD - 3 year
    a2_ram = data['CP-COMPUTEENGINE-A2-CUD-3-YEAR-RAM']
    a2_cpu = data['CP-COMPUTEENGINE-A2-CUD-3-YEAR-CPU']
    for k, v in a2_instance_types.items():
        for reg, a2_cpu_region_cost in a2_cpu.items():
            for reg2, a2_ram_region_cost in a2_ram.items():
                if reg == reg2:
                    output['a2'][k]['regions'][reg]['cud-3y'] = nice(v['cpu'] * a2_cpu_region_cost + v[
                        'memory'] * a2_ram_region_cost)

    # M1
    # On Demand and SUD
    m1_ram = data['CP-COMPUTEENGINE-M1-PREDEFINED-VM-RAM']
    m1_cpu = data['CP-COMPUTEENGINE-M1-PREDEFINED-VM-CORE']
    for k, v in m1_instance_types.items():
        if 'ultramem' in k:
            output['m1'][k]['specs'].update({'cores': v['cpu'], 'memory': v['memory'], 'local_ssd': v['local_ssd'],
                                             'network_egress': v['network_egress'],
                                             'cpu': ['Skylake', 'Broadwell E5'], 'gpu': -1, 'sole_tenant': -1,
                                             'nested_virtualization': -1})
        if 'megamem' in k:
            output['m1'][k]['specs'].update({'cores': v['cpu'], 'memory': v['memory'], 'local_ssd': v['local_ssd'],
                                             'network_egress': v['network_egress'],
                                             'cpu': ['Cascade Lake', 'Broadwell E7'], 'gpu': -1, 'sole_tenant': -1,
                                             'nested_virtualization': -1, 'regional_disk': 0})
        for reg, m1_cpu_region_cost in m1_cpu.items():
            for reg2, m1_ram_region_cost in m1_ram.items():
                if reg == reg2:
                    output['m1'][k]['regions'][reg]['ondemand'] = nice(v['cpu'] * m1_cpu_region_cost + v[
                        'memory'] * m1_ram_region_cost)
                    output['m1'][k]['regions'][reg]['sud'] = nice(
                        m1_sud_discount * (v['cpu'] * m1_cpu_region_cost + v[
                            'memory'] * m1_ram_region_cost))
    # Preemptible
    m1_ram = data['CP-COMPUTEENGINE-M1-PREDEFINED-VM-RAM-PREEMPTIBLE']
    m1_cpu = data['CP-COMPUTEENGINE-M1-PREDEFINED-VM-CORE-PREEMPTIBLE']
    for k, v in m1_instance_types.items():
        for reg, m1_cpu_region_cost in m1_cpu.items():
            for reg2, m1_ram_region_cost in m1_ram.items():
                if reg == reg2:
                    output['m1'][k]['regions'][reg]['preemptible'] = nice(v['cpu'] * m1_cpu_region_cost + v[
                        'memory'] * m1_ram_region_cost)
    # CUD - 1 year
    m1_ram = data['CP-COMPUTEENGINE-M1-CUD-1-YEAR-RAM']
    m1_cpu = data['CP-COMPUTEENGINE-M1-CUD-1-YEAR-CPU']
    for k, v in m1_instance_types.items():
        for reg, m1_cpu_region_cost in m1_cpu.items():
            for reg2, m1_ram_region_cost in m1_ram.items():
                if reg == reg2:
                    output['m1'][k]['regions'][reg]['cud-1y'] = nice(v['cpu'] * m1_cpu_region_cost + v[
                        'memory'] * m1_ram_region_cost)
    # CUD - 3 year
    m1_ram = data['CP-COMPUTEENGINE-M1-CUD-3-YEAR-RAM']
    m1_cpu = data['CP-COMPUTEENGINE-M1-CUD-3-YEAR-CPU']
    for k, v in m1_instance_types.items():
        for reg, m1_cpu_region_cost in m1_cpu.items():
            for reg2, m1_ram_region_cost in m1_ram.items():
                if reg == reg2:
                    output['m1'][k]['regions'][reg]['cud-3y'] = nice(v['cpu'] * m1_cpu_region_cost + v[
                        'memory'] * m1_ram_region_cost)

    # M2
    # On Demand and SUD
    m2_ram = data['CP-COMPUTEENGINE-M2-PREDEFINED-VM-RAM']
    m2_cpu = data['CP-COMPUTEENGINE-M2-PREDEFINED-VM-CORE']
    for k, v in m2_instance_types.items():
        output['m2'][k]['specs'].update({'cores': v['cpu'], 'memory': v['memory'], 'local_ssd': v['local_ssd'],
                                         'network_egress': v['network_egress'], 'cpu': ['Cascade Lake'], 'gpu': -1,
                                         'sole_tenant': -1, 'nested_virtualization': -1, 'regional_disk': 1})
        for reg, m2_cpu_region_cost in m2_cpu.items():
            for reg2, m2_ram_region_cost in m2_ram.items():
                if reg == reg2:
                    output['m2'][k]['regions'][reg]['ondemand'] = nice(v['cpu'] * m2_cpu_region_cost + v[
                        'memory'] * m2_ram_region_cost)
                    output['m2'][k]['regions'][reg]['sud'] = nice(
                        m2_sud_discount * (v['cpu'] * m2_cpu_region_cost + v[
                            'memory'] * m2_ram_region_cost))
    # CUD - 1 year
    m2_ram = data['CP-COMPUTEENGINE-M2-CUD-1-YEAR-RAM']
    m2_cpu = data['CP-COMPUTEENGINE-M2-CUD-1-YEAR-CPU']
    for k, v in m2_instance_types.items():
        for reg, m2_cpu_region_cost in m2_cpu.items():
            for reg2, m2_ram_region_cost in m2_ram.items():
                if reg == reg2:
                    output['m2'][k]['regions'][reg]['cud-1y'] = nice(v['cpu'] * m2_cpu_region_cost + v[
                        'memory'] * m2_ram_region_cost)
    # CUD - 3 year
    m2_ram = data['CP-COMPUTEENGINE-M2-CUD-3-YEAR-RAM']
    m2_cpu = data['CP-COMPUTEENGINE-M2-CUD-3-YEAR-CPU']
    for k, v in m2_instance_types.items():
        for reg, m2_cpu_region_cost in m2_cpu.items():
            for reg2, m2_ram_region_cost in m2_ram.items():
                if reg == reg2:
                    output['m2'][k]['regions'][reg]['cud-3y'] = nice(v['cpu'] * m2_cpu_region_cost + v[
                        'memory'] * m2_ram_region_cost)

    # N2
    # On Demand and SUD
    n2_ram = data['CP-COMPUTEENGINE-N2-PREDEFINED-VM-RAM']
    n2_cpu = data['CP-COMPUTEENGINE-N2-PREDEFINED-VM-CORE']
    for k, v in n2_instance_types.items():
        output['n2'][k]['specs'].update({'cores': v['cpu'], 'memory': v['memory'], 'local_ssd': v['local_ssd'],
                                         'network_egress': v['network_egress'], 'cpu': ['Cascade Lake'], 'gpu': 0,
                                         'sole_tenant': 1, 'nested_virtualization': 1, 'regional_disk': 1})
        for reg, n2_cpu_region_cost in n2_cpu.items():
            for reg2, n2_ram_region_cost in n2_ram.items():
                if reg == reg2:
                    output['n2'][k]['regions'][reg]['ondemand'] = nice(v['cpu'] * n2_cpu_region_cost + v[
                        'memory'] * n2_ram_region_cost)
                    output['n2'][k]['regions'][reg]['sud'] = nice(
                        n2_sud_discount * (v['cpu'] * n2_cpu_region_cost + v[
                            'memory'] * n2_ram_region_cost))
    # Preemptible
    n2_ram = data['CP-COMPUTEENGINE-N2-PREDEFINED-VM-RAM-PREEMPTIBLE']
    n2_cpu = data['CP-COMPUTEENGINE-N2-PREDEFINED-VM-CORE-PREEMPTIBLE']
    for k, v in n2_instance_types.items():
        for reg, n2_cpu_region_cost in n2_cpu.items():
            for reg2, n2_ram_region_cost in n2_ram.items():
                if reg == reg2:
                    output['n2'][k]['regions'][reg]['preemptible'] = nice(v['cpu'] * n2_cpu_region_cost + v[
                        'memory'] * n2_ram_region_cost)
    # CUD - 1 year
    n2_ram = data['CP-COMPUTEENGINE-N2-CUD-1-YEAR-RAM']
    n2_cpu = data['CP-COMPUTEENGINE-N2-CUD-1-YEAR-CPU']
    for k, v in n2_instance_types.items():
        for reg, n2_cpu_region_cost in n2_cpu.items():
            for reg2, n2_ram_region_cost in n2_ram.items():
                if reg == reg2:
                    output['n2'][k]['regions'][reg]['cud-1y'] = nice(v['cpu'] * n2_cpu_region_cost + v[
                        'memory'] * n2_ram_region_cost)
    # CUD - 3 year
    n2_ram = data['CP-COMPUTEENGINE-N2-CUD-3-YEAR-RAM']
    n2_cpu = data['CP-COMPUTEENGINE-N2-CUD-3-YEAR-CPU']
    for k, v in n2_instance_types.items():
        for reg, n2_cpu_region_cost in n2_cpu.items():
            for reg2, n2_ram_region_cost in n2_ram.items():
                if reg == reg2:
                    output['n2'][k]['regions'][reg]['cud-3y'] = nice(v['cpu'] * n2_cpu_region_cost + v[
                        'memory'] * n2_ram_region_cost)
    # N1 CUDS
    # CUD - 1 year
    n1_ram = data['CP-COMPUTEENGINE-N1-CUD-1-YEAR-RAM']
    n1_cpu = data['CP-COMPUTEENGINE-N1-CUD-1-YEAR-CPU']
    for k, v in n1_instance_types.items():
        for reg, n1_cpu_region_cost in n1_cpu.items():
            for reg2, n1_ram_region_cost in n1_ram.items():
                if reg == reg2:
                    output['n1'][k]['regions'][reg]['cud-1y'] = nice(v['cpu'] * n1_cpu_region_cost + v[
                        'memory'] * n1_ram_region_cost)
    # CUD - 3 year
    n1_ram = data['CP-COMPUTEENGINE-N1-CUD-3-YEAR-RAM']
    n1_cpu = data['CP-COMPUTEENGINE-N1-CUD-3-YEAR-CPU']
    for k, v in n1_instance_types.items():
        for reg, n1_cpu_region_cost in n1_cpu.items():
            for reg2, n1_ram_region_cost in n1_ram.items():
                if reg == reg2:
                    output['n1'][k]['regions'][reg]['cud-3y'] = nice(v['cpu'] * n1_cpu_region_cost + v[
                        'memory'] * n1_ram_region_cost)

    # N2D
    # On Demand and SUD
    n2d_ram = data['CP-COMPUTEENGINE-N2D-PREDEFINED-VM-RAM']
    n2d_cpu = data['CP-COMPUTEENGINE-N2D-PREDEFINED-VM-CORE']
    for k, v in n2d_instance_types.items():
        output['n2d'][k]['specs'].update({'cores': v['cpu'], 'memory': v['memory'], 'local_ssd': v['local_ssd'],
                                          'network_egress': v['network_egress'], 'cpu': ['AMD EPYC Rome'], 'gpu': 0,
                                          'sole_tenant': 0, 'nested_virtualization': 0, 'regional_disk': 1})
        for reg, n2d_cpu_region_cost in n2d_cpu.items():
            for reg2, n2d_ram_region_cost in n2d_ram.items():
                if reg == reg2:
                    output['n2d'][k]['regions'][reg]['ondemand'] = nice(v['cpu'] * n2d_cpu_region_cost + v[
                        'memory'] * n2d_ram_region_cost)
                    output['n2d'][k]['regions'][reg]['sud'] = nice(n2d_sud_discount * (
                            v['cpu'] * n2d_cpu_region_cost + v[
                        'memory'] * n2d_ram_region_cost))
    # Preemptible
    n2d_ram = data['CP-COMPUTEENGINE-N2D-PREDEFINED-VM-RAM-PREEMPTIBLE']
    n2d_cpu = data['CP-COMPUTEENGINE-N2D-PREDEFINED-VM-CORE-PREEMPTIBLE']
    for k, v in n2d_instance_types.items():
        for reg, n2d_cpu_region_cost in n2d_cpu.items():
            for reg2, n2d_ram_region_cost in n2d_ram.items():
                if reg == reg2:
                    output['n2d'][k]['regions'][reg]['preemptible'] = nice(v['cpu'] * n2d_cpu_region_cost + v[
                        'memory'] * n2d_ram_region_cost)
    # CUD - 1 year
    n2d_ram = data['CP-COMPUTEENGINE-N2D-CUD-1-YEAR-RAM']
    n2d_cpu = data['CP-COMPUTEENGINE-N2D-CUD-1-YEAR-CPU']
    for k, v in n2d_instance_types.items():
        for reg, n2d_cpu_region_cost in n2d_cpu.items():
            for reg2, n2d_ram_region_cost in n2d_ram.items():
                if reg == reg2:
                    output['n2d'][k]['regions'][reg]['cud-1y'] = nice(v['cpu'] * n2d_cpu_region_cost + v[
                        'memory'] * n2d_ram_region_cost)
    # CUD - 3 year
    n2d_ram = data['CP-COMPUTEENGINE-N2D-CUD-3-YEAR-RAM']
    n2d_cpu = data['CP-COMPUTEENGINE-N2D-CUD-3-YEAR-CPU']
    for k, v in n2d_instance_types.items():
        for reg, n2d_cpu_region_cost in n2d_cpu.items():
            for reg2, n2d_ram_region_cost in n2d_ram.items():
                if reg == reg2:
                    output['n2d'][k]['regions'][reg]['cud-3y'] = nice(v['cpu'] * n2d_cpu_region_cost + v[
                        'memory'] * n2d_ram_region_cost)

    # e2
    # On Demand and SUD
    e2_ram = data['CP-COMPUTEENGINE-E2-PREDEFINED-VM-RAM']
    e2_cpu = data['CP-COMPUTEENGINE-E2-PREDEFINED-VM-CORE']
    for k, v in e2_instance_types.items():
        output['e2'][k]['specs'].update({'cores': v['cpu'], 'memory': v['memory'], 'local_ssd': v['local_ssd'],
                                         'network_egress': v['network_egress'],
                                         'cpu': ['Skylake', 'Broadwell', 'Haswell', 'AMD EPYC Rome (coming soon)'],
                                         'gpu': 0, 'sole_tenant': 0, 'nested_virtualization': 0, 'regional_disk': 1})
        for reg, e2_cpu_region_cost in e2_cpu.items():
            for reg2, e2_ram_region_cost in e2_ram.items():
                if reg == reg2:
                    output['e2'][k]['regions'][reg]['ondemand'] = nice(v['cpu'] * e2_cpu_region_cost + v[
                        'memory'] * e2_ram_region_cost)
                    output['e2'][k]['regions'][reg]['sud'] = nice(e2_sud_discount * (
                            v['cpu'] * e2_cpu_region_cost + v[
                        'memory'] * e2_ram_region_cost))
    # Preemptible
    e2_ram = data['CP-COMPUTEENGINE-E2-PREDEFINED-VM-RAM-PREEMPTIBLE']
    e2_cpu = data['CP-COMPUTEENGINE-E2-PREDEFINED-VM-CORE-PREEMPTIBLE']
    for k, v in e2_instance_types.items():
        for reg, e2_cpu_region_cost in e2_cpu.items():
            for reg2, e2_ram_region_cost in e2_ram.items():
                if reg == reg2:
                    output['e2'][k]['regions'][reg]['preemptible'] = nice(v['cpu'] * e2_cpu_region_cost + v[
                        'memory'] * e2_ram_region_cost)
    # CUD - 1 year
    e2_ram = data['CP-COMPUTEENGINE-E2-CUD-1-YEAR-RAM']
    e2_cpu = data['CP-COMPUTEENGINE-E2-CUD-1-YEAR-CPU']
    for k, v in e2_instance_types.items():
        for reg, e2_cpu_region_cost in e2_cpu.items():
            for reg2, e2_ram_region_cost in e2_ram.items():
                if reg == reg2:
                    output['e2'][k]['regions'][reg]['cud-1y'] = nice(v['cpu'] * e2_cpu_region_cost + v[
                        'memory'] * e2_ram_region_cost)
    # CUD - 3 year
    e2_ram = data['CP-COMPUTEENGINE-E2-CUD-3-YEAR-RAM']
    e2_cpu = data['CP-COMPUTEENGINE-E2-CUD-3-YEAR-CPU']
    for k, v in e2_instance_types.items():
        for reg, e2_cpu_region_cost in e2_cpu.items():
            for reg2, e2_ram_region_cost in e2_ram.items():
                if reg == reg2:
                    output['e2'][k]['regions'][reg]['cud-3y'] = nice(v['cpu'] * e2_cpu_region_cost + v[
                        'memory'] * e2_ram_region_cost)

    # print json output
    print(json.dumps(output))


text:
<repo_name>JessCheung128/42-Piscine<file_sep>/Revision/exam02/aff_first_param.c
/* Write a program that takes strings as arguments, and displays its first argument followed by a \n.*/

#include <unistd.h>

int main (int ac, char **av)
{
	if (ac > 1)
		while (*av[1])
			write (1, av[1]++, 1);
	write (1, "\n", 1);
	return (0);
}
<file_sep>/Revision/exam02/ft_countdown.c
/*Write a program that displays all digits in descending order, followed by a
newline.*/

#include <unistd.h>

int main(void)
{
	write(1, "9876543210\n",11);
	return(0);
}
<file_sep>/Revision/exam02/aff_last_param.c
/*Write a program that takes strings as arguments, and displays its last
argument followed by a newline. If the number of arguments is less than 1, the program displays a newline*/

#include <unistd.h>

int main(int argc, char *argv[])
{
	int i;

	i = 0;
	if (argc > 1)
	{
		while(argv[argc - 1] [i])
			write(1, &argv[argc - 1] [i++], 1);
	}
	write(1, "\n", 1);
	return(0);
}
<file_sep>/Revision/exam02/aff_a.c
/* Write a program that takes a string, and displays the first 'a' character it
encounters in it, followed by a newline. If there are no 'a' characters in the
string, the program just writes a newline. If the number of parameters is not
1, the program displays 'a' followed by a newline.*/

#include <unistd.h>

int main(int ac, char **av)
{
	int i;

	i = 0;
	if (ac != 2)
		write(1, "a\n" 2);
	else
	{
		while (av[1][i])
		{
			if (av[1][i] != 'a')
				i++;
			else
			{
				write(1, "a", 1);
				break;
			}
		}
			write(1, "\n", 1);
		}
		return (0);
}
<file_sep>/j01/ex04/MAC.sh
ifconfig -a ether |grep ether | cut -d " " -f 2
<file_sep>/j09/ex02/find_nicolas_bauer.sh
cat $1 | grep -i "<NAME>" |
<file_sep>/j01/ex03/count_files.sh
find . \( -type f -or -type d \) | wc -l | tr -d "\t " | cat -e

branch_name: refs/heads/master

languages: C Shell

repo_language: C


text:
<repo_name>Crumbls/common-passwords<file_sep>/src/Migrations/2021_08_30_000010_create_common_passwords_table.php
<?php declare(strict_types=1);

use Crumbls\CommonPasswords\Models\Password;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCommonPasswordsTable extends Migration
{
    /**
     * Get the table.
     * @return string
     */
    private function getTable() : string {
        $model = Password::class;
        $table = with(new $model)->getTable();
        return $table;
    }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up(): void {
        Schema::create($this->getTable(), function (Blueprint $table) {
            $table->id();
            $table->string('password')->unique();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down() : void {
        Schema::drop($this->getTable());
    }
}
<file_sep>/src/Providers/CommonPasswordServiceProvider.php
<?php

namespace Crumbls\CommonPasswords\Providers;

use Crumbls\CommonPasswords\Commands\Install;
use Illuminate\Support\ServiceProvider;

class CommonPasswordServiceProvider extends ServiceProvider
{
    public function register()
    {
        //
    }

    public function boot()
    {
        $this->loadMigrationsFrom(dirname(__DIR__).'/Migrations/');
        $this->commands([Install::class]);
    }
}
<file_sep>/src/Commands/Install.php
<?php

namespace Crumbls\CommonPasswords\Commands;

use Crumbls\CommonPasswords\Seeders\CommonPasswordsSeeder;
use Illuminate\Console\Command;

class Install extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'common-passwords:install';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Install the common passwords migration and data.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        /**
         * Run our migration.
         */

        $files = glob(dirname(__DIR__).'/Migrations/*.php');
        $x = count($files);
        if ($x > 1) {
            $this->info('Running migrations.');
        } else if ($x) {
            $this->info('Running migration.');
        }
        $x = strlen(base_path());
        foreach($files as $file) {
            $file = substr($file, $x);
            $temp = sprintf('migrate:refresh --path=%s', $file);
            $response = \Artisan::call($temp);
        }

        $this->info('Running seeder.');
        $seeder = new CommonPasswordsSeeder();
        $seeder->run();
//        $temp = sprintf('db:seed --class="\%s"', CommonPasswordsSeeder::class);
  //      $response = \Artisan::call($temp);

        $this->info('Done!');
    }

}
<file_sep>/src/Models/Password.php
<?php

namespace Crumbls\CommonPasswords\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Class Password
 * @package Crumbls\CommonPasswords\Models
 */
class Password extends Model
{
    protected $table = 'common_passwords';
    public $timestamps = false;
}
<file_sep>/src/Seeders/CommonPasswordsSeeder.php
<?php

namespace Crumbls\CommonPasswords\Seeders;

use Crumbls\CommonPasswords\Models\Password;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

class CommonPasswordsSeeder extends Seeder
{
    /**
     * Run the database seeders.
     *
     * @return void
     */
    public function run()
    {
        $file = dirname(dirname(__DIR__)).'/invalid-passwords.txt';
        $content = \File::get($file);
        $content = array_filter(preg_split("/\r\n|\n|\r/", $content));
        $content = array_chunk($content, 20);

        $model = Password::class;
        $table = with(new $model)->getTable();

        foreach($content as $idx => $chunk) {
            $chunk = array_map(function($e) {
                return ['password' => $e];
            }, $chunk);
            \DB::table($table)->insertOrIgnore($chunk);
        }
    }
}
<file_sep>/src/Rules/NotCommonPassword.php
<?php

namespace Crumbls\CommonPasswords\Rules;

use Crumbls\CommonPasswords\Models\Password;
use Illuminate\Contracts\Validation\Rule;

class NotCommonPassword implements Rule {
    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value) : bool
    {
        if (!is_string($value)) {
            return false;
        }
        if (!$value) {
            return false;
        }

        $model = Password::class;
        $table = with(new $model)->getTable();

        return !\DB::table($table)->where('password', $value)->count();
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return ':attribute can not be a commonly used password.';
    }
}

<file_sep>/README.md
# common-passwords
A simple package to validate against common passwords and help keep your application secure.

```shell
composer require crumbls/common-passwords
```

* php artisan common-passwords:install
* Add the \Crumbls\CommonPasswords\Rules\NotCommonPassword() rule to your password field.
   * Best practice says that the best place to do this is to put it into your registration and password recovery validators.
* You can add any extra passwords using the \Crumbls\CommonPasswords\Models\Password model.  It only has one field: password

Attached is a simple example that can be ran from anywhere.  It will throw a validation exception because we are
verifying the password "<PASSWORD>" which is a commonly used password.

```php
try {
    $validator = \Illuminate\Support\Facades\Validator::make([
        'password' => '<PASSWORD>'
    ], [
        'password' => [
            'required',
            'string',
            'min:1',
            'max:256',
            new \Crumbls\CommonPasswords\Rules\NotCommonPassword()
        ],
    ]);
    print_r($validator->validated());
} catch (\Illuminate\Validation\ValidationException $e) {
    echo $e->getMessage();
}
```

Since authentication and registration are commonly reinvented based on the application, this is an example
of how you could do it in a very basic RegistrationController out of Laravel 8.x.  This would overwrite your
validator method.

```php
 /**
     * Get a validator for an incoming registration request.
     *
     * @param  array $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed', new \Crumbls\CommonPasswords\Rules\NotCommonPassword()],
        ]);
    }
```

I've had a people ask if you can use this to directly check if a user's password is on this list.  It's a horrible idea
because of the resources it consumes and this is just brute force testing.  That is why you should verify it when you
are setting the password.  But, if you need to for some reason, here is a simple sample on how to do it.

```php
// Take a random user.  You should be more pointed than this.
$user = \App\Models\User::inRandomOrder()->take(1)->first();
    $passwords = \Crumbls\CommonPasswords\Models\Password::orderBy(
        with(new \Crumbls\CommonPasswords\Models\Password())->getKeyName(),
        'asc'
    )->get();
    foreach($passwords as $password) {
        if (\Hash::check($password->password, $user->password)) {
            printf('User had an invalid password: %s .', $password->password);
            break;
        }
    }
```

The documentation is sparse.  If you have any questions, feel free to ask here or on twitter @chasecmiller
Remember that this is only designed to be a validation rule.

branch_name: refs/heads/main

languages: Markdown PHP

repo_language: Markdown

repo_name: Crumbls/common-passwords


text:
<file_sep># sandbox-loopback

<file_sep>module.exports = function(app) {
  app.dataSources.mysqlDatasource.automigrate('Recipe');
};
<file_sep>module.exports = function (Recipe) {

};
<file_sep>module.exports = function(RecipeIngredient) {

};

languages: Markdown JavaScript

repo_name: adamdonahue/sandbox-loopback


text:
<repo_name>Tenkir/daft-labs-site<file_sep>/README.md
# daft-labs-site
<file_sep>/app/index.jade
extends layouts/default

block content
  #frontPageHeader
    canvas#headerCanvas(height="600px")
    .headerContent
      img#moonsvg.moon(src="/images/thats_no_moon.svg")
      .companyName
        h1 daft labs
      .socialLinks
        a(href="https://github.com/daftlabs")
          img.socialImage(src="/images/github_logo.png" srcset="/images/github_logo@2x.png 2x, /images/github_logo.png 1x")
  #frontPageInfo
    .content
      img(src="/images/vt_stroke.png")
      p Made in VT at Daft Labs

languages: Markdown Pug

repo_name: Tenkir/daft-labs-site


text:
<file_sep>FROM ubuntu:focal
LABEL maintainer "<NAME> <<EMAIL>>"

ARG USER=all
ARG HOME=/home/all

ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV TZ Asia/Tokyo

RUN apt-get update && \
    apt-get install -y \
        gosu locales tzdata build-essential \
        coreutils moreutils dnsutils net-tools iproute2 iputils-ping iputils-arping traceroute curl wget \
        openssh-client telnet bash zsh csh fish tmux screen vim neovim && \
    apt-get clean && \
    rm -rf /var/lib/apt/list/*

RUN locale-gen en_US.UTF-8
RUN useradd -m -d $HOME -s /usr/bin/fish $USER

ADD entrypoint.sh /sbin/entrypoint.sh
RUN chmod +x /sbin/entrypoint.sh

USER $USER
WORKDIR $HOME

ENTRYPOINT ["/sbin/entrypoint.sh"]
CMD ["/usr/bin/fish"]
<file_sep>build:
	docker build . -t docker.pkg.github.com/yamaoka-kitaguchi-lab/dockersh/dockersh-ubuntu:latest
<file_sep># dockersh
![Docker Build](https://github.com/yamaoka-kitaguchi-lab/dockersh/workflows/Docker%20Build/badge.svg?branch=master)

廃棄可能なSSH踏み台サーバ。研究室生活線・マネジメント線踏み台用のDockerイメージなので，他所では使えない。
公開鍵認証は[yamaoka-kitaguchi-lab/publickeys](https://github.com/yamaoka-kitaguchi-lab/publickeys)を併用する前提の設計。
<file_sep>#!/bin/bash

COMMAND="$@"

echob(){ echo -e "\033[0;34m$@\033[0m"; }

echob "New container: $(hostname)"
echob "Command: $COMMAND"

exec $COMMAND
<file_sep>#!/bin/bash

IMAGE="docker.pkg.github.com/yamaoka-kitaguchi-lab/dockersh/dockersh-ubuntu:latest"
MEMORY=64mb
DNS1=10.0.5.55
DNS2=10.0.5.56
HOSTNAME="fumidai-life-$(openssl rand -base64 12 2> /dev/null | md5sum | cut -b 1-7)"

(( $# == 0 )) && is_empty_command=true || is_empty_command=false
(( $# > 1 )) && [[ $1 == '-c' ]] && ARGS="${@:2:($#-1)}" || ARGS="$@"
(( ${#ARGS[@]} == 1 )) && ! $is_empty_command && is_single_command=true || is_single_command=false

echox(){
    (( $# < 2 )) && echo
    local level="$1"
    local message="$2"
    case $level in
        "W")
            echo -e "\033[1;31m[ WARNING ] $message\033[0m" ;;
        "C")
            echo -e "\033[0;31m[ CAUTION ] $message\033[0m" ;;
        "S")
            echo -e "\033[1;34m[ SUCCESS ] $message\033[0m" ;;
    esac
}

echox; echox
echox W "All changes will be lost"
echox C "You are going to log into a container - a private space which is isolated from physical environment"
echox C "This container is automatically created and destroyed for every new session"

if ! $is_empty_command; then
    option="-i"
    cmd="/bin/bash -c $ARGS"
else
    option="-it"
    cmd=""
    echox S "Allocate a pseudo-TTY"
fi

echox; echox

docker run --rm $option -h $HOSTNAME --name $HOSTNAME \
           --memory=${MEMORY} --dns=${DNS1} --dns=${DNS2} \
           $IMAGE $cmd

echox; echox
echox S "Your container has been destroyed"
echox; echox

languages: Makefile Markdown Shell Dockerfile

repo_language: Makefile

repo_name: yamaoka-kitaguchi-lab/dockersh


text:
<repo_name>mromanjr93/ftp-watcher<file_sep>/Dockerfile
FROM ubuntu:14.04
MAINTAINER <NAME>

ENV USER ftpuser
ENV PASS <PASSWORD>

RUN apt-get update && \
    apt-get install -y vsftpd supervisor curl inotify-tools && \
    mkdir -p /var/run/vsftpd/empty && \
    mkdir -p /var/log/supervisord && \
    chmod -R 777 /var/log/supervisord

RUN mkdir -p /var/log/supervisor

COPY conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
ADD scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
ADD scripts/watcher.sh /usr/local/bin/watcher.sh
ADD conf/vsftpd.conf /etc/vsftpd.conf

RUN chmod +x /usr/local/bin/entrypoint.sh && chmod +x /usr/local/bin/watcher.sh

RUN mkdir /ftp

VOLUME ["/ftp"]

EXPOSE 20 21
EXPOSE 12020 12021 12022 12023 12024 12025

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

CMD ["/usr/bin/supervisord"]<file_sep>/docker-compose.yml
version: '3'
services:
  vftpd:
    build: .
    ports:
     - "21:21"
     - "22:22" <file_sep>/scripts/watcher.sh
#!/bin/bash
MONITORDIR="/ftp/$USER/files/"

inotifywait -m -r  --format '%w%f' "${MONITORDIR}" -e moved_to -e create |
        while read -r path; do
            filepath="${path}"
            echo "pasta: '${path}'"
        done

languages: Shell Dockerfile YAML

repo_language: Shell


text:
<repo_name>pz8l8t/terraform-common-modules<file_sep>/README.md
# terraform-common-modules
Terraform Training Repo


text:
<file_sep>/**
 *
 */
package com.dsa.mtech.adt.impl;

import java.util.LinkedList;
import java.util.Queue;

import com.dsa.mtech.adt.spec.Node;
import com.dsa.mtech.adt.spec.Tree;

/**
 * @author shivaak on 02-Feb-2019
 *
 */
public class BinarySearchTree implements Tree<Integer>{

	public Node<Integer> root;

	private Queue<Node<Integer>> queue;

	public BinarySearchTree() {
		root = null;
		queue = new LinkedList<Node<Integer>>();
	}

	public void insert(Integer d) {
		this.root = insert(this.root, d);
	}

	@Override
	public Node<Integer> insert(Node<Integer> current, Integer data) {
		if(current==null) {
			current = new Node<Integer>(data);
			return current;
		}
		if(data <= current.data) {
			current.left = insert(current.left, data);
		}else {
			current.right = insert(current.right, data);
		}
		return current;
	}

	@Override
	public Node<Integer> remove(Node<Integer> root, Integer data) {
		return null;
	}

	public Integer countNodes() {
		return this.countNodes(this.root);
	}

	@Override
	public Integer countNodes(Node<Integer> current) {
		if(current==null) return 0;

		int nodes = 1;

		if(current.left!=null)  nodes += countNodes(current.left);
		if(current.right!=null) nodes += countNodes(current.right);

		return nodes;
	}

	public Integer countLeaf() {
		return this.countLeaf(this.root);
	}

	@Override
	public Integer countLeaf(Node<Integer> current) {
		if(current==null) return 0;

		if(current.left == null && current.right == null)
			return 1;

		return countLeaf(current.left) + countLeaf(current.right);
	}

	public Boolean search(Integer data) {
		return this.search(this.root,data);
	}

	@Override
	public Boolean search(Node<Integer> current, Integer data) {
		if(current==null) return false;

		if(current.data==data) return true;

		if(data<=current.data)
			return search(current.left,data);
		else
			return search(current.right,data);
	}

	public void inOrder() {
		inOrder(this.root);
	}

	@Override
	public void inOrder(Node<Integer> current) {
		if(current==null) System.out.println("Tree is not created");

		if(current.left!=null) {
			inOrder(current.left);
		}
		System.out.print(current.data + " ");

		if(current.right!=null) {
			inOrder(current.right);
		}

	}

	public void preOrder() {
		this.preOrder(this.root);
	}

	@Override
	public void preOrder(Node<Integer> current) {
		if(current==null) System.out.println("Tree is not created");

		System.out.print(current.data + " ");

		if(current.left!=null) preOrder(current.left);
		if(current.right!=null) preOrder(current.right);

	}

	public void postOrder() {
		this.postOrder(this.root);
	}

	@Override
	public void postOrder(Node<Integer> current) {
		if(current!=null) {
			postOrder(current.left);
			postOrder(current.right);
			System.out.println(current.data);
		}

	}

	public void levelOrder() {
		this.levelOrder(this.root);
	}

	@Override
	public void levelOrder(Node<Integer> current) {
		if(current==null) return;

		System.out.print(current.data + " ");
		if(current.left!=null)queue.add(current.left);
		if(current.right!=null)queue.add(current.right);

		Node<Integer> nextNode = queue.remove();

		levelOrder(nextNode);
	}

	public Integer findMin() {
		return findMin(root);
	}

	@Override
	public Integer findMin(Node<Integer> root) {
		if(root==null) return null;

		if(root.left!=null) return findMin(root.left);

		return root.data;
	}

	public Integer findMax() {
		return findMax(root);
	}

	@Override
	public Integer findMax(Node<Integer> root) {
		if(root==null) return null;
		if(root.right!=null) return findMax(root.right);
		return root.data;
	}

	public Integer findHeight() {
		return findHeight(this.root);
	}

	@Override
	public Integer findHeight(Node<Integer> current) {
		if(current==null) return 0;
		int Lheight = 0;
		int Rheight = 0;
		if(current.left!=null) Lheight = findHeight(current.left);
		if(current.right!=null) Rheight = findHeight(current.right);
		return Math.max(Lheight, Rheight) + 1;
	}

	@Override
	public void printAllPaths(Node<Integer> root) {
		// TODO Auto-generated method stub

	}

	@Override
	public void printAllLeafs(Node<Integer> root) {
		// TODO Auto-generated method stub

	}

	public Boolean isBinarySearchTree() {
		return this.isBinarySearchTree(this.root);
	}

	@Override
	public Boolean isBinarySearchTree(Node<Integer> current) {
		if(current==null) return true; //NULL is considered as binary tree

		Boolean result = true;

		if(current.left!=null && current.left.data>current.data) result = false;
		if(current.right!=null && current.right.data<=current.data) result = false;

		return result && isBinarySearchTree(current.left) && isBinarySearchTree(current.right);
	}

	@Override
	public void balanceTheTree(Node<Integer> root) {
		// TODO Auto-generated method stub

	}

	@Override
	public String findPathTo(Node<Integer> root, Integer data) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer greatestCommonAncestor(Node<Integer> root, Integer d1, Integer d2) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer[] printPostOrder(Integer[] in, Integer[] pre) {
		// TODO Auto-generated method stub
		return null;
	}

}
<file_sep>/**
 *
 */
package com.dsa.mtech.adt.spec;

/**
 * @author shivaak on 02-Feb-2019
 *
 */
public class Node<T> {

	public T data;
	public Node<T> left;
	public Node<T> right;

	public Node(T data){
		this.data = data;
		this.left = null;
		this.right = null;
	}

}
<file_sep>/**
 *
 */
package com.dsa.mtech;

/**
 * @author shivaak on 18-Jan-2019
 *
 */

public class SelectionSort {

	public static int[] sort_recursive(int arr[], int start, int end) {
		if(start == end) {
			return arr;
		}

		int minIndex = start;
		for(int i=start; i<end; i++) {
			if(arr[i]<arr[minIndex]) {
				minIndex = i;
			}
		}
		if(minIndex!=start)swap(arr, start, minIndex);

		return sort_recursive(arr, start+1, end);
	}

	public static int[] sort_iterative(int arr[], int n) {
		for(int i=0;i<n;i++) {
			int minIndex=i;
			for(int j=i;j<n;j++) {
				if(arr[j]< arr[minIndex]) {
					minIndex=j;
				}
			}
			//swap only if required
			if(minIndex!=i) swap(arr,i,minIndex);
		}
		return arr;
	}

	private static void swap(int[] arr, int i, int minIndex) {
		int t =arr[i];
		arr[i]=arr[minIndex];
		arr[minIndex] = t;
	}

	private static void print(int arr[]) {
		for (int i : arr) {
			System.out.print(i + " ");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		print(sort_iterative(new int[] {34, 56,12,54,11,10,87,65}, 8));
		print(sort_iterative(new int[] {8,5,3,9,1}, 5));
		print(sort_iterative(new int[] {1,2,3,4,5}, 5));

		print(sort_recursive(new int[] {34, 56,12,54,11,10,87,65}, 0,8));
		print(sort_recursive(new int[] {8,5,3,9,1}, 0,5));
		print(sort_recursive(new int[] {1,2,3,4,5}, 0,5));

	}

}
<file_sep>/**
 *
 */
package com.dsa.mtech;

/**
 * @author shivaak on 25-Jan-2019
 *
 */
public class GCD {

	public static int gcd(int x, int y) {

		if(x==0) return y;
		if(y==0) return x;

		return gcd(y, x%y);

	}

	public static void main(String[] args) {

		//System.out.println(2%10);
		System.out.println(gcd(19,475));
	}

}
<file_sep>/**
 *
 */
package com.dsa.mtech.adt.impl;

import com.dsa.mtech.adt.spec.Stack;

/**
 * @author shivaak on 27-Jan-2019
 *
 */
public class StackArrayImpl implements Stack{

	private final Integer MAX_SIZE = 5;
	private Integer[] arr = new Integer[MAX_SIZE];
	private Integer top = -1;

	@Override
	public Integer pop() {
		if(isEmpty()) {
			System.out.println("Stack is Empty");
			return null;
		}
		int n = arr[top];
		top--;
		System.out.println(n + " popped");
		return n;
	}

	@Override
	public Integer peek() {
		if(isEmpty()) {
			System.out.println("Stack is Empty");
			return null;
		}
		System.out.println("Element at top : " + arr[top]);
		return arr[top];
	}

	@Override
	public void push(Integer n) {
		if(top==MAX_SIZE-1) {
			System.out.println("Stack is full");
			return;
		}
		top++;
		arr[top] = n;
		System.out.println(n + " Inserted");
	}

	@Override
	public Boolean isEmpty() {
		if(top ==  -1) {
			System.out.println("Stack is Empty");
			return true;
		}
		return false;
	}

	@Override
	public Integer size() {
		if(isEmpty()) {
			System.out.println("Stack is Empty");
			return null;
		}
		System.out.println("Stack size now : "+ (top+1));
		return top+1;
	}

	public static void main(String[] args) {
		StackArrayImpl stack = new StackArrayImpl();

		stack.size();

		stack.push(5);
		stack.push(2);

		stack.size();
		stack.peek();
		stack.pop();
		stack.size();

		stack.push(5);
		stack.push(2);
		stack.push(14);
		stack.push(21);
		stack.push(50);
		stack.push(22);
		stack.pop();
		stack.size();
	}

}
<file_sep># DSA-Assignements

These are my MTech First Semester Data Structures Assignments
<file_sep>/**
 *
 */
package com.dsa.mtech;

import java.util.stream.IntStream;

/**
 * @author shivaak on 17-Jan-2019
 *
 */
public class Factorial {

	public static int fact(int n) {
		if(n==0 || n==1) return 1;
		return fact(n-1) * n;
	}

	public static void main(String[] args) {
		IntStream.range(0, 8).forEach(n-> System.out.println(fact(n)));
	}

}
<file_sep>/**
 *
 */
package com.dsa.mtech.adt.spec;

/**
 * @author shivaak on 28-Jan-2019
 *
 */
public interface Deque<T> extends Queue<T>{

	public void addFront(T data);

	public T removeLast();

}
<file_sep>/**
 *
 */
package com.dsa.mtech.adt.impl;

import com.dsa.mtech.adt.spec.Queue;

/**
 * @author shivaak on 27-Jan-2019
 *
 */
public class CircularQueue implements Queue<Integer>{

	private static final Integer MAX_SIZE = 3;

	private Integer[] arr = new Integer[MAX_SIZE];

	private Integer front, rear;

	public CircularQueue() {
		super();
		this.front = -1;
		this.rear = -1;
	}

	@Override
	public void add(Integer data) {
		if(((rear+1)%MAX_SIZE) == front) {
			System.out.println("Queue is Full");
			return;
		}
		rear = (rear+1) % MAX_SIZE;
		arr[rear]=data;
		if(front==-1) front = rear;
		print();
	}

	@Override
	public Integer remove() {
		if(front==-1) {
			System.out.println("Queue is Empty");
			return null;
		}
		int d = arr[front];
		if(front==rear && front==MAX_SIZE) {
			front=-1; rear=-1;
			return d;
		}

		front= (front+1) % MAX_SIZE;
		print();
		return d;
	}

	@Override
	public Integer size() {
		if(front==-1) { System.out.println("Size : 0 ");return 0;}

		if(rear>=front) {
			System.out.println(rear-front +1);
			return rear-front+1;
		}else {
			System.out.println(MAX_SIZE - (front-rear-1));
			return MAX_SIZE - (front-rear-1);
		}
	}

	public void print() {
		if(front==-1) return;

		if(front<=rear) {
			for (int i = front; i <= rear; i++)
				System.out.print(arr[i] + " - ");
		}else {
			for (int i = front; i < MAX_SIZE; i++)
				System.out.print(arr[i] + " - ");

	        for (int i = 0; i <= rear; i++)
	        	System.out.print(arr[i] + " - ");

		}
		System.out.println();
	}

	public static void main(String[] args) {
		CircularQueue q = new CircularQueue();

		q.remove();
		q.add(5);
		q.add(10);
		q.add(15);
		q.add(100);
		q.remove();
		q.add(20);
		q.remove();
		q.remove();
		q.size();

	}

}

languages: Java Markdown

repo_language: Java

repo_name: shivaak/DSA-Assignements