Merge pull request #130 in YUNIONIO/onecloud from ~TANGBIN/onecloud:feature/tb-notice-api to release/2.2.0

* commit 'a0da87cee59ac767059b47241a3ad131749cab84':
  allow return update time
  add notice climc command
  bugfix
  add notice mod
  add notice mod
This commit is contained in:
邱剑
2018-08-28 20:10:23 +08:00
2 changed files with 105 additions and 0 deletions
+79
View File
@@ -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
})
}
+26
View File
@@ -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)
}