Ejemplo n.º 1
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    disk = Disk(gcp_config, ctx.logger, name=name)
    utils.delete_if_not_external(disk)
    ctx.instance.runtime_properties.pop(constants.DISK, None)
    ctx.instance.runtime_properties.pop(constants.NAME, None)
Ejemplo n.º 2
0
def delete(user, private_key_path, **kwargs):
    gcp_config = utils.get_gcp_config()
    keypair = KeyPair(gcp_config, ctx.logger, user, private_key_path, None)
    keypair.public_key = ctx.instance.runtime_properties[constants.PUBLIC_KEY]
    if not utils.should_use_external_resource():
        keypair.remove_private_key()
    ctx.instance.runtime_properties.pop(constants.PRIVATE_KEY, None)
    ctx.instance.runtime_properties.pop(constants.PUBLIC_KEY, None)
Ejemplo n.º 3
0
def create(name, default_service, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    url_map = UrlMap(gcp_config, ctx.logger, name, default_service)
    utils.create(url_map)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.SELF_URL] = \
        url_map.get_self_url()
Ejemplo n.º 4
0
def create(name, default_service, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    url_map = UrlMap(gcp_config, ctx.logger, name, default_service)
    utils.create(url_map)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.SELF_URL] = \
        url_map.get_self_url()
Ejemplo n.º 5
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if name:
        static_ip = StaticIP(gcp_config, ctx.logger, name=name)
        utils.delete_if_not_external(static_ip)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
        ctx.instance.runtime_properties.pop(constants.IP, None)
Ejemplo n.º 6
0
def create(image, name, size, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    disk = Disk(gcp_config, ctx.logger, image=image, name=name, size_gb=size)
    utils.create(disk)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.DISK] = \
        disk.disk_to_insert_instance_dict(name)
Ejemplo n.º 7
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if not name:
        return
    network = Network(gcp_config, ctx.logger, network={'name': name})
    utils.delete_if_not_external(network)
    ctx.instance.runtime_properties.pop(constants.NAME, None)
Ejemplo n.º 8
0
def create(network, **kwargs):
    gcp_config = utils.get_gcp_config()
    network['name'] = utils.get_final_resource_name(network['name'])
    network = Network(gcp_config, ctx.logger, network=network)
    utils.create(network)
    ctx.instance.runtime_properties[constants.NAME] = network.name
    # will be updated only if the resource is created before
    ctx.instance.runtime_properties['ip_range'] = network.iprange
Ejemplo n.º 9
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if name:
        instance_group = InstanceGroup(gcp_config, ctx.logger, name=name)
        utils.delete_if_not_external(instance_group)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
        ctx.instance.runtime_properties.pop(constants.SELF_URL, None)
Ejemplo n.º 10
0
def create(name, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    static_ip = StaticIP(gcp_config, ctx.logger, name)
    utils.create(static_ip)
    ip_address = get_reserved_ip_address(static_ip)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.IP] = ip_address
Ejemplo n.º 11
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if name:
        url_map = UrlMap(gcp_config, ctx.logger, name=name)
        utils.delete_if_not_external(url_map)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
        ctx.instance.runtime_properties.pop(constants.SELF_URL, None)
Ejemplo n.º 12
0
def remove_external_ip(instance_name, **kwargs):
    if not instance_name:
        return
    gcp_config = utils.get_gcp_config()
    gcp_config['network'] = utils.get_gcp_resource_name(gcp_config['network'])
    instance = Instance(gcp_config,
                        ctx.logger,
                        name=instance_name)
    instance.delete_access_config()
Ejemplo n.º 13
0
def add_instance_tag(instance_name, tag, **kwargs):
    if not tag:
        return
    gcp_config = utils.get_gcp_config()
    gcp_config['network'] = utils.get_gcp_resource_name(gcp_config['network'])
    instance = Instance(gcp_config,
                        ctx.logger,
                        name=instance_name)
    instance.set_tags([utils.get_gcp_resource_name(t) for t in tag])
Ejemplo n.º 14
0
def __modify_backends(backend_service_name, group_self_url, modify_function):
    gcp_config = utils.get_gcp_config()
    backend_service = BackendService(gcp_config,
                                     ctx.logger,
                                     backend_service_name)
    backends = ctx.source.instance.runtime_properties[constants.BACKENDS]
    modify_function(backend_service, backends, group_self_url)
    ctx.source.instance.runtime_properties[constants.BACKENDS] = \
        backend_service.backends
Ejemplo n.º 15
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if name:
        forwarding_rule = GlobalForwardingRule(gcp_config,
                                               ctx.logger,
                                               name=name)
        utils.delete_if_not_external(forwarding_rule)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
Ejemplo n.º 16
0
def remove_instance_tag(instance_name, tag, **kwargs):
    gcp_config = utils.get_gcp_config()
    if not instance_name:
        return
    gcp_config['network'] = utils.get_gcp_resource_name(gcp_config['network'])
    instance = Instance(gcp_config,
                        ctx.logger,
                        name=instance_name)
    instance.remove_tags([utils.get_gcp_resource_name(t) for t in tag])
Ejemplo n.º 17
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    disk = Disk(gcp_config,
                ctx.logger,
                name=name)
    utils.delete_if_not_external(disk)
    ctx.instance.runtime_properties.pop(constants.DISK, None)
    ctx.instance.runtime_properties.pop(constants.NAME, None)
Ejemplo n.º 18
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME)
    if name:
        ssl_certificate = SslCertificate(config=gcp_config,
                                         logger=ctx.logger,
                                         name=name)
        utils.delete_if_not_external(ssl_certificate)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
        ctx.instance.runtime_properties.pop(constants.SELF_URL, None)
Ejemplo n.º 19
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if not name:
        return
    network = Network(gcp_config,
                      ctx.logger,
                      network={'name': name})
    utils.delete_if_not_external(network)
    ctx.instance.runtime_properties.pop(constants.NAME, None)
Ejemplo n.º 20
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if name:
        static_ip = StaticIP(gcp_config,
                             ctx.logger,
                             name=name)
        utils.delete_if_not_external(static_ip)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
        ctx.instance.runtime_properties.pop(constants.IP, None)
Ejemplo n.º 21
0
def create(name, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    static_ip = StaticIP(gcp_config,
                         ctx.logger,
                         name)
    utils.create(static_ip)
    ip_address = get_reserved_ip_address(static_ip)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.IP] = ip_address
Ejemplo n.º 22
0
def create(network, **kwargs):
    gcp_config = utils.get_gcp_config()
    network['name'] = utils.get_final_resource_name(network['name'])
    network = Network(gcp_config,
                      ctx.logger,
                      network=network)
    utils.create(network)
    ctx.instance.runtime_properties[constants.NAME] = network.name
    # will be updated only if the resource is created before
    ctx.instance.runtime_properties['ip_range'] = network.iprange
Ejemplo n.º 23
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if name:
        backend_service = BackendService(gcp_config,
                                         ctx.logger,
                                         name=name)
        utils.delete_if_not_external(backend_service)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
        ctx.instance.runtime_properties.pop(constants.SELF_URL, None)
        ctx.instance.runtime_properties.pop(constants.BACKENDS, None)
Ejemplo n.º 24
0
def create(firewall_rule, **kwargs):
    gcp_config = utils.get_gcp_config()
    network_name = utils.get_gcp_resource_name(gcp_config['network'])
    set_firewall_rule_name(firewall_rule, network_name)
    firewall = FirewallRule(gcp_config,
                            ctx.logger,
                            firewall=firewall_rule,
                            network=network_name)

    utils.create(firewall)
    ctx.instance.runtime_properties[constants.NAME] = firewall.name
Ejemplo n.º 25
0
def create(firewall_rule, **kwargs):
    gcp_config = utils.get_gcp_config()
    network_name = utils.get_gcp_resource_name(gcp_config['network'])
    set_firewall_rule_name(firewall_rule, network_name)
    firewall = FirewallRule(gcp_config,
                            ctx.logger,
                            firewall=firewall_rule,
                            network=network_name)

    utils.create(firewall)
    ctx.instance.runtime_properties[constants.NAME] = firewall.name
Ejemplo n.º 26
0
def create(user, private_key_path, public_key_path, **kwargs):
    gcp_config = utils.get_gcp_config()
    keypair = KeyPair(gcp_config, ctx.logger, user, private_key_path,
                      public_key_path)
    create_keypair(keypair)
    ctx.instance.runtime_properties[constants.USER] = user
    ctx.instance.runtime_properties[constants.PRIVATE_KEY] = \
        keypair.private_key
    ctx.instance.runtime_properties[constants.PUBLIC_KEY] = keypair.public_key
    if not utils.should_use_external_resource():
        keypair.save_private_key()
Ejemplo n.º 27
0
def create(name, target_proxy, port_range, ip_address, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    forwarding_rule = GlobalForwardingRule(gcp_config,
                                           ctx.logger,
                                           name,
                                           target_proxy,
                                           port_range,
                                           ip_address)
    utils.create(forwarding_rule)
    ctx.instance.runtime_properties[constants.NAME] = name
Ejemplo n.º 28
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    firewall_name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if not firewall_name:
        return
    network_name = utils.get_gcp_resource_name(gcp_config['network'])
    firewall = FirewallRule(gcp_config,
                            ctx.logger,
                            firewall={'name': firewall_name},
                            network=network_name)
    utils.delete_if_not_external(firewall)
    ctx.instance.runtime_properties.pop(constants.NAME, None)
Ejemplo n.º 29
0
def create(image, name, size, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    disk = Disk(gcp_config,
                ctx.logger,
                image=image,
                name=name,
                size_gb=size)
    utils.create(disk)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.DISK] = \
        disk.disk_to_insert_instance_dict(name)
def create(name, named_ports, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    instance_group = InstanceGroup(gcp_config,
                                   ctx.logger,
                                   name=name,
                                   named_ports=named_ports)

    utils.create(instance_group)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.SELF_URL] = \
        instance_group.get_self_url()
Ejemplo n.º 31
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if name:
        instance = Instance(gcp_config,
                            ctx.logger,
                            name=name)
        utils.delete_if_not_external(instance)

        ctx.instance.runtime_properties.pop(constants.DISK, None)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
        ctx.instance.runtime_properties.pop(constants.GCP_ZONE, None)
Ejemplo n.º 32
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    firewall_name = ctx.instance.runtime_properties.get(constants.NAME, None)
    if not firewall_name:
        return
    network_name = utils.get_gcp_resource_name(gcp_config['network'])
    firewall = FirewallRule(gcp_config,
                            ctx.logger,
                            firewall={'name': firewall_name},
                            network=network_name)
    utils.delete_if_not_external(firewall)
    ctx.instance.runtime_properties.pop(constants.NAME, None)
Ejemplo n.º 33
0
def create(name, named_ports, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    instance_group = InstanceGroup(gcp_config,
                                   ctx.logger,
                                   name=name,
                                   named_ports=named_ports)

    utils.create(instance_group)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.SELF_URL] = \
        instance_group.get_self_url()
Ejemplo n.º 34
0
def delete(user, private_key_path, **kwargs):
    gcp_config = utils.get_gcp_config()
    keypair = KeyPair(gcp_config,
                      ctx.logger,
                      user,
                      private_key_path,
                      None)
    keypair.public_key = ctx.instance.runtime_properties[constants.PUBLIC_KEY]
    if not utils.should_use_external_resource():
        keypair.remove_private_key()
    ctx.instance.runtime_properties.pop(constants.PRIVATE_KEY, None)
    ctx.instance.runtime_properties.pop(constants.PUBLIC_KEY, None)
Ejemplo n.º 35
0
def create_security_group(rules, **kwargs):
    gcp_config = utils.get_gcp_config()
    firewall_structure = create_firewall_structure_from_rules(
        gcp_config['network'], rules)
    ctx.instance.runtime_properties[constants.TARGET_TAGS] = \
        firewall_structure[constants.TARGET_TAGS]
    ctx.instance.runtime_properties[constants.SOURCE_TAGS] = \
        firewall_structure[constants.SOURCE_TAGS]
    firewall = FirewallRule(gcp_config, ctx.logger, firewall_structure,
                            gcp_config['network'])
    ctx.instance.runtime_properties[constants.NAME] = firewall.name
    utils.create(firewall)
Ejemplo n.º 36
0
def create(name, health_check, additional_settings, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    backend_service = BackendService(gcp_config,
                                     ctx.logger,
                                     name,
                                     health_check,
                                     additional_settings)
    utils.create(backend_service)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.SELF_URL] = \
        backend_service.get_self_url()
    ctx.instance.runtime_properties[constants.BACKENDS] = []
Ejemplo n.º 37
0
def create(name, health_check_type, additional_settings, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    health_check = health_check_of_type(health_check_type,
                                        config=gcp_config,
                                        logger=ctx.logger,
                                        name=name,
                                        additional_settings=additional_settings)
    utils.create(health_check)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.HEALTH_CHECK_TYPE] = \
        health_check_type
    ctx.instance.runtime_properties[constants.SELF_URL] = \
        health_check.get_self_url()
Ejemplo n.º 38
0
def create(name, private_key, certificate, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    private_key_data = get_pem_data(private_key['type'], private_key['data'])
    certificate_data = get_pem_data(certificate['type'], certificate['data'])
    ssl_certificate = SslCertificate(config=gcp_config,
                                     logger=ctx.logger,
                                     name=name,
                                     private_key=private_key_data,
                                     certificate=certificate_data)
    utils.create(ssl_certificate)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.SELF_URL] = \
        ssl_certificate.get_self_url()
Ejemplo n.º 39
0
def create(name, target_proxy_type, url_map, ssl_certificate, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    target_proxy = target_proxy_of_type(target_proxy_type,
                                        config=gcp_config,
                                        logger=ctx.logger,
                                        name=name,
                                        url_map=url_map,
                                        ssl_certificate=ssl_certificate)
    utils.create(target_proxy)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.TARGET_PROXY_TYPE] = \
        target_proxy_type
    ctx.instance.runtime_properties[constants.SELF_URL] = \
        target_proxy.get_self_url()
Ejemplo n.º 40
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME)
    target_proxy_type = ctx.instance.runtime_properties.get(
        constants.TARGET_PROXY_TYPE)

    if name:
        target_proxy = target_proxy_of_type(target_proxy_type,
                                            config=gcp_config,
                                            logger=ctx.logger,
                                            name=name)
        utils.delete_if_not_external(target_proxy)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
        ctx.instance.runtime_properties.pop(constants.TARGET_PROXY_TYPE, None)
        ctx.instance.runtime_properties.pop(constants.SELF_URL, None)
Ejemplo n.º 41
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME)
    target_proxy_type = ctx.instance.runtime_properties.get(
        constants.TARGET_PROXY_TYPE)

    if name:
        target_proxy = target_proxy_of_type(target_proxy_type,
                                            config=gcp_config,
                                            logger=ctx.logger,
                                            name=name)
        utils.delete_if_not_external(target_proxy)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
        ctx.instance.runtime_properties.pop(constants.TARGET_PROXY_TYPE, None)
        ctx.instance.runtime_properties.pop(constants.SELF_URL, None)
Ejemplo n.º 42
0
def create(name, target_proxy_type, url_map, ssl_certificate, **kwargs):
    name = utils.get_final_resource_name(name)
    gcp_config = utils.get_gcp_config()
    target_proxy = target_proxy_of_type(target_proxy_type,
                                        config=gcp_config,
                                        logger=ctx.logger,
                                        name=name,
                                        url_map=url_map,
                                        ssl_certificate=ssl_certificate)
    utils.create(target_proxy)
    ctx.instance.runtime_properties[constants.NAME] = name
    ctx.instance.runtime_properties[constants.TARGET_PROXY_TYPE] = \
        target_proxy_type
    ctx.instance.runtime_properties[constants.SELF_URL] = \
        target_proxy.get_self_url()
Ejemplo n.º 43
0
def create_security_group(rules, **kwargs):
    gcp_config = utils.get_gcp_config()
    firewall_structure = create_firewall_structure_from_rules(
        gcp_config['network'],
        rules)
    ctx.instance.runtime_properties[constants.TARGET_TAGS] = \
        firewall_structure[constants.TARGET_TAGS]
    ctx.instance.runtime_properties[constants.SOURCE_TAGS] = \
        firewall_structure[constants.SOURCE_TAGS]
    firewall = FirewallRule(gcp_config,
                            ctx.logger,
                            firewall_structure,
                            gcp_config['network'])
    ctx.instance.runtime_properties[constants.NAME] = firewall.name
    utils.create(firewall)
Ejemplo n.º 44
0
def delete(**kwargs):
    gcp_config = utils.get_gcp_config()
    name = ctx.instance.runtime_properties.get(constants.NAME)
    health_check_type = ctx.instance.runtime_properties.get(
        constants.HEALTH_CHECK_TYPE)

    if name:
        health_check = health_check_of_type(health_check_type,
                                            config=gcp_config,
                                            logger=ctx.logger,
                                            name=name)
        utils.delete_if_not_external(health_check)
        ctx.instance.runtime_properties.pop(constants.NAME, None)
        ctx.instance.runtime_properties.pop(constants.HEALTH_CHECK_TYPE, None)
        ctx.instance.runtime_properties.pop(constants.SELF_URL, None)
Ejemplo n.º 45
0
def add_external_ip(instance_name, **kwargs):
    gcp_config = utils.get_gcp_config()
    # check if the instance has no external ips, only one is supported so far
    gcp_config['network'] = utils.get_gcp_resource_name(gcp_config['network'])
    ip_node = ctx.target.node
    instance = Instance(gcp_config,
                        ctx.logger,
                        name=instance_name)
    if ip_node.properties[constants.USE_EXTERNAL_RESOURCE]:
        ip_address = ip_node.properties['ip_address']
        if not ip_address:
            raise GCPError('{} is set, but ip_address is not set'
                           .format(constants.USE_EXTERNAL_RESOURCE))
        instance.add_access_config(ip_address)
    else:
        instance.add_access_config()
    set_ip(instance, relationship=True)
Ejemplo n.º 46
0
def create(user,
           private_key_path,
           public_key_path,
           **kwargs):
    gcp_config = utils.get_gcp_config()
    keypair = KeyPair(gcp_config,
                      ctx.logger,
                      user,
                      private_key_path,
                      public_key_path)
    create_keypair(keypair)
    ctx.instance.runtime_properties[constants.USER] = user
    ctx.instance.runtime_properties[constants.PRIVATE_KEY] = \
        keypair.private_key
    ctx.instance.runtime_properties[constants.PUBLIC_KEY] = keypair.public_key
    if not utils.should_use_external_resource():
        keypair.save_private_key()