Пример #1
0
func destroy(c *cli.Context) {
	log.Infoln("Destroy")

	additionalEnvs, err := config.CreateEnvItemsModelFromSlice(MachineParamsAdditionalEnvs.Get())
	if err != nil {
		log.Fatalf("Invalid Environment parameter: %s", err)
	}

	configModel, err := config.ReadMachineConfigFileFromDir(MachineWorkdir.Get(), additionalEnvs)
	if err != nil {
		log.Fatalln("Failed to read Config file: ", err)
	}

	isOK, err := pathutil.IsPathExists(path.Join(MachineWorkdir.Get(), "Vagrantfile"))
	if err != nil {
		log.Fatalln("Failed to check 'Vagrantfile' in the WorkDir: ", err)
	}
	if !isOK {
		log.Fatalln("Vagrantfile not found in the WorkDir!")
	}

	log.Infof("configModel: %#v", configModel)

	if err := doCleanup(configModel, "will-be-destroyed"); err != nil {
		log.Fatalf("Failed to Cleanup: %s", err)
	}

	if err := doDestroy(configModel); err != nil {
		log.Fatalf("Failed to Destroy: %s", err)
	}

	log.Infoln("=> Destroy DONE - OK")
}
Пример #2
0
func cleanup(c *cli.Context) {
	log.Infoln("Cleanup")

	additionalEnvs, err := config.CreateEnvItemsModelFromSlice(MachineParamsAdditionalEnvs.Get())
	if err != nil {
		log.Fatalf("Invalid Environment parameter: %s", err)
	}
	log.Debugf("additionalEnvs: %#v", additionalEnvs)

	configModel, err := config.ReadMachineConfigFileFromDir(MachineWorkdir.Get(), additionalEnvs)
	if err != nil {
		log.Fatalln("Failed to read Config file: ", err)
	}

	log.Infof("configModel: %#v", configModel)

	if err := doCleanup(configModel, ""); err != nil {
		log.Fatalf("Failed to Cleanup: %s", err)
	}

	log.Infoln("Cleanup - DONE - OK")
}
Пример #3
0
func setup(c *cli.Context) {
	log.Infoln("Setup")

	additionalEnvs, err := config.CreateEnvItemsModelFromSlice(MachineParamsAdditionalEnvs.Get())
	if err != nil {
		log.Fatalf("Invalid Environment parameter: %s", err)
	}

	configModel, err := config.ReadMachineConfigFileFromDir(MachineWorkdir.Get(), additionalEnvs)
	if err != nil {
		log.Fatalln("Failed to read Config file: ", err)
	}

	isOK, err := pathutil.IsPathExists(path.Join(MachineWorkdir.Get(), "Vagrantfile"))
	if err != nil {
		log.Fatalln("Failed to check 'Vagrantfile' in the WorkDir: ", err)
	}
	if !isOK {
		log.Fatalln("Vagrantfile not found in the WorkDir!")
	}

	log.Infof("configModel: %#v", configModel)

	isSkipSetups := false
	if config.IsSSHKeypairFileExistInDirectory(MachineWorkdir.Get()) && !c.Bool(ForceFlagKey) {
		log.Info("Host is already prepared and no --force flag was specified, skipping setup.")
		isSkipSetups = true
	}

	if !isSkipSetups {
		// doCleanup
		if configModel.IsCleanupBeforeSetup {
			if err := doCleanup(configModel, ""); err != nil {
				log.Fatalf("Failed to Cleanup: %s", err)
			}
		}

		if configModel.CleanupMode == config.CleanupModeDestroy || configModel.IsAllowVagrantCreateInSetup {
			if err := doCreateIfRequired(configModel); err != nil {
				log.Fatalf("Failed to Create the VM: %s", err)
			}
		}

		// ssh
		_, err := doSetupSSH(configModel)
		if err != nil {
			log.Fatalf("Failed to Setup SSH: %s", err)
		}
	}

	// time sync
	sshConfigModel, err := config.ReadSSHConfigFileFromDir(MachineWorkdir.Get())
	if err != nil {
		log.Fatalf("Failed to read SSH Config file! Error: %s", err)
	}
	if configModel.IsDoTimesyncAtSetup {
		if err := doTimesync(sshConfigModel); err != nil {
			log.Fatalf("Failed to do Time Sync: %s", err)
		}
	}

	log.Infoln("=> Setup DONE - OK")
}