Module: Platform

Defined in:
lib/cem_acpt/platform/gcp.rb

Overview

GCP platform implementation

Instance Method Summary collapse

Instance Method Details

#gcp_credentials_fileObject



37
38
39
# File 'lib/cem_acpt/platform/gcp.rb', line 37

def gcp_credentials_file
  @gcp_credentials_file ||= (@config.get('platform.credentials_file') || File.join(Dir.home, '.config', 'gcloud', 'application_default_credentials.json'))
end

#gcp_disk_sizeObject



69
70
71
# File 'lib/cem_acpt/platform/gcp.rb', line 69

def gcp_disk_size
  @gcp_disk_size ||= (@config.get('node_data.disk_size') || 40)
end

#gcp_machine_typeObject



65
66
67
# File 'lib/cem_acpt/platform/gcp.rb', line 65

def gcp_machine_type
  @gcp_machine_type ||= (@config.get('node_data.machine_type') || 'e2-medium')
end

#gcp_max_run_durationObject



73
74
75
# File 'lib/cem_acpt/platform/gcp.rb', line 73

def gcp_max_run_duration
  @gcp_max_run_duration ||= (@config.get('node_data.max_run_duration') || 3600)
end

#gcp_private_keyObject



57
58
59
# File 'lib/cem_acpt/platform/gcp.rb', line 57

def gcp_private_key
  @gcp_private_key ||= (@run_data[:private_key] || File.join(Dir.home, '.ssh', 'google_compute_engine'))
end

#gcp_projectObject



41
42
43
# File 'lib/cem_acpt/platform/gcp.rb', line 41

def gcp_project
  @gcp_project ||= (@config.get('platform.project') || `gcloud config get-value project`.chomp)
end

#gcp_public_keyObject



61
62
63
# File 'lib/cem_acpt/platform/gcp.rb', line 61

def gcp_public_key
  @gcp_public_key ||= (@run_data[:public_key] || File.join(Dir.home, '.ssh', 'google_compute_engine.pub'))
end

#gcp_regionObject



45
46
47
# File 'lib/cem_acpt/platform/gcp.rb', line 45

def gcp_region
  @gcp_region ||= (@config.get('platform.region') || `gcloud config get-value compute/region`.chomp)
end

#gcp_subnetworkObject



53
54
55
# File 'lib/cem_acpt/platform/gcp.rb', line 53

def gcp_subnetwork
  @gcp_subnetwork ||= (@config.get('platform.subnetwork') || 'default')
end

#gcp_usernameObject



30
31
32
33
34
35
# File 'lib/cem_acpt/platform/gcp.rb', line 30

def gcp_username
  return @gcp_username if @gcp_username

  @gcp_username = @config.get('platform.username')
  @gcp_username ||= JSON.parse(`gcloud compute os-login describe-profile --format json`.chomp)['posixAccounts'].first['username']
end

#gcp_zoneObject



49
50
51
# File 'lib/cem_acpt/platform/gcp.rb', line 49

def gcp_zone
  @gcp_zone ||= (@config.get('platform.zone') || `gcloud config get-value compute/zone`.chomp)
end

#node_dataObject



20
21
22
23
24
25
26
27
28
# File 'lib/cem_acpt/platform/gcp.rb', line 20

def node_data
  nd = {}
  nd[:machine_type] = gcp_machine_type
  nd[:disk_size] = gcp_disk_size
  nd[:max_run_duration] = gcp_max_run_duration
  nd[:image] = image_name if image_name
  nd[:test_name] = @test_data[:test_name] if @test_data&.key?(:test_name)
  nd
end

#platform_dataObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cem_acpt/platform/gcp.rb', line 7

def platform_data
  {
    username: gcp_username,
    credentials_file: gcp_credentials_file,
    project: gcp_project,
    region: gcp_region,
    zone: gcp_zone,
    subnetwork: gcp_subnetwork,
    private_key: gcp_private_key,
    public_key: gcp_public_key,
  }
end