Exemple #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
}
Exemple #2
0
func runDestroy(args []string) (exit int) {
	if len(args) == 0 {
		return exitError("no Swarm given. Usage: kocho destroy <swarm>")
	} else if len(args) > 1 {
		return exitError("too many arguments. Usage: kocho destroy <swarm>")
	}
	swarmName := args[0]

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

	if !forceDestroying {
		if err := confirm(fmt.Sprintf("are you sure you want to destroy '%s'? Enter yes:", swarmName)); err != nil {
			return exitError("failed to read from stdin", err)
		}
	}

	if err := s.Destroy(); err != nil {
		return exitError(fmt.Sprintf("couldn't delete swarm: %s", swarmName), err)
	}

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

	if !sharedFlags.NoBlock {
		err := s.WaitUntil(provider.StatusDeleted)
		if err != nil {
			return exitError("couldn't find out if swarm was deleted correctly", err)
		}
	} else {
		fmt.Printf("triggered swarm %s deletion\n", swarmName)
	}
	fireNotification()

	return 0
}