diff --git a/cmd/climc/shell/notices.go b/cmd/climc/shell/notices.go new file mode 100644 index 0000000000..697316fb62 --- /dev/null +++ b/cmd/climc/shell/notices.go @@ -0,0 +1,79 @@ +package shell + +import ( + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +func init() { + type NoticesListOptions struct { + BaseListOptions + } + + R(&NoticesListOptions{}, "notice-list", "list notices", func(s *mcclient.ClientSession, args *NoticesListOptions) error { + params := FetchPagingParams(args.BaseListOptions) + + result, err := modules.Notice.List(s, params) + if err != nil { + return err + } + printList(result, modules.Notice.GetColumns(s)) + return nil + }) + + type NoticesCreateOptions struct { + TITLE string `help:"The notice title"` + CONTENT string `help:"The notice content"` + } + + R(&NoticesCreateOptions{}, "notice-create", "create a notice", func(s *mcclient.ClientSession, args *NoticesCreateOptions) error { + params := jsonutils.NewDict() + params.Add(jsonutils.NewString(args.TITLE), "title") + params.Add(jsonutils.NewString(args.CONTENT), "content") + + notice, err := modules.Notice.Create(s, params) + if err != nil { + return err + } + printObject(notice) + return nil + }) + + type NoticesUpdateOptions struct { + ID string `help:"ID of notice to update"` + Title string `help:"The notice title"` + Content string `help:"The notice content"` + } + + R(&NoticesUpdateOptions{}, "notice-update", "update notice", func(s *mcclient.ClientSession, args *NoticesUpdateOptions) error { + params := jsonutils.NewDict() + if len(args.Title) > 0 { + params.Add(jsonutils.NewString(args.Title), "title") + } + + if len(args.Content) > 0 { + params.Add(jsonutils.NewString(args.Content), "content") + } + + notice, err := modules.Notice.Update(s, args.ID, params) + if err != nil { + return err + } + printObject(notice) + return nil + }) + + type NoticesDeleteOptions struct { + ID string `help:"ID of notice to update"` + } + + R(&NoticesDeleteOptions{}, "notice-delete", "delete notice", func(s *mcclient.ClientSession, args *NoticesDeleteOptions) error { + notice, err := modules.Notice.Delete(s, args.ID, nil) + if err != nil { + return err + } + printObject(notice) + return nil + }) +} diff --git a/pkg/mcclient/modules/mod_notices.go b/pkg/mcclient/modules/mod_notices.go new file mode 100644 index 0000000000..48c704d450 --- /dev/null +++ b/pkg/mcclient/modules/mod_notices.go @@ -0,0 +1,26 @@ +package modules + +type NoticeManager struct { + ResourceManager +} + +type NoticeReadMarkManager struct { + ResourceManager +} + +var ( + Notice NoticeManager + NoticeReadMark NoticeReadMarkManager +) + +func init() { + Notice = NoticeManager{NewYunionAgentManager("notice", "notices", + []string{"id", "created_at", "updated_at","author_id", "author", "title", "content"}, + []string{})} + register(&Notice) + + NoticeReadMark = NoticeReadMarkManager{NewYunionAgentManager("readmark", "readmarks", + []string{}, + []string{"notice_id", "user_id"})} + register(&NoticeReadMark) +}