コード例 #1
0
 private ExecCmdResult ExecAppcmd(string arguments,
     ushort numTries = 1, TimeSpan? retrySleepInterval = null, bool expectError = false)
 {
     var execCmd = new ExecCmd(log, appCmdPath, arguments);
     return execCmd.Run(numTries, retrySleepInterval, expectError);
 }
コード例 #2
0
ファイル: BoshAgent.cs プロジェクト: kirannadell/ironfoundry
        private bool Sysprep()
        {
            bool wasSysprepped = false;

            VMSetupState vmSetupState = settings["vm-setup-state"].ToObject<VMSetupState>();
            if (vmSetupState.IsSysprepped)
            {
                return wasSysprepped;
            }

            string unattendXml = Resources.UnattendXML;
            var xdoc = XDocument.Parse(unattendXml);
            XNamespace ns = xdoc.Root.GetDefaultNamespace();
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable());
            nsMgr.AddNamespace("ns", ns.NamespaceName);

            // ComputerName
            var eleComputerName = xdoc.XPathSelectElement(@"/ns:unattend/ns:settings/ns:component/ns:ComputerName", nsMgr);
            string computerName = (string)settings["vm"]["name"];
            eleComputerName.Value = computerName.Substring(0, Math.Min(15, computerName.Length));

            // RegisteredOrganization
            var elements = xdoc.XPathSelectElements(@"//ns:component/ns:RegisteredOrganization", nsMgr);
            foreach (var ele in elements)
            {
                ele.Value = "Tier3"; // TODO
            }

            // RegisteredOwner
            elements = xdoc.XPathSelectElements(@"//ns:component/ns:RegisteredOwner", nsMgr);
            foreach (var ele in elements)
            {
                ele.Value = "Tier3"; // TODO
            }

            string pathToUnattend = Path.GetTempFileName();
            using (var writer = XmlWriter.Create(pathToUnattend))
            {
                xdoc.WriteTo(writer);
            }
            // TODO: this is the sysprep location on 2008
            // http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1005593
            var cmd = new ExecCmd(log, @"C:\Windows\System32\sysprep\sysprep.exe", "/quit /generalize /oobe /unattend:" + pathToUnattend);
            log.Info("Executing: '{0}'", cmd);
            ExecCmdResult rslt = cmd.Run();
            log.Info("Result: '{0}'", rslt);
            if (rslt.Success)
            {
                wasSysprepped = vmSetupState.IsSysprepped = true;
                settings["vm-setup-state"] = JObject.FromObject(vmSetupState);
                SaveSettings();
            }
            cmd = new ExecCmd(log, @"C:\Windows\System32\shutdown.exe", "/r /t 10 /c BOSHAgent /d p:4:2");
            log.Info("Executing: '{0}'", cmd);
            rslt = cmd.Run();
            log.Info("Result: '{0}'", rslt);
            return wasSysprepped;
        }