modules/mu/clouds/azure/vpc.rb in cloud-mu-3.1.3 vs modules/mu/clouds/azure/vpc.rb in cloud-mu-3.1.4

- old
+ new

@@ -51,11 +51,10 @@ # Called automatically by {MU::Deploy#createResources} def groom if @config['peers'] - count = 0 @config['peers'].each { |peer| if peer['vpc']['name'] peer_obj = @deploy.findLitterMate(name: peer['vpc']['name'], type: "vpcs", habitat: peer['vpc']['project']) next if peer_obj.mu_name < @mu_name # both of us would try to create this peering, otherwise, so don't step on each other else @@ -111,21 +110,20 @@ end # Describe this VPC # @return [Hash] def notify - base = {} base = MU.structToHash(cloud_desc) base["cloud_id"] = @cloud_id.name base.merge!(@config.to_h) base end -# + # Describe this VPC from the cloud platform's perspective # @return [Hash] - def cloud_desc - if @cloud_desc_cache + def cloud_desc(use_cache: true) + if @cloud_desc_cache and use_cache return @cloud_desc_cache end @cloud_desc_cache = MU::Cloud::Azure::VPC.find(cloud_id: @cloud_id, resource_group: @resource_group).values.first @cloud_id ||= Id.new(@cloud_desc_cache.id) @@ -190,14 +188,13 @@ # information similar to what MU::Cloud.describe builds for first-class # resources. # @param use_cache [Boolean]: If available, use saved deployment metadata to describe subnets, instead of querying the cloud API # @return [Array<Hash>]: A list of cloud provider identifiers of subnets associated with this VPC. def loadSubnets(use_cache: false) - desc = cloud_desc @subnets = [] - MU::Cloud::Azure.network(credentials: @credentials).subnets.list(@resource_group, cloud_desc.name).each { |subnet| + MU::Cloud::Azure.network(credentials: @credentials).subnets.list(@resource_group, cloud_desc(use_cache: use_cache).name).each { |subnet| subnet_cfg = { "cloud_id" => subnet.name, "mu_name" => subnet.name, "credentials" => @config['credentials'], "region" => @config['region'], @@ -332,11 +329,11 @@ # Reverse-map our cloud description into a runnable config hash. # We assume that any values we have in +@config+ are placeholders, and # calculate our own accordingly based on what's live in the cloud. # XXX add flag to return the diff between @config and live cloud - def toKitten(rootparent: nil, billing: nil) + def toKitten(**_args) return nil if cloud_desc.name == "default" # parent project builds these bok = { "cloud" => "Azure", "project" => @config['project'], "credentials" => @config['credentials'] @@ -344,13 +341,13 @@ bok end # Cloud-specific configuration properties. - # @param config [MU::Config]: The calling MU::Config object + # @param _config [MU::Config]: The calling MU::Config object # @return [Array<Array,Hash>]: List of required fields, and json-schema Hash of cloud-specific configuration parameters for this resource - def self.schema(config = nil) + def self.schema(_config = nil) toplevel_required = [] schema = { "peers" => { "items" => { "properties" => { @@ -520,11 +517,10 @@ end # this is slow, so maybe thread it rtb_map = {} routethreads = [] - create_nat_gateway = false @config['route_tables'].each { |rtb_cfg| routethreads << Thread.new(rtb_cfg) { |rtb| rtb_name = @mu_name+"-"+rtb['name'].upcase rtb_obj = MU::Cloud::Azure.network(:RouteTable).new rtb_obj.location = @config['region'] @@ -571,10 +567,13 @@ route_obj = MU::Cloud::Azure.network(:Route).new route_obj.address_prefix = route['destination_network'] routename = rtb_name+"-"+route['destination_network'].gsub(/[^a-z0-9]/i, "_") route_obj.next_hop_type = if route['gateway'] == "#NAT" and @config['bastion'] routename = rtb_name+"-NAT" + if @config['bastion'].is_a?(Hash) and !@config['bastion']['id'] and !@config['bastion']['deploy_id'] + @config['bastion']['deploy_id'] = @deploy.deploy_id + end bastion_ref = MU::Config::Ref.get(@config['bastion']) if bastion_ref.kitten and bastion_ref.kitten.cloud_desc iface_id = Id.new(bastion_ref.kitten.cloud_desc.network_profile.network_interfaces.first.id) iface_desc = MU::Cloud::Azure.network(credentials: @credentials).network_interfaces.get(@resource_group, iface_id.name) if iface_desc and iface_desc.ip_configurations and iface_desc.ip_configurations.size > 0 @@ -716,12 +715,10 @@ end loadSubnets end - protected - # Subnets are almost a first-class resource. So let's kinda sorta treat # them like one. This should only be invoked on objects that already # exists in the cloud layer. class Subnet < MU::Cloud::Azure::VPC @@ -770,11 +767,11 @@ def notify MU.structToHash(cloud_desc) end # Describe this VPC Subnet from the cloud platform's perspective - def cloud_desc - return @cloud_desc_cache if !@cloud_desc_cache.nil? + def cloud_desc(use_cache: true) + return @cloud_desc_cache if @cloud_desc_cache and use_cache @cloud_desc_cache = MU::Cloud::Azure.network(credentials: @parent.credentials).subnets.get(@parent.resource_group, @parent.cloud_desc.name, @cloud_id.to_s) @cloud_desc_cache end # Is this subnet privately-routable only, or public?