コード例 #1
0
def sink_exists(organization, sink_name):
    result_ = base.run_command_readonly([
        'gcloud', 'logging', 'sinks', 'describe', sink_name, '--organization',
        organization
    ])
    return not result_.decode("utf-8").strip().__contains__(
        'NOT_FOUND: Sink {} does not exist'.format(sink_name))
コード例 #2
0
def deployment_exists(project_name, deployment_name):
    result_ = base.run_command_readonly([
        'gcloud', 'deployment-manager', 'deployments', 'list', '--filter',
        'NAME=' + deployment_name, '--format', 'json', '--project',
        project_name
    ])
    return result_.decode("utf-8").strip() != '[]'
コード例 #3
0
def get_backend_service(project_id, _filter, value='name'):
    result_ = run_command_readonly([
        'gcloud', 'compute', 'backend-services', 'list', '--project',
        project_id, "--format", "value({})".format(value),
        "--filter='{}'".format(_filter)
    ])
    return result_.decode("utf-8").strip()
コード例 #4
0
def get_firewall_rules(project):
    firewall_rules = base.run_command_readonly([
        'gcloud', 'compute', 'firewall-rules', 'list',
        '--format=\'value(NAME)\'', '--project', project
    ])
    return firewall_rules.decode(
        'utf-8').splitlines() if firewall_rules else []
コード例 #5
0
def iam_org_level_role_exist(organization_id, role):
    role_id_full_name = build_org_level_role_full_name(organization_id, role)
    current_role_name = base.run_command_readonly([
        'gcloud', 'iam', 'roles', 'list', '--organization', organization_id,
        '--filter', role, '--format', "value(name)"
    ])
    return current_role_name.decode("utf-8").strip() == role_id_full_name
コード例 #6
0
def __get_functions(project):
    cmd = [
        'gcloud', 'functions', 'list', '--project', project, '--format=json'
    ]
    functions = run_command_readonly(cmd).decode("utf-8").strip()
    functions = json.loads(functions)
    return functions
コード例 #7
0
def get_enabled_apis_on_project(project_id):
    print('Getting enabled apis on project {}\n'.format(project_id))
    result_ = run_command_readonly([
        'gcloud', 'services', 'list', '--enabled',
        '--format="(NAME:format=json)"', '--project', project_id
    ])
    return json.loads(result_.decode("utf-8").strip())
コード例 #8
0
def get_cluster_version(project_id, zone):
    """Get version of GKE"""
    versions = run_command_readonly([
        'gcloud', 'container', 'get-server-config', '--quiet', '--zone', zone,
        '--project', project_id, '--format="value(validMasterVersions[0])"'
    ])
    return versions.decode("utf-8").splitlines()[-1]
コード例 #9
0
def service_account_exists(service_account_email, project):
    cmd = [
        'gcloud', 'iam', 'service-accounts', 'list',
        '--filter="email={}"'.format(service_account_email), '--project',
        project, '--format', 'json'
    ]
    result = base.run_command_readonly(cmd).decode('utf8').strip()
    return result != '[]'
コード例 #10
0
def __get_subscriptions(project):
    cmd = [
        'gcloud', 'pubsub', 'subscriptions', 'list', '--project', project,
        '--format=json'
    ]
    subscriptions = run_command_readonly(cmd).decode("utf-8").strip()
    subscriptions = json.loads(subscriptions)
    return subscriptions
コード例 #11
0
def __get_dataflow_jobs(project):
    cmd = [
        'gcloud', 'dataflow', 'jobs', 'list', '--project', project,
        '--filter=state=running', '--format=json'
    ]
    jobs = run_command_readonly(cmd).decode("utf-8").strip()
    jobs = json.loads(jobs)
    return jobs
コード例 #12
0
def get_region_by_zone(zone):
    """Get the region based on specified zone"""
    cmd = [
        'gcloud', 'compute', 'zones', 'describe', zone,
        '--format=value(region)'
    ]
    region_url = str(run_command_readonly(cmd).decode('utf-8')).split('/')
    return region_url[len(region_url) - 1].replace('\n', '')
コード例 #13
0
ファイル: dns.py プロジェクト: Tabrarian/python-docs-samples
def get_dns_record(dns_project_id, dns_zone, record_name, record_type):
    dns_ip = run_command_readonly([
        'gcloud', 'dns', 'record-sets', 'list', '--name', record_name, '-z',
        dns_zone, '--type', record_type, '--format', 'value(DATA)',
        '--project', dns_project_id
    ])
    if dns_ip:
        return dns_ip.decode("utf-8").strip()
    return None
コード例 #14
0
ファイル: dns.py プロジェクト: Tabrarian/python-docs-samples
def get_dns_ttl(dns_project_id, dns_zone, record_name, record_type):
    ttl = run_command_readonly([
        'gcloud', 'dns', 'record-sets', 'list', '--name', record_name, '-z',
        dns_zone, '--type', record_type, '--format', 'value(ttl)', '--project',
        dns_project_id
    ])
    if ttl:
        return ttl.decode("utf-8").strip()
    return None
コード例 #15
0
def cloud_sql_instance_running(instance_name, project):
    """Verify if the given SQL instance has started"""
    command_ = [
        'gcloud', 'sql', 'instances', 'describe', instance_name,
        '--format', 'value(settings.activationPolicy)',
        '--project', project
    ]
    result_ = run_command_readonly(command_).decode("utf-8").strip()
    return result_ == 'ALWAYS'
コード例 #16
0
def gae_exists(project_name):
    if helpers.DRY_RUN:
        return False
    result_ = base.run_command_readonly([
        'gcloud', 'app', 'describe', '--project', project_name, '--format',
        'json'
    ])
    clean_result = result_.decode("utf-8").strip()
    return 'does not contain an App Engine application' not in clean_result
コード例 #17
0
def gae_service_exist(project_name, service_name):
    if helpers.DRY_RUN:
        return False
    result_ = base.run_command_readonly([
        'gcloud', 'app', 'services', 'describe', service_name, '--project',
        project_name, '--format', 'value(id)'
    ])
    clean_result = result_.decode("utf-8").strip()
    return service_name == clean_result
コード例 #18
0
def bucket_status(bucket_name):
    result_ = base.run_command_readonly(
        ['gsutil', 'ls', '-L', '-b', 'gs://' + bucket_name])
    clean_result = result_.decode("utf-8").strip()
    if "BucketNotFoundException" in clean_result:
        return "NotFound"
    if "AccessDeniedException" in clean_result:
        return "AccessDenied"
    return "Found"
コード例 #19
0
def gcp_zone_list(project_id):
    """Validate if given project id exists on GCP and user has access"""
    cmd = [
        'gcloud', 'compute', 'zones', 'list', '--format="value(NAME)"',
        '--project', project_id
    ]
    result = run_command_readonly(cmd).decode('utf8').strip()

    return result
コード例 #20
0
def get_managed_zones_by_project(project_id):
    """Get managed zones for the given project id"""
    cmd = [
        'gcloud', 'dns', 'managed-zones', 'list', '--project', project_id,
        '--format=value(name)'
    ]
    result = run_command_readonly(cmd).decode('utf8').strip()

    return result
コード例 #21
0
def gcp_project_exists(project_id):
    """Validate if given project id exists on GCP and user has access"""
    cmd = [
        'gcloud', 'projects', 'list',
        '--filter', 'PROJECT_ID=' + project_id,
        '--format', 'json'
    ]
    result = run_command_readonly(cmd).decode('utf8').strip()

    return result != '[]'
コード例 #22
0
def get_external_ip(dns_project_id, name):
    cmd = [
        'gcloud', 'compute', 'addresses', 'list',
        '--filter="name:{}"'.format(name), "--format='value(address)'",
        '--project', dns_project_id
    ]
    return run_command_readonly(cmd)\
           .decode("utf-8")\
           .replace("\r", "")\
           .replace("\n", "")
コード例 #23
0
ファイル: dns.py プロジェクト: Tabrarian/python-docs-samples
def get_servers_names(dns_zone, dns_project_id):
    LOGGER.info("Retrieving names servers in %s, project %s", dns_zone,
                dns_project_id)
    returned_servers = run_command_readonly([
        'gcloud', 'dns', 'managed-zones', 'describe', dns_zone, '--project',
        dns_project_id, "--format='value(nameServers)'"
    ])

    servers = returned_servers.decode("utf-8")\
                .replace("\r", "").replace("\n", "").split(";")

    return servers
コード例 #24
0
ファイル: dns.py プロジェクト: Tabrarian/python-docs-samples
def retrieve_servers_names(dns_zone, dns_project_id):
    LOGGER.info("Retrieving names servers in %s, project %s", dns_zone,
                dns_project_id)
    returned_servers = run_command_readonly([
        'gcloud', 'dns', 'managed-zones', 'describe', dns_zone, '--project',
        dns_project_id
    ])

    servers = returned_servers.decode("utf-8")

    LOGGER.warning("Keep these names servers for the next step\n")
    LOGGER.warning(servers)
コード例 #25
0
def default_network_has_no_instances(project):
    result_ = run_command_readonly([
        'gcloud',
        'compute',
        'instances',
        'list',
        '--filter',
        '"networkInterfaces[].network:default"',
        '--format',
        'json',
        '--project',
        project,
    ])
    return result_.decode("utf-8").strip() == '[]'
コード例 #26
0
def default_network_has_no_instances(project_id):
    """
    Check if default network has instances associated.
    :param project_id: project id
    :return: if has instances associated.
    """
    result_ = run_command_readonly([
        'gcloud',
        'compute',
        'instances',
        'list',
        '--filter',
        '"networkInterfaces[].network:default"',
        '--format',
        'json',
        '--project',
        project_id,
    ])
    return result_.decode("utf-8").strip() == '[]'
コード例 #27
0
def topic_exists(project_name, topic_name):
    topic = 'projects/{}/topics/{}'.format(project_name, topic_name)
    result_ = base.run_command_readonly(
        ['gcloud', 'pubsub', 'topics', 'describe', topic])
    return result_.decode("utf-8").strip().__contains__(topic)
コード例 #28
0
def subscription_exists(project_name, subscription_name):
    subscription = 'projects/{}/subscriptions/{}'.format(
        project_name, subscription_name)
    result_ = base.run_command_readonly(
        ['gcloud', 'pubsub', 'subscriptions', 'describe', subscription])
    return result_.decode("utf-8").strip().__contains__(subscription)
コード例 #29
0
def project_exists(project_id):
    result_ = base.run_command_readonly([
        'gcloud', 'projects', 'list', '--filter', 'PROJECT_ID=' + project_id,
        '--format', 'json'
    ])
    return result_.decode("utf-8").strip() != '[]'
コード例 #30
0
def project_has_billing(project_id):
    result = base.run_command_readonly([
        'gcloud', 'beta', 'billing', 'projects', 'describe', project_id,
        '--format', 'value(billingEnabled)'
    ])
    return 'TRUE' == result.decode("utf-8").strip().upper()