Chapter 09/circuit-oneops-1-master/components/cookbooks/azure/libraries/network_interface_card.rb
# this manages building the network profile in preperation of creating
# the vm.
this manages building the network profile in preperation of creating
the vm.
this manages building the network profile in preperation of creating the vm .
def build_network_profile(express_route_enabled, master_rg, pre_vnet, network_address, subnet_address_list, dns_list, ip_type, security_group_name)
      virtual_network = AzureNetwork::VirtualNetwork.new(creds, subscription)
      virtual_network.location = @location
      subnet_cls = AzureNetwork::Subnet.new(creds, subscription)
      if express_route_enabled == 'true'
        OOLog.info("Master resource group: '#{master_rg}'")
        OOLog.info("Pre VNET: '#{pre_vnet}'")
        virtual_network.name = pre_vnet
        network = virtual_network.get(master_rg)
        OOLog.fatal('Expressroute requires preconfigured networks') if network.nil?
      else
        network_name = 'vnet_'+ network_address.gsub('.','_').gsub('/', '_')
        OOLog.info("Using RG: '#{@rg_name}' to find vnet: '#{network_name}'")
        virtual_network.name = network_name
        if !virtual_network.exists?(@rg_name)
          virtual_network.address = network_address
          virtual_network.sub_address = subnet_address_list
          virtual_network.dns_list = dns_list
          new_vnet = virtual_network.build_network_object
          network = virtual_network.create_update(@rg_name, new_vnet)
        else
          network = virtual_network.get(@rg_name)
        end
      end
      subnetlist = network.body.properties.subnets
      subnet =
          subnet_cls.get_subnet_with_available_ips(subnetlist,
                                                   express_route_enabled)
      nic_ip_config = define_nic_ip_config(ip_type, subnet)
      network_interface = define_network_interface(nic_ip_config)
      nsg = AzureNetwork::NetworkSecurityGroup.new(creds, subscription)
      network_security_group = nsg.get(@rg_name, security_group_name)
      if !network_security_group.nil?
        network_interface.properties.network_security_group = network_security_group
      end
      nic = create_update(network_interface)
      @private_ip =
          nic.properties.ip_configurations[0].properties.private_ipaddress
      OOLog.info('Private IP is: ' + @private_ip)
      network_interface.id = nic.id
      network_profile = Azure::ARM::Compute::Models::NetworkProfile.new
      network_profile.network_interfaces = [network_interface]
      @profile = network_profile
    end
def build_network_profile ( express_route_enabled , master_rg , pre_vnet , network_address , subnet_address_list , dns_list , ip_type , security_group_name ) virtual_network = AzureNetwork :: VirtualNetwork . new ( creds , subscription ) virtual_network . location = @location subnet_cls = AzureNetwork :: Subnet . new ( creds , subscription ) if express_route_enabled == 'true' OOLog . info ( "Master resource group: '#{master_rg}'" ) OOLog . info ( "Pre VNET: '#{pre_vnet}'" ) virtual_network . name = pre_vnet network = virtual_network . get ( master_rg ) OOLog . fatal ( 'Expressroute requires preconfigured networks' ) if network . nil? else network_name = 'vnet_' + network_address . gsub ( '.' , '_' ) . gsub ( '/' , '_' ) OOLog . info ( "Using RG: '#{@rg_name}' to find vnet: '#{network_name}'" ) virtual_network . name = network_name if ! virtual_network . exists? ( @rg_name ) virtual_network . address = network_address virtual_network . sub_address = subnet_address_list virtual_network . dns_list = dns_list new_vnet = virtual_network . build_network_object network = virtual_network . create_update ( @rg_name , new_vnet ) else network = virtual_network . get ( @rg_name ) end end subnetlist = network . body . properties . subnets subnet = subnet_cls . get_subnet_with_available_ips ( subnetlist , express_route_enabled ) nic_ip_config = define_nic_ip_config ( ip_type , subnet ) network_interface = define_network_interface ( nic_ip_config ) nsg = AzureNetwork :: NetworkSecurityGroup . new ( creds , subscription ) network_security_group = nsg . get ( @rg_name , security_group_name ) if ! network_security_group . nil? network_interface . properties . network_security_group = network_security_group end nic = create_update ( network_interface ) @private_ip = nic . properties . ip_configurations [ 0 ] . properties . private_ipaddress OOLog . info ( 'Private IP is: ' + @private_ip ) network_interface . id = nic . id network_profile = Azure :: ARM :: Compute :: Models :: NetworkProfile . new network_profile . network_interfaces = [ network_interface ] @profile = network_profile end
this manages building the network profile in preperation of creating
the vm.
this manages building the network profile in preperation of creating the vm .
# get the objects needed to build the profile # if the express route is enabled we will look for a preconfigured vnet #TODO add checks for master rg and preconf vnet # get the preconfigured vnet from Azure # fail if we can't find a vnet # network = virtual_network.get(@rg_name) # if network.nil? # set the network info on the object # build the network object # create the vnet # get the subnet to use for the network # define the NIC ip config object # define the nic #include the network securtiry group to the network interface # create the nic # retrieve and set the private ip # set the nic id on the network_interface object # create the network profile # set the nic on the profile # set the profile on the object.
express_route_enabled
<not_specific>
master_rg
<not_specific>
pre_vnet
<not_specific>
network_address
<not_specific>
subnet_address_list
<not_specific>
dns_list
<not_specific>
ip_type
<not_specific>
security_group_name
<not_specific>