private void connectButton_Click(object sender, EventArgs e) { connectButton.Enabled = false; connectButton.Text = "Connecting. Please wait..."; connectButton.Refresh(); VCenterUserName = userIDTextbox.Text; VCenterUserPassword = passwordTextbox.Text; VCenterServer = vcenterServerName.Text; try { VCenterClient = new VimClient(); VCenterClient.Connect(String.Format("https://{0}/sdk", vcenterServerName.Text)); VCenterClient.Login(VCenterUserName, VCenterUserPassword); IList<EntityViewBase> dataCenterList = VCenterClient.FindEntityViews(typeof(Datacenter), null, null, null); foreach (Datacenter dc in dataCenterList) { datacenterCombobox.Items.Add(new ComboboxItem(dc.Name, dc.MoRef.Value)); } connectButton.Text = "Connected. Click OK or Select a datacenter and click Import."; button2.Enabled = true; datacenterCombobox.Enabled = true; datacenterCombobox.SelectedIndex = 0; powerStateCombobox.Enabled = true; powerStateCombobox.SelectedIndex = 0; DCMoRef = ((ComboboxItem)datacenterCombobox.SelectedItem).Value; PowerState = powerStateCombobox.SelectedText; button1.Enabled = true; Connected = true; } catch (Exception ex) { connectButton.Text = "Error occurred. Adjust settings and Connect."; connectButton.Enabled = true; } finally { } }
protected VimClient ConnectServer(string viServer, string viUser, string viPassword) { // // Establish a connetion to the provided sdk server // VimClient vimClient = new VimClient(); ServiceContent vimServiceContent = new ServiceContent(); UserSession vimSession = new UserSession(); // // Connect over https to the /sdk page // try { vimClient.Connect(viServer); vimSession = vimClient.Login(viUser, viPassword); vimServiceContent = vimClient.ServiceContent; return vimClient; } catch (VimException ex) { // // VMware Exception occurred // txtErrors.Text = "A server fault of type " + ex.MethodFault.GetType().Name + " with message '" + ex.Message + "' occured while performing requested operation."; Error_Panel.Visible = true; return null; } catch (Exception e) { // // Regular Exception occurred // txtErrors.Text = "A server fault of type " + e.GetType().Name + " with message '" + e.Message + "' occured while performing requested operation."; Error_Panel.Visible = true; vimClient = null; return vimClient; } }
public string Connect() { // connect to vSphere service _client.Connect(_serviceUrl); // Login using username/_password credentials _client.Login(_userName, _password); return(_client.SessionSecret); }
private void btnConnect_Click(object sender, EventArgs e) { lbVM.Items.Clear(); //lbHost.Items.Clear(); //lbCluster.Items.Clear(); // Connect to the VMware vCenter SDK service Client.Connect("https://" + tbVCS.Text + "/sdk"); Client.Login(tbUN.Text, tbPW.Text); // Get a list of Windows VM's NameValueCollection filter = new NameValueCollection(); filter.Add("Config.GuestFullName", "Windows"); vmlist = Client.FindEntityViews(typeof(VirtualMachine), null, filter, null); //Populate the VM names into the VM ListBox foreach (VirtualMachine vm in vmlist) { lbVM.Items.Add(vm.Name); } //Get a list of ESXi hosts //hostlist = Client.FindEntityViews(typeof(HostSystem), null, null, null); //Populate the Host names into the Host ListBox //foreach (HostSystem vmhost in hostlist) //{ // lbHost.Items.Add(vmhost.Name); //} //Get a list of Clusters //clusterlist = Client.FindEntityViews(typeof(ClusterComputeResource), null, null, null); //Populate the Cluster names into the Cluster ListBox /*foreach (ClusterComputeResource cluster in clusterlist) * { * * lbCluster.Items.Add(cluster.Name); * }*/ }
public VAPIConnection(string server, string user, string password) { var config = new NLog.Config.LoggingConfiguration(); // Targets where to log to: File and Console var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "MToolVapiClient.log", Layout = "${longdate} | ${level:uppercase=true:padding=-5:fixedLength=true} | ${logger:padding=-35:fixedLength=true} | ${message}" }; var logconsole = new NLog.Targets.ConsoleTarget("logconsole") { Layout = "${longdate} | ${level:uppercase=true:padding=-5:fixedLength=true} | ${logger:padding=-35:fixedLength=true} | ${message}" }; // Rules for mapping loggers to targets config.AddRule(LogLevel.Trace, LogLevel.Fatal, logconsole); config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); // Apply config NLog.LogManager.Configuration = config; Logger.Info("Logging Initialized"); try { vClient.IgnoreServerCertificateErrors = true; Logger.Info("Connecting to server https://{0}/sdk", server); vClient.Connect("https://" + server + "/sdk"); vClient.Login(user, password); } catch (VimException e) { Logger.Error("EXCEPTION: {0}", e.Message); Logger.Error("EXCEPTION: {0}", e.StackTrace); throw; } }
public VSphereClient(string serviceUrl, string userName, string password) { _client = new VimClient(); _client.Connect(serviceUrl); _client.Login(userName, password); }
private void btnConnect_Click(object sender, EventArgs e) { clearConnections(); progressBar1.Visible = false; btnConnect.Enabled = false; lbHost.Items.Clear(); String _hostIP = null; String _userID = null; String _password = null; if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\Config.xml")) { _appConfig = new XmlDocument(); try { _appConfig.Load(AppDomain.CurrentDomain.BaseDirectory + "\\Config.xml"); } catch (Exception xm) { MessageBox.Show(xm.Message.ToString()); } _hostIP = _appConfig.SelectSingleNode("settings/vmhost").InnerText; _userID = _appConfig.SelectSingleNode("settings/vmhostuserid").InnerText; _password = _appConfig.SelectSingleNode("settings/vmhostpassword").InnerText; _genericUID = _appConfig.SelectSingleNode("settings/vmcommonuserid").InnerText; _genricPWD = _appConfig.SelectSingleNode("settings/vmcommonpassword").InnerText; // Connect to the VMware vCenter SDK service // Client.Connect("https://" + tbVCS.Text + "/sdk"); Client.Connect(@"https://" + _hostIP + "/sdk"); Client.Login(_userID, _password); // Get a list of Windows VM's NameValueCollection Onfilter = new NameValueCollection(); NameValueCollection OFFfilter = new NameValueCollection(); Onfilter.Add("Runtime.PowerState", "PoweredOn"); // filter.Add("Config.GuestFullName", "Windows"); poweredOnvmlist = Client.FindEntityViews(typeof(VirtualMachine), null, Onfilter, null); OFFfilter.Add("Runtime.PowerState", "PoweredOff"); poweredOffvmlist = Client.FindEntityViews(typeof(VirtualMachine), null, OFFfilter, null); listVM.Sorted = true; listBoxPowerOff.Sorted = true; foreach (VirtualMachine vm in poweredOnvmlist) { listVM.Items.Add(vm.Name); PowerOnvmNameList.Add(vm.Name); if (vm.Snapshot != null) { vmSnaps.Add(vm.Name, vm.Snapshot.RootSnapshotList); } } foreach (VirtualMachine vm in poweredOffvmlist) { listBoxPowerOff.Items.Add(vm.Name); if (vm.Snapshot != null) { vmSnaps.Add(vm.Name, vm.Snapshot.RootSnapshotList); } } btnConnect.Enabled = true; //Get a list of ESXi hosts // hostlist = Client.FindEntityViews(typeof(HostSystem), null, null, null); //Populate the Host names into the Host ListBox // foreach (HostSystem vmhost in hostlist) //{ // lbHost.Items.Add(vmhost.Name); //} } else { MessageBox.Show("Config XML is not present"); } }