From c303afcb4644e4fac09da0ca18a8a3ce18e5a144 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Thu, 1 Nov 2018 22:30:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0keystone=20project=20add=20ta?= =?UTF-8?q?g=E6=8E=A5=E5=8F=A3=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/climc/shell/projects.go | 13 +++++++++++++ pkg/mcclient/modules/mod_projects.go | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/cmd/climc/shell/projects.go b/cmd/climc/shell/projects.go index 8751c5b67d..7b8f5b5242 100644 --- a/cmd/climc/shell/projects.go +++ b/cmd/climc/shell/projects.go @@ -2,6 +2,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" ) @@ -350,4 +351,16 @@ func init() { printList(imgs, modules.Images.GetColumns(s)) return nil }) + + type ProjectAddTagsOptions struct { + ID string `help:"ID or name of project"` + Tags []string `help:"tags added to project"` + } + R(&ProjectAddTagsOptions{}, "project-add-tags", "Add project with tags", func(s *mcclient.ClientSession, args *ProjectAddTagsOptions) error { + err := modules.Projects.AddTags(s, args.ID, args.Tags) + if err != nil { + return err + } + return nil + }) } diff --git a/pkg/mcclient/modules/mod_projects.go b/pkg/mcclient/modules/mod_projects.go index 61ae01147a..5152cdc525 100644 --- a/pkg/mcclient/modules/mod_projects.go +++ b/pkg/mcclient/modules/mod_projects.go @@ -268,6 +268,17 @@ func (this *ProjectManagerV3) BatchDeleteInContexts(session *mcclient.ClientSess }) } +func (this *ProjectManagerV3) AddTags(session *mcclient.ClientSession, id string, tags []string) error { + path := fmt.Sprintf("/projects/%s/tags", id) + body := jsonutils.NewDict() + body.Add(jsonutils.NewStringArray(tags), "tags") + _, err := this._put(session, path, body, "") + if err != nil { + return err + } + return nil +} + func init() { Projects = ProjectManagerV3{NewIdentityV3Manager("project", "projects", []string{},