You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/10/25 19:11:01 UTC

[07/19] brooklyn-client git commit: add br catalog delete for entities, locations, policies

add br catalog delete for entities, locations, policies


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/625ad88d
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/625ad88d
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/625ad88d

Branch: refs/heads/master
Commit: 625ad88d382ebd87b03d8ca9dd2829d9a79503dc
Parents: 9ea65f9
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Fri Oct 14 13:44:59 2016 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Fri Oct 14 13:44:59 2016 +0100

----------------------------------------------------------------------
 cli/api/catalog/catalog.go                 | 11 +++-
 cli/commands/catalog.go                    |  2 +-
 cli/commands/delete-catalog-application.go | 78 ++++++++++++++++++++-----
 3 files changed, 74 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/625ad88d/cli/api/catalog/catalog.go
----------------------------------------------------------------------
diff --git a/cli/api/catalog/catalog.go b/cli/api/catalog/catalog.go
index 6f0797a..56b37cb 100644
--- a/cli/api/catalog/catalog.go
+++ b/cli/api/catalog/catalog.go
@@ -100,7 +100,7 @@ func GetPolicyWithVersion(network *net.Network, policyId, version string) (model
 }
 
 func DeletePolicyWithVersion(network *net.Network, policyId, version string) (string, error) {
-	url := fmt.Sprintf("/v1/catalog/policies/%s/%s", policyId)
+	url := fmt.Sprintf("/v1/catalog/policies/%s/%s", policyId, version)
 	body, err := network.SendDeleteRequest(url)
 	if err != nil {
 		return "", err
@@ -139,6 +139,15 @@ func DeleteApplicationWithVersion(network *net.Network, applicationId, version s
 	return string(body), nil
 }
 
+func DeleteLocationWithVersion(network *net.Network, locationId, version string) (string, error) {
+	url := fmt.Sprintf("/v1/catalog/locations/%s/%s", locationId, version)
+	body, err := network.SendDeleteRequest(url)
+	if err != nil {
+		return "", err
+	}
+	return string(body), nil
+}
+
 func Policies(network *net.Network) ([]models.CatalogPolicySummary, error) {
 	url := "/v1/catalog/policies"
 	var policies []models.CatalogPolicySummary

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/625ad88d/cli/commands/catalog.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog.go b/cli/commands/catalog.go
index 1a870b6..0cc3380 100644
--- a/cli/commands/catalog.go
+++ b/cli/commands/catalog.go
@@ -40,7 +40,7 @@ func NewCatalog(network *net.Network) (cmd *Catalog) {
 	cmd.catalogCommands = map[string]command.Command {
 		ListCatalogCommand: NewCatalogList(cmd.network),
 		AddCatalogCommand: NewAddCatalog(cmd.network),
-		DeleteCatalogCommand: NewDeleteCatalogApplication(cmd.network),
+		DeleteCatalogCommand: NewDeleteCatalogItem(cmd.network),
 	}
 	return
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/625ad88d/cli/commands/delete-catalog-application.go
----------------------------------------------------------------------
diff --git a/cli/commands/delete-catalog-application.go b/cli/commands/delete-catalog-application.go
index ef8c561..888184c 100644
--- a/cli/commands/delete-catalog-application.go
+++ b/cli/commands/delete-catalog-application.go
@@ -28,40 +28,88 @@ import (
 	"github.com/apache/brooklyn-client/cli/api/catalog"
 )
 
-type DeleteCatalogApplication struct {
+type DeleteCatalogItem  struct {
 	network *net.Network
 }
 
-func NewDeleteCatalogApplication(network *net.Network) (cmd *DeleteCatalogApplication) {
-	cmd = new(DeleteCatalogApplication)
+func NewDeleteCatalogItem(network *net.Network) (cmd *DeleteCatalogItem) {
+	cmd = new(DeleteCatalogItem)
 	cmd.network = network
 	return
 }
 
-func (cmd *DeleteCatalogApplication) Metadata() command_metadata.CommandMetadata {
+func (cmd *DeleteCatalogItem) Metadata() command_metadata.CommandMetadata {
 	return command_metadata.CommandMetadata{
 		Name:        "delete",
-		Description: "delete the given catalog application",
-		Usage:       "BROOKLYN_NAME catalog delete [APPLICATION_ID:VERSION]",
-		Flags:       []cli.Flag{},
+		Description: "delete the given catalog item",
+		Usage:       "BROOKLYN_NAME catalog delete [ITEM_ID:VERSION]",
+		Flags:       []cli.Flag{
+			cli.BoolFlag{
+				Name:  "applications, a",
+				Usage: "delete application (default)",
+			},
+			cli.BoolFlag{
+				Name:  "entities, e",
+				Usage: "delete entity",
+			},
+			cli.BoolFlag{
+				Name:  "locations, l",
+				Usage: "delete location",
+			},
+			cli.BoolFlag{
+				Name:  "policies, p",
+				Usage: "delete policy",
+			},
+		},
 	}
 }
 
-func (cmd *DeleteCatalogApplication) Run(scope scope.Scope, c *cli.Context) {
+func (cmd *DeleteCatalogItem) Run(scope scope.Scope, c *cli.Context) {
 	if err := net.VerifyLoginURL(cmd.network); err != nil {
 		error_handler.ErrorExit(err)
 	}
 	if len(c.Args()) != 1 {
-		error_handler.ErrorExit("command requires single argument APPLICATION_ID:VERSION")
+		error_handler.ErrorExit("command requires single argument ITEM_ID:VERSION")
 	}
-	appVersion := strings.Split(c.Args().First(), ":")
-	if len(appVersion) != 2 {
-		error_handler.ErrorExit("command requires single argument APPLICATION_ID:VERSION")
+	itemVersion := strings.Split(c.Args().First(), ":")
+	if len(itemVersion) != 2 {
+		error_handler.ErrorExit("command requires single argument ITEM_ID:VERSION")
 	}
-	appId := appVersion[0]
-	version := appVersion[1]
-	_, err := catalog.DeleteApplicationWithVersion(cmd.network, appId, version)
+	itemId := itemVersion[0]
+	version := itemVersion[1]
+	err := cmd.deleteItem(c, itemId, version)
 	if nil != err {
 		error_handler.ErrorExit(err)
 	}
 }
+
+func (cmd *DeleteCatalogItem) deleteItem(c *cli.Context, itemId string, version string) (error){
+	if c.IsSet("entities") {
+		return cmd.deleteEntity(c, itemId, version)
+	} else if c.IsSet("locations") {
+		return cmd.deleteLocation(c, itemId, version)
+	} else if c.IsSet("policies") {
+		return cmd.deletePolicy(c, itemId, version)
+	}
+	return cmd.deleteApplication(c, itemId, version)
+}
+
+func (cmd *DeleteCatalogItem) deleteApplication(c *cli.Context, itemId string, version string) (error){
+	_, err := catalog.DeleteApplicationWithVersion(cmd.network, itemId, version)
+	return err
+}
+
+func (cmd *DeleteCatalogItem) deleteEntity(c *cli.Context, itemId string, version string) (error){
+	_, err := catalog.DeleteEntityWithVersion(cmd.network, itemId, version)
+	return err
+}
+
+func (cmd *DeleteCatalogItem) deletePolicy(c *cli.Context, itemId string, version string) (error){
+	_, err := catalog.DeletePolicyWithVersion(cmd.network, itemId, version)
+	return err
+}
+
+func (cmd *DeleteCatalogItem) deleteLocation(c *cli.Context, itemId string, version string) (error){
+	_, err := catalog.DeleteLocationWithVersion(cmd.network, itemId, version)
+	return err
+}
\ No newline at end of file