# VMware vCloud Director 5.1 API client ## Introduction Collection and Model representation in vcloud_director fog provider. ```no-highlight organizations organization vdcs -> vdc -> vapps -> vapp -> vms -> vm -> customizations -> script -> network -> disks -> disk -> tags -> tag -> power_on networks -> network catalogs -> catalog -> catalog_items -> catalog_item -> instantiate_vapp medias -> media ``` ### Actions Every collection supports the following methods: Method Name | Lazy Load ----------------- | --------- get(id) | false get_by_name(name) | false all | true all(false) | false ### Lazy Loading When listing a collection (eg: `vdc.vapps`), lazy load will be used by default to improve the performance, otherwise it will make as many requests as items are in the collection. You can disable lazy load using the explict caller and passing a *false* option: `vdc.vapps.all(false)`. Attributes showing the value **NonLoaded** will be populated when accessing the value, if there are more than one **NonLoaded** values the first time accessing on any of those values will populate the others. You can explicitly load those attributes with the `reload` method: ```ruby org = vcloud.organizations.first org.reload ``` Lazy load isn't used with `get` and `get_by_name` methods are used. ## Initialization ```ruby vcloud = Fog::Compute::VcloudDirector.new( vcloud_director_username: "@", vcloud_director_password: "", vcloud_director_host: 'example.com', :connection_options => { :ssl_verify_peer => false, :connect_timeout => 200, :read_timeout => 200 } ) ``` ## Organizations ### List Organizations Note that when listing, by default only the attributes `id`, `name`, `type`, and `href` are loaded. To disable lazy loading, and load all attributes, just specify `false`. Another option is to reload a specific item: `vcloud.organizations.first.reload` ```ruby vcloud.organizations ``` ``` ] > ``` ### Retrieve an Organization by Id ```ruby org = vcloud.organizations.get("c6a4c623-c158-41cf-a87a-dbc1637ad55a") ``` ### Retrieve an Organization by Name ```ruby org = vcloud.organizations.get_by_name("DevOps") ``` ## vDCs It shows the Organization's vDCs. ### List vDCs ```ruby org = vcloud.organizations.first org.vdcs ``` ```ruby [ ] > ``` ### Retrieve a vDC ```ruby org = vcloud.organizations.first org.vdcs.get_by_name("DevOps - VDC") ``` ```ruby "application/vnd.vmware.vcloud.network+xml", :name=>"DevOps - Dev Network Connection", :href=>"https://example.com/api/network/d5f47bbf-de27-4cf5-aaaa-56772f2ccd17"}, compute_capacity_cpu=NonLoaded, compute_capacity_memory={:Units=>"MB", :Allocated=>"0", :Limit=>"0", :Used=>"3584", :Overhead=>"65"}, storage_capacity={:Units=>"MB", :Allocated=>"1048320", :Limit=>"1048320", :Used=>"903168", :Overhead=>"0"}, allocation_model="AllocationVApp", capabilities={:SupportedHardwareVersion=>"vmx-09"}, nic_quota=0, network_quota=1024, vm_quota=0, is_enabled=true > ``` ## vApps ### List vApps ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vdc.vapps ``` ```ruby [ , ] > ``` ### Retrieve a vApp ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vdc.vapps.get_by_name("segundo") ``` ```ruby "0", :ovf_stopAction=>"powerOff", :ovf_startDelay=>"0", :ovf_startAction=>"powerOn", :ovf_order=>"0", :ovf_id=>"DEVWEB"}, network_section={:ovf_name=>"DevOps - Dev Network Connection", :"ovf:Description"=>""}, network_config={:networkName=>"DevOps - Dev Network Connection", :Link=>{:rel=>"repair", :href=>"https://example.com/api/admin/network/82a07044-4dda-4a3e-a53d-8981cf0d5baa/action/reset"}, :Description=>"", :Configuration=>{:IpScope=>{:IsInherited=>"true", :Gateway=>"10.192.0.1", :Netmask=>"255.255.252.0", :Dns1=>"10.192.0.11", :Dns2=>"10.192.0.12", :DnsSuffix=>"dev.ad.mdsol.com", :IpRanges=>{:IpRange=>{:StartAddress=>"10.192.0.100", :EndAddress=>"10.192.3.254"}}}, :ParentNetwork=>{:name=>"DevOps - Dev Network Connection", :id=>"d5f47bbf-de27-4cf5-aaaa-56772f2ccd17", :href=>"https://example.com/api/admin/network/d5f47bbf-de27-4cf5-aaaa-56772f2ccd17"}, :FenceMode=>"bridged", :RetainNetInfoAcrossDeployments=>"false"}, :IsDeployed=>"false"}, owner={:type=>"application/vnd.vmware.admin.user+xml", :name=>"restebanez", :href=>"https://example.com/api/admin/user/c3ca7b97-ddea-425f-8bdb-1fdb946f7349"}, InMaintenanceMode=false > ``` ## VMs ### List VMs ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vapp.vms ``` ```ruby "0", :ovf_stopAction=>"powerOff", :ovf_startDelay=>"0", :ovf_startAction=>"powerOn", :ovf_order=>"0", :ovf_id=>"DEVWEB"}, network_section={:ovf_name=>"DevOps - Dev Network Connection", :"ovf:Description"=>""}, network_config={:networkName=>"DevOps - Dev Network Connection", :Link=>{:rel=>"repair", :href=>"https://example.com/api/admin/network/82a07044-4dda-4a3e-a53d-8981cf0d5baa/action/reset"}, :Description=>"", :Configuration=>{:IpScope=>{:IsInherited=>"true", :Gateway=>"10.192.0.1", :Netmask=>"255.255.252.0", :Dns1=>"10.192.0.11", :Dns2=>"10.192.0.12", :DnsSuffix=>"dev.ad.mdsol.com", :IpRanges=>{:IpRange=>{:StartAddress=>"10.192.0.100", :EndAddress=>"10.192.3.254"}}}, :ParentNetwork=>{:name=>"DevOps - Dev Network Connection", :id=>"d5f47bbf-de27-4cf5-aaaa-56772f2ccd17", :href=>"https://example.com/api/admin/network/d5f47bbf-de27-4cf5-aaaa-56772f2ccd17"}, :FenceMode=>"bridged", :RetainNetInfoAcrossDeployments=>"false"}, :IsDeployed=>"false"}, owner={:type=>"application/vnd.vmware.admin.user+xml", :name=>"restebanez", :href=>"https://example.com/api/admin/user/c3ca7b97-ddea-425f-8bdb-1fdb946f7349"}, InMaintenanceMode=false > [ 163840}] > ] > ``` ### Retrieve a VM ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vapp.vms.get_by_name("DEVWEB") ``` ```ruby 163840}] > ``` ### Modify CPU ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.cpu = 4 ``` ```no-highlight ... success 4 ``` ### Modify Memory ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.memory = 4096 ``` ```no-highlight ... success 4096 ``` ### Power On a VM ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.power_on ``` ```no-highlight ..... success true ``` ## VM Customization ### Retrieve VM Customization ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.customization ``` ```ruby ``` ### Modify VM Customization Customization attributes model requires to `save` it after setting the attributes. ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") customization = vm.customization customization.compute_name = "NEWNAME" customization.enabled = false customization.script = "new userdata script" customization.save ``` ```no-highlight .. success true ``` ## VM Network ### Show VM Networks ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.network ``` ```ruby ``` ### Modify one or more attributes Network attributes model requires to `save` it after setting the attributes. ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") network = vm.network network.is_connected = false network.ip_address_allocation_mode = "DHCP" network.save ``` ```no-highlight .. success true ``` ## VM Disk ### List VM Disks ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.disks ``` ```ruby 163840}] > [ , , ] > ``` ### Create a New Disk ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.disks.create(1024) ``` ```no-highlight ... success true ``` The new disk should show up. ```ruby >> vm.disks 163840}] > [ , , , ] > ``` ### Modify the Hard Disk Size ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") disk = vm.disks.get_by_name("Hard disk 2") disk.capacity = 2048 ``` ```no-highlight ... success true ``` ### Destroy a Hard Disk ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") disk = vm.disks.get_by_name("Hard disk 2") disk.destroy ``` ```no-highlight ... success true ``` ## VM Tags ### List VM Tags ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.tags ``` ```ruby 163840}] > [ , , , ] > ``` ### Create a Tag ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.tags.create('this_is_a_key', 'this_is_a_value') ``` ```no-highlight success true ``` ### Retrieve a Tag ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.tags.get_by_name('this_is_a_key') ``` ```ruby ``` ### Modify a Tag ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.tags.get_by_name('this_is_a_key').value = 'new_value' ``` ```no-highlight success "new_value" ``` ### Destroy a Tag ```ruby org = vcloud.organizations.first vdc = org.vdcs.first vapp = vdc.vapps.get_by_name("segundo") vm = vapp.vms.get_by_name("DEVWEB") vm.tags.get_by_name('this_is_a_key').destroy ``` ```no-highlight success true ``` ## Networks It shows the Organization's Networks. ### List Networks ```ruby org = vcloud.organizations.first org.networks ``` ```ruby [ ] > ``` ### Retrieve a Network ```ruby org = vcloud.organizations.first org.networks.get_by_name("DevOps - Dev Network Connection") ``` ```ruby "10.192.0.100", :end_address=>"10.192.3.254"}] > ``` ## Catalogs It shows the Organization's Catalogs. ### List Catalogs ```ruby org = vcloud.organizations.first org.catalogs ``` ```ruby [ , ] > ``` ### Retrieve a Catalog ```ruby org = vcloud.organizations.first org.catalogs.get("4ee720e5-173a-41ac-824b-6f4908bac975") # or get_by_name("Public VM Templates") ``` ```ruby ``` ## Catalog Items ### List Catalog Items ```ruby org = vcloud.organizations.first catalog = org.catalogs.first catalog.catalog_items ``` ```ruby [ , , ] > ``` ### Retrieve a Catalog Item ```ruby org = vcloud.organizations.first catalog = org.catalogs.first catalog.catalog_items.get_by_name('DEVAPP') ``` ```ruby ``` ### Instantiate a vApp Template It creates a Vapp from a CatalogItem. ```ruby org = vcloud.organizations.first catalog = org.catalogs.first template = catalog.catalog_items.get_by_name('DEVAPP') template.instantiate('webserver') ``` It there were more than one vDC or/and network you'd have to specify it as a second param: ```ruby template.instantiate('webserver', { vdc_id: "9a06a16b-12c6-44dc-aee1-06aa52262ea3", network_id: "d5f47bbf-de27-4cf5-aaaa-56772f2ccd17" } ```