Exemple #1
0
// pull <pkg> <instance>
// puull <instance>
func pullRun(args []string) (err error) {

	if len(args) < 1 {
		return lib.Error("Not enough arguments for pull!")
	}

	instance, err := lib.GetInstanceByName(args[0])

	if err != nil {
		return
	}

	var packageName string

	if len(args) == 1 {
		packageName = "default"
	} else {
		packageName = args[1]
	}

	pkg, err := lib.ImportPackage(packageName)

	if err != nil {
		return
	}

	err = lib.TryLogIn(&instance)

	if err != nil {
		return
	}

	id, err := lib.TryRetrieve(pkg, instance)

	if err != nil {
		return
	}

	finished := false
	contents := []byte("")
	maxTime := int(time.Minute * 5)
	currentTime := 0

	for !finished {
		sleepTime := int(3 * time.Second)
		currentTime += sleepTime

		if currentTime <= maxTime {
			time.Sleep(time.Duration(sleepTime))
			finished, contents = lib.CheckAsyncRetrieve(id, instance)
		} else {
			return lib.Error("Job exceeded maximum time!")
		}
	}

	err = writePulledFiles(contents)

	if err != nil {
		return
	}

	return
}
Exemple #2
0
// implemented as :
// dev deploy instance package
// TODO: Add flags for max time, etc
func deployRun(args []string) (err error) {

	if len(args) < 1 {
		err = lib.Error("Not enough arguments for deploy!")
		return
	}

	instanceName := args[0]
	packageName := ""

	if len(args) == 1 {
		packageName = "default"
	} else if len(args) == 2 {
		packageName = args[1]
	}

	instance, err := lib.GetInstanceByName(instanceName)

	if err != nil {
		return
	}

	pkg, err := lib.ImportPackage(packageName)

	if err != nil {
		return
	}

	contents, err := pkg.ZipPackageIntoBytes()

	if err != nil {
		return
	}

	err = lib.TryLogIn(&instance)

	if err != nil {
		return
	}

	id, err := lib.TryDeploy(contents, instance)

	if err != nil {
		return
	}

	finished := false
	maxTime := int(time.Minute * 5)
	currentTime := 0

	for !finished {
		sleepTime := int(3 * time.Second)
		currentTime += sleepTime

		if currentTime <= maxTime {
			time.Sleep(time.Duration(sleepTime))
			finished = lib.CheckAsyncDeploy(id, instance)
		} else {
			return lib.Error("Job exceeded maximum time!")
		}
	}

	return
}
Exemple #3
0
func instanceRun(args []string) (err error) {

	if len(args) == 0 {
		return lib.Error("Not enough arguments in command!")
	}

	instanceName := args[0]

	err = instanceFlagSet.Parse(args[1:])

	if err != nil {
		return
	}

	var instance lib.Instance

	if !newFlag {
		instance, err = lib.GetInstanceByName(instanceName)

		if err != nil {
			return err
		}
	}

	instanceExists := lib.InstanceExists(instanceName)

	if removeFlag {
		err = lib.RemoveInstance(instanceName)

		if err == nil {
			fmt.Println("Instance has been removed!")
		}

		return
	}

	if newFlag && instanceExists {
		err = lib.Error("Instance already exists!")
		return
	} else if newFlag && !instanceExists {
		instance.Name = instanceName
		instance.UserInfo = *new(lib.UserInfo)

		instance.Sandbox = sandboxFlag
		instance.Version = strconv.FormatFloat(versionFlag, 'f', 1, 32)
	}

	if usernameFlag != "" {
		instance.UserInfo.Username = usernameFlag
	}

	if passwordFlag != "" {
		instance.UserInfo.Password = passwordFlag
	}

	if tokenFlag != "" {
		instance.UserInfo.Token = tokenFlag
	}

	if versionFlag != versionFlagDefault {
		instance.Version = strconv.FormatFloat(versionFlag, 'f', 1, 32)
	}

	err = instance.SaveInstance()

	if err != nil {
		return
	}

	return
}