Skip to content

Instantly share code, notes, and snippets.

@timogoebel
Created March 23, 2020 12:58
Show Gist options
  • Save timogoebel/0809d97444f3fc614b0a50f7dc057b61 to your computer and use it in GitHub Desktop.
Save timogoebel/0809d97444f3fc614b0a50f7dc057b61 to your computer and use it in GitHub Desktop.
create a vm on vsphere with fog-vsphere
#!/usr/bin/env ruby
require 'fog'
require 'awesome_print'
require 'pry'
client = ::Fog::Compute.new(
:provider => 'vsphere',
:vsphere_username => 'xx',
:vsphere_password => 'xx',
:vsphere_server => 'xx',
:vsphere_expected_pubkey_hash => 'xx',
)
interface_attrs = {:network=>"SomeNetwork", :type=>"VirtualE1000"}
attrs = {
:name => "testvm.example.com",
:memory_mb => "768",
:interfaces => [ interface_attrs ],
:volumes => [
{
:storage_pod=>"EXAMPLE-POD",
:name=>"Hard disk",
:size_gb=>"10",
:thin=>"true",
:eager_zero=>"false"
}
],
:scsi_controller=> {
:type=>"VirtualLsiLogicController"
},
:datacenter => "DC",
:boot_order => ["network", "disk"],
:cpus => "1",
:corespersocket => "1",
:cluster=>"CLUSTER",
:resource_pool=>"default",
:path => "/Datencenter/My/Folder",
:guest_id=>"rhel7_64Guest",
:memoryHotAddEnabled=>"1",
:cpuHotAddEnabled=>"1",
:start=>"1",
:annotation=>"Test VM"
}
vm = client.servers.new(attrs)
binding.pry
#vm.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment