Beispiel #1
0
func run(c *cli.Context) error {
	utils.InitConsoleLog()

	var sn = getSN()
	isVm := isVirtualMachine()
	if isVm {
		sn = getMacAddress()
	}

	if sn == "" {
		return errors.New("get sn failed")
	}

	//init cloudboot server host
	serverIp := getDomainLookupIP(serverHost)
	if serverIp != "" {
		serverHost = serverIp
	}

	if !utils.PingLoop(serverHost, 30, 2) {
		return errors.New("ping timeout")
	}

	// get xml for install windows
	if err := getXmlFile(sn, serverHost); err != nil {
		return err
	}

	// mount samba
	if err := mountSamba(); err != nil {
		return err
	}

	//load drive
	loadDrive()

	utils.ReportProgress(0.6, sn, "开始安装", "start install", serverHost)
	// install windows
	if err := installWindows(); err != nil {
		return err
	}

	// xcopy firstboot
	if err := copyFirstBoot(); err != nil {
		return err
	}

	// reboot
	return reboot()
}
Beispiel #2
0
func run(c *cli.Context) error {
	// init log
	utils.InitFileLog()

	if utils.CheckFileIsExist(preInstallScript) {
		if _, err := utils.ExecScript(preInstallScript); err != nil {
			utils.Logger.Error("preinstall error: %s", err.Error())
		}
	}
	//init cloudboot server host
	serverIp := getDomainLookupIP(serverHost)
	if serverIp != "" {
		serverHost = serverIp
	}

	if !utils.PingLoop(serverHost, 300, 2) {
		return errors.New("ping timeout")
	}

	var sn = getSN()
	isVm := isVirtualMachine()
	if isVm {
		sn = getMacAddress()
	}

	if sn == "" {
		utils.Logger.Error("get sn failed!")
	}

	restInfo, err := getRestInfo(sn, serverHost)
	if err != nil {
		utils.Logger.Error(err.Error())
	}
	// fmt.Println(restInfo)

	var nicInterfaceIndex = getNicInterfaceIndex(restInfo.HWADDR)
	if nicInterfaceIndex == "" {
		utils.Logger.Error("get nic interface index failed")
	}

	var dns = getDNS()
	if dns == "" {
		utils.Logger.Error("get dns failed")
	}

	if err = diskpart(); err != nil {
		utils.Logger.Error(err.Error())
	}
	utils.ReportProgress(0.7, sn, "分区", "diskpart", serverHost)

	if err = changeHostname(restInfo.Hostname); err != nil {
		utils.Logger.Error(err.Error())
	}
	utils.ReportProgress(0.75, sn, "修改主机名", "change hostname", serverHost)

	if err = changeIP(nicInterfaceIndex, restInfo.Ip, restInfo.Netmask, restInfo.Gateway); err != nil {
		utils.Logger.Error(err.Error())
	}

	if err = changeDNS(nicInterfaceIndex, dns); err != nil {
		utils.Logger.Error(err.Error())
	}

	time.Sleep(30 * time.Second)
	if !utils.PingLoop(serverHost, 300, 2) {
		return errors.New("ping timeout")
	}
	utils.ReportProgress(0.8, sn, "修改网络配置", "change network", serverHost)

	if err = changeReg(); err != nil {
		utils.Logger.Error(err.Error())
	}
	utils.ReportProgress(0.9, sn, "修改注册表", "change reg", serverHost)

	utils.ReportProgress(1.0, sn, "安装完成", "finish", serverHost)

	if utils.CheckFileIsExist(postInstallScript) {
		if _, err := utils.ExecScript(postInstallScript); err != nil {
			utils.Logger.Error("postInstall error: %s", err.Error())
		}
	}

	reboot()

	return nil
}