cloud-mu 2.0.0.pre.alpha2 → 2.0.0.pre.alpha3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea07140b34d57b4dea2bc06b6a9184896585db834782e6b2b4c40184b6cdee71
4
- data.tar.gz: 5382c8d82180c39d6797ccbfabb4903877f29f914f2c968aa4550033c6607db8
3
+ metadata.gz: 674e427624161a3b7026346a10320e7dcf5331222d8cc683d186c3d648fc0c77
4
+ data.tar.gz: 71c6ddb375bf199f767fa2b8143b98f7de422d6095921c5db0d0cf191bac39bb
5
5
  SHA512:
6
- metadata.gz: b4f27d9340d4146cadcd2eeb0a9a2abe650a0822158b136560ff3c8f409975f1a83e8106372c0e8c1f51e35a5868de3764492026f50e6aed9faa410fc133199a
7
- data.tar.gz: 411b9b7d3e8db61459dfc480a1d2d874603580d87e3597956d882a0e9e9e41fc0eff61d3af3d01924a4ddd8c6f10916bcb6df8a18576bd3fd5f3a187a2d460b7
6
+ metadata.gz: 8cac89b0d850377f39635f40aafc4fe148fc6b38c971da05592a55dba83a7f8847c3734eddbdb830724e2cda51c7c3968c38facd22eab15814b892913641b2ab
7
+ data.tar.gz: bce36278c7e00872d5f1f553d41f24abf0593d0a8f1bf076e071d472932e1aa727f196a8e34b37dc4ba3465068420305c3079cd472d9c8a26a9ed65edc06ddc0
data/cloud-mu.gemspec CHANGED
@@ -17,7 +17,7 @@ end
17
17
 
18
18
  Gem::Specification.new do |s|
19
19
  s.name = 'cloud-mu'
20
- s.version = '2.0.0-alpha2'
20
+ s.version = '2.0.0-alpha3'
21
21
  s.date = '2018-12-11'
22
22
  s.require_paths = ['modules']
23
23
  s.required_ruby_version = '>= 2.4'
@@ -91,7 +91,7 @@ module MU
91
91
  if $MU_CFG[cloud.downcase] and $MU_CFG[cloud.downcase].size > 0
92
92
  cloudclass = Object.const_get("MU").const_get("Cloud").const_get(cloud)
93
93
  creds[cloud] ||= {}
94
- $MU_CFG[cloud.downcase].keys.each { |credset|
94
+ cloudclass.listCredentials.each { |credset|
95
95
  creds[cloud][credset] = cloudclass.listRegions(credentials: credset)
96
96
  }
97
97
  end
@@ -115,7 +115,8 @@ module MU
115
115
  projects << $MU_CFG[provider.downcase][credset]["project"]
116
116
  end
117
117
 
118
- if projects == [""]
118
+ if projects == []
119
+ projects << "" # dummy
119
120
  MU.log "Checking for #{provider}/#{credset} resources from #{MU.deploy_id} in #{r}", MU::NOTICE
120
121
  end
121
122
 
@@ -160,7 +161,6 @@ module MU
160
161
 
161
162
  if @mommacat.nil? or @mommacat.numKittens(types: [t]) > 0
162
163
  begin
163
- puts t if t == "Habitat"
164
164
  resclass = Object.const_get("MU").const_get("Cloud").const_get(t)
165
165
  resclass.cleanup(
166
166
  noop: @noop,
data/modules/mu/cloud.rb CHANGED
@@ -1434,12 +1434,10 @@ MU.log "in dependencies() and findLitterMate gave me "+sib_by_name.to_s+" on beh
1434
1434
  begin
1435
1435
  cloudclass = MU::Cloud.loadCloudType(cloud, shortname)
1436
1436
  raise MuCloudResourceNotImplemented if !cloudclass.respond_to?(:cleanup) or cloudclass.method(:cleanup).owner.to_s != "#<Class:#{cloudclass}>"
1437
- if cfg_name == "habitat"
1438
- MU.log "Invoking #{cloudclass}.cleanup from #{shortname}", MU::WARN, details: flags
1439
- end
1437
+ MU.log "Invoking #{cloudclass}.cleanup from #{shortname}", MU::DEBUG, details: flags
1440
1438
  cloudclass.cleanup(params)
1441
1439
  rescue MuCloudResourceNotImplemented
1442
- MU.log "No #{cloud} implementation of #{shortname}.cleanup, skipping", MU::WARN, details: flags
1440
+ MU.log "No #{cloud} implementation of #{shortname}.cleanup, skipping", MU::DEBUG, details: flags
1443
1441
  end
1444
1442
  }
1445
1443
  MU::MommaCat.unlockAll
@@ -152,12 +152,24 @@ module MU
152
152
  return nil
153
153
  end
154
154
 
155
- if $MU_CFG and $MU_CFG['aws'] and $MU_CFG['aws']['region']
156
- @@myRegion_var ||= MU::Cloud::AWS.ec2(region: $MU_CFG['aws']['region']).describe_availability_zones.availability_zones.first.region_name
157
- elsif ENV.has_key?("EC2_REGION") and !ENV['EC2_REGION'].empty?
158
- @@myRegion_var ||= MU::Cloud::AWS.ec2(region: ENV['EC2_REGION']).describe_availability_zones.availability_zones.first.region_name
155
+ def self.validate_region(r)
156
+ MU::Cloud::AWS.ec2(region: r).describe_availability_zones.availability_zones.first.region_name
157
+ end
158
+
159
+ if $MU_CFG and $MU_CFG['aws']
160
+ $MU_CFG['aws'].each_pair { |credset, cfg|
161
+ next if !cfg['region']
162
+ if (cfg['default'] or !@@myRegion_var) and validate_region(cfg['region'])
163
+ @@myRegion_var = cfg['region']
164
+ break if cfg['default']
165
+ end
166
+ }
167
+ elsif ENV.has_key?("EC2_REGION") and !ENV['EC2_REGION'].empty? and
168
+ validate_region(ENV['EC2_REGION'])
169
+ # Make sure this string is valid by way of the API
170
+ @@myRegion_var = ENV['EC2_REGION']
159
171
  else
160
- # hacky, but useful in a pinch
172
+ # hacky, but useful in a pinch (and if we're hosted in AWS)
161
173
  az_str = MU::Cloud::AWS.getAWSMetaData("placement/availability-zone")
162
174
  @@myRegion_var = az_str.sub(/[a-z]$/i, "") if az_str
163
175
  end
@@ -936,7 +948,8 @@ module MU
936
948
  # Amazon's Organizations API
937
949
  def self.orgs(credentials: nil)
938
950
  @@organizations_api ||= {}
939
- @@organizations_api[credentials] ||= MU::Cloud::AWS::Endpoint.new(api: "Organizations", credentials: credentials)
951
+ # XXX org api doesn't seem to work in many regions
952
+ @@organizations_api[credentials] ||= MU::Cloud::AWS::Endpoint.new(api: "Organizations", credentials: credentials, region: "us-east-1")
940
953
  @@organizations_api[credentials]
941
954
  end
942
955
 
@@ -62,6 +62,8 @@ module MU
62
62
  end
63
63
  end while resp.create_account_status.state == "IN_PROGRESS"
64
64
 
65
+ @cloud_id = resp.create_account_status.account_id
66
+
65
67
  MU.log "Creation of account #{@mu_name} (#{resp.create_account_status.account_id}) complete"
66
68
  end
67
69
 
@@ -96,14 +98,21 @@ module MU
96
98
  # @param region [String]: The cloud provider region
97
99
  # @return [void]
98
100
  def self.cleanup(noop: false, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
99
- puts "IN HABITAT CLEANUP"
100
101
  return if !orgMasterCreds?(credentials)
101
102
 
102
103
  resp = MU::Cloud::AWS.orgs(credentials: credentials).list_accounts
103
104
 
104
105
  if resp and resp.accounts
105
106
  resp.accounts.each { |acct|
106
- pp acct
107
+ if acct.name.match(/^#{Regexp.quote(MU.deploy_id)}/)
108
+ MU.log "Would delete account #{acct.name} if that was a thing"
109
+ if !noop
110
+ pp acct
111
+ end
112
+ else
113
+ pp acct if acct.name.match(/BUNS/)
114
+ #https://687950501457.signin.aws.amazon.com/console/organizations/complete-signup
115
+ end
107
116
  }
108
117
  end
109
118
  end
@@ -65,11 +65,11 @@ module MU
65
65
  "TODO"
66
66
  end
67
67
 
68
- def self.listRegions
68
+ def self.listRegions(credentials = nil)
69
69
  "TODO"
70
70
  end
71
71
 
72
- def self.listAZs
72
+ def self.listAZs(region = nil)
73
73
  "TODO"
74
74
  end
75
75
 
data/modules/mu/config.rb CHANGED
@@ -33,17 +33,24 @@ module MU
33
33
  end
34
34
 
35
35
  # The default cloud provider for new resources. Must exist in MU.supportedClouds
36
+ # return [String]
36
37
  def self.defaultCloud
37
- begin
38
- MU.myCloud
39
- rescue NoMethodError
40
- "AWS"
41
- end
42
- # XXX this can be more generic (loop through supportedClouds and try this)
43
- if MU::Cloud::Google.hosted?
44
- "Google"
45
- elsif MU::Cloud::AWS.hosted?
46
- "AWS"
38
+ configured = {}
39
+ MU::Cloud.supportedClouds.each { |cloud|
40
+ cloudclass = Object.const_get("MU").const_get("Cloud").const_get(cloud)
41
+ if $MU_CFG[cloud.downcase] and !$MU_CFG[cloud.downcase].empty?
42
+ configured[cloud] = $MU_CFG[cloud.downcase].size
43
+ configured[cloud] += 0.5 if cloudclass.hosted? # tiebreaker
44
+ elsif cloudclass.hosted?
45
+ configured[cloud] = 1
46
+ end
47
+ }
48
+ if configured.size > 0
49
+ return configured.keys.sort { |a, b|
50
+ configured[b] <=> configured[a]
51
+ }.first
52
+ else
53
+ return MU::Cloud.supportedClouds.first
47
54
  end
48
55
  end
49
56
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud-mu
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.alpha2
4
+ version: 2.0.0.pre.alpha3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Stange