Module: GClouder::Resources::Project::Local

Includes:
Config::CLIArgs, Config::Project, GCloud, Logging, Shell
Defined in:
lib/gclouder/resources/project.rb

Class Method Summary collapse

Methods included from Config::CLIArgs

check, #cli_args, cli_args, included, load, valid_resources

Methods included from GCloud

#gcloud, included, #verify

Methods included from Config::Project

load, #project, project

Methods included from Helpers

#hash_to_args, included, #module_exists?, #to_arg, #to_deep_merge_hash, #valid_json?

Methods included from Logging

#add, #bad, #change, #debug, #error, #fatal, #good, included, #info, log, loggers, #remove, report, #resource_state, setup, #warn, #warning

Methods included from Shell

included, #shell

Class Method Details

.account_idObject



79
80
81
# File 'lib/gclouder/resources/project.rb', line 79

def self.
  project["account_id"]
end

.create_projectObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gclouder/resources/project.rb', line 37

def self.create_project
  if exists?
    good project_id, indent: 2
    return
  end

  # FIXME: wait for project to exist and apis be enabled before continuing..
  # FIXME: enable compute engine api..

  add project_id, indent: 2
  gcloud("alpha projects create #{project_id} --enable-cloud-apis --name=#{project_id}")

  # FIXME: billing account isn't listed until linked..
  #sleep 0.5 until exists? unless cli_args[:dry_run]
end

.ensureObject



32
33
34
35
# File 'lib/gclouder/resources/project.rb', line 32

def self.ensure
  create_project
  
end

.exists?Boolean

Returns:



67
68
69
# File 'lib/gclouder/resources/project.rb', line 67

def self.exists?
  ! project_data(project_id).empty?
end


53
54
55
56
57
58
59
60
61
# File 'lib/gclouder/resources/project.rb', line 53

def self.
  if linked_to_billing_account?
    good "linked to billing account: #{}", indent: 3
    return
  end

  add "link to billing account: #{}", indent: 3
  gcloud("alpha billing accounts projects link #{project_id} --account-id=#{}")
end

.linked_to_billing_account?Boolean

Returns:



63
64
65
# File 'lib/gclouder/resources/project.rb', line 63

def self.linked_to_billing_account?
  project_data(project_id)["billingEnabled"]
end

.project_data(project) ⇒ Object



71
72
73
# File 'lib/gclouder/resources/project.rb', line 71

def self.project_data(project)
  shell("gcloud --format json alpha billing accounts projects list #{} | jq '.[] | select(.projectId == \"#{project}\")'")
end

.project_idObject



75
76
77
# File 'lib/gclouder/resources/project.rb', line 75

def self.project_id
  project["project_id"]
end