コード例 #1
0
        public void Login( string login, string password )
        {
            if ( !VirtualMachineIsRunning() )
            {
                throw new VirtualMachineIsNotReadyException( this, "Virtual machine must be powered on first." );
            }

            _manager.UpdateViewData();

            GuestAuthManager auth = new GuestAuthManager( _virtualMachine.Client, _manager.AuthManager );
            _authentication = new NamePasswordAuthentication
                                  {
                                      Username = login,
                                      Password = password,
                                      InteractiveSession = true
                                  };
            while ( _virtualMachine.Guest.ToolsStatus.GetValueOrDefault( VirtualMachineToolsStatus.toolsNotRunning ) != VirtualMachineToolsStatus.toolsOk
                    || !_virtualMachine.Guest.InteractiveGuestOperationsReady.GetValueOrDefault( false ) )
            {
                Thread.Sleep( 1000 );
                _virtualMachine.UpdateViewData();

                if ( !VirtualMachineIsRunning() )
                {
                    throw new VirtualMachineIsNotReadyException( this, "Virtual machine must be powered on first." );
                }
            }
            auth.ValidateCredentialsInGuest( _virtualMachine.MoRef, _authentication );
            _fileManager = new GuestFileManager( _virtualMachine.Client, _manager.FileManager );
        }
コード例 #2
0
        public override string tryGetFileFromGuest(string srcpath, out Exception errorOrNull)
        {
            try
            {
                NamePasswordAuthentication Auth = new NamePasswordAuthentication
                {
                    Username           = _spec.kernelVMUsername,
                    Password           = _spec.kernelVMPassword,
                    InteractiveSession = true
                };

                VimClientImpl  vClient      = conn.getConnection();
                VirtualMachine underlyingVM = conn.getMachine();

                GuestOperationsManager gom = (GuestOperationsManager)vClient.GetView(vClient.ServiceContent.GuestOperationsManager, null);
                GuestAuthManager       guestAuthManager = vClient.GetView(gom.AuthManager, null) as GuestAuthManager;
                guestAuthManager.ValidateCredentialsInGuest(underlyingVM.MoRef, Auth);
                GuestFileManager GFM = vClient.GetView(gom.FileManager, null) as GuestFileManager;

                FileTransferInformation transferOutput = GFM.InitiateFileTransferFromGuest(underlyingVM.MoRef, Auth, srcpath);
                string nodeIpAddress = vClient.ServiceUrl;
                nodeIpAddress = nodeIpAddress.Remove(nodeIpAddress.LastIndexOf('/'));
                string url = transferOutput.Url.Replace("https://*", nodeIpAddress);
                using (WebClient webClient = new WebClient())
                {
                    errorOrNull = null;
                    return(webClient.DownloadString(url));
                }
            }
            catch (Exception e)
            {
                errorOrNull = e;
                return(null);
            }
        }
コード例 #3
0
        public override void copyToGuest(string dstpath, string srcpath, cancellableDateTime deadline = null)
        {
            if (!File.Exists(srcpath))
            {
                throw new Exception("src file not found");
            }

            // TODO: deadline is ignored here

            NamePasswordAuthentication Auth = new NamePasswordAuthentication
            {
                Username           = _spec.kernelVMUsername,
                Password           = _spec.kernelVMPassword,
                InteractiveSession = true
            };

            VimClientImpl  _vClient      = conn.getConnection();
            VirtualMachine _underlyingVM = conn.getMachine();

            GuestOperationsManager gom = (GuestOperationsManager)_vClient.GetView(_vClient.ServiceContent.GuestOperationsManager, null);
            GuestAuthManager       guestAuthManager = _vClient.GetView(gom.AuthManager, null) as GuestAuthManager;

            guestAuthManager.ValidateCredentialsInGuest(_underlyingVM.MoRef, Auth);
            GuestFileManager GFM = _vClient.GetView(gom.FileManager, null) as GuestFileManager;

            System.IO.FileInfo  FileToTransfer = new System.IO.FileInfo(srcpath);
            GuestFileAttributes GFA            = new GuestFileAttributes()
            {
                AccessTime       = FileToTransfer.LastAccessTimeUtc,
                ModificationTime = FileToTransfer.LastWriteTimeUtc
            };

            if (dstpath.EndsWith("\\"))
            {
                dstpath += Path.GetFileName(srcpath);
            }

            string transferOutput = GFM.InitiateFileTransferToGuest(_underlyingVM.MoRef, Auth, dstpath, GFA, FileToTransfer.Length, true);
            string nodeIpAddress  = _vClient.ServiceUrl.ToString();

            nodeIpAddress  = nodeIpAddress.Remove(nodeIpAddress.LastIndexOf('/'));
            transferOutput = transferOutput.Replace("https://*", nodeIpAddress);
            Uri oUri = new Uri(transferOutput);

            using (WebClient webClient = new WebClient())
            {
                webClient.UploadFile(oUri, "PUT", srcpath);
            }
        }
コード例 #4
0
        public override void mkdir(string newDir, cancellableDateTime deadline)
        {
            // TODO: timeouts
            NamePasswordAuthentication Auth = new NamePasswordAuthentication
            {
                Username           = _spec.kernelVMUsername,
                Password           = _spec.kernelVMPassword,
                InteractiveSession = true
            };

            VimClientImpl  _vClient      = conn.getConnection();
            VirtualMachine _underlyingVM = conn.getMachine();

            GuestOperationsManager gom = (GuestOperationsManager)_vClient.GetView(_vClient.ServiceContent.GuestOperationsManager, null);
            GuestAuthManager       guestAuthManager = _vClient.GetView(gom.AuthManager, null) as GuestAuthManager;

            guestAuthManager.ValidateCredentialsInGuest(_underlyingVM.MoRef, Auth);
            GuestFileManager GFM = _vClient.GetView(gom.FileManager, null) as GuestFileManager;

            GFM.MakeDirectoryInGuest(_underlyingVM.MoRef, Auth, newDir, true);
        }
コード例 #5
0
        public override IAsyncExecutionResult startExecutableAsync(string toExecute, string args, string workingDir = null)
        {
            string tempDir = String.Format("C:\\users\\{0}\\", _spec.kernelVMUsername);

            if (workingDir == null)
            {
                workingDir = tempDir;
            }

            execFileSet fileSet = prepareForExecution(toExecute, args, tempDir);

            NamePasswordAuthentication auth = new NamePasswordAuthentication
            {
                Username           = _spec.kernelVMUsername,
                Password           = _spec.kernelVMPassword,
                InteractiveSession = true
            };

            VimClientImpl  _vClient      = conn.getConnection();
            VirtualMachine _underlyingVM = conn.getMachine();

            GuestOperationsManager gom = (GuestOperationsManager)_vClient.GetView(_vClient.ServiceContent.GuestOperationsManager, null);
            GuestAuthManager       guestAuthManager = (GuestAuthManager)_vClient.GetView(gom.AuthManager, null);

            guestAuthManager.ValidateCredentialsInGuest(_underlyingVM.MoRef, auth);
            GuestProcessManager guestProcessManager = _vClient.GetView(gom.ProcessManager, null) as GuestProcessManager;
            GuestProgramSpec    progSpec            = new GuestProgramSpec
            {
                ProgramPath      = fileSet.launcherPath,
                Arguments        = "",
                WorkingDirectory = workingDir
            };

            guestProcessManager.StartProgramInGuest(_underlyingVM.MoRef, auth, progSpec);

            return(new asyncExecutionResultViaFile(this, fileSet));
        }
コード例 #6
0
        public void AuthenticateInGuest()
        {
            _manager.UpdateViewData();

            GuestAuthManager auth = new GuestAuthManager( _virtualHost, _manager.AuthManager );

            while ( true )
            {
                try
                {
                    auth.ValidateCredentialsInGuest( _vm.MoRef, _authentication );
                    break;
                }
                catch ( VimException )
                {
                    Thread.Sleep( 10000 );
                }
            }

            _fileManager = new GuestFileManager( _virtualHost, _manager.FileManager );
        }