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)
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)
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()
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)
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 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)
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
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)
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
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)
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()
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])
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
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)
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])
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)
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)
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
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()
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
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)
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()
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)
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)
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] = []
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()
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()
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()
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)
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)
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)