lib/azure/common-deploy.rb
# Create a Virtual Machine and return it
Create a Virtual Machine and return it
Create a Virtual Machine and return it
def put_vm(group, name, storage_acct, subnet, public_ip, location=WEST_US)
      puts "Putting vm named #{name} in #{location}"
      nic = self.network.network_interfaces.create_or_update(
          group.name,
          "nic-#{name}",
          NetworkModels::NetworkInterface.new.tap do |interface|
            interface.location = WEST_US
            interface.ip_configurations = [
                NetworkModels::NetworkInterfaceIPConfiguration.new.tap do |nic_conf|
                  nic_conf.name = "nic-#{name}"
                  nic_conf.private_ipallocation_method = NetworkModels::IPAllocationMethod::Dynamic
                  nic_conf.subnet = subnet
                  nic_conf.public_ipaddress = public_ip
                end
            ]
          end
      )
      vm_create_params = ComputeModels::VirtualMachine.new.tap do |vm|
        vm.location = location
        vm.os_profile = ComputeModels::OSProfile.new.tap do |os_profile|
          os_profile.computer_name = name
          os_profile.admin_username = 'deploy'
          os_profile.admin_password = 'aslu23r09qoIFnqoiwnfawr!!'
        end
        vm.storage_profile = ComputeModels::StorageProfile.new.tap do |store_profile|
          store_profile.image_reference = ComputeModels::ImageReference.new.tap do |ref|
            ref.publisher = 'canonical'
            ref.offer = 'UbuntuServer'
            ref.sku = '16.04.0-LTS'
            ref.version = 'latest'
          end
          store_profile.os_disk = ComputeModels::OSDisk.new.tap do |os_disk|
            os_disk.name = "os-disk-#{name}"
            os_disk.caching = ComputeModels::CachingTypes::None
            os_disk.create_option = ComputeModels::DiskCreateOptionTypes::FromImage
            os_disk.vhd = ComputeModels::VirtualHardDisk.new.tap do |vhd|
              vhd.uri = "https://#{storage_acct.name}.blob.core.windows.net/confoo/#{name}.vhd"
            end
          end
        end
        vm.hardware_profile = ComputeModels::HardwareProfile.new.tap do |hardware|
          hardware.vm_size = ComputeModels::VirtualMachineSizeTypes::StandardDS2V2
        end
        vm.network_profile = ComputeModels::NetworkProfile.new.tap do |net_profile|
          net_profile.network_interfaces = [
              ComputeModels::NetworkInterfaceReference.new.tap do |ref|
                ref.id = nic.id
                ref.primary = true
              end
          ]
        end
      end
      key_data = default_pub_key
      vm_create_params.os_profile.linux_configuration = ComputeModels::LinuxConfiguration.new.tap do |linux|
        linux.disable_password_authentication = true
        linux.ssh = ComputeModels::SshConfiguration.new.tap do |ssh_config|
          ssh_config.public_keys = [
              ComputeModels::SshPublicKey.new.tap do |pub_key|
                pub_key.key_data = key_data
                pub_key.path = '/home/deploy/.ssh/authorized_keys'
              end
          ]
        end
      end
      self.compute.virtual_machines.create_or_update(group.name, name, vm_create_params)
    end
def put_vm ( group , name , storage_acct , subnet , public_ip , location = WEST_US ) puts "Putting vm named #{name} in #{location}" nic = self . network . network_interfaces . create_or_update ( group . name , "nic-#{name}" , NetworkModels :: NetworkInterface . new . tap do | interface | interface . location = WEST_US interface . ip_configurations = [ NetworkModels :: NetworkInterfaceIPConfiguration . new . tap do | nic_conf | nic_conf . name = "nic-#{name}" nic_conf . private_ipallocation_method = NetworkModels :: IPAllocationMethod :: Dynamic nic_conf . subnet = subnet nic_conf . public_ipaddress = public_ip end ] end ) vm_create_params = ComputeModels :: VirtualMachine . new . tap do | vm | vm . location = location vm . os_profile = ComputeModels :: OSProfile . new . tap do | os_profile | os_profile . computer_name = name os_profile . admin_username = 'deploy' os_profile . admin_password = 'aslu23r09qoIFnqoiwnfawr!!' end vm . storage_profile = ComputeModels :: StorageProfile . new . tap do | store_profile | store_profile . image_reference = ComputeModels :: ImageReference . new . tap do | ref | ref . publisher = 'canonical' ref . offer = 'UbuntuServer' ref . sku = '16.04.0-LTS' ref . version = 'latest' end store_profile . os_disk = ComputeModels :: OSDisk . new . tap do | os_disk | os_disk . name = "os-disk-#{name}" os_disk . caching = ComputeModels :: CachingTypes :: None os_disk . create_option = ComputeModels :: DiskCreateOptionTypes :: FromImage os_disk . vhd = ComputeModels :: VirtualHardDisk . new . tap do | vhd | vhd . uri = "https://#{storage_acct.name}.blob.core.windows.net/confoo/#{name}.vhd" end end end vm . hardware_profile = ComputeModels :: HardwareProfile . new . tap do | hardware | hardware . vm_size = ComputeModels :: VirtualMachineSizeTypes :: StandardDS2V2 end vm . network_profile = ComputeModels :: NetworkProfile . new . tap do | net_profile | net_profile . network_interfaces = [ ComputeModels :: NetworkInterfaceReference . new . tap do | ref | ref . id = nic . id ref . primary = true end ] end end key_data = default_pub_key vm_create_params . os_profile . linux_configuration = ComputeModels :: LinuxConfiguration . new . tap do | linux | linux . disable_password_authentication = true linux . ssh = ComputeModels :: SshConfiguration . new . tap do | ssh_config | ssh_config . public_keys = [ ComputeModels :: SshPublicKey . new . tap do | pub_key | pub_key . key_data = key_data pub_key . path = '/home/deploy/.ssh/authorized_keys' end ] end end self . compute . virtual_machines . create_or_update ( group . name , name , vm_create_params ) end
Create a Virtual Machine and return it
Create a Virtual Machine and return it
group
<not_specific>
name
<not_specific>
storage_acct
<not_specific>
subnet
<not_specific>
public_ip
<not_specific>
location
<not_specific>