/*
* Copyright 2014 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
*/
package govcd
import (
"github.com/hmrc/vmware-govcd/testutil"
. "gopkg.in/check.v1"
)
func (s *S) Test_ComposeVApp(c *C) {
testServer.ResponseMap(7, testutil.ResponseMap{
"/api/org/11111111-1111-1111-1111-111111111111": testutil.Response{200, nil, orgExample},
"/api/network/44444444-4444-4444-4444-4444444444444": testutil.Response{200, nil, orgvdcnetExample},
"/api/catalog/e8a20fdf-8a78-440c-ac71-0420db59f854": testutil.Response{200, nil, catalogExample},
"/api/catalogItem/1176e485-8858-4e15-94e5-ae4face605ae": testutil.Response{200, nil, catalogitemExample},
"/api/vAppTemplate/vappTemplate-40cb9721-5f1a-44f9-b5c3-98c5f518c4f5": testutil.Response{200, nil, vapptemplateExample},
"/api/vdc/00000000-0000-0000-0000-000000000000/action/composeVApp": testutil.Response{200, nil, instantiatedvappExample},
"/api/vApp/vapp-00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, vappExample},
})
// Get the Org populated
org, err := s.vdc.GetVDCOrg()
c.Assert(err, IsNil)
// Populate OrgVDCNetwork
net, err := s.vdc.FindVDCNetwork("networkName")
c.Assert(err, IsNil)
// Populate Catalog
cat, err := org.FindCatalog("Public Catalog")
c.Assert(err, IsNil)
// Populate Catalog Item
catitem, err := cat.FindCatalogItem("CentOS64-32bit")
c.Assert(err, IsNil)
// Get VAppTemplate
vapptemplate, err := catitem.GetVAppTemplate()
c.Assert(err, IsNil)
// Compose VApp
task, err := s.vapp.ComposeVApp(net, vapptemplate, "name", "description")
c.Assert(err, IsNil)
c.Assert(task.Task.OperationName, Equals, "vdcInstantiateVapp")
c.Assert(s.vapp.VApp.HREF, Equals, "http://localhost:4444/api/vApp/vapp-00000000-0000-0000-0000-000000000000")
status, err := s.vapp.GetStatus()
c.Assert(err, IsNil)
c.Assert(status, Equals, "POWERED_OFF")
_ = testServer.WaitRequests(7)
}
func (s *S) Test_PowerOn(c *C) {
testServer.Response(200, nil, taskExample)
task, err := s.vapp.PowerOn()
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
}
func (s *S) Test_PowerOff(c *C) {
testServer.Response(200, nil, taskExample)
task, err := s.vapp.PowerOff()
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
}
func (s *S) Test_Reboot(c *C) {
testServer.Response(200, nil, taskExample)
task, err := s.vapp.Reboot()
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
}
func (s *S) Test_AddMetadata(c *C) {
testServer.ResponseMap(8, testutil.ResponseMap{
"/api/org/11111111-1111-1111-1111-111111111111": testutil.Response{200, nil, orgExample},
"/api/network/44444444-4444-4444-4444-4444444444444": testutil.Response{200, nil, orgvdcnetExample},
"/api/catalog/e8a20fdf-8a78-440c-ac71-0420db59f854": testutil.Response{200, nil, catalogExample},
"/api/catalogItem/1176e485-8858-4e15-94e5-ae4face605ae": testutil.Response{200, nil, catalogitemExample},
"/api/vAppTemplate/vappTemplate-40cb9721-5f1a-44f9-b5c3-98c5f518c4f5": testutil.Response{200, nil, vapptemplateExample},
"/api/vdc/00000000-0000-0000-0000-000000000000/action/composeVApp": testutil.Response{200, nil, instantiatedvappExample},
"/api/vApp/vapp-00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, vappExample},
"/api/vApp/vm-00000000-0000-0000-0000-000000000000/metadata/key": testutil.Response{200, nil, taskExample},
})
// Get the Org populated
org, err := s.vdc.GetVDCOrg()
c.Assert(err, IsNil)
// Populate OrgVDCNetwork
net, err := s.vdc.FindVDCNetwork("networkName")
c.Assert(err, IsNil)
// Populate Catalog
cat, err := org.FindCatalog("Public Catalog")
c.Assert(err, IsNil)
// Populate Catalog Item
catitem, err := cat.FindCatalogItem("CentOS64-32bit")
c.Assert(err, IsNil)
// Get VAppTemplate
vapptemplate, err := catitem.GetVAppTemplate()
c.Assert(err, IsNil)
// Compose VApp
task, err := s.vapp.ComposeVApp(net, vapptemplate, "name", "description")
c.Assert(err, IsNil)
c.Assert(task.Task.OperationName, Equals, "vdcInstantiateVapp")
c.Assert(s.vapp.VApp.HREF, Equals, "http://localhost:4444/api/vApp/vapp-00000000-0000-0000-0000-000000000000")
task, err = s.vapp.AddMetadata("key", "value")
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
_ = testServer.WaitRequests(8)
}
func (s *S) Test_ChangeVMName(c *C) {
testServer.ResponseMap(8, testutil.ResponseMap{
"/api/org/11111111-1111-1111-1111-111111111111": testutil.Response{200, nil, orgExample},
"/api/network/44444444-4444-4444-4444-4444444444444": testutil.Response{200, nil, orgvdcnetExample},
"/api/catalog/e8a20fdf-8a78-440c-ac71-0420db59f854": testutil.Response{200, nil, catalogExample},
"/api/catalogItem/1176e485-8858-4e15-94e5-ae4face605ae": testutil.Response{200, nil, catalogitemExample},
"/api/vAppTemplate/vappTemplate-40cb9721-5f1a-44f9-b5c3-98c5f518c4f5": testutil.Response{200, nil, vapptemplateExample},
"/api/vdc/00000000-0000-0000-0000-000000000000/action/composeVApp": testutil.Response{200, nil, instantiatedvappExample},
"/api/vApp/vapp-00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, vappExample},
"/api/vApp/vm-00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, taskExample},
})
// Get the Org populated
org, err := s.vdc.GetVDCOrg()
c.Assert(err, IsNil)
// Populate OrgVDCNetwork
net, err := s.vdc.FindVDCNetwork("networkName")
c.Assert(err, IsNil)
// Populate Catalog
cat, err := org.FindCatalog("Public Catalog")
c.Assert(err, IsNil)
// Populate Catalog Item
catitem, err := cat.FindCatalogItem("CentOS64-32bit")
c.Assert(err, IsNil)
// Get VAppTemplate
vapptemplate, err := catitem.GetVAppTemplate()
c.Assert(err, IsNil)
// Compose VApp
task, err := s.vapp.ComposeVApp(net, vapptemplate, "name", "description")
c.Assert(err, IsNil)
c.Assert(task.Task.OperationName, Equals, "vdcInstantiateVapp")
c.Assert(s.vapp.VApp.HREF, Equals, "http://localhost:4444/api/vApp/vapp-00000000-0000-0000-0000-000000000000")
task, err = s.vapp.ChangeVMName("My-vm")
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
_ = testServer.WaitRequests(8)
}
func (s *S) Test_Reset(c *C) {
testServer.Response(200, nil, taskExample)
task, err := s.vapp.Reset()
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
}
func (s *S) Test_Suspend(c *C) {
testServer.Response(200, nil, taskExample)
task, err := s.vapp.Suspend()
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
}
func (s *S) Test_Shutdown(c *C) {
testServer.Response(200, nil, taskExample)
task, err := s.vapp.Shutdown()
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
}
func (s *S) Test_Undeploy(c *C) {
testServer.Response(200, nil, taskExample)
task, err := s.vapp.Undeploy()
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
}
func (s *S) Test_Deploy(c *C) {
testServer.Response(200, nil, taskExample)
task, err := s.vapp.Deploy()
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
}
func (s *S) Test_Delete(c *C) {
testServer.Response(200, nil, taskExample)
task, err := s.vapp.Delete()
_ = testServer.WaitRequest()
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
}
func (s *S) Test_RunCustomizationScript(c *C) {
testServer.ResponseMap(8, testutil.ResponseMap{
"/api/org/11111111-1111-1111-1111-111111111111": testutil.Response{200, nil, orgExample},
"/api/network/44444444-4444-4444-4444-4444444444444": testutil.Response{200, nil, orgvdcnetExample},
"/api/catalog/e8a20fdf-8a78-440c-ac71-0420db59f854": testutil.Response{200, nil, catalogExample},
"/api/catalogItem/1176e485-8858-4e15-94e5-ae4face605ae": testutil.Response{200, nil, catalogitemExample},
"/api/vAppTemplate/vappTemplate-40cb9721-5f1a-44f9-b5c3-98c5f518c4f5": testutil.Response{200, nil, vapptemplateExample},
"/api/vdc/00000000-0000-0000-0000-000000000000/action/composeVApp": testutil.Response{200, nil, instantiatedvappExample},
"/api/vApp/vapp-00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, vappExample},
"/api/vApp/vm-00000000-0000-0000-0000-000000000000/guestCustomizationSection/": testutil.Response{200, nil, taskExample},
})
// Get the Org populated
org, err := s.vdc.GetVDCOrg()
c.Assert(err, IsNil)
// Populate OrgVDCNetwork
net, err := s.vdc.FindVDCNetwork("networkName")
c.Assert(err, IsNil)
// Populate Catalog
cat, err := org.FindCatalog("Public Catalog")
c.Assert(err, IsNil)
// Populate Catalog Item
catitem, err := cat.FindCatalogItem("CentOS64-32bit")
c.Assert(err, IsNil)
// Get VAppTemplate
vapptemplate, err := catitem.GetVAppTemplate()
c.Assert(err, IsNil)
// Compose VApp
task, err := s.vapp.ComposeVApp(net, vapptemplate, "name", "description")
c.Assert(err, IsNil)
c.Assert(task.Task.OperationName, Equals, "vdcInstantiateVapp")
c.Assert(s.vapp.VApp.HREF, Equals, "http://localhost:4444/api/vApp/vapp-00000000-0000-0000-0000-000000000000")
task, err = s.vapp.RunCustomizationScript("computername", "this is my script")
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
_ = testServer.WaitRequests(8)
}
func (s *S) Test_ChangeCPUcount(c *C) {
testServer.ResponseMap(8, testutil.ResponseMap{
"/api/org/11111111-1111-1111-1111-111111111111": testutil.Response{200, nil, orgExample},
"/api/network/44444444-4444-4444-4444-4444444444444": testutil.Response{200, nil, orgvdcnetExample},
"/api/catalog/e8a20fdf-8a78-440c-ac71-0420db59f854": testutil.Response{200, nil, catalogExample},
"/api/catalogItem/1176e485-8858-4e15-94e5-ae4face605ae": testutil.Response{200, nil, catalogitemExample},
"/api/vAppTemplate/vappTemplate-40cb9721-5f1a-44f9-b5c3-98c5f518c4f5": testutil.Response{200, nil, vapptemplateExample},
"/api/vdc/00000000-0000-0000-0000-000000000000/action/composeVApp": testutil.Response{200, nil, instantiatedvappExample},
"/api/vApp/vapp-00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, vappExample},
"/api/vApp/vm-00000000-0000-0000-0000-000000000000/virtualHardwareSection/cpu": testutil.Response{200, nil, taskExample},
})
// Get the Org populated
org, err := s.vdc.GetVDCOrg()
c.Assert(err, IsNil)
// Populate OrgVDCNetwork
net, err := s.vdc.FindVDCNetwork("networkName")
c.Assert(err, IsNil)
// Populate Catalog
cat, err := org.FindCatalog("Public Catalog")
c.Assert(err, IsNil)
// Populate Catalog Item
catitem, err := cat.FindCatalogItem("CentOS64-32bit")
c.Assert(err, IsNil)
// Get VAppTemplate
vapptemplate, err := catitem.GetVAppTemplate()
c.Assert(err, IsNil)
// Compose VApp
task, err := s.vapp.ComposeVApp(net, vapptemplate, "name", "description")
c.Assert(err, IsNil)
c.Assert(task.Task.OperationName, Equals, "vdcInstantiateVapp")
c.Assert(s.vapp.VApp.HREF, Equals, "http://localhost:4444/api/vApp/vapp-00000000-0000-0000-0000-000000000000")
task, err = s.vapp.ChangeCPUcount(2)
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
_ = testServer.WaitRequests(8)
}
func (s *S) Test_ChangeMemorySize(c *C) {
testServer.ResponseMap(8, testutil.ResponseMap{
"/api/org/11111111-1111-1111-1111-111111111111": testutil.Response{200, nil, orgExample},
"/api/network/44444444-4444-4444-4444-4444444444444": testutil.Response{200, nil, orgvdcnetExample},
"/api/catalog/e8a20fdf-8a78-440c-ac71-0420db59f854": testutil.Response{200, nil, catalogExample},
"/api/catalogItem/1176e485-8858-4e15-94e5-ae4face605ae": testutil.Response{200, nil, catalogitemExample},
"/api/vAppTemplate/vappTemplate-40cb9721-5f1a-44f9-b5c3-98c5f518c4f5": testutil.Response{200, nil, vapptemplateExample},
"/api/vdc/00000000-0000-0000-0000-000000000000/action/composeVApp": testutil.Response{200, nil, instantiatedvappExample},
"/api/vApp/vapp-00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, vappExample},
"/api/vApp/vm-00000000-0000-0000-0000-000000000000/virtualHardwareSection/memory": testutil.Response{200, nil, taskExample},
})
// Get the Org populated
org, err := s.vdc.GetVDCOrg()
c.Assert(err, IsNil)
// Populate OrgVDCNetwork
net, err := s.vdc.FindVDCNetwork("networkName")
c.Assert(err, IsNil)
// Populate Catalog
cat, err := org.FindCatalog("Public Catalog")
c.Assert(err, IsNil)
// Populate Catalog Item
catitem, err := cat.FindCatalogItem("CentOS64-32bit")
c.Assert(err, IsNil)
// Get VAppTemplate
vapptemplate, err := catitem.GetVAppTemplate()
c.Assert(err, IsNil)
// Compose VApp
task, err := s.vapp.ComposeVApp(net, vapptemplate, "name", "description")
c.Assert(err, IsNil)
c.Assert(task.Task.OperationName, Equals, "vdcInstantiateVapp")
c.Assert(s.vapp.VApp.HREF, Equals, "http://localhost:4444/api/vApp/vapp-00000000-0000-0000-0000-000000000000")
task, err = s.vapp.ChangeMemorySize(4096)
c.Assert(err, IsNil)
c.Assert(task.Task.Status, Equals, "success")
_ = testServer.WaitRequests(8)
}
var instantiatedvappExample = `
My vApp to be deployed
2014-10-24T15:26:59.067Z
false
`
var vappExample = `
Test API GO4444!
Lease settings section
0
0
VApp startup section
The list of logical networks
This isolated network was created with Create VDC.
This is a special place-holder used for disconnected network interfaces.
The configuration parameters for logical networks
This isolated network was created with Create VDC.
true
192.168.99.1
255.255.255.0
true
192.168.99.2
192.168.99.100
bridged
false
false
This is a special place-holder used for disconnected network interfaces.
false
196.254.254.254
255.255.0.0
196.254.254.254
isolated
false
Snapshot information section
2014-11-06T22:24:43.913Z
false
id: cts-6.4-32bit
Virtual hardware requirements
Virtual Hardware Family
0
CentOS64-32bit
vmx-09
00:50:56:02:0b:36
0
false
none
E1000 ethernet adapter on "none"
Network adapter 0
1
E1000
10
0
SCSI Controller
SCSI Controller 0
2
lsilogic
6
0
Hard disk
Hard disk 1
2000
2
17
1
IDE Controller
IDE Controller 1
3
5
0
false
CD/DVD Drive
CD/DVD Drive 1
3002
3
15
0
false
Floppy Drive
Floppy Drive 1
8000
14
hertz * 10^6
Number of Virtual CPUs
1 virtual CPU(s)
4
0
3
1
0
1
byte * 2^20
Memory Size
1024 MB of memory
5
0
4
1024
0
Specifies the operating system installed
CentOS 4/5/6 (32-bit)
Specifies the available VM network connections
0
0
false
00:50:56:02:0b:36
NONE
Specifies Guest OS Customization Settings
true
false
00000000-0000-0000-0000-000000000000
false
false
true
true
false
0
true
cts-6.4-32bit
Specifies Runtime info
Snapshot information section
CentOS64-32bit
false
false
`