modules/mu/config/schema_helpers.rb in cloud-mu-3.1.6 vs modules/mu/config/schema_helpers.rb in cloud-mu-3.2.0
- old
+ new
@@ -20,24 +20,22 @@
# The default cloud provider for new resources. Must exist in MU.supportedClouds
# return [String]
def self.defaultCloud
configured = {}
MU::Cloud.supportedClouds.each { |cloud|
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(cloud)
if $MU_CFG[cloud.downcase] and !$MU_CFG[cloud.downcase].empty?
configured[cloud] = $MU_CFG[cloud.downcase].size
- configured[cloud] += 0.5 if cloudclass.hosted? # tiebreaker
+ configured[cloud] += 0.5 if MU::Cloud.cloudClass(cloud).hosted? # tiebreaker
end
}
if configured.size > 0
return configured.keys.sort { |a, b|
configured[b] <=> configured[a]
}.first
else
MU::Cloud.supportedClouds.each { |cloud|
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(cloud)
- return cloud if cloudclass.hosted?
+ return cloud if MU::Cloud.cloudClass(cloud).hosted?
}
return MU::Cloud.supportedClouds.first
end
end
@@ -81,13 +79,12 @@
@@allregions = []
@@loadfails = []
MU::Cloud.availableClouds.each { |cloud|
next if @@loadfails.include?(cloud)
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(cloud)
begin
- regions = cloudclass.listRegions()
+ regions = MU::Cloud.cloudClass(cloud).listRegions()
@@allregions.concat(regions) if regions
rescue MU::MuError => e
@@loadfails << cloud
MU.log e.message, MU::WARN
end
@@ -98,11 +95,11 @@
def self.region_primitive
if !@@allregions or @@allregions.empty?
@@allregions = []
MU::Cloud.availableClouds.each { |cloud|
next if @@loadfails.include?(cloud)
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(cloud)
+ cloudclass = MU::Cloud.cloudClass(cloud)
begin
return @@allregions if !cloudclass.listRegions()
@@allregions.concat(cloudclass.listRegions())
rescue MU::MuError => e
@@loadfails << cloud
@@ -176,31 +173,31 @@
# @return [Hash]
def self.dependencies_primitive
{
"type" => "array",
"items" => {
- "type" => "object",
- "description" => "Declare other objects which this resource requires. This resource will wait until the others are available to create itself.",
- "required" => ["name", "type"],
- "additionalProperties" => false,
- "properties" => {
- "name" => {"type" => "string"},
- "type" => {
- "type" => "string",
- "enum" => MU::Cloud.resource_types.values.map { |v| v[:cfg_name] }
- },
- "phase" => {
- "type" => "string",
- "description" => "Which part of the creation process of the resource we depend on should we wait for before starting our own creation? Defaults are usually sensible, but sometimes you want, say, a Server to wait on another Server to be completely ready (through its groom phase) before starting up.",
- "enum" => ["create", "groom"]
- },
- "no_create_wait" => {
- "type" => "boolean",
- "default" => false,
- "description" => "By default, it's assumed that we want to wait on our parents' creation phase, in addition to whatever is declared in this stanza. Setting this flag will bypass waiting on our parent resource's creation, so that our create or groom phase can instead depend only on the parent's groom phase. "
- }
+ "type" => "object",
+ "description" => "Declare other objects which this resource requires. This resource will wait until the others are available to create itself.",
+ "required" => ["name", "type"],
+ "additionalProperties" => false,
+ "properties" => {
+ "name" => {"type" => "string"},
+ "type" => {
+ "type" => "string",
+ "enum" => MU::Cloud.resource_types.values.map { |v| v[:cfg_name] }
+ },
+ "phase" => {
+ "type" => "string",
+ "description" => "Which part of the creation process of the resource we depend on should we wait for before starting our own creation? Defaults are usually sensible, but sometimes you want, say, a Server to wait on another Server to be completely ready (through its groom phase) before starting up.",
+ "enum" => ["create", "groom"]
+ },
+ "no_create_wait" => {
+ "type" => "boolean",
+ "default" => false,
+ "description" => "By default, it's assumed that we want to wait on our parents' creation phase, in addition to whatever is declared in this stanza. Setting this flag will bypass waiting on our parent resource's creation, so that our create or groom phase can instead depend only on the parent's groom phase. "
}
+ }
}
}
end
# Have a default value available for config schema elements that take an
@@ -242,11 +239,11 @@
schema["properties"]["cloud"] = MU::Config.cloud_primitive
schema["properties"]["credentials"] = MU::Config.credentials_primitive
schema["title"] = type.to_s
if cloud
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(cloud).const_get(shortclass)
+ cloudclass = MU::Cloud.resourceClass(cloud, type)
if cloudclass.respond_to?(:schema)
_reqd, cloudschema = cloudclass.schema
cloudschema.each { |key, cfg|
if schema["properties"][key]
@@ -296,15 +293,14 @@
conf_chunk.map! { |item|
# If we're working on a resource type, go get implementation-specific
# schema information so that we set those defaults correctly.
realschema = if type and schema_chunk["items"] and schema_chunk["items"]["properties"] and item["cloud"] and MU::Cloud.supportedClouds.include?(item['cloud'])
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(item["cloud"]).const_get(type)
- _toplevel_required, cloudschema = cloudclass.schema(self)
+ _toplevel_required, cloudschema = MU::Cloud.resourceClass(item["cloud"], type).schema(self)
newschema = schema_chunk["items"].dup
- newschema["properties"].merge!(cloudschema)
+ MU::Config.schemaMerge(newschema["properties"], cloudschema, item["cloud"])
newschema
else
schema_chunk["items"].dup
end
@@ -337,12 +333,12 @@
if !MU::Cloud.supportedClouds.include?(kitten['cloud'])
return
end
- cloudclass = Object.const_get("MU").const_get("Cloud").const_get(kitten['cloud'])
- shortclass, _cfg_name, _cfg_plural, _classname = MU::Cloud.getResourceNames(type)
- resclass = Object.const_get("MU").const_get("Cloud").const_get(kitten['cloud']).const_get(shortclass)
+ cloudclass = MU::Cloud.cloudClass(kitten['cloud'])
+
+ resclass = MU::Cloud.resourceClass(kitten['cloud'], type)
schema_fields = ["us_only", "scrub_mu_isms", "credentials", "billing_acct"]
if !resclass.isGlobal?
kitten['region'] ||= @config['region']
kitten['region'] ||= cloudclass.myRegion(kitten['credentials'])