Hello at all.
I'm trying to use Visual Studio 2005 to acquire information about Virtual Center / ESX environments.
After adding DLLs VIToolkitForWindows, I used the standard code for undocumented connect to the structure (Virtual Center):
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Config As New VMware.VimAutomation.Client20.VimClient
Config.ConnectivityService.Login("https", "192.168.178.101", "443", "root", "vmware")
MsgBox(Config.ConnectivityService.IsConnected)
End Sub
End Class
Now i try to use Config.InventoryService.GetVM :
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Config As New VMware.VimAutomation.Client20.VimClient
Config.ConnectivityService.Login("https", "192.168.178.101", "443", "root", "vmware")
MsgBox(Config.ConnectivityService.IsConnected)
Dim MyVM As New System.Collections.Generic.List(Of VimAutomation.Types.VirtualMachine)
Dim MyVMName() As String
Dim MyVMId() As String
Dim MyConts As New System.Collections.Generic.List(Of VimAutomation.Types.VIContainer)
Dim MyDataStore() As Datastore
MyVM = Config.InventoryService.GetVM(MyVMId, MyVMName, MyConts, False, MyDataStore)
End Sub
End Class
but I always get the error of "Username / Password error" in debug mode step-by-step at line MyVM = ....
Someone was able to use this method or documentation exists on how to exploit it in Visual Studio 2005?
Thanks to all.
This source works perfect with visual studio 2008
If I add the following source...
For Each david3 As VMware.VimAutomation.Types.VirtualMachine In MyVM
MsgBox(david3.ID)
MsgBox(david3.Name.ToString)
MsgBox(david3.PowerState)
MsgBox(david3.Host.State)
MsgBox(david3.NetworkAdapters)
Next
There is no output.
and msgbox(MyVM.count) gives zero..
any idea ?
thanx! David
Carter Shanklin created a nice little slideshow about Using VI Toolkit (For Windows) From .NET and uploaded it to SlideShare. Although all the examples are written in C++ you can learn a lot from his presentation. You also should take a look at the VMware Infrastructure .NET Toolkit 1.0 Developer's Guide. Finally I was able to convert most of Carter's code to Visual Basic Express 2008 and make a connection to my ESX 3.5 server. Here's the source code, just paste it under a button.
Dim MySession As New VMware.Vim.VimClient
MySession.Connect("https://192.168.178.110/sdk")
MySession.Login("root", "vmware")
MsgBox(MySession.ServiceContent.About.FullName)
MySession.Logout()
Hello at all,
Sorry for the response so slow.
So, I managed to build an application that captures all the data of a Virtual Infrastructure and save them in RTF format and / or CSV.
This before the version 1.0.
Example:
Public Class Form1
Public Config As New VMWare.VimAutomation.Client20.VimClient
Public MyConts As New System.Collections.Generic.List(Of VimAutomation.Types.VIContainer)
Public MyDataCenter As System.Collections.Generic.List(Of VimAutomation.Types.Datacenter)
Public MyVM As New System.Collections.Generic.List(Of VimAutomation.Types.VirtualMachine)
Public _MyVMName() As String
Public _MyVMId() As String
Public _MyDataStore() As Datastore
Public _MyVM() As VimAutomation.Types.VirtualMachine
Public _MyCluster() As VimAutomation.Types.Cluster
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim T As Byte
Info.ForeColor = Color.YellowGreen
Info.Text = "Connecting......"
Button1.Enabled = False
Button3.Enabled = False
Me.Cursor = Cursors.WaitCursor
My.Application.DoEvents()
Config.ConnectivityService.Login("https", TBServer.Text, "443", TBUsername.Text, TBPassword.Text)
My.Application.DoEvents()
If Config.ConnectivityService.IsConnected Then
Info.ForeColor = Color.Green
Info.Text = "Connected!"
TBServer.Enabled = False
TBUsername.Enabled = False
TBPassword.Enabled = False
Button1.Enabled = False
Button2.Enabled = True
ComboBox1.Enabled = True
MyConf = New VMWare.VimAutomation.Client20.VimClientConfig(TBServer.Text, TBUsername.Text, TBPassword.Text)
List.Server = MyServer
MsgBox(Config.ConnectivityService.CurrentUserSession.UserName + vbCrLf + "System Version" + Str(Config.ConnectivityService.GetApiInfo.ApiVersion), MsgBoxStyle.Information, "Wellcome")
MyVM = Config.InventoryService.GetVM(_MyVMId, _MyVMId, MyConts, True, _MyDataStore)
MyDataCenter = Config.InventoryService.GetDatacenter(_MyVMId, _MyVMName, MyConts, True, _MyCluster, _MyVM)
Else
Info.ForeColor = Color.Red
Info.Text = "Not Connected!"
Button1.Enabled = True
End If
Button3.Enabled = True
Me.Cursor = Cursors.Default
End Sub
End Class
OK, variable MyVM and MyDataCenter conatain all VM and all DataCenter in VC or ESX contacted.
When i installed version 1.0, i must add ErrorCallBak in some Function Call:
Public Class Form1
Public Config As New VMWare.VimAutomation.Client20.VimClient
Public MyConts As New System.Collections.Generic.List(Of VimAutomation.Types.VIContainer)
Public MyDataCenter As System.Collections.Generic.List(Of VimAutomation.Types.Datacenter)
Public MyVM As New System.Collections.Generic.List(Of VimAutomation.Types.VirtualMachine)
Public _MyVMName() As String
Public _MyVMId() As String
Public _MyDataStore() As Datastore
Public _MyVM() As VimAutomation.Types.VirtualMachine
Public _MyCluster() As VimAutomation.Types.Cluster
Public _MyErrorCB As VimAutomation.Types.ErrorCallback
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim T As Byte
Info.ForeColor = Color.YellowGreen
Info.Text = "Connecting......"
Button1.Enabled = False
Button3.Enabled = False
Me.Cursor = Cursors.WaitCursor
My.Application.DoEvents()
Config.ConnectivityService.Login("https", TBServer.Text, "443", TBUsername.Text, TBPassword.Text)
My.Application.DoEvents()
If Config.ConnectivityService.IsConnected Then
Info.ForeColor = Color.Green
Info.Text = "Connected!"
TBServer.Enabled = False
TBUsername.Enabled = False
TBPassword.Enabled = False
Button1.Enabled = False
Button2.Enabled = True
MyConf = New VMWare.VimAutomation.Client20.VimClientConfig(TBServer.Text, TBUsername.Text, TBPassword.Text)
List.Server = MyServer
MsgBox(Config.ConnectivityService.CurrentUserSession.UserName + vbCrLf + "System Version" + Str(Config.ConnectivityService.GetApiInfo.ApiVersion), MsgBoxStyle.Information, "Wellcome")
MyVM = Config.InventoryService.GetVM(_MyVMId, _MyVMId, MyConts, True, _MyDataStore)
MyDataCenter = Config.InventoryService.GetDatacenter(_MyVMId, _MyVMName, MyConts, True, _MyCluster, _MyVM, _MyErrorCB)
Else
Info.ForeColor = Color.Red
Info.Text = "Not Connected!"
Button1.Enabled = True
End If
Button3.Enabled = True
Me.Cursor = Cursors.Default
End Sub
End Class
Now, I get an error when requests GetVm and GetDataStore: first-chance exception of type 'System.ArgumentException' in Mscorlib.dll = A delegate of a method for instance can not have 'this' null.
Same declaration, same variable, same all and only new version.
Can someone help me?
Thanks to all.