Esempio n. 1
0
// Deploy uses juju deploy to create a new service
func (jj *Juju) Deploy(user, service string) (*simplejson.Json, error) {
	args := []string{"deploy", "--show-log"}
	id := jj.id(user, service)
	report := JSON(fmt.Sprintf(`{"time": "%s"}`, time.Now()))
	log.Infof("deploy juju service: %s\n", id)

	// Get charms location
	storePath, storePrefix, err := jj.Charmstore(service)
	if err != nil {
		return EmptyJSON(), err
	}
	if storePrefix == "local" {
		args = append(args, "--repository")
		args = append(args, storePath)
	}

	// Add final service syntax to deploy
	args = append(args, fmt.Sprintf("%s:%s/%s", storePrefix, defaultSeries, service))
	args = append(args, id)

	// Read and dump user configuration
	confPath, err := jj.fetchConfig(user, service)
	if err != nil {
		return EmptyJSON(), err
	}
	if confPath != "" {
		args = append(args, "--config")
		args = append(args, confPath)
	}

	// Charm deployment
	log.Infof("enqueue process")
	client, err := goresque.Dial(redisURL)
	if err != nil {
		return EmptyJSON(), err
	}
	client.Enqueue(workerClass, "fork", jj.Path, args)

	report.Set("deployed", id)
	report.Set("provider", "juju")
	report.Set("arguments", args)
	report.Set("series", defaultSeries)
	return report, nil
}
Esempio n. 2
0
// AddRelation links two juju services
func (jj *Juju) AddRelation(user, serviceOne, serviceTwo string) (*simplejson.Json, error) {
	idOne := jj.id(user, serviceOne)
	idTwo := jj.id(user, serviceTwo)
	report := JSON(fmt.Sprintf(`{"time": "%s"}`, time.Now()))
	log.Infof("add juju relation: %s -> %s\n", idOne, idTwo)

	args := []string{"add-relation", "--show-log", idOne, idTwo}
	client, err := goresque.Dial(redisURL)
	if err != nil {
		return EmptyJSON(), err
	}
	log.Infof("enqueue add-relation")
	client.Enqueue(workerClass, "fork", jj.Path, args)

	report.Set("provider", "juju")
	report.Set("plugged", fmt.Sprintf("%s -> %s", idOne, idTwo))
	report.Set("relation arguments", args)
	return report, nil
}
Esempio n. 3
0
// Destroy uses juju destroy to remove a service
func (jj *Juju) Destroy(user, service string) (*simplejson.Json, error) {
	id := jj.id(user, service)
	report := JSON(fmt.Sprintf(`{"time": "%s"}`, time.Now()))
	log.Infof("destroy juju service: %s\n", id)

	//Note For now this is massive and basic destruction
	unitArgs := []string{"destroy-unit", id + "/0", "--show-log"}
	serviceArgs := []string{"destroy-service", id, "--show-log"}

	cmd := exec.Command("juju", "status", id, "--format", "json")
	output, err := cmd.CombinedOutput()
	if err != nil {
		return EmptyJSON(), err
	}
	status, err := simplejson.NewJson(output)
	machineID, err := status.GetPath("services", id, "units", id+"/0", "machine").String()
	if err != nil {
		return EmptyJSON(), err
	}
	machineArgs := []string{"destroy-machine", machineID, "--show-log"}

	client, err := goresque.Dial(redisURL)
	if err != nil {
		return EmptyJSON(), err
	}
	log.Infof("enqueue destroy-unit")
	client.Enqueue(workerClass, "fork", jj.Path, unitArgs)
	time.Sleep(5 * time.Second)
	log.Infof("enqueue destroy-service")
	client.Enqueue(workerClass, "fork", jj.Path, serviceArgs)
	time.Sleep(5 * time.Second)
	log.Infof("enqueue destroy-machine")
	client.Enqueue(workerClass, "fork", jj.Path, machineArgs)

	report.Set("provider", "juju")
	report.Set("unit destroyed", id+"/0")
	report.Set("service destroyed", id)
	report.Set("machine destroyed", machineID)
	report.Set("unit arguments", unitArgs)
	report.Set("service arguments", serviceArgs)
	report.Set("machine arguments", machineArgs)
	return report, nil
}