Exemple #1
0
func (cmd *Deploy) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}

	var create models.TaskSummary
	var err error
	var blueprint []byte
	if c.Args().First() == "" {
		error_handler.ErrorExit("A filename or URL or '-' must be provided as the first argument", error_handler.CLIUsageErrorExitCode)
	}
	if c.Args().First() == "-" {
		blueprint, err = ioutil.ReadAll(os.Stdin)
		if err != nil {
			error_handler.ErrorExit(err)
		}
		create, err = application.CreateFromBytes(cmd.network, blueprint)
	} else {
		create, err = application.Create(cmd.network, c.Args().First())
	}
	if nil != err {
		if httpErr, ok := err.(net.HttpError); ok {
			error_handler.ErrorExit(strings.Join([]string{httpErr.Status, httpErr.Body}, "\n"), httpErr.Code)
		} else {
			error_handler.ErrorExit(err)
		}
	}
	table := terminal.NewTable([]string{"Id:", create.EntityId})
	table.Add("Name:", create.EntityDisplayName)
	table.Add("Status:", create.CurrentStatus)
	table.Print()
}
func (cmd *Application) show(appName string) {
	application, err := application.Application(cmd.network, appName)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	entity, err := entities.GetEntity(cmd.network, appName, appName)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	state, err := entity_sensors.CurrentState(cmd.network, appName, appName)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	location, err := locations.GetLocation(cmd.network, application.Spec.Locations[0])
	if nil != err {
		error_handler.ErrorExit(err)
	}
	table := terminal.NewTable([]string{"Id:", application.Id})
	table.Add("Name:", application.Spec.Name)
	table.Add("Status:", string(application.Status))
	if serviceUp, ok := state[serviceIsUpStr]; ok {
		table.Add("ServiceUp:", fmt.Sprintf("%v", serviceUp))
	}
	table.Add("Type:", application.Spec.Type)
	table.Add("CatalogItemId:", entity.CatalogItemId)
	table.Add("LocationId:", strings.Join(application.Spec.Locations, ", "))
	table.Add("LocationName:", location.Name)
	table.Add("LocationSpec:", location.Spec)
	table.Add("LocationType:", location.Type)
	table.Print()
}
Exemple #3
0
func (cmd *Config) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	if c.Args().Present() {
		configValue, err := entity_config.ConfigValue(cmd.network, scope.Application, scope.Entity, c.Args().First())

		if nil != err {
			error_handler.ErrorExit(err)
		}
		displayValue, err := stringRepresentation(configValue)
		if nil != err {
			error_handler.ErrorExit(err)
		}
		fmt.Println(displayValue)

	} else {
		config, err := entity_config.ConfigCurrentState(cmd.network, scope.Application, scope.Entity)
		if nil != err {
			error_handler.ErrorExit(err)
		}
		table := terminal.NewTable([]string{"Key", "Value"})
		for key, value := range config {
			table.Add(key, fmt.Sprintf("%v", value))
		}
		table.Print()
	}
}
Exemple #4
0
func (cmd *Login) Run(scope scope.Scope, c *cli.Context) {
	if !c.Args().Present() {
		error_handler.ErrorExit("A URL must be provided as the first argument", error_handler.CLIUsageErrorExitCode)
	}

	// If an argument was not supplied, it is set to empty string
	cmd.network.BrooklynUrl = c.Args().Get(0)
	cmd.network.BrooklynUser = c.Args().Get(1)
	cmd.network.BrooklynPass = c.Args().Get(2)
	cmd.network.SkipSslChecks = c.GlobalBool("skipSslChecks")

	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}

	// Strip off trailing '/' from URL if present.
	if cmd.network.BrooklynUrl[len(cmd.network.BrooklynUrl)-1] == '/' {
		if len(cmd.network.BrooklynUrl) == 1 {
			error_handler.ErrorExit("URL must not be a single \"/\" character", error_handler.CLIUsageErrorExitCode)
		}
		cmd.network.BrooklynUrl = cmd.network.BrooklynUrl[0 : len(cmd.network.BrooklynUrl)-1]
	}

	// Prompt for password if not supplied (password is not echoed to screen
	if cmd.network.BrooklynUser != "" && cmd.network.BrooklynPass == "" {
		fmt.Print("Enter Password: "******"\n")
		cmd.network.BrooklynPass = string(bytePassword)
	}

	if cmd.config.Map == nil {
		cmd.config.Map = make(map[string]interface{})
	}
	// now persist these credentials to the yaml file
	auth, ok := cmd.config.Map["auth"].(map[string]interface{})
	if !ok {
		auth = make(map[string]interface{})
		cmd.config.Map["auth"] = auth
	}

	auth[cmd.network.BrooklynUrl] = map[string]string{
		"username": cmd.network.BrooklynUser,
		"password": cmd.network.BrooklynPass,
	}

	cmd.config.Map["target"] = cmd.network.BrooklynUrl
	cmd.config.Map["skipSslChecks"] = cmd.network.SkipSslChecks
	cmd.config.Write()

	loginVersion, err := version.Version(cmd.network)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Printf("Connected to Brooklyn version %s at %s\n", loginVersion.Version, cmd.network.BrooklynUrl)
}
Exemple #5
0
func (cmd *SetConfig) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	response, err := entity_config.SetConfig(cmd.network, scope.Application, scope.Entity, scope.Config, c.Args().First())
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Println(response)
}
Exemple #6
0
func (cmd *Tree) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	trees, err := application.Tree(cmd.network)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	cmd.printTrees(trees, "")
}
Exemple #7
0
func (cmd *Delete) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	del, err := application.Delete(cmd.network, scope.Application)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Println(del)
}
func (cmd *AddCatalog) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	create, err := catalog.AddCatalog(cmd.network, c.Args().First())
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Println(create)
}
Exemple #9
0
func (cmd *Spec) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	spec, err := entities.Spec(cmd.network, scope.Application, scope.Entity)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Println(spec)
}
Exemple #10
0
func (cmd *Rename) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	rename, err := entities.Rename(cmd.network, scope.Application, scope.Entity, c.Args().First())
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Println(rename)
}
func (cmd *StopPolicy) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	spec, err := entity_policies.StopPolicy(cmd.network, scope.Application, scope.Entity, c.Args().First())
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Println(spec)
}
func (cmd *ActivityStreamStdout) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	activityStream, err := activities.ActivityStream(cmd.network, scope.Activity, "stdout")
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Println(activityStream)
}
Exemple #13
0
func (cmd *Version) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	version, err := version.Version(cmd.network)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Println(version.Version)
}
Exemple #14
0
func (cmd *Access) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	access, err := access_control.Access(cmd.network)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Println("Location Provisioning Allowed:", access.LocationProvisioningAllowed)
}
Exemple #15
0
func (cmd *Sensor) show(application, entity, sensor string) {
	sensorValue, err := entity_sensors.SensorValue(cmd.network, application, entity, sensor)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	displayValue, err := stringRepresentation(sensorValue)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	fmt.Println(displayValue)
}
func (cmd *AddChildren) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	activity, err := entities.AddChildren(cmd.network, scope.Application, scope.Entity, c.Args().First())
	if nil != err {
		error_handler.ErrorExit(err)
	}
	table := terminal.NewTable([]string{"Id", "Task", "Submitted", "Status"})
	table.Add(activity.Id, activity.DisplayName, time.Unix(activity.SubmitTimeUtc/1000, 0).Format(time.UnixDate), activity.CurrentStatus)

	table.Print()
}
func (cmd *Locations) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	locationList, err := locations.LocationList(cmd.network)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	table := terminal.NewTable([]string{"Id", "Name", "Spec"})
	for _, location := range locationList {
		table.Add(location.Id, location.Name, location.Spec)
	}
	table.Print()
}
Exemple #18
0
func (cmd *Catalog) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	catalog, err := catalog.Catalog(cmd.network)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	table := terminal.NewTable([]string{"Id", "Name", "Description"})
	for _, app := range catalog {
		table.Add(app.Id, app.Name, app.Description)
	}
	table.Print()
}
Exemple #19
0
func (cmd *Restart) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	parms := c.StringSlice("param")
	invoke(cmd.network, scope.Application, scope.Entity, restartEffector, parms)
}
Exemple #20
0
func (cmd *Activity) show(activityId string) {
	activity, err := activities.Activity(cmd.network, activityId)
	if nil != err {
		error_handler.ErrorExit(err)
	}

	table := terminal.NewTable([]string{"Id:", activity.Id})
	table.Add("DisplayName:", activity.DisplayName)
	table.Add("Description:", activity.Description)
	table.Add("EntityId:", activity.EntityId)
	table.Add("EntityDisplayName:", activity.EntityDisplayName)
	table.Add("Submitted:", time.Unix(activity.SubmitTimeUtc/1000, 0).Format(time.UnixDate))
	table.Add("Started:", time.Unix(activity.StartTimeUtc/1000, 0).Format(time.UnixDate))
	table.Add("Ended:", time.Unix(activity.EndTimeUtc/1000, 0).Format(time.UnixDate))
	table.Add("CurrentStatus:", activity.CurrentStatus)
	table.Add("IsError:", strconv.FormatBool(activity.IsError))
	table.Add("IsCancelled:", strconv.FormatBool(activity.IsCancelled))
	table.Add("SubmittedByTask:", activity.SubmittedByTask.Metadata.Id)
	if activity.Streams["stdin"].Metadata.Size > 0 ||
		activity.Streams["stdout"].Metadata.Size > 0 ||
		activity.Streams["stderr"].Metadata.Size > 0 ||
		activity.Streams["env"].Metadata.Size > 0 {
		table.Add("Streams:", fmt.Sprintf("stdin: %d, stdout: %d, stderr: %d, env %d",
			activity.Streams["stdin"].Metadata.Size,
			activity.Streams["stdout"].Metadata.Size,
			activity.Streams["stderr"].Metadata.Size,
			activity.Streams["env"].Metadata.Size))
	} else {
		table.Add("Streams:", "")
	}
	table.Add("DetailedStatus:", fmt.Sprintf("\"%s\"", activity.DetailedStatus))
	table.Print()
}
Exemple #21
0
func (config *Config) Read() {
	fileToRead, err := os.Open(config.FilePath)
	if err != nil {
		error_handler.ErrorExit(err)
	}
	dec := json.NewDecoder(fileToRead)
	dec.Decode(&config.Map)
}
Exemple #22
0
func (cmd *Policy) show(application, entity, policy string) {
	configs, err := entity_policy_config.GetAllConfigValues(cmd.network, application, entity, policy)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	table := terminal.NewTable([]string{"Name", "Value", "Description"})
	var theConfigs policyConfigList = configs
	sort.Sort(theConfigs)

	for _, config := range theConfigs {
		value, err := entity_policy_config.GetConfigValue(cmd.network, application, entity, policy, config.Name)
		if nil != err {
			error_handler.ErrorExit(err)
		}
		table.Add(config.Name, value, config.Description)
	}
	table.Print()
}
Exemple #23
0
func (cmd *Policy) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	if c.Args().Present() {
		cmd.show(scope.Application, scope.Entity, c.Args().First())
	} else {
		cmd.list(scope.Application, scope.Entity)
	}
}
Exemple #24
0
func (config *Config) Write() {
	// Create file as read/write by user (but does not change perms of existing file)
	fileToWrite, err := os.OpenFile(config.FilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		error_handler.ErrorExit(err)
	}
	defer fileToWrite.Close()

	enc := json.NewEncoder(fileToWrite)
	enc.Encode(config.Map)
}
Exemple #25
0
func invoke(network *net.Network, application, entity, effector string, parms []string) {
	names, vals, err := extractParams(parms)
	result, err := entity_effectors.TriggerEffector(network, application, entity, effector, names, vals)
	if nil != err {
		error_handler.ErrorExit(err)
	} else {
		if "" != result {
			fmt.Println(result)
		}
	}
}
func (cmd *Application) list() {
	applications, err := application.Applications(cmd.network)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	table := terminal.NewTable([]string{"Id", "Name", "Status", "Location"})
	for _, app := range applications {
		table.Add(app.Id, app.Spec.Name, string(app.Status), strings.Join(app.Spec.Locations, ", "))
	}
	table.Print()
}
Exemple #27
0
func (cmd *Policy) list(application, entity string) {
	policies, err := entity_policies.PolicyList(cmd.network, application, entity)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	table := terminal.NewTable([]string{"Id", "Name", "State"})
	for _, policy := range policies {
		table.Add(policy.Id, policy.Name, string(policy.State))
	}
	table.Print()
}
func (cmd *Effector) Run(scope scope.Scope, c *cli.Context) {
	if err := net.VerifyLoginURL(cmd.network); err != nil {
		error_handler.ErrorExit(err)
	}
	effectors, err := entity_effectors.EffectorList(cmd.network, scope.Application, scope.Entity)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	table := terminal.NewTable([]string{"Name", "Description", "Parameters"})
	for _, effector := range effectors {
		var parameters []string
		for _, parameter := range effector.Parameters {
			parameters = append(parameters, parameter.Name)
		}
		if !c.Args().Present() || c.Args().First() == effector.Name {
			table.Add(effector.Name, effector.Description, strings.Join(parameters, ","))
		}
	}
	table.Print()
}
Exemple #29
0
func (cmd *Entity) listapp(application string) {
	entitiesList, err := entities.EntityList(cmd.network, application)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	table := terminal.NewTable([]string{"Id", "Name", "Type"})
	for _, entityitem := range entitiesList {
		table.Add(entityitem.Id, entityitem.Name, entityitem.Type)
	}
	table.Print()
}
Exemple #30
0
func (cmd *Activity) listchildren(activity string) {
	activityList, err := activities.ActivityChildren(cmd.network, activity)
	if nil != err {
		error_handler.ErrorExit(err)
	}
	table := terminal.NewTable([]string{"Id", "Task", "Submitted", "Status", "Streams"})
	for _, activity := range activityList {
		table.Add(activity.Id,
			truncate(activity.DisplayName),
			time.Unix(activity.SubmitTimeUtc/1000, 0).Format(time.UnixDate), truncate(activity.CurrentStatus),
			streams(activity))
	}
	table.Print()
}