modules/mu/clouds/google/server_pool.rb in cloud-mu-2.0.0.pre.beta2 vs modules/mu/clouds/google/server_pool.rb in cloud-mu-2.0.0.pre.beta3
- old
+ new
@@ -17,10 +17,11 @@
class Google
# A server pool as configured in {MU::Config::BasketofKittens::server_pools}
class ServerPool < MU::Cloud::ServerPool
@deploy = nil
+ @project_id = nil
@config = nil
attr_reader :mu_name
attr_reader :cloud_id
attr_reader :config
@@ -30,19 +31,25 @@
@deploy = mommacat
@config = MU::Config.manxify(kitten_cfg)
@cloud_id ||= cloud_id
if !mu_name.nil?
@mu_name = mu_name
+ @config['project'] ||= MU::Cloud::Google.defaultProject(@config['credentials'])
+ if !@project_id
+ project = MU::Cloud::Google.projectLookup(@config['project'], @deploy, sibling_only: true, raise_on_fail: false)
+ @project_id = project.nil? ? @config['project'] : project.cloudobj.cloud_id
+ end
elsif @config['scrub_mu_isms']
@mu_name = @config['name']
else
@mu_name = @deploy.getResourceName(@config['name'])
end
end
# Called automatically by {MU::Deploy#createResources}
def create
+ @project_id = MU::Cloud::Google.projectLookup(@config['project'], @deploy).cloudobj.cloud_id
port_objs = []
@config['named_ports'].each { |port_cfg|
port_objs << MU::Cloud::Google.compute(:NamedPort).new(
name: port_cfg['name'],
@@ -93,11 +100,11 @@
properties: instance_props
)
MU.log "Creating instance template #{@mu_name}", details: template_obj
template = MU::Cloud::Google.compute(credentials: @config['credentials']).insert_instance_template(
- @config['project'],
+ @project_id,
template_obj
)
# XXX AWS-style @config['health_check_type'] doesn't make a lick of sense here
healing_obj = MU::Cloud::Google.compute(:InstanceGroupManager).new(
@@ -115,11 +122,11 @@
auto_healing_policies: [healing_obj]
)
MU.log "Creating region instance group manager #{@mu_name}", details: mgr_obj
mgr = MU::Cloud::Google.compute(credentials: @config['credentials']).insert_region_instance_group_manager(
- @config['project'],
+ @project_id,
@config['region'],
mgr_obj
)
# TODO this thing supports based on CPU usage, LB usage, or an arbitrary Cloud
@@ -141,11 +148,11 @@
autoscaling_policy: policy_obj
)
MU.log "Creating autoscaler policy #{@mu_name}", details: scaler_obj
MU::Cloud::Google.compute(credentials: @config['credentials']).insert_region_autoscaler(
- @config['project'],
+ @project_id,
@config['region'],
scaler_obj
)
# TODO honor wait_for_instances
@@ -246,9 +253,15 @@
# Does this resource type exist as a global (cloud-wide) artifact, or
# is it localized to a region/zone?
# @return [Boolean]
def self.isGlobal?
false
+ end
+
+ # Denote whether this resource implementation is experiment, ready for
+ # testing, or ready for production use.
+ def self.quality
+ MU::Cloud::RELEASE
end
# Remove all autoscale groups associated with the currently loaded deployment.
# @param noop [Boolean]: If true, will only print what would be done
# @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server