Ejemplo n.º 1
0
func runDns(args []string) (exit int) {
	if len(args) == 0 {
		return exitError("no Swarm given. Usage: kocho dns <swarm>")
	} else if len(args) > 1 {
		return exitError("too many arguments. Usage: kocho dns <swarm>")
	}
	name := args[0]

	err := dns.DeleteEntries(dnsService, viperConfig.getDNSNamingPattern(), name)
	if err != nil {
		return exitError("couldn't delete dns entries", err)
	}

	if !flagDelete {
		s, err := swarmService.Get(name, swarm.AWS)
		if err != nil {
			return exitError(fmt.Sprintf("couldn't find swarm: %s", name), err)
		}

		err = dns.CreateSwarmEntries(dnsService, viperConfig.getDNSNamingPattern(), s)
		if err != nil {
			return exitError("couldn't update dns entries", err)
		}
	}
	fireNotification()

	return 0
}
Ejemplo n.º 2
0
func runCreate(args []string) (exit int) {
	flags := viperConfig.newViperCreateFlags()

	if createShowCreateFlags {
		data, err := json.MarshalIndent(flags, "", "  ")
		if err != nil {
			exitError("Failed to json encode flags: %v", err)
		}
		fmt.Printf("%s\n", string(data))
		return
	}

	if flags.FleetVersion == "" {
		return exitError("couldn't create swarm: fleet version must be set using --fleet-version=<version>")
	}

	if flags.EtcdVersion == "" {
		return exitError("couldn't create swarm: etcd version must be set using --etcd-version=<version>")
	}

	if flags.MachineType == "" {
		return exitError("couldn't create swarm: --machine-type must be provided")
	}
	if flags.ImageURI == "" {
		return exitError("couldn't create swarm: --image must be provided")
	}

	if flags.UseIgnition && flags.ImageURI == awsEuWest1CoreOS {
		return exitError(fmt.Sprintf("couldn't create swarm: --use-ignition requires a more recent CoreOS AMI than '%s'", awsEuWest1CoreOS))
	}

	if len(args) == 0 {
		return exitError("no Swarm given. Usage: kocho create <swarm>")
	} else if len(args) > 1 {
		return exitError("too many arguments. Usage: kocho create <swarm>")
	}
	name := args[0]

	s, err := swarmService.Create(name, swarm.AWS, flags)
	if err != nil {
		return exitError(fmt.Sprintf("couldn't create swarm: %s", name), err)
	}

	if !sharedFlags.NoBlock {
		err = s.WaitUntil(provider.StatusCreated)
		if err != nil {
			return exitError("couldn't find out if swarm was started correctly", err)
		}

		err = dns.CreateSwarmEntries(dnsService, viperConfig.getDNSNamingPattern(), s)
		if err != nil {
			return exitError("couldn't create dns entries", err)
		}
	} else {
		fmt.Printf("triggered swarm %s start. No DNS will be configured\n", name)
	}
	fireNotification()

	return 0
}