From d654c0f1d7d75a35e78f9a13f7b4f220a9a56ce1 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Mon, 13 Aug 2018 19:22:34 +0800 Subject: [PATCH 1/4] climc: k8s resource cli --- cmd/climc/shell/k8s/configmap.go | 27 +++++ cmd/climc/shell/k8s/deployment.go | 145 +++++++++++++++++++++++++ cmd/climc/shell/k8s/k8s.go | 67 +++++++++++- cmd/climc/shell/k8s/pods.go | 20 +++- cmd/climc/shell/k8s/raw.go | 35 ++++++ cmd/climc/shell/k8s/repos.go | 106 ++++++++++++++++++ cmd/climc/shell/k8s/service.go | 27 +++++ pkg/mcclient/modules/k8s/base.go | 47 +++++++- pkg/mcclient/modules/k8s/cluster.go | 4 +- pkg/mcclient/modules/k8s/configmap.go | 20 ++++ pkg/mcclient/modules/k8s/deployment.go | 20 ++++ pkg/mcclient/modules/k8s/event.go | 4 +- pkg/mcclient/modules/k8s/helm.go | 17 +++ pkg/mcclient/modules/k8s/node.go | 2 +- pkg/mcclient/modules/k8s/pod.go | 4 +- pkg/mcclient/modules/k8s/raw.go | 95 ++++++++++++++++ pkg/mcclient/modules/k8s/service.go | 20 ++++ 17 files changed, 646 insertions(+), 14 deletions(-) create mode 100644 cmd/climc/shell/k8s/configmap.go create mode 100644 cmd/climc/shell/k8s/deployment.go create mode 100644 cmd/climc/shell/k8s/raw.go create mode 100644 cmd/climc/shell/k8s/repos.go create mode 100644 cmd/climc/shell/k8s/service.go create mode 100644 pkg/mcclient/modules/k8s/configmap.go create mode 100644 pkg/mcclient/modules/k8s/deployment.go create mode 100644 pkg/mcclient/modules/k8s/helm.go create mode 100644 pkg/mcclient/modules/k8s/raw.go create mode 100644 pkg/mcclient/modules/k8s/service.go diff --git a/cmd/climc/shell/k8s/configmap.go b/cmd/climc/shell/k8s/configmap.go new file mode 100644 index 0000000000..30d8fd6d9e --- /dev/null +++ b/cmd/climc/shell/k8s/configmap.go @@ -0,0 +1,27 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initConfigMap() { + cmdN := func(suffix string) string { + return resourceCmdN("configmap", suffix) + } + + type listOpt struct { + namespaceListOptions + baseListOptions + } + R(&listOpt{}, cmdN("list"), "List k8s configmap", func(s *mcclient.ClientSession, args *listOpt) error { + params := fetchNamespaceParams(args.namespaceListOptions) + params.Update(fetchPagingParams(args.baseListOptions)) + ret, err := k8s.ConfigMaps.ListInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printList(ret, k8s.ConfigMaps.GetColumns(s)) + return nil + }) +} diff --git a/cmd/climc/shell/k8s/deployment.go b/cmd/climc/shell/k8s/deployment.go new file mode 100644 index 0000000000..dfdc392bba --- /dev/null +++ b/cmd/climc/shell/k8s/deployment.go @@ -0,0 +1,145 @@ +package k8s + +import ( + "fmt" + "strconv" + "strings" + + "yunion.io/x/jsonutils" + "yunion.io/x/pkg/util/sets" + + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initDeployment() { + cmdN := func(suffix string) string { + return resourceCmdN("deployment", suffix) + } + + type listOpt struct { + namespaceListOptions + baseListOptions + } + R(&listOpt{}, cmdN("list"), "List k8s deployment", func(s *mcclient.ClientSession, args *listOpt) error { + params := fetchNamespaceParams(args.namespaceListOptions) + params.Update(fetchPagingParams(args.baseListOptions)) + ret, err := k8s.Deployments.ListInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printList(ret, k8s.Deployments.GetColumns(s)) + return nil + }) + + type createOpt struct { + namespaceOptions + NAME string `help:"Name of deployment"` + Image string `help:"The image for the container to run"` + Replicas int64 `help:"Number of replicas for pods in this deployment"` + RunAsPrivileged bool `help:"Whether to run the container as privileged user"` + Labels string `help:"Comma separated labels to apply to the pod(s)"` + Env []string `help:"Environment variables to set in container"` + Port []string `help:"Port for the service that is created, format is :: e.g. tcp:80:3000"` + } + R(&createOpt{}, cmdN("create"), "Create deployment resource", func(s *mcclient.ClientSession, args *createOpt) error { + params := jsonutils.NewDict() + if len(args.Image) == 0 { + return fmt.Errorf("Image must provided") + } + params.Add(jsonutils.NewString(args.NAME), "name") + params.Add(jsonutils.NewString(args.Image), "containerImage") + if args.Namespace != "" { + params.Add(jsonutils.NewString(args.Namespace), "namespace") + } + if args.Replicas > 1 { + params.Add(jsonutils.NewInt(args.Replicas), "replicas") + } + if args.RunAsPrivileged { + params.Add(jsonutils.JSONTrue, "runAsPrivileged") + } + if len(args.Port) != 0 { + portMappings, err := parsePortMappings(args.Port) + if err != nil { + return err + } + params.Add(portMappings, "portMappings") + } + ret, err := k8s.Deployments.CreateInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printObject(ret) + return nil + }) + + type getOpt struct { + resourceGetOptions + } + R(&getOpt{}, cmdN("show"), "Get deployment details", func(s *mcclient.ClientSession, args *getOpt) error { + id := args.NAME + params := jsonutils.NewDict() + if args.Namespace != "" { + params.Add(jsonutils.NewString(args.Namespace), "namespace") + } + ret, err := k8s.Deployments.GetInContexts(s, id, params, args.ClusterContext()) + if err != nil { + return err + } + printObjectYAML(ret) + return nil + }) +} + +type portMapping struct { + Port int32 `json:"port"` + TargetPort int32 `json:"targetPort"` + Protocol string `json:"protocol"` +} + +func parsePortMapping(port string) (*portMapping, error) { + if len(port) == 0 { + return nil, fmt.Errorf("empty port mapping desc string") + } + parts := strings.Split(port, ":") + mapping := &portMapping{} + for _, part := range parts { + if sets.NewString("tcp", "udp").Has(strings.ToLower(part)) { + mapping.Protocol = strings.ToUpper(part) + } + if port, err := strconv.Atoi(part); err != nil { + continue + } else { + if mapping.Port == 0 { + mapping.Port = int32(port) + } else { + mapping.TargetPort = int32(port) + } + } + } + if mapping.Protocol == "" { + mapping.Protocol = "TCP" + } + if mapping.Port <= 0 { + return nil, fmt.Errorf("Service port not provided") + } + if mapping.TargetPort < 0 { + return nil, fmt.Errorf("Container invalid targetPort %d", mapping.TargetPort) + } + if mapping.TargetPort == 0 { + mapping.TargetPort = mapping.Port + } + return mapping, nil +} + +func parsePortMappings(ports []string) (*jsonutils.JSONArray, error) { + ret := jsonutils.NewArray() + for _, port := range ports { + mapping, err := parsePortMapping(port) + if err != nil { + return nil, fmt.Errorf("Port %q error: %v", port, err) + } + ret.Add(jsonutils.Marshal(mapping)) + } + return ret, nil +} diff --git a/cmd/climc/shell/k8s/k8s.go b/cmd/climc/shell/k8s/k8s.go index 2e63757294..af4892e71a 100644 --- a/cmd/climc/shell/k8s/k8s.go +++ b/cmd/climc/shell/k8s/k8s.go @@ -12,24 +12,81 @@ import ( ) func init() { + // cluster resources initCluster() initNode() + + // helm resources + initRepo() + + // kubernetes original resources + initRaw() + initConfigMap() + initDeployment() initPod() + initService() } type BaseListOptions shell.BaseListOptions type clusterBaseOptions struct { - Cluster string `default:"$K8S_CLUSTER" help:"Kubernetes cluster name"` + Cluster string `default:"$K8S_CLUSTER|default" help:"Kubernetes cluster name"` } func (o clusterBaseOptions) ClusterContext() []modules.ManagerContext { return []modules.ManagerContext{clusterContext(o.Cluster)} } -type k8sBaseListOptions struct { +type baseListOptions struct { + Limit int `default:"20" help:"Page limit"` + Offset int `default:"0" help:"page offset"` +} + +func fetchPagingParams(opt baseListOptions) *jsonutils.JSONDict { + params := jsonutils.NewDict() + if opt.Limit > 0 { + params.Add(jsonutils.NewInt(int64(opt.Limit)), "limit") + } + if opt.Offset > 0 { + params.Add(jsonutils.NewInt(int64(opt.Offset)), "offset") + } + return params +} + +type namespaceListOptions struct { + namespaceOptions + AllNamespace bool `help:"Show resource in all namespace"` +} + +type namespaceOptions struct { clusterBaseOptions - Limit int `default:"20" help:"Page limit"` + Namespace string `help:"Namespace of this resource"` +} + +type resourceGetOptions struct { + clusterBaseOptions + Namespace string `help:"Namespace of this resource"` + NAME string `help:"Name ident of the resource"` +} + +func (o resourceGetOptions) ToJSON() *jsonutils.JSONDict { + params := jsonutils.NewDict() + if o.Namespace != "" { + params.Add(jsonutils.NewString(o.Namespace), "namespace") + } + return params +} + +func fetchNamespaceParams(opt namespaceListOptions) *jsonutils.JSONDict { + params := jsonutils.NewDict() + if opt.AllNamespace { + params.Add(jsonutils.JSONTrue, "all_namespace") + return params + } + if opt.Namespace != "" { + params.Add(jsonutils.NewString(opt.Namespace), "namespace") + } + return params } var ( @@ -53,3 +110,7 @@ func clusterContext(clusterId string) modules.ManagerContext { InstanceId: clusterId, } } + +func printObjectYAML(obj jsonutils.JSONObject) { + fmt.Println(obj.YAMLString()) +} diff --git a/cmd/climc/shell/k8s/pods.go b/cmd/climc/shell/k8s/pods.go index 8d2fdd0d3b..ee8803c414 100644 --- a/cmd/climc/shell/k8s/pods.go +++ b/cmd/climc/shell/k8s/pods.go @@ -13,10 +13,26 @@ func initPod() { } type listOpt struct { - k8sBaseListOptions + namespaceListOptions + baseListOptions } R(&listOpt{}, cmdN("list"), "List k8s pod", func(s *mcclient.ClientSession, args *listOpt) error { - ret, err := k8s.Pods.ListInContexts(s, nil, args.ClusterContext()) + params := fetchNamespaceParams(args.namespaceListOptions) + params.Update(fetchPagingParams(args.baseListOptions)) + ret, err := k8s.Pods.ListInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printList(ret, k8s.Pods.GetColumns(s)) + return nil + }) + + type deleteOpt struct { + resourceGetOptions + } + R(&deleteOpt{}, cmdN("delete"), "Delete pod", func(s *mcclient.ClientSession, args *deleteOpt) error { + id := args.NAME + ret, err := k8s.Pods.DeleteInContexts(s, id, args.ToJSON(), args.ClusterContext()) if err != nil { return err } diff --git a/cmd/climc/shell/k8s/raw.go b/cmd/climc/shell/k8s/raw.go new file mode 100644 index 0000000000..6aeb500f91 --- /dev/null +++ b/cmd/climc/shell/k8s/raw.go @@ -0,0 +1,35 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +type rawGetOpt struct { + namespaceOptions + KIND string `help:"resource kind"` + NAME string `help:"instance name"` +} + +type rawDeleteOpt struct { + rawGetOpt +} + +func initRaw() { + R(&rawGetOpt{}, "k8s-get", "Get k8s resource instance raw info", func(s *mcclient.ClientSession, args *rawGetOpt) error { + obj, err := k8s.RawResource.Get(s, args.KIND, args.Namespace, args.NAME, nil, args.ClusterContext()) + if err != nil { + return err + } + printObjectYAML(obj) + return nil + }) + + R(&rawDeleteOpt{}, "k8s-delete", "Delete k8s resource instance", func(s *mcclient.ClientSession, args *rawDeleteOpt) error { + err := k8s.RawResource.Delete(s, args.KIND, args.Namespace, args.NAME, nil, args.ClusterContext()) + if err != nil { + return err + } + return nil + }) +} diff --git a/cmd/climc/shell/k8s/repos.go b/cmd/climc/shell/k8s/repos.go new file mode 100644 index 0000000000..ee34d8a2f9 --- /dev/null +++ b/cmd/climc/shell/k8s/repos.go @@ -0,0 +1,106 @@ +package k8s + +import ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initRepo() { + cmdN := func(suffix string) string { + return resourceCmdN("repo", suffix) + } + type listOpt struct { + BaseListOptions + } + R(&listOpt{}, cmdN("list"), "List k8s global helm repos", func(s *mcclient.ClientSession, args *listOpt) error { + params := FetchPagingParams(args.BaseListOptions) + result, err := k8s.Repos.List(s, params) + if err != nil { + return err + } + printList(result, k8s.Repos.GetColumns(s)) + return nil + }) + + type getOpt struct { + NAME string `help:"ID or name of the repo"` + } + R(&getOpt{}, cmdN("show"), "Show details fo a repo", func(s *mcclient.ClientSession, args *getOpt) error { + repo, err := k8s.Repos.Get(s, args.NAME, nil) + if err != nil { + return err + } + printObject(repo) + return nil + }) + + type createOpt struct { + getOpt + URL string `help:"Repository url"` + Public bool `help:"Make repository public"` + } + R(&createOpt{}, cmdN("create"), "Add repository", func(s *mcclient.ClientSession, args *createOpt) error { + params := jsonutils.NewDict() + params.Add(jsonutils.NewString(args.NAME), "name") + params.Add(jsonutils.NewString(args.URL), "url") + if args.Public { + params.Add(jsonutils.JSONTrue, "is_public") + } + repo, err := k8s.Repos.Create(s, params) + if err != nil { + return err + } + printObject(repo) + return nil + }) + + type updateOpt struct { + getOpt + Name string `help:"Repository name to change"` + Url string `help:"Repository url to change"` + } + R(&updateOpt{}, cmdN("update"), "Update helm repository", func(s *mcclient.ClientSession, args *updateOpt) error { + params := jsonutils.NewDict() + if args.Name != "" { + params.Add(jsonutils.NewString(args.Name), "name") + } + if args.Url != "" { + params.Add(jsonutils.NewString(args.Url), "url") + } + repo, err := k8s.Repos.Update(s, args.NAME, params) + if err != nil { + return err + } + printObject(repo) + return nil + }) + + R(&getOpt{}, cmdN("private"), "Make repository private", func(s *mcclient.ClientSession, args *getOpt) error { + repo, err := k8s.Repos.PerformAction(s, args.NAME, "private", nil) + if err != nil { + return err + } + printObject(repo) + return nil + }) + + R(&getOpt{}, cmdN("public"), "Make repository public", func(s *mcclient.ClientSession, args *getOpt) error { + repo, err := k8s.Repos.PerformAction(s, args.NAME, "public", nil) + if err != nil { + return err + } + printObject(repo) + return nil + }) + + R(&getOpt{}, cmdN("delete"), "Delete a repository", func(s *mcclient.ClientSession, args *getOpt) error { + repo, err := k8s.Repos.Delete(s, args.NAME, nil) + if err != nil { + return err + } + printObject(repo) + return nil + }) +} diff --git a/cmd/climc/shell/k8s/service.go b/cmd/climc/shell/k8s/service.go new file mode 100644 index 0000000000..3260b28b88 --- /dev/null +++ b/cmd/climc/shell/k8s/service.go @@ -0,0 +1,27 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initService() { + cmdN := func(suffix string) string { + return resourceCmdN("service", suffix) + } + + type listOpt struct { + namespaceListOptions + baseListOptions + } + R(&listOpt{}, cmdN("list"), "List k8s service", func(s *mcclient.ClientSession, args *listOpt) error { + params := fetchNamespaceParams(args.namespaceListOptions) + params.Update(fetchPagingParams(args.baseListOptions)) + ret, err := k8s.Services.ListInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printList(ret, k8s.Services.GetColumns(s)) + return nil + }) +} diff --git a/pkg/mcclient/modules/k8s/base.go b/pkg/mcclient/modules/k8s/base.go index 6c5eef1847..3b5fc20b61 100644 --- a/pkg/mcclient/modules/k8s/base.go +++ b/pkg/mcclient/modules/k8s/base.go @@ -1,13 +1,56 @@ package k8s import ( + "yunion.io/x/pkg/util/sets" + "yunion.io/x/onecloud/pkg/mcclient/modules" ) -func NewManager(keyword, keywordPlural string, columns, adminColumns []string) *modules.ResourceManager { +func NewManager(keyword, keywordPlural string, columns, adminColumns *Columns) *modules.ResourceManager { return &modules.ResourceManager{ - BaseManager: *modules.NewBaseManager("k8s", "", "", columns, adminColumns), + BaseManager: *modules.NewBaseManager("k8s", "", "", columns.Array(), adminColumns.Array()), Keyword: keyword, KeywordPlural: keywordPlural, } } + +type Columns struct { + cols []string +} + +func NewColumns(cols ...string) *Columns { + c := &Columns{cols: make([]string, 0)} + return c.Add(cols...) +} + +func (c *Columns) Add(cols ...string) *Columns { + for _, col := range cols { + c.add(col) + } + return c +} + +func (c *Columns) add(col string) *Columns { + src := sets.NewString(c.Array()...) + if src.Has(col) { + return c + } + c.cols = append(c.cols, col) + return c +} + +func (c Columns) Array() []string { + return c.cols +} + +func NewNamespaceCols(col ...string) *Columns { + return NewColumns("name", "namespace").Add(col...) +} + +func NewClusterCols(col ...string) *Columns { + return NewColumns("cluster").Add(col...) +} + +func NewResourceCols(col ...string) *Columns { + return NewColumns("name", "id").Add(col...) +} diff --git a/pkg/mcclient/modules/k8s/cluster.go b/pkg/mcclient/modules/k8s/cluster.go index df2df5ca39..42ee41d6b1 100644 --- a/pkg/mcclient/modules/k8s/cluster.go +++ b/pkg/mcclient/modules/k8s/cluster.go @@ -10,7 +10,7 @@ var ( func init() { Clusters = NewManager("cluster", "clusters", - []string{"id", "name", "mode", "k8s_version", "status", "api_endpoint"}, - []string{}) + NewResourceCols("mode", "k8s_version", "status", "api_endpoint"), + NewColumns()) modules.Register(Clusters) } diff --git a/pkg/mcclient/modules/k8s/configmap.go b/pkg/mcclient/modules/k8s/configmap.go new file mode 100644 index 0000000000..4bfcbbafdf --- /dev/null +++ b/pkg/mcclient/modules/k8s/configmap.go @@ -0,0 +1,20 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var ConfigMaps *ConfigMapManager + +type ConfigMapManager struct { + modules.ResourceManager +} + +func init() { + ConfigMaps = &ConfigMapManager{ + ResourceManager: *NewManager( + "configmap", "configmaps", + NewNamespaceCols(), + NewClusterCols())} + modules.Register(ConfigMaps) +} diff --git a/pkg/mcclient/modules/k8s/deployment.go b/pkg/mcclient/modules/k8s/deployment.go new file mode 100644 index 0000000000..f56a2947ef --- /dev/null +++ b/pkg/mcclient/modules/k8s/deployment.go @@ -0,0 +1,20 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var Deployments *DeploymentManager + +type DeploymentManager struct { + modules.ResourceManager +} + +func init() { + Deployments = &DeploymentManager{ + ResourceManager: *NewManager( + "deployment", "deployments", + NewNamespaceCols("labels"), + NewClusterCols())} + modules.Register(Deployments) +} diff --git a/pkg/mcclient/modules/k8s/event.go b/pkg/mcclient/modules/k8s/event.go index f71c5541ef..584ddbc376 100644 --- a/pkg/mcclient/modules/k8s/event.go +++ b/pkg/mcclient/modules/k8s/event.go @@ -10,7 +10,7 @@ var ( func init() { Logs = NewManager("kube_event", "kube_events", - []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"}, - []string{}) + NewColumns("id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"), + NewColumns()) modules.Register(Logs) } diff --git a/pkg/mcclient/modules/k8s/helm.go b/pkg/mcclient/modules/k8s/helm.go new file mode 100644 index 0000000000..b3e04f21ea --- /dev/null +++ b/pkg/mcclient/modules/k8s/helm.go @@ -0,0 +1,17 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var ( + Repos *modules.ResourceManager +) + +func init() { + Repos = NewManager("repo", "repos", + NewResourceCols("url", "is_public", "source"), + NewColumns(), + ) + modules.Register(Repos) +} diff --git a/pkg/mcclient/modules/k8s/node.go b/pkg/mcclient/modules/k8s/node.go index 5b8cb0798b..60f5bd6ade 100644 --- a/pkg/mcclient/modules/k8s/node.go +++ b/pkg/mcclient/modules/k8s/node.go @@ -9,6 +9,6 @@ var ( ) func init() { - Nodes = NewManager("node", "nodes", []string{"id", "name", "cluster", "roles", "address", "status"}, []string{}) + Nodes = NewManager("node", "nodes", NewResourceCols("cluster", "roles", "address", "status"), NewColumns()) modules.Register(Nodes) } diff --git a/pkg/mcclient/modules/k8s/pod.go b/pkg/mcclient/modules/k8s/pod.go index 46417df838..218ef6a243 100644 --- a/pkg/mcclient/modules/k8s/pod.go +++ b/pkg/mcclient/modules/k8s/pod.go @@ -14,7 +14,7 @@ func init() { Pods = &PodManager{ ResourceManager: *NewManager( "pod", "pods", - []string{"id", "name", "cluster", "roles", "address", "status"}, - []string{})} + NewNamespaceCols("podIP", "status", "restartCount", "labels"), + NewClusterCols("nodeName"))} modules.Register(Pods) } diff --git a/pkg/mcclient/modules/k8s/raw.go b/pkg/mcclient/modules/k8s/raw.go new file mode 100644 index 0000000000..8853a18742 --- /dev/null +++ b/pkg/mcclient/modules/k8s/raw.go @@ -0,0 +1,95 @@ +package k8s + +import ( + "fmt" + "net/url" + "strings" + + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var RawResource *RawResourceManager + +func init() { + RawResource = &RawResourceManager{ + serviceType: "k8s", + } +} + +type rawResourceContext struct { + kind string + name string + query jsonutils.JSONObject + ctxs []modules.ManagerContext +} + +func newRawResourceContext(kind, namespace, name string, query jsonutils.JSONObject, ctxs []modules.ManagerContext) *rawResourceContext { + nsQuery := getNamespaceQuery(namespace) + if query != nil { + nsQuery.Update(query) + } + ctx := &rawResourceContext{kind: kind, name: name, query: nsQuery, ctxs: ctxs} + return ctx +} + +func (ctx rawResourceContext) contextPath() string { + segs := make([]string, 0) + ctxs := ctx.ctxs + if ctxs != nil && len(ctxs) > 0 { + for _, c := range ctxs { + segs = append(segs, c.InstanceManager.KeyString()) + if len(c.InstanceId) > 0 { + segs = append(segs, url.PathEscape(c.InstanceId)) + } + } + } + segs = append(segs, "_raw", ctx.kind, ctx.name) + path := fmt.Sprintf("/%s", strings.Join(segs, "/")) + if ctx.query != nil { + qs := ctx.query.QueryString() + if len(qs) > 0 { + path = fmt.Sprintf("%s?%s", path, qs) + } + } + return path +} + +type RawResourceManager struct { + serviceType string +} + +func (m *RawResourceManager) request(s *mcclient.ClientSession, method string, path string, body jsonutils.JSONObject) (jsonutils.JSONObject, error) { + _, ret, err := s.JSONRequest(m.serviceType, "", method, path, nil, body) + return ret, err +} + +func getNamespaceQuery(namespace string) *jsonutils.JSONDict { + query := jsonutils.NewDict() + if namespace != "" { + query.Set("namespace", jsonutils.NewString(namespace)) + } + return query +} + +func (m *RawResourceManager) Get(s *mcclient.ClientSession, kind string, namespace string, name string, query jsonutils.JSONObject, ctxs []modules.ManagerContext) (jsonutils.JSONObject, error) { + ctx := newRawResourceContext(kind, namespace, name, query, ctxs) + return m.request(s, "GET", ctx.contextPath(), nil) +} + +func (m *RawResourceManager) Put(s *mcclient.ClientSession, kind string, namespace string, name string, body jsonutils.JSONObject, ctxs []modules.ManagerContext) error { + rawBytes := body.String() + newBody := jsonutils.NewDict() + newBody.Add(jsonutils.NewString(rawBytes), "raw") + ctx := newRawResourceContext(kind, namespace, name, nil, ctxs) + _, err := m.request(s, "PUT", ctx.contextPath(), newBody) + return err +} + +func (m *RawResourceManager) Delete(s *mcclient.ClientSession, kind string, namespace string, name string, query jsonutils.JSONObject, ctxs []modules.ManagerContext) error { + ctx := newRawResourceContext(kind, namespace, name, query, ctxs) + _, err := m.request(s, "DELETE", ctx.contextPath(), nil) + return err +} diff --git a/pkg/mcclient/modules/k8s/service.go b/pkg/mcclient/modules/k8s/service.go new file mode 100644 index 0000000000..e66f38dda3 --- /dev/null +++ b/pkg/mcclient/modules/k8s/service.go @@ -0,0 +1,20 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var Services *ServiceManager + +type ServiceManager struct { + modules.ResourceManager +} + +func init() { + Services = &ServiceManager{ + ResourceManager: *NewManager( + "service", "services", + NewNamespaceCols("clusterIP", "selector", "internalEndpoint", "externalEndpoints"), + NewClusterCols())} + modules.Register(Services) +} From 9cdbeb943b5c08fa84a77ff68216797564bdb347 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Mon, 13 Aug 2018 19:22:34 +0800 Subject: [PATCH 2/4] climc: k8s resource cli --- cmd/climc/shell/k8s/configmap.go | 27 +++++ cmd/climc/shell/k8s/deployment.go | 145 +++++++++++++++++++++++++ cmd/climc/shell/k8s/k8s.go | 67 +++++++++++- cmd/climc/shell/k8s/pods.go | 20 +++- cmd/climc/shell/k8s/raw.go | 35 ++++++ cmd/climc/shell/k8s/repos.go | 106 ++++++++++++++++++ cmd/climc/shell/k8s/service.go | 27 +++++ pkg/mcclient/modules/k8s/base.go | 47 +++++++- pkg/mcclient/modules/k8s/cluster.go | 4 +- pkg/mcclient/modules/k8s/configmap.go | 20 ++++ pkg/mcclient/modules/k8s/deployment.go | 20 ++++ pkg/mcclient/modules/k8s/event.go | 4 +- pkg/mcclient/modules/k8s/helm.go | 17 +++ pkg/mcclient/modules/k8s/node.go | 2 +- pkg/mcclient/modules/k8s/pod.go | 4 +- pkg/mcclient/modules/k8s/raw.go | 95 ++++++++++++++++ pkg/mcclient/modules/k8s/service.go | 20 ++++ 17 files changed, 646 insertions(+), 14 deletions(-) create mode 100644 cmd/climc/shell/k8s/configmap.go create mode 100644 cmd/climc/shell/k8s/deployment.go create mode 100644 cmd/climc/shell/k8s/raw.go create mode 100644 cmd/climc/shell/k8s/repos.go create mode 100644 cmd/climc/shell/k8s/service.go create mode 100644 pkg/mcclient/modules/k8s/configmap.go create mode 100644 pkg/mcclient/modules/k8s/deployment.go create mode 100644 pkg/mcclient/modules/k8s/helm.go create mode 100644 pkg/mcclient/modules/k8s/raw.go create mode 100644 pkg/mcclient/modules/k8s/service.go diff --git a/cmd/climc/shell/k8s/configmap.go b/cmd/climc/shell/k8s/configmap.go new file mode 100644 index 0000000000..30d8fd6d9e --- /dev/null +++ b/cmd/climc/shell/k8s/configmap.go @@ -0,0 +1,27 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initConfigMap() { + cmdN := func(suffix string) string { + return resourceCmdN("configmap", suffix) + } + + type listOpt struct { + namespaceListOptions + baseListOptions + } + R(&listOpt{}, cmdN("list"), "List k8s configmap", func(s *mcclient.ClientSession, args *listOpt) error { + params := fetchNamespaceParams(args.namespaceListOptions) + params.Update(fetchPagingParams(args.baseListOptions)) + ret, err := k8s.ConfigMaps.ListInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printList(ret, k8s.ConfigMaps.GetColumns(s)) + return nil + }) +} diff --git a/cmd/climc/shell/k8s/deployment.go b/cmd/climc/shell/k8s/deployment.go new file mode 100644 index 0000000000..dfdc392bba --- /dev/null +++ b/cmd/climc/shell/k8s/deployment.go @@ -0,0 +1,145 @@ +package k8s + +import ( + "fmt" + "strconv" + "strings" + + "yunion.io/x/jsonutils" + "yunion.io/x/pkg/util/sets" + + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initDeployment() { + cmdN := func(suffix string) string { + return resourceCmdN("deployment", suffix) + } + + type listOpt struct { + namespaceListOptions + baseListOptions + } + R(&listOpt{}, cmdN("list"), "List k8s deployment", func(s *mcclient.ClientSession, args *listOpt) error { + params := fetchNamespaceParams(args.namespaceListOptions) + params.Update(fetchPagingParams(args.baseListOptions)) + ret, err := k8s.Deployments.ListInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printList(ret, k8s.Deployments.GetColumns(s)) + return nil + }) + + type createOpt struct { + namespaceOptions + NAME string `help:"Name of deployment"` + Image string `help:"The image for the container to run"` + Replicas int64 `help:"Number of replicas for pods in this deployment"` + RunAsPrivileged bool `help:"Whether to run the container as privileged user"` + Labels string `help:"Comma separated labels to apply to the pod(s)"` + Env []string `help:"Environment variables to set in container"` + Port []string `help:"Port for the service that is created, format is :: e.g. tcp:80:3000"` + } + R(&createOpt{}, cmdN("create"), "Create deployment resource", func(s *mcclient.ClientSession, args *createOpt) error { + params := jsonutils.NewDict() + if len(args.Image) == 0 { + return fmt.Errorf("Image must provided") + } + params.Add(jsonutils.NewString(args.NAME), "name") + params.Add(jsonutils.NewString(args.Image), "containerImage") + if args.Namespace != "" { + params.Add(jsonutils.NewString(args.Namespace), "namespace") + } + if args.Replicas > 1 { + params.Add(jsonutils.NewInt(args.Replicas), "replicas") + } + if args.RunAsPrivileged { + params.Add(jsonutils.JSONTrue, "runAsPrivileged") + } + if len(args.Port) != 0 { + portMappings, err := parsePortMappings(args.Port) + if err != nil { + return err + } + params.Add(portMappings, "portMappings") + } + ret, err := k8s.Deployments.CreateInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printObject(ret) + return nil + }) + + type getOpt struct { + resourceGetOptions + } + R(&getOpt{}, cmdN("show"), "Get deployment details", func(s *mcclient.ClientSession, args *getOpt) error { + id := args.NAME + params := jsonutils.NewDict() + if args.Namespace != "" { + params.Add(jsonutils.NewString(args.Namespace), "namespace") + } + ret, err := k8s.Deployments.GetInContexts(s, id, params, args.ClusterContext()) + if err != nil { + return err + } + printObjectYAML(ret) + return nil + }) +} + +type portMapping struct { + Port int32 `json:"port"` + TargetPort int32 `json:"targetPort"` + Protocol string `json:"protocol"` +} + +func parsePortMapping(port string) (*portMapping, error) { + if len(port) == 0 { + return nil, fmt.Errorf("empty port mapping desc string") + } + parts := strings.Split(port, ":") + mapping := &portMapping{} + for _, part := range parts { + if sets.NewString("tcp", "udp").Has(strings.ToLower(part)) { + mapping.Protocol = strings.ToUpper(part) + } + if port, err := strconv.Atoi(part); err != nil { + continue + } else { + if mapping.Port == 0 { + mapping.Port = int32(port) + } else { + mapping.TargetPort = int32(port) + } + } + } + if mapping.Protocol == "" { + mapping.Protocol = "TCP" + } + if mapping.Port <= 0 { + return nil, fmt.Errorf("Service port not provided") + } + if mapping.TargetPort < 0 { + return nil, fmt.Errorf("Container invalid targetPort %d", mapping.TargetPort) + } + if mapping.TargetPort == 0 { + mapping.TargetPort = mapping.Port + } + return mapping, nil +} + +func parsePortMappings(ports []string) (*jsonutils.JSONArray, error) { + ret := jsonutils.NewArray() + for _, port := range ports { + mapping, err := parsePortMapping(port) + if err != nil { + return nil, fmt.Errorf("Port %q error: %v", port, err) + } + ret.Add(jsonutils.Marshal(mapping)) + } + return ret, nil +} diff --git a/cmd/climc/shell/k8s/k8s.go b/cmd/climc/shell/k8s/k8s.go index 2e63757294..af4892e71a 100644 --- a/cmd/climc/shell/k8s/k8s.go +++ b/cmd/climc/shell/k8s/k8s.go @@ -12,24 +12,81 @@ import ( ) func init() { + // cluster resources initCluster() initNode() + + // helm resources + initRepo() + + // kubernetes original resources + initRaw() + initConfigMap() + initDeployment() initPod() + initService() } type BaseListOptions shell.BaseListOptions type clusterBaseOptions struct { - Cluster string `default:"$K8S_CLUSTER" help:"Kubernetes cluster name"` + Cluster string `default:"$K8S_CLUSTER|default" help:"Kubernetes cluster name"` } func (o clusterBaseOptions) ClusterContext() []modules.ManagerContext { return []modules.ManagerContext{clusterContext(o.Cluster)} } -type k8sBaseListOptions struct { +type baseListOptions struct { + Limit int `default:"20" help:"Page limit"` + Offset int `default:"0" help:"page offset"` +} + +func fetchPagingParams(opt baseListOptions) *jsonutils.JSONDict { + params := jsonutils.NewDict() + if opt.Limit > 0 { + params.Add(jsonutils.NewInt(int64(opt.Limit)), "limit") + } + if opt.Offset > 0 { + params.Add(jsonutils.NewInt(int64(opt.Offset)), "offset") + } + return params +} + +type namespaceListOptions struct { + namespaceOptions + AllNamespace bool `help:"Show resource in all namespace"` +} + +type namespaceOptions struct { clusterBaseOptions - Limit int `default:"20" help:"Page limit"` + Namespace string `help:"Namespace of this resource"` +} + +type resourceGetOptions struct { + clusterBaseOptions + Namespace string `help:"Namespace of this resource"` + NAME string `help:"Name ident of the resource"` +} + +func (o resourceGetOptions) ToJSON() *jsonutils.JSONDict { + params := jsonutils.NewDict() + if o.Namespace != "" { + params.Add(jsonutils.NewString(o.Namespace), "namespace") + } + return params +} + +func fetchNamespaceParams(opt namespaceListOptions) *jsonutils.JSONDict { + params := jsonutils.NewDict() + if opt.AllNamespace { + params.Add(jsonutils.JSONTrue, "all_namespace") + return params + } + if opt.Namespace != "" { + params.Add(jsonutils.NewString(opt.Namespace), "namespace") + } + return params } var ( @@ -53,3 +110,7 @@ func clusterContext(clusterId string) modules.ManagerContext { InstanceId: clusterId, } } + +func printObjectYAML(obj jsonutils.JSONObject) { + fmt.Println(obj.YAMLString()) +} diff --git a/cmd/climc/shell/k8s/pods.go b/cmd/climc/shell/k8s/pods.go index 8d2fdd0d3b..ee8803c414 100644 --- a/cmd/climc/shell/k8s/pods.go +++ b/cmd/climc/shell/k8s/pods.go @@ -13,10 +13,26 @@ func initPod() { } type listOpt struct { - k8sBaseListOptions + namespaceListOptions + baseListOptions } R(&listOpt{}, cmdN("list"), "List k8s pod", func(s *mcclient.ClientSession, args *listOpt) error { - ret, err := k8s.Pods.ListInContexts(s, nil, args.ClusterContext()) + params := fetchNamespaceParams(args.namespaceListOptions) + params.Update(fetchPagingParams(args.baseListOptions)) + ret, err := k8s.Pods.ListInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printList(ret, k8s.Pods.GetColumns(s)) + return nil + }) + + type deleteOpt struct { + resourceGetOptions + } + R(&deleteOpt{}, cmdN("delete"), "Delete pod", func(s *mcclient.ClientSession, args *deleteOpt) error { + id := args.NAME + ret, err := k8s.Pods.DeleteInContexts(s, id, args.ToJSON(), args.ClusterContext()) if err != nil { return err } diff --git a/cmd/climc/shell/k8s/raw.go b/cmd/climc/shell/k8s/raw.go new file mode 100644 index 0000000000..6aeb500f91 --- /dev/null +++ b/cmd/climc/shell/k8s/raw.go @@ -0,0 +1,35 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +type rawGetOpt struct { + namespaceOptions + KIND string `help:"resource kind"` + NAME string `help:"instance name"` +} + +type rawDeleteOpt struct { + rawGetOpt +} + +func initRaw() { + R(&rawGetOpt{}, "k8s-get", "Get k8s resource instance raw info", func(s *mcclient.ClientSession, args *rawGetOpt) error { + obj, err := k8s.RawResource.Get(s, args.KIND, args.Namespace, args.NAME, nil, args.ClusterContext()) + if err != nil { + return err + } + printObjectYAML(obj) + return nil + }) + + R(&rawDeleteOpt{}, "k8s-delete", "Delete k8s resource instance", func(s *mcclient.ClientSession, args *rawDeleteOpt) error { + err := k8s.RawResource.Delete(s, args.KIND, args.Namespace, args.NAME, nil, args.ClusterContext()) + if err != nil { + return err + } + return nil + }) +} diff --git a/cmd/climc/shell/k8s/repos.go b/cmd/climc/shell/k8s/repos.go new file mode 100644 index 0000000000..ee34d8a2f9 --- /dev/null +++ b/cmd/climc/shell/k8s/repos.go @@ -0,0 +1,106 @@ +package k8s + +import ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initRepo() { + cmdN := func(suffix string) string { + return resourceCmdN("repo", suffix) + } + type listOpt struct { + BaseListOptions + } + R(&listOpt{}, cmdN("list"), "List k8s global helm repos", func(s *mcclient.ClientSession, args *listOpt) error { + params := FetchPagingParams(args.BaseListOptions) + result, err := k8s.Repos.List(s, params) + if err != nil { + return err + } + printList(result, k8s.Repos.GetColumns(s)) + return nil + }) + + type getOpt struct { + NAME string `help:"ID or name of the repo"` + } + R(&getOpt{}, cmdN("show"), "Show details fo a repo", func(s *mcclient.ClientSession, args *getOpt) error { + repo, err := k8s.Repos.Get(s, args.NAME, nil) + if err != nil { + return err + } + printObject(repo) + return nil + }) + + type createOpt struct { + getOpt + URL string `help:"Repository url"` + Public bool `help:"Make repository public"` + } + R(&createOpt{}, cmdN("create"), "Add repository", func(s *mcclient.ClientSession, args *createOpt) error { + params := jsonutils.NewDict() + params.Add(jsonutils.NewString(args.NAME), "name") + params.Add(jsonutils.NewString(args.URL), "url") + if args.Public { + params.Add(jsonutils.JSONTrue, "is_public") + } + repo, err := k8s.Repos.Create(s, params) + if err != nil { + return err + } + printObject(repo) + return nil + }) + + type updateOpt struct { + getOpt + Name string `help:"Repository name to change"` + Url string `help:"Repository url to change"` + } + R(&updateOpt{}, cmdN("update"), "Update helm repository", func(s *mcclient.ClientSession, args *updateOpt) error { + params := jsonutils.NewDict() + if args.Name != "" { + params.Add(jsonutils.NewString(args.Name), "name") + } + if args.Url != "" { + params.Add(jsonutils.NewString(args.Url), "url") + } + repo, err := k8s.Repos.Update(s, args.NAME, params) + if err != nil { + return err + } + printObject(repo) + return nil + }) + + R(&getOpt{}, cmdN("private"), "Make repository private", func(s *mcclient.ClientSession, args *getOpt) error { + repo, err := k8s.Repos.PerformAction(s, args.NAME, "private", nil) + if err != nil { + return err + } + printObject(repo) + return nil + }) + + R(&getOpt{}, cmdN("public"), "Make repository public", func(s *mcclient.ClientSession, args *getOpt) error { + repo, err := k8s.Repos.PerformAction(s, args.NAME, "public", nil) + if err != nil { + return err + } + printObject(repo) + return nil + }) + + R(&getOpt{}, cmdN("delete"), "Delete a repository", func(s *mcclient.ClientSession, args *getOpt) error { + repo, err := k8s.Repos.Delete(s, args.NAME, nil) + if err != nil { + return err + } + printObject(repo) + return nil + }) +} diff --git a/cmd/climc/shell/k8s/service.go b/cmd/climc/shell/k8s/service.go new file mode 100644 index 0000000000..3260b28b88 --- /dev/null +++ b/cmd/climc/shell/k8s/service.go @@ -0,0 +1,27 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initService() { + cmdN := func(suffix string) string { + return resourceCmdN("service", suffix) + } + + type listOpt struct { + namespaceListOptions + baseListOptions + } + R(&listOpt{}, cmdN("list"), "List k8s service", func(s *mcclient.ClientSession, args *listOpt) error { + params := fetchNamespaceParams(args.namespaceListOptions) + params.Update(fetchPagingParams(args.baseListOptions)) + ret, err := k8s.Services.ListInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printList(ret, k8s.Services.GetColumns(s)) + return nil + }) +} diff --git a/pkg/mcclient/modules/k8s/base.go b/pkg/mcclient/modules/k8s/base.go index 6c5eef1847..3b5fc20b61 100644 --- a/pkg/mcclient/modules/k8s/base.go +++ b/pkg/mcclient/modules/k8s/base.go @@ -1,13 +1,56 @@ package k8s import ( + "yunion.io/x/pkg/util/sets" + "yunion.io/x/onecloud/pkg/mcclient/modules" ) -func NewManager(keyword, keywordPlural string, columns, adminColumns []string) *modules.ResourceManager { +func NewManager(keyword, keywordPlural string, columns, adminColumns *Columns) *modules.ResourceManager { return &modules.ResourceManager{ - BaseManager: *modules.NewBaseManager("k8s", "", "", columns, adminColumns), + BaseManager: *modules.NewBaseManager("k8s", "", "", columns.Array(), adminColumns.Array()), Keyword: keyword, KeywordPlural: keywordPlural, } } + +type Columns struct { + cols []string +} + +func NewColumns(cols ...string) *Columns { + c := &Columns{cols: make([]string, 0)} + return c.Add(cols...) +} + +func (c *Columns) Add(cols ...string) *Columns { + for _, col := range cols { + c.add(col) + } + return c +} + +func (c *Columns) add(col string) *Columns { + src := sets.NewString(c.Array()...) + if src.Has(col) { + return c + } + c.cols = append(c.cols, col) + return c +} + +func (c Columns) Array() []string { + return c.cols +} + +func NewNamespaceCols(col ...string) *Columns { + return NewColumns("name", "namespace").Add(col...) +} + +func NewClusterCols(col ...string) *Columns { + return NewColumns("cluster").Add(col...) +} + +func NewResourceCols(col ...string) *Columns { + return NewColumns("name", "id").Add(col...) +} diff --git a/pkg/mcclient/modules/k8s/cluster.go b/pkg/mcclient/modules/k8s/cluster.go index df2df5ca39..42ee41d6b1 100644 --- a/pkg/mcclient/modules/k8s/cluster.go +++ b/pkg/mcclient/modules/k8s/cluster.go @@ -10,7 +10,7 @@ var ( func init() { Clusters = NewManager("cluster", "clusters", - []string{"id", "name", "mode", "k8s_version", "status", "api_endpoint"}, - []string{}) + NewResourceCols("mode", "k8s_version", "status", "api_endpoint"), + NewColumns()) modules.Register(Clusters) } diff --git a/pkg/mcclient/modules/k8s/configmap.go b/pkg/mcclient/modules/k8s/configmap.go new file mode 100644 index 0000000000..4bfcbbafdf --- /dev/null +++ b/pkg/mcclient/modules/k8s/configmap.go @@ -0,0 +1,20 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var ConfigMaps *ConfigMapManager + +type ConfigMapManager struct { + modules.ResourceManager +} + +func init() { + ConfigMaps = &ConfigMapManager{ + ResourceManager: *NewManager( + "configmap", "configmaps", + NewNamespaceCols(), + NewClusterCols())} + modules.Register(ConfigMaps) +} diff --git a/pkg/mcclient/modules/k8s/deployment.go b/pkg/mcclient/modules/k8s/deployment.go new file mode 100644 index 0000000000..f56a2947ef --- /dev/null +++ b/pkg/mcclient/modules/k8s/deployment.go @@ -0,0 +1,20 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var Deployments *DeploymentManager + +type DeploymentManager struct { + modules.ResourceManager +} + +func init() { + Deployments = &DeploymentManager{ + ResourceManager: *NewManager( + "deployment", "deployments", + NewNamespaceCols("labels"), + NewClusterCols())} + modules.Register(Deployments) +} diff --git a/pkg/mcclient/modules/k8s/event.go b/pkg/mcclient/modules/k8s/event.go index f71c5541ef..584ddbc376 100644 --- a/pkg/mcclient/modules/k8s/event.go +++ b/pkg/mcclient/modules/k8s/event.go @@ -10,7 +10,7 @@ var ( func init() { Logs = NewManager("kube_event", "kube_events", - []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"}, - []string{}) + NewColumns("id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"), + NewColumns()) modules.Register(Logs) } diff --git a/pkg/mcclient/modules/k8s/helm.go b/pkg/mcclient/modules/k8s/helm.go new file mode 100644 index 0000000000..b3e04f21ea --- /dev/null +++ b/pkg/mcclient/modules/k8s/helm.go @@ -0,0 +1,17 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var ( + Repos *modules.ResourceManager +) + +func init() { + Repos = NewManager("repo", "repos", + NewResourceCols("url", "is_public", "source"), + NewColumns(), + ) + modules.Register(Repos) +} diff --git a/pkg/mcclient/modules/k8s/node.go b/pkg/mcclient/modules/k8s/node.go index 5b8cb0798b..60f5bd6ade 100644 --- a/pkg/mcclient/modules/k8s/node.go +++ b/pkg/mcclient/modules/k8s/node.go @@ -9,6 +9,6 @@ var ( ) func init() { - Nodes = NewManager("node", "nodes", []string{"id", "name", "cluster", "roles", "address", "status"}, []string{}) + Nodes = NewManager("node", "nodes", NewResourceCols("cluster", "roles", "address", "status"), NewColumns()) modules.Register(Nodes) } diff --git a/pkg/mcclient/modules/k8s/pod.go b/pkg/mcclient/modules/k8s/pod.go index 46417df838..218ef6a243 100644 --- a/pkg/mcclient/modules/k8s/pod.go +++ b/pkg/mcclient/modules/k8s/pod.go @@ -14,7 +14,7 @@ func init() { Pods = &PodManager{ ResourceManager: *NewManager( "pod", "pods", - []string{"id", "name", "cluster", "roles", "address", "status"}, - []string{})} + NewNamespaceCols("podIP", "status", "restartCount", "labels"), + NewClusterCols("nodeName"))} modules.Register(Pods) } diff --git a/pkg/mcclient/modules/k8s/raw.go b/pkg/mcclient/modules/k8s/raw.go new file mode 100644 index 0000000000..8853a18742 --- /dev/null +++ b/pkg/mcclient/modules/k8s/raw.go @@ -0,0 +1,95 @@ +package k8s + +import ( + "fmt" + "net/url" + "strings" + + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var RawResource *RawResourceManager + +func init() { + RawResource = &RawResourceManager{ + serviceType: "k8s", + } +} + +type rawResourceContext struct { + kind string + name string + query jsonutils.JSONObject + ctxs []modules.ManagerContext +} + +func newRawResourceContext(kind, namespace, name string, query jsonutils.JSONObject, ctxs []modules.ManagerContext) *rawResourceContext { + nsQuery := getNamespaceQuery(namespace) + if query != nil { + nsQuery.Update(query) + } + ctx := &rawResourceContext{kind: kind, name: name, query: nsQuery, ctxs: ctxs} + return ctx +} + +func (ctx rawResourceContext) contextPath() string { + segs := make([]string, 0) + ctxs := ctx.ctxs + if ctxs != nil && len(ctxs) > 0 { + for _, c := range ctxs { + segs = append(segs, c.InstanceManager.KeyString()) + if len(c.InstanceId) > 0 { + segs = append(segs, url.PathEscape(c.InstanceId)) + } + } + } + segs = append(segs, "_raw", ctx.kind, ctx.name) + path := fmt.Sprintf("/%s", strings.Join(segs, "/")) + if ctx.query != nil { + qs := ctx.query.QueryString() + if len(qs) > 0 { + path = fmt.Sprintf("%s?%s", path, qs) + } + } + return path +} + +type RawResourceManager struct { + serviceType string +} + +func (m *RawResourceManager) request(s *mcclient.ClientSession, method string, path string, body jsonutils.JSONObject) (jsonutils.JSONObject, error) { + _, ret, err := s.JSONRequest(m.serviceType, "", method, path, nil, body) + return ret, err +} + +func getNamespaceQuery(namespace string) *jsonutils.JSONDict { + query := jsonutils.NewDict() + if namespace != "" { + query.Set("namespace", jsonutils.NewString(namespace)) + } + return query +} + +func (m *RawResourceManager) Get(s *mcclient.ClientSession, kind string, namespace string, name string, query jsonutils.JSONObject, ctxs []modules.ManagerContext) (jsonutils.JSONObject, error) { + ctx := newRawResourceContext(kind, namespace, name, query, ctxs) + return m.request(s, "GET", ctx.contextPath(), nil) +} + +func (m *RawResourceManager) Put(s *mcclient.ClientSession, kind string, namespace string, name string, body jsonutils.JSONObject, ctxs []modules.ManagerContext) error { + rawBytes := body.String() + newBody := jsonutils.NewDict() + newBody.Add(jsonutils.NewString(rawBytes), "raw") + ctx := newRawResourceContext(kind, namespace, name, nil, ctxs) + _, err := m.request(s, "PUT", ctx.contextPath(), newBody) + return err +} + +func (m *RawResourceManager) Delete(s *mcclient.ClientSession, kind string, namespace string, name string, query jsonutils.JSONObject, ctxs []modules.ManagerContext) error { + ctx := newRawResourceContext(kind, namespace, name, query, ctxs) + _, err := m.request(s, "DELETE", ctx.contextPath(), nil) + return err +} diff --git a/pkg/mcclient/modules/k8s/service.go b/pkg/mcclient/modules/k8s/service.go new file mode 100644 index 0000000000..e66f38dda3 --- /dev/null +++ b/pkg/mcclient/modules/k8s/service.go @@ -0,0 +1,20 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var Services *ServiceManager + +type ServiceManager struct { + modules.ResourceManager +} + +func init() { + Services = &ServiceManager{ + ResourceManager: *NewManager( + "service", "services", + NewNamespaceCols("clusterIP", "selector", "internalEndpoint", "externalEndpoints"), + NewClusterCols())} + modules.Register(Services) +} From b95af3dc79e418a6d33b16835b43b49d958383ba Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Tue, 21 Aug 2018 17:39:55 +0800 Subject: [PATCH 3/4] climc: helm api --- cmd/climc/shell/k8s/charts.go | 63 ++++++++ cmd/climc/shell/k8s/helm_list.go | 51 +++++++ cmd/climc/shell/k8s/k8s.go | 3 + cmd/climc/shell/k8s/releases.go | 177 +++++++++++++++++++++++ cmd/climc/shell/k8s/tiller.go | 56 +++++++ pkg/mcclient/modules/k8s/helm_chart.go | 16 ++ pkg/mcclient/modules/k8s/helm_release.go | 23 +++ pkg/mcclient/modules/k8s/helm_tiller.go | 23 +++ 8 files changed, 412 insertions(+) create mode 100644 cmd/climc/shell/k8s/charts.go create mode 100644 cmd/climc/shell/k8s/helm_list.go create mode 100644 cmd/climc/shell/k8s/releases.go create mode 100644 cmd/climc/shell/k8s/tiller.go create mode 100644 pkg/mcclient/modules/k8s/helm_chart.go create mode 100644 pkg/mcclient/modules/k8s/helm_release.go create mode 100644 pkg/mcclient/modules/k8s/helm_tiller.go diff --git a/cmd/climc/shell/k8s/charts.go b/cmd/climc/shell/k8s/charts.go new file mode 100644 index 0000000000..8cb609642a --- /dev/null +++ b/cmd/climc/shell/k8s/charts.go @@ -0,0 +1,63 @@ +package k8s + +import ( + "fmt" + + json "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initChart() { + cmdN := func(suffix string) string { + return resourceCmdN("chart", suffix) + } + + type listOpt struct { + baseListOptions + Name string `help:"Chart name"` + Repo string `help:"Repository name"` + RepoUrl string `help:"Repository url"` + AllVersion bool `json:"Get Chart all history versions"` + Keyword string `json:"Chart keyword"` + } + R(&listOpt{}, cmdN("list"), "List k8s helm global charts", func(s *mcclient.ClientSession, args *listOpt) error { + params := fetchPagingParams(args.baseListOptions) + if len(args.Name) != 0 { + params.Add(json.NewString(args.Name), "name") + } + if len(args.Repo) != 0 { + params.Add(json.NewString(args.Repo), "repo") + } + if len(args.RepoUrl) != 0 { + params.Add(json.NewString(args.RepoUrl), "repo_url") + } + if args.AllVersion { + params.Add(json.JSONTrue, "all_version") + } + if len(args.Keyword) != 0 { + params.Add(json.NewString(args.Keyword), "keyword") + } + charts, err := k8s.Charts.List(s, params) + if err != nil { + return err + } + PrintHelmListResult(charts, ChartPrinter{}) + return nil + }) +} + +type ChartPrinter struct{} + +func (p ChartPrinter) Columns() []interface{} { + return []interface{}{"REPO/NAME", "VERSION", "DESCRIPTION"} +} + +func (p ChartPrinter) RowKeys(obj *json.JSONDict) []interface{} { + repo, _ := obj.GetString("repo") + name, _ := obj.GetString("chart", "metadata", "name") + version, _ := obj.GetString("chart", "metadata", "version") + desc, _ := obj.GetString("chart", "metadata", "description") + return []interface{}{fmt.Sprintf("%s/%s", repo, name), version, desc} +} diff --git a/cmd/climc/shell/k8s/helm_list.go b/cmd/climc/shell/k8s/helm_list.go new file mode 100644 index 0000000000..df1055a29e --- /dev/null +++ b/cmd/climc/shell/k8s/helm_list.go @@ -0,0 +1,51 @@ +package k8s + +import ( + "fmt" + + "github.com/gosuri/uitable" + + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +type ListPrinter interface { + Columns() []interface{} + RowKeys(obj *jsonutils.JSONDict) []interface{} +} + +func ListerTable(res *modules.ListResult, printer ListPrinter) *uitable.Table { + min := func(x, y int) int { + if x < y { + return x + } + return y + } + table := uitable.New() + table.MaxColWidth = 80 + table.AddRow(printer.Columns()...) + var idx int + for ; idx < min(res.Limit, res.Total); idx++ { + table.AddRow(printer.RowKeys(res.Data[idx].(*jsonutils.JSONDict))...) + } + return table +} + +func PrintHelmListResult(res *modules.ListResult, printer ListPrinter) { + fmt.Println(ListerTable(res, printer)) + + table := uitable.New() + total := res.Total + offset := res.Offset + limit := res.Limit + page := (offset / limit) + 1 + pages := total / limit + if pages*limit < total { + pages += 1 + } + table.AddRow("") + table.AddRow("Total", "Pages", "Limit", "Offset", "Page") + table.AddRow(total, pages, limit, offset, page) + fmt.Println(table) +} diff --git a/cmd/climc/shell/k8s/k8s.go b/cmd/climc/shell/k8s/k8s.go index af4892e71a..d7b46f482a 100644 --- a/cmd/climc/shell/k8s/k8s.go +++ b/cmd/climc/shell/k8s/k8s.go @@ -17,7 +17,10 @@ func init() { initNode() // helm resources + initTiller() initRepo() + initChart() + initRelease() // kubernetes original resources initRaw() diff --git a/cmd/climc/shell/k8s/releases.go b/cmd/climc/shell/k8s/releases.go new file mode 100644 index 0000000000..179fb199b4 --- /dev/null +++ b/cmd/climc/shell/k8s/releases.go @@ -0,0 +1,177 @@ +package k8s + +import ( + "fmt" + "io/ioutil" + + json "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initRelease() { + cmdN := func(suffix string) string { + return resourceCmdN("release", suffix) + } + type listOpt struct { + namespaceListOptions + baseListOptions + Filter string `help:"Filter, split by space"` + Admin bool `help:"Admin to show all namespace releases"` + Deployed bool `help:"Show deployed status releases"` + Deleted bool `help:"Show deleted status releases"` + Deleting bool `help:"Show deleting status releases"` + Failed bool `help:"Show failed status releases"` + Superseded bool `help:"Show superseded status releases"` + Pending bool `help:"Show pending status releases"` + } + R(&listOpt{}, cmdN("list"), "List k8s cluster helm releases", func(s *mcclient.ClientSession, args *listOpt) error { + params := fetchNamespaceParams(args.namespaceListOptions) + params.Update(fetchPagingParams(args.baseListOptions)) + if args.Filter != "" { + params.Add(json.NewString(args.Filter), "filter") + } + if args.Namespace != "" { + params.Add(json.NewString(args.Namespace), "namespace") + } + params.Add(json.JSONTrue, "all") + if args.Admin { + params.Add(json.JSONTrue, "admin") + } + if args.Deployed { + params.Add(json.JSONTrue, "deployed") + } + if args.Deleted { + params.Add(json.JSONTrue, "deleted") + } + if args.Deleting { + params.Add(json.JSONTrue, "deleting") + } + if args.Failed { + params.Add(json.JSONTrue, "failed") + } + if args.Superseded { + params.Add(json.JSONTrue, "superseded") + } + if args.Pending { + params.Add(json.JSONTrue, "pending") + } + ret, err := k8s.Releases.ListInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printList(ret, k8s.Releases.GetColumns(s)) + return nil + }) + + type showOpt struct { + clusterBaseOptions + NAME string `help:"Release instance name"` + } + R(&showOpt{}, cmdN("show"), "Get helm release details", func(s *mcclient.ClientSession, args *showOpt) error { + ret, err := k8s.Releases.GetInContexts(s, args.NAME, nil, args.ClusterContext()) + if err != nil { + return err + } + resources, err := ret.GetString("info", "status", "resources") + if err != nil { + return err + } + fmt.Println(resources) + return nil + }) + + type releaseCUOpts struct { + Values string `help:"Specify values in a YAML file (can specify multiple)" short-token:"f"` + Version string `help:"Specify the exact chart version to install. If not specified, latest version installed"` + //Set []string `help:"set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)"` + DryRun bool `help:"Simulate an install"` + Details bool `help:"Show release deploy details, include kubernetes created resources"` + Timeout int64 `help:"Time in seconds to wait for any individual kubernetes operation (like Jobs for hooks)" default:"600"` + } + releaseCUDict := func(args releaseCUOpts) (*json.JSONDict, error) { + params := json.NewDict() + if args.Version != "" { + params.Add(json.NewString(args.Version), "version") + } + if args.DryRun { + params.Add(json.JSONTrue, "dry_run") + } + params.Add(json.NewInt(args.Timeout), "timeout") + if args.Values != "" { + //vals, err := helm.MergeValuesF(args.Values, args.Set, []string{}) + vals, err := ioutil.ReadFile(args.Values) + if err != nil { + return nil, err + } + params.Add(json.NewString(string(vals)), "values") + } + return params, nil + } + + type releaseCreateOpts struct { + namespaceOptions + releaseCUOpts + Name string `help:"Release name, If unspecified, it will autogenerate one for you"` + CHARTNAME string `help:"Helm chart name, e.g stable/etcd"` + } + R(&releaseCreateOpts{}, cmdN("create"), "Create release with specified helm chart", func(s *mcclient.ClientSession, args *releaseCreateOpts) error { + params, err := releaseCUDict(args.releaseCUOpts) + if err != nil { + return err + } + params.Add(json.NewString(args.CHARTNAME), "chart_name") + if args.Namespace != "" { + params.Add(json.NewString(args.Namespace), "namespace") + } + if args.Name != "" { + params.Add(json.NewString(args.Name), "release_name") + } + ret, err := k8s.Releases.CreateInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printObject(ret) + return nil + }) + + type releaseUpgradeOpts struct { + clusterBaseOptions + releaseCUOpts + NAME string `help:"Release instance name"` + CHARTNAME string `help:"Helm chart name, e.g stable/etcd"` + ReuseValues bool `help:"When upgrading, reuse the last release's values, and merge in any new values. If '--reset-values' is specified, this is ignored"` + ResetValues bool `help:"When upgrading, reset the values to the ones built into the chart"` + } + R(&releaseUpgradeOpts{}, cmdN("upgrade"), "Upgrade release", func(s *mcclient.ClientSession, args *releaseUpgradeOpts) error { + params, err := releaseCUDict(args.releaseCUOpts) + if err != nil { + return err + } + params.Add(json.NewString(args.CHARTNAME), "chart_name") + params.Add(json.NewString(args.NAME), "release_name") + if args.ReuseValues { + params.Add(json.JSONTrue, "reuse_values") + } + if args.ResetValues { + params.Add(json.JSONTrue, "reset_values") + } + + res, err := k8s.Releases.PutInContexts(s, args.NAME, params, args.ClusterContext()) + if err != nil { + return err + } + printObject(res) + return nil + }) + + type deleteOpt struct { + clusterBaseOptions + NAME string `help:"Release instance name"` + } + R(&deleteOpt{}, cmdN("delete"), "Delete release", func(s *mcclient.ClientSession, args *deleteOpt) error { + _, err := k8s.Releases.DeleteInContexts(s, args.NAME, nil, args.ClusterContext()) + return err + }) +} diff --git a/cmd/climc/shell/k8s/tiller.go b/cmd/climc/shell/k8s/tiller.go new file mode 100644 index 0000000000..247e5fba13 --- /dev/null +++ b/cmd/climc/shell/k8s/tiller.go @@ -0,0 +1,56 @@ +package k8s + +import ( + json "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" +) + +func initTiller() { + cmdN := func(suffix string) string { + return resourceCmdN("tiller", suffix) + } + type createOpt struct { + clusterBaseOptions + KubeContext string `json:"kube_context"` + Namespace string `json:"namespace" default:"kube-system"` + // Upgrade if Tiller is already installed + Upgrade bool `json:"upgrade"` + // Name of service account + ServiceAccount string `json:"service_account" default:"tiller"` + // Use the canary Tiller image + Canary bool `json:"canary_image"` + + // Override Tiller image + Image string `json:"tiller_image" default:"yunion/tiller:v2.9.0"` + // Limit the maximum number of revisions saved per release. Use 0 for no limit. + MaxHistory int `json:"history_max"` + } + R(&createOpt{}, cmdN("create"), "Install helm tiller server to Kubernetes cluster", func(s *mcclient.ClientSession, args *createOpt) error { + params := json.NewDict() + if len(args.KubeContext) > 0 { + params.Add(json.NewString(args.KubeContext), "kube_context") + } + params.Add(json.NewString(args.Namespace), "namespace") + params.Add(json.NewString(args.ServiceAccount), "service_account") + if args.Canary { + params.Add(json.JSONTrue, "canary_image") + } + if args.Upgrade { + params.Add(json.JSONTrue, "upgrade") + } + if len(args.Image) > 0 { + params.Add(json.NewString(args.Image), "tiller_image") + } + if args.MaxHistory > 0 { + params.Add(json.NewInt(int64(args.MaxHistory)), "history_max") + } + ret, err := k8s.Tiller.CreateInContexts(s, params, args.ClusterContext()) + if err != nil { + return err + } + printObject(ret) + return nil + }) +} diff --git a/pkg/mcclient/modules/k8s/helm_chart.go b/pkg/mcclient/modules/k8s/helm_chart.go new file mode 100644 index 0000000000..522628793f --- /dev/null +++ b/pkg/mcclient/modules/k8s/helm_chart.go @@ -0,0 +1,16 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var ( + Charts *modules.ResourceManager +) + +func init() { + Charts = NewManager("chart", "charts", + NewResourceCols(), + NewColumns()) + modules.Register(Charts) +} diff --git a/pkg/mcclient/modules/k8s/helm_release.go b/pkg/mcclient/modules/k8s/helm_release.go new file mode 100644 index 0000000000..ef254c0a45 --- /dev/null +++ b/pkg/mcclient/modules/k8s/helm_release.go @@ -0,0 +1,23 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var ( + Releases *ReleaseManager +) + +type ReleaseManager struct { + modules.ResourceManager +} + +func init() { + Releases = &ReleaseManager{ + ResourceManager: *NewManager( + "release", "releases", + NewNamespaceCols(""), + NewColumns(), + )} + modules.Register(Releases) +} diff --git a/pkg/mcclient/modules/k8s/helm_tiller.go b/pkg/mcclient/modules/k8s/helm_tiller.go new file mode 100644 index 0000000000..ddb442561f --- /dev/null +++ b/pkg/mcclient/modules/k8s/helm_tiller.go @@ -0,0 +1,23 @@ +package k8s + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var ( + Tiller *TillerManager +) + +type TillerManager struct { + modules.ResourceManager +} + +func init() { + Tiller = &TillerManager{ + ResourceManager: *NewManager( + "tiller", "tiller", + NewColumns(), + NewColumns(), + )} + modules.Register(Tiller) +} From 295b9d8fae6b21649bc2f654cb48a01b23421a9b Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Tue, 21 Aug 2018 20:38:22 +0800 Subject: [PATCH 4/4] vendor update --- Gopkg.lock | 341 ++++++++++++++++-- .../services/push/push_notice_to_android.go | 110 ------ .../services/push/push_notice_toi_os.go | 111 ------ vendor/github.com/gosuri/uitable/.travis.yml | 8 + vendor/github.com/gosuri/uitable/LICENSE | 10 + vendor/github.com/gosuri/uitable/Makefile | 4 + vendor/github.com/gosuri/uitable/README.md | 67 ++++ vendor/github.com/gosuri/uitable/table.go | 203 +++++++++++ .../gosuri/uitable/util/strutil/strutil.go | 76 ++++ .../gosuri/uitable/util/wordwrap/LICENSE.md | 21 ++ .../gosuri/uitable/util/wordwrap/README.md | 39 ++ .../gosuri/uitable/util/wordwrap/wordwrap.go | 84 +++++ .../govmomi/simulator/license_manager.go | 156 -------- 13 files changed, 824 insertions(+), 406 deletions(-) delete mode 100644 vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/push/push_notice_to_android.go delete mode 100644 vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/push/push_notice_toi_os.go create mode 100644 vendor/github.com/gosuri/uitable/.travis.yml create mode 100644 vendor/github.com/gosuri/uitable/LICENSE create mode 100644 vendor/github.com/gosuri/uitable/Makefile create mode 100644 vendor/github.com/gosuri/uitable/README.md create mode 100644 vendor/github.com/gosuri/uitable/table.go create mode 100644 vendor/github.com/gosuri/uitable/util/strutil/strutil.go create mode 100644 vendor/github.com/gosuri/uitable/util/wordwrap/LICENSE.md create mode 100644 vendor/github.com/gosuri/uitable/util/wordwrap/README.md create mode 100644 vendor/github.com/gosuri/uitable/util/wordwrap/wordwrap.go delete mode 100644 vendor/github.com/vmware/govmomi/simulator/license_manager.go diff --git a/Gopkg.lock b/Gopkg.lock index 8b923166b6..2499f89c7f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,22 +2,27 @@ [[projects]] + digest = "1:f7a3877d7116adfcdcd641f9f6ad18fc2126bd5c080d8854cc3b395a01e0b7f3" name = "github.com/DataDog/dd-trace-go" packages = [ "opentracing", "tracer", - "tracer/ext" + "tracer/ext", ] + pruneopts = "UT" revision = "27617015d45e6cd550b9a7ac7715c37cc2f7d020" version = "v0.6.1" [[projects]] + digest = "1:66b8ed452b31eb9075bc53295952487c333a9cb555de57ed61f5664c058d9050" name = "github.com/Shopify/sarama" packages = ["."] + pruneopts = "UT" revision = "35324cf48e33d8260e1c7c18854465a904ade249" version = "v1.17.0" [[projects]] + digest = "1:37a8ee6652ff3c42043fa26c0930858d1a72f26928ae26e5261fe81c5f0c2e8d" name = "github.com/aliyun/alibaba-cloud-sdk-go" packages = [ "sdk", @@ -28,47 +33,61 @@ "sdk/errors", "sdk/requests", "sdk/responses", - "sdk/utils" + "sdk/utils", ] + pruneopts = "UT" revision = "f53c66e9cf53d68bcf063643c09cc667efa0e613" version = "1.23.3" [[projects]] + digest = "1:fff66556e25e676b296f9f2c78853831911e6ae41d84303a9be7a534bd1c0901" name = "github.com/aliyun/aliyun-oss-go-sdk" packages = ["oss"] + pruneopts = "UT" revision = "36bf7aa2f916f274137aedd05d1d36f6a3c0f4a6" version = "1.9.0" [[projects]] + digest = "1:8f5416c7f59da8600725ae1ff00a99af1da8b04c211ae6f3c8f8bcab0164f650" name = "github.com/aokoli/goutils" packages = ["."] + pruneopts = "UT" revision = "3391d3790d23d03408670993e957e8f408993c34" version = "v1.0.1" [[projects]] + digest = "1:eee9386329f4fcdf8d6c0def0c9771b634bdd5ba460d888aa98c17d59b37a76c" name = "github.com/apache/thrift" packages = ["lib/go/thrift"] + pruneopts = "UT" revision = "e59b73d3c2bf1c328ccb78e683c0462fa1a473c7" [[projects]] branch = "master" + digest = "1:d6afaeed1502aa28e80a4ed0981d570ad91b2579193404256ce672ed0a609e0d" name = "github.com/beorn7/perks" packages = ["quantile"] + pruneopts = "UT" revision = "3a771d992973f24aa725d07868b467d1ddfceafb" [[projects]] + digest = "1:b520b55fc1146c5b0eea03b07233f7a3d4a9be985c037c91ea6b82ecb81bd521" name = "github.com/bitly/go-simplejson" packages = ["."] + pruneopts = "UT" revision = "aabad6e819789e569bd6aabf444c935aa9ba1e44" version = "v0.5.0" [[projects]] + digest = "1:a2486f94bda33b301614ff5cfce102b7eed4c923fa650c2b83dba1fcf2117466" name = "github.com/c-bata/go-prompt" packages = ["."] + pruneopts = "UT" revision = "c52492ff1b386e5c0ba5271b5eaad165fab09eca" version = "v0.2.2" [[projects]] + digest = "1:40098afbdd06a76dee4b6bcb85a22fed81ac9d2ebaf775c91e558c80f57aaff1" name = "github.com/coredns/coredns" packages = [ "core/dnsserver", @@ -118,108 +137,140 @@ "plugin/reload", "plugin/test", "plugin/trace", - "request" + "request", ] + pruneopts = "UT" revision = "2e322f6e8a54f18c6aef9c25a7c432c291a3d9f7" version = "v1.2.0" [[projects]] + digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39" name = "github.com/davecgh/go-spew" packages = ["spew"] + pruneopts = "UT" revision = "346938d642f2ec3594ed81d874461961cd0faa76" version = "v1.1.0" [[projects]] branch = "master" + digest = "1:737260890e4b00d73a76993eac1a772cf6a57292f723c47e26f005821efcabcf" name = "github.com/dnstap/golang-dnstap" packages = ["."] + pruneopts = "UT" revision = "2cf77a2b5e11ac8d0ba3892772ac8e1f7b528344" [[projects]] + digest = "1:1f0c7ab489b407a7f8f9ad16c25a504d28ab461517a971d341388a56156c1bd7" name = "github.com/eapache/go-resiliency" packages = ["breaker"] + pruneopts = "UT" revision = "ea41b0fad31007accc7f806884dcdf3da98b79ce" version = "v1.1.0" [[projects]] branch = "master" + digest = "1:0448d1c1a596941c608762912fe7c865f88d9ffa45afb8af1edcf1401762bf7e" name = "github.com/eapache/go-xerial-snappy" packages = ["."] + pruneopts = "UT" revision = "040cc1a32f578808623071247fdbd5cc43f37f5f" [[projects]] + digest = "1:444b82bfe35c83bbcaf84e310fb81a1f9ece03edfed586483c869e2c046aef69" name = "github.com/eapache/queue" packages = ["."] + pruneopts = "UT" revision = "44cc805cf13205b55f69e14bcb69867d1ae92f98" version = "v1.1.0" [[projects]] branch = "master" + digest = "1:a76c5e933af8688d9dcfbe718f2b0bfc955208fe0e47e74218b45f1df83ef2ae" name = "github.com/farsightsec/golang-framestream" packages = ["."] + pruneopts = "UT" revision = "c06a5734334d9629b3db143d74b47eb94ea68612" [[projects]] + digest = "1:865079840386857c809b72ce300be7580cb50d3d3129ce11bf9aa6ca2bc1934a" name = "github.com/fatih/color" packages = ["."] + pruneopts = "UT" revision = "5b77d2a35fb0ede96d138fc9a99f5c9b6aef11b4" version = "v1.7.0" [[projects]] branch = "master" + digest = "1:50a46ab1d5edbbdd55125b4d37f1bf503d0807c26461f9ad7b358d6006641d09" name = "github.com/flynn/go-shlex" packages = ["."] + pruneopts = "UT" revision = "3f9db97f856818214da2e1057f8ad84803971cff" [[projects]] + digest = "1:2cd7915ab26ede7d95b8749e6b1f933f1c6d5398030684e6505940a10f31cfda" name = "github.com/ghodss/yaml" packages = ["."] + pruneopts = "UT" revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" version = "v1.0.0" [[projects]] branch = "master" + digest = "1:36fe9527deed01d2a317617e59304eb2c4ce9f8a24115bcc5c2e37b3aee5bae4" name = "github.com/gin-contrib/sse" packages = ["."] + pruneopts = "UT" revision = "22d885f9ecc78bf4ee5d72b937e4bbcdc58e8cae" [[projects]] + digest = "1:ab00ecdc9607692ffd5fb1ac21a9ba2d6cc95bae011f327022c0b1c323d218e2" name = "github.com/gin-gonic/gin" packages = [ "binding", - "render" + "render", ] + pruneopts = "UT" revision = "d459835d2b077e44f7c9b453505ee29881d5d12d" version = "v1.2" [[projects]] + digest = "1:31a18dae27a29aa074515e43a443abfd2ba6deb6d69309d8d7ce789c45f34659" name = "github.com/go-logfmt/logfmt" packages = ["."] + pruneopts = "UT" revision = "390ab7935ee28ec6b286364bba9b4dd6410cb3d5" version = "v0.3.0" [[projects]] + digest = "1:adea5a94903eb4384abef30f3d878dc9ff6b6b5b0722da25b82e5169216dfb61" name = "github.com/go-sql-driver/mysql" packages = ["."] + pruneopts = "UT" revision = "d523deb1b23d913de5bdada721a6071e71283618" version = "v1.4.0" [[projects]] + digest = "1:34e709f36fd4f868fb00dbaf8a6cab4c1ae685832d392874ba9d7c5dec2429d1" name = "github.com/gogo/protobuf" packages = [ "proto", - "sortkeys" + "sortkeys", ] + pruneopts = "UT" revision = "636bf0302bc95575d69441b25a2603156ffdddf1" version = "v1.1.1" [[projects]] + digest = "1:94d8c9e3a4954505ca89243e2121180972eecf8e3d160f3b34a48825ddd95cc1" name = "github.com/golang-plus/errors" packages = ["."] + pruneopts = "UT" revision = "a61c34ead85085f3e1b87b8c04e49bbf60c99fb1" version = "v1.0.0" [[projects]] + digest = "1:224bf08a201edf15ec9f086549321257d5a2ee0d23dc649e7e6ad90ce5502439" name = "github.com/golang-plus/uuid" packages = [ ".", @@ -229,205 +280,275 @@ "internal/namebased/md5", "internal/namebased/sha1", "internal/random", - "internal/timebased" + "internal/timebased", ] + pruneopts = "UT" revision = "a0510c37ef1f49c8290c3a9911d0f7f9ed24d335" version = "v1.0.0" [[projects]] branch = "master" + digest = "1:1ba1d79f2810270045c328ae5d674321db34e3aae468eb4233883b473c5c0467" name = "github.com/golang/glog" packages = ["."] + pruneopts = "UT" revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998" [[projects]] + digest = "1:17fe264ee908afc795734e8c4e63db2accabaf57326dbf21763a7d6b86096260" name = "github.com/golang/protobuf" packages = [ "proto", "ptypes", "ptypes/any", "ptypes/duration", - "ptypes/timestamp" + "ptypes/timestamp", ] + pruneopts = "UT" revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265" version = "v1.1.0" [[projects]] branch = "master" + digest = "1:4a0c6bb4805508a6287675fac876be2ac1182539ca8a32468d8128882e9d5009" name = "github.com/golang/snappy" packages = ["."] + pruneopts = "UT" revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a" [[projects]] branch = "master" + digest = "1:9887333bbef17574b1db5f9893ea137ac44107235d624408a3ac9e0b98fbb2cb" name = "github.com/google/btree" packages = ["."] + pruneopts = "UT" revision = "e89373fe6b4a7413d7acd6da1725b83ef713e6e4" [[projects]] branch = "master" + digest = "1:3ee90c0d94da31b442dde97c99635aaafec68d0b8a3c12ee2075c6bdabeec6bb" name = "github.com/google/gofuzz" packages = ["."] + pruneopts = "UT" revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1" [[projects]] + digest = "1:8f8811f9be822914c3a25c6a071e93beb4c805d7b026cbf298bc577bc1cc945b" name = "github.com/google/uuid" packages = ["."] + pruneopts = "UT" revision = "064e2069ce9c359c118179501254f67d7d37ba24" version = "0.2" [[projects]] + digest = "1:65c4414eeb350c47b8de71110150d0ea8a281835b1f386eacaa3ad7325929c21" name = "github.com/googleapis/gnostic" packages = [ "OpenAPIv2", "compiler", - "extensions" + "extensions", ] + pruneopts = "UT" revision = "7c663266750e7d82587642f65e60bc4083f1f84e" version = "v0.2.0" [[projects]] branch = "master" + digest = "1:4e08dc2383a46b3107f0b34ca338c4459e8fc8ee90e46a60e728aa8a2b21d558" + name = "github.com/gosuri/uitable" + packages = [ + ".", + "util/strutil", + "util/wordwrap", + ] + pruneopts = "UT" + revision = "36ee7e946282a3fb1cfecd476ddc9b35d8847e42" + +[[projects]] + branch = "master" + digest = "1:86c1210529e69d69860f2bb3ee9ccce0b595aa3f9165e7dd1388e5c612915888" name = "github.com/gregjones/httpcache" packages = [ ".", - "diskcache" + "diskcache", ] + pruneopts = "UT" revision = "9cad4c3443a7200dd6400aef47183728de563a38" [[projects]] branch = "master" + digest = "1:1a1206efd03a54d336dce7bb8719e74f2f8932f661cb9f57d5813a1d99c083d8" name = "github.com/grpc-ecosystem/grpc-opentracing" packages = ["go/otgrpc"] + pruneopts = "UT" revision = "8e809c8a86450a29b90dcc9efbf062d0fe6d9746" [[projects]] + digest = "1:8eb1de8112c9924d59bf1d3e5c26f5eaa2bfc2a5fcbb92dc1c2e4546d695f277" name = "github.com/imdario/mergo" packages = ["."] + pruneopts = "UT" revision = "9f23e2d6bd2a77f959b2bf6acdbefd708a83a4a4" version = "v0.3.6" [[projects]] + digest = "1:b6f4477f09f11785097a121811f3a90d8d26cab73c1aa71abda859bdf6ad2334" name = "github.com/jinzhu/gorm" packages = [ ".", - "dialects/mysql" + "dialects/mysql", ] + pruneopts = "UT" revision = "6ed508ec6a4ecb3531899a69cbc746ccf65a4166" version = "v1.9.1" [[projects]] branch = "master" + digest = "1:fd97437fbb6b7dce04132cf06775bd258cce305c44add58eb55ca86c6c325160" name = "github.com/jinzhu/inflection" packages = ["."] + pruneopts = "UT" revision = "04140366298a54a039076d798123ffa108fff46c" [[projects]] + digest = "1:b87714e57a511d88f307aba7d5b63522da12bed0a050889c81272fc50f71100e" name = "github.com/jmespath/go-jmespath" packages = ["."] + pruneopts = "UT" revision = "3433f3ea46d9f8019119e7dd41274e112a2359a9" version = "0.2.2" [[projects]] + digest = "1:eaefc85d32c03e5f0c2b88ea2f79fce3d993e2c78316d21319575dd4ea9153ca" name = "github.com/json-iterator/go" packages = ["."] + pruneopts = "UT" revision = "ab8a2e0c74be9d3be70b3184d9acc634935ded82" version = "1.1.4" [[projects]] branch = "master" + digest = "1:a64e323dc06b73892e5bb5d040ced475c4645d456038333883f58934abbf6f72" name = "github.com/kr/logfmt" packages = ["."] + pruneopts = "UT" revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0" [[projects]] + digest = "1:c658e84ad3916da105a761660dcaeb01e63416c8ec7bc62256a9b411a05fcd67" name = "github.com/mattn/go-colorable" packages = ["."] + pruneopts = "UT" revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" version = "v0.0.9" [[projects]] + digest = "1:d4d17353dbd05cb52a2a52b7fe1771883b682806f68db442b436294926bbfafb" name = "github.com/mattn/go-isatty" packages = ["."] + pruneopts = "UT" revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" version = "v0.0.3" [[projects]] branch = "master" + digest = "1:cdb899c199f907ac9fb50495ec71212c95cb5b0e0a8ee0800da0238036091033" name = "github.com/mattn/go-runewidth" packages = ["."] + pruneopts = "UT" revision = "ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb" [[projects]] branch = "master" + digest = "1:d775613e6db40f54d34cc8b319ee5c2df56752f9f5e55e2f6004d11684bdc8fd" name = "github.com/mattn/go-tty" packages = ["."] + pruneopts = "UT" revision = "931426f7535ac39720c8909d70ece5a41a2502a6" [[projects]] + digest = "1:ff5ebae34cfbf047d505ee150de27e60570e8c394b3b8fdbb720ff6ac71985fc" name = "github.com/matttproud/golang_protobuf_extensions" packages = ["pbutil"] + pruneopts = "UT" revision = "c12348ce28de40eed0136aa2b644d0ee0650e56c" version = "v1.0.1" [[projects]] branch = "master" + digest = "1:2b32af4d2a529083275afc192d1067d8126b578c7a9613b26600e4df9c735155" name = "github.com/mgutz/ansi" packages = ["."] + pruneopts = "UT" revision = "9520e82c474b0a04dd04f8a40959027271bab992" [[projects]] + digest = "1:2e9ce249cbffeaf99b7b8d13b2191591bda8421f416e1366bdde8f7785f034cd" name = "github.com/mholt/caddy" packages = [ ".", "caddyfile", "onevent/hook", - "startupshutdown" + "startupshutdown", ] + pruneopts = "UT" revision = "d3f338ddab9ee24b376b5c9c51e202581e2d43ba" version = "v0.10.11" [[projects]] + digest = "1:463e4140189f8194f9121ca1c7fe3b8e9e9a2ab3d949b43c835c21034927dc62" name = "github.com/miekg/dns" packages = ["."] + pruneopts = "UT" revision = "5a2b9fab83ff0f8bfc99684bd5f43a37abe560f1" version = "v1.0.8" [[projects]] + digest = "1:33422d238f147d247752996a26574ac48dcf472976eda7f5134015f06bf16563" name = "github.com/modern-go/concurrent" packages = ["."] + pruneopts = "UT" revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" version = "1.0.3" [[projects]] + digest = "1:e32bdbdb7c377a07a9a46378290059822efdce5c8d96fe71940d87cb4f918855" name = "github.com/modern-go/reflect2" packages = ["."] + pruneopts = "UT" revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" version = "1.0.1" [[projects]] branch = "master" + digest = "1:7aefb397a53fc437c90f0fdb3e1419c751c5a3a165ced52325d5d797edf1aca6" name = "github.com/moul/http2curl" packages = ["."] + pruneopts = "UT" revision = "9ac6cf4d929b2fa8fd2d2e6dec5bb0feb4f4911d" [[projects]] branch = "master" + digest = "1:2da0e5077ed40453dc281b9a2428d84cf6ad14063aed189f6296ca5dd25cf13d" name = "github.com/opentracing-contrib/go-observer" packages = ["."] + pruneopts = "UT" revision = "a52f2342449246d5bcc273e65cbdcfa5f7d6c63c" [[projects]] + digest = "1:450b7623b185031f3a456801155c8320209f75d0d4c4e633c6b1e59d44d6e392" name = "github.com/opentracing/opentracing-go" packages = [ ".", "ext", - "log" + "log", ] + pruneopts = "UT" revision = "1949ddbfd147afd4d964a9f00b24eb291e0e7c38" version = "v1.0.2" [[projects]] + digest = "1:a427dd5035907bf7ad9a1fa269805f3a9ead9cfab056b32e2d86c230e28e31c0" name = "github.com/openzipkin/zipkin-go-opentracing" packages = [ ".", @@ -435,117 +556,149 @@ "thrift/gen-go/scribe", "thrift/gen-go/zipkincore", "types", - "wire" + "wire", ] + pruneopts = "UT" revision = "26cf9707480e6b90e5eff22cf0bbf05319154232" version = "v0.3.4" [[projects]] branch = "master" + digest = "1:3bf17a6e6eaa6ad24152148a631d18662f7212e21637c2699bff3369b7f00fa2" name = "github.com/petar/GoLLRB" packages = ["llrb"] + pruneopts = "UT" revision = "53be0d36a84c2a886ca057d34b6aa4468df9ccb4" [[projects]] + digest = "1:0e7775ebbcf00d8dd28ac663614af924411c868dca3d5aa762af0fae3808d852" name = "github.com/peterbourgon/diskv" packages = ["."] + pruneopts = "UT" revision = "5f041e8faa004a95c88a202771f4cc3e991971e6" version = "v2.0.1" [[projects]] + digest = "1:29803f52611cbcc1dfe55b456e9fdac362af7248b3d29d7ea1bec0a12e71dff4" name = "github.com/pierrec/lz4" packages = [ ".", - "internal/xxh32" + "internal/xxh32", ] + pruneopts = "UT" revision = "1958fd8fff7f115e79725b1288e0b878b3e06b00" version = "v2.0.3" [[projects]] branch = "master" + digest = "1:4f43b3c1b7e44980a5f3c593f8bf0e18844dc44f451a071c93e77e28cf990db6" name = "github.com/pkg/term" packages = ["termios"] + pruneopts = "UT" revision = "cda20d4ac917ad418d86e151eff439648b06185b" [[projects]] + digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" name = "github.com/pmezard/go-difflib" packages = ["difflib"] + pruneopts = "UT" revision = "792786c7400a136282c1664665ae0a8db921c6c2" version = "v1.0.0" [[projects]] + digest = "1:d14a5f4bfecf017cb780bdde1b6483e5deb87e12c332544d2c430eda58734bcb" name = "github.com/prometheus/client_golang" packages = [ "prometheus", - "prometheus/promhttp" + "prometheus/promhttp", ] + pruneopts = "UT" revision = "c5b7fccd204277076155f10851dad72b76a49317" version = "v0.8.0" [[projects]] branch = "master" + digest = "1:2d5cd61daa5565187e1d96bae64dbbc6080dacf741448e9629c64fd93203b0d4" name = "github.com/prometheus/client_model" packages = ["go"] + pruneopts = "UT" revision = "5c3871d89910bfb32f5fcab2aa4b9ec68e65a99f" [[projects]] branch = "master" + digest = "1:e469cd65badf7694aeb44874518606d93c1d59e7735d3754ad442782437d3cc3" name = "github.com/prometheus/common" packages = [ "expfmt", "internal/bitbucket.org/ww/goautoneg", - "model" + "model", ] + pruneopts = "UT" revision = "7600349dcfe1abd18d72d3a1770870d9800a7801" [[projects]] branch = "master" + digest = "1:8c49953a1414305f2ff5465147ee576dd705487c35b15918fcd4efdc0cb7a290" name = "github.com/prometheus/procfs" packages = [ ".", "internal/util", "nfs", - "xfs" + "xfs", ] + pruneopts = "UT" revision = "05ee40e3a273f7245e8777337fc7b46e533a9a92" [[projects]] branch = "master" + digest = "1:c4556a44e350b50a490544d9b06e9fba9c286c21d6c0e47f54f3a9214597298c" name = "github.com/rcrowley/go-metrics" packages = ["."] + pruneopts = "UT" revision = "e2704e165165ec55d062f5919b4b29494e9fa790" [[projects]] + digest = "1:274f67cb6fed9588ea2521ecdac05a6d62a8c51c074c1fccc6a49a40ba80e925" name = "github.com/satori/go.uuid" packages = ["."] + pruneopts = "UT" revision = "f58768cc1a7a7e77a3bd49e98cdd21419399b6a3" version = "v1.2.0" [[projects]] + digest = "1:d867dfa6751c8d7a435821ad3b736310c2ed68945d05b50fb9d23aee0540c8cc" name = "github.com/sirupsen/logrus" packages = ["."] + pruneopts = "UT" revision = "3e01752db0189b9157070a0e1668a620f9a85da2" version = "v1.0.6" [[projects]] + digest = "1:9424f440bba8f7508b69414634aef3b2b3a877e522d8a4624692412805407bb7" name = "github.com/spf13/pflag" packages = ["."] + pruneopts = "UT" revision = "583c0c0531f06d5278b7d917446061adc344b5cd" version = "v1.0.1" [[projects]] + digest = "1:18752d0b95816a1b777505a97f71c7467a8445b8ffb55631a7bf779f6ba4fa83" name = "github.com/stretchr/testify" packages = ["assert"] + pruneopts = "UT" revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686" version = "v1.2.2" [[projects]] + digest = "1:98e5cda86f67cd1ac95389d98670b66dea8cae480fe6292b83bccccfe60b4106" name = "github.com/ugorji/go" packages = ["codec"] + pruneopts = "UT" revision = "f3cacc17c85ecb7f1b6a9e373ee85d1480919868" [[projects]] branch = "master" + digest = "1:91771429c8de08d4d9b32663ad78bfa8ee1e0a146e921d9937c117665fd0377f" name = "github.com/vmware/govmomi" packages = [ ".", @@ -562,12 +715,14 @@ "vim25/progress", "vim25/soap", "vim25/types", - "vim25/xml" + "vim25/xml", ] + pruneopts = "UT" revision = "bbd99532a768d2fe369079ceda730e30726ae1a6" [[projects]] branch = "master" + digest = "1:014ee502e4880ffba2a0103cefa6af78cf8767ce08bc29376e6b86cdcaa2ec06" name = "golang.org/x/crypto" packages = [ "curve25519", @@ -577,12 +732,14 @@ "internal/subtle", "poly1305", "ssh", - "ssh/terminal" + "ssh/terminal", ] + pruneopts = "UT" revision = "c126467f60eb25f8f27e5a981f32a87e3965053f" [[projects]] branch = "master" + digest = "1:c945d925a3dae287abe075a89c6b09e1015da39d350eb512bb5d01ebcd7783e7" name = "golang.org/x/net" packages = [ "bpf", @@ -596,20 +753,24 @@ "internal/timeseries", "ipv4", "ipv6", - "trace" + "trace", ] + pruneopts = "UT" revision = "f4c29de78a2a91c00474a2e689954305c350adf9" [[projects]] branch = "master" + digest = "1:be95d758fc4d9216e5d41ff5b98b46938fba85ca5bc2ddc45a1b03e2bb10fe7c" name = "golang.org/x/sys" packages = [ "unix", - "windows" + "windows", ] + pruneopts = "UT" revision = "e072cadbbdc8dd3d3ffa82b8b4b9304c261d9311" [[projects]] + digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" name = "golang.org/x/text" packages = [ "collate", @@ -625,30 +786,38 @@ "unicode/bidi", "unicode/cldr", "unicode/norm", - "unicode/rangetable" + "unicode/rangetable", ] + pruneopts = "UT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] branch = "master" + digest = "1:c9e7a4b4d47c0ed205d257648b0e5b0440880cb728506e318f8ac7cd36270bc4" name = "golang.org/x/time" packages = ["rate"] + pruneopts = "UT" revision = "fbb02b2291d28baffd63558aa44b4b56f178d650" [[projects]] + digest = "1:c25289f43ac4a68d88b02245742347c94f1e108c534dda442188015ff80669b3" name = "google.golang.org/appengine" packages = ["cloudsql"] + pruneopts = "UT" revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" version = "v1.1.0" [[projects]] branch = "master" + digest = "1:077c1c599507b3b3e9156d17d36e1e61928ee9b53a5b420f10f28ebd4a0b275c" name = "google.golang.org/genproto" packages = ["googleapis/rpc/status"] + pruneopts = "UT" revision = "daca94659cb50e9f37c1b834680f2e46358f10b0" [[projects]] + digest = "1:3dd7996ce6bf52dec6a2f69fa43e7c4cefea1d4dfa3c8ab7a5f8a9f7434e239d" name = "google.golang.org/grpc" packages = [ ".", @@ -676,36 +845,46 @@ "resolver/passthrough", "stats", "status", - "tap" + "tap", ] + pruneopts = "UT" revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455" version = "v1.14.0" [[projects]] + digest = "1:2655728699af00d823b0a68bd7169fd241a30c04252f456b34421908701b9c3f" name = "gopkg.in/gin-gonic/gin.v1" packages = ["."] + pruneopts = "UT" revision = "d459835d2b077e44f7c9b453505ee29881d5d12d" version = "v1.2" [[projects]] + digest = "1:cbc72c4c4886a918d6ab4b95e347ffe259846260f99ebdd8a198c2331cf2b2e9" name = "gopkg.in/go-playground/validator.v8" packages = ["."] + pruneopts = "UT" revision = "5f1438d3fca68893a817e4a66806cea46a9e4ebf" version = "v8.18.2" [[projects]] + digest = "1:2d1fbdc6777e5408cabeb02bf336305e724b925ff4546ded0fa8715a7267922a" name = "gopkg.in/inf.v0" packages = ["."] + pruneopts = "UT" revision = "d2d2541c53f18d2a059457998ce2876cc8e67cbf" version = "v0.9.1" [[projects]] + digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" name = "gopkg.in/yaml.v2" packages = ["."] + pruneopts = "UT" revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" version = "v2.2.1" [[projects]] + digest = "1:74142cd2275f77547c35ac51514108d9798a09aa0cf377a5c1084718ef7aa225" name = "k8s.io/api" packages = [ "admissionregistration/v1alpha1", @@ -736,11 +915,13 @@ "settings/v1alpha1", "storage/v1", "storage/v1alpha1", - "storage/v1beta1" + "storage/v1beta1", ] + pruneopts = "UT" revision = "072894a440bdee3a891dea811fe42902311cd2a3" [[projects]] + digest = "1:29d5abc33d8cbec19b4cd032a87d28010dd615578dd695a655fc3d5ec3ab86b6" name = "k8s.io/apimachinery" packages = [ "pkg/api/errors", @@ -777,11 +958,13 @@ "pkg/util/yaml", "pkg/version", "pkg/watch", - "third_party/forked/golang/reflect" + "third_party/forked/golang/reflect", ] + pruneopts = "UT" revision = "103fd098999dc9c0c88536f5c9ad2e5da39373ae" [[projects]] + digest = "1:ac46cc5d5c55dd93d4844327334d2253d563d76f14d4b38a8b522b97f0f52214" name = "k8s.io/client-go" packages = [ "discovery", @@ -835,28 +1018,34 @@ "util/connrotation", "util/flowcontrol", "util/homedir", - "util/integer" + "util/integer", ] + pruneopts = "UT" revision = "7d04d0e2a0a1a4d4a1cd6baa432a2301492e4e65" version = "v8.0.0" [[projects]] branch = "master" + digest = "1:5ede93047a3e04f6ede8fbc011f13ee94c397b727613fd9712cc99ebc47ff906" name = "yunion.io/x/jsonutils" packages = ["."] + pruneopts = "UT" revision = "41e805b221e8fcd9435b706b4dd473df3dd8cff4" [[projects]] branch = "master" + digest = "1:b707a5d591b21dad9ebdb264281632ed43d34e2b980dce967acb2c7adcc93ad3" name = "yunion.io/x/log" packages = [ ".", - "hooks" + "hooks", ] + pruneopts = "UT" revision = "a10b94c5038480920262e0f344656328434955a2" [[projects]] branch = "master" + digest = "1:13da776b435ec7873c6f9309191296d920a110145372d2a9e1a58ab9e8b34b0d" name = "yunion.io/x/pkg" packages = [ "gotypes", @@ -888,25 +1077,119 @@ "util/version", "util/wait", "util/workqueue", - "utils" + "utils", ] + pruneopts = "UT" revision = "56b426f0ca15288cc26442f5802c949f137ade60" [[projects]] branch = "master" + digest = "1:3d3e1ecb41c63448df5d66eeafa5f6da720ca6e32543e89faa82b5bc4b9adebc" name = "yunion.io/x/sqlchemy" packages = ["."] + pruneopts = "UT" revision = "a74ef73e555a1ed2e19b1a47e0567814c289eaf9" [[projects]] branch = "master" + digest = "1:6baf7b4ee14e156a9dd6c5c850bb8201af47665e3267e3cdee26edf2a90eaf73" name = "yunion.io/x/structarg" packages = ["."] + pruneopts = "UT" revision = "d5e5d87357b9bc2164215117763f6b15b2a3e75d" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "8b3cd1b8309273551ebd55dfb0cadeaaad0aecc1b3a94d680a4a1769d2f42512" + input-imports = [ + "github.com/aliyun/alibaba-cloud-sdk-go/sdk", + "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests", + "github.com/aliyun/aliyun-oss-go-sdk/oss", + "github.com/aokoli/goutils", + "github.com/bitly/go-simplejson", + "github.com/c-bata/go-prompt", + "github.com/coredns/coredns/core/dnsserver", + "github.com/coredns/coredns/coremain", + "github.com/coredns/coredns/plugin", + "github.com/coredns/coredns/plugin/cache", + "github.com/coredns/coredns/plugin/chaos", + "github.com/coredns/coredns/plugin/debug", + "github.com/coredns/coredns/plugin/errors", + "github.com/coredns/coredns/plugin/etcd/msg", + "github.com/coredns/coredns/plugin/file", + "github.com/coredns/coredns/plugin/forward", + "github.com/coredns/coredns/plugin/health", + "github.com/coredns/coredns/plugin/hosts", + "github.com/coredns/coredns/plugin/log", + "github.com/coredns/coredns/plugin/metrics", + "github.com/coredns/coredns/plugin/nsid", + "github.com/coredns/coredns/plugin/pkg/dnsutil", + "github.com/coredns/coredns/plugin/pkg/fall", + "github.com/coredns/coredns/plugin/pkg/upstream", + "github.com/coredns/coredns/plugin/proxy", + "github.com/coredns/coredns/plugin/reload", + "github.com/coredns/coredns/plugin/trace", + "github.com/coredns/coredns/request", + "github.com/fatih/color", + "github.com/go-sql-driver/mysql", + "github.com/golang-plus/uuid", + "github.com/gosuri/uitable", + "github.com/jinzhu/gorm", + "github.com/jinzhu/gorm/dialects/mysql", + "github.com/json-iterator/go", + "github.com/mholt/caddy", + "github.com/mholt/caddy/startupshutdown", + "github.com/miekg/dns", + "github.com/moul/http2curl", + "github.com/stretchr/testify/assert", + "github.com/vmware/govmomi", + "github.com/vmware/govmomi/object", + "github.com/vmware/govmomi/property", + "github.com/vmware/govmomi/session", + "github.com/vmware/govmomi/view", + "github.com/vmware/govmomi/vim25/mo", + "github.com/vmware/govmomi/vim25/types", + "golang.org/x/crypto/ssh", + "gopkg.in/gin-gonic/gin.v1", + "k8s.io/api/core/v1", + "k8s.io/apimachinery/pkg/apis/meta/v1", + "k8s.io/apimachinery/pkg/fields", + "k8s.io/apimachinery/pkg/labels", + "k8s.io/client-go/kubernetes", + "k8s.io/client-go/rest", + "k8s.io/client-go/tools/clientcmd", + "yunion.io/x/jsonutils", + "yunion.io/x/log", + "yunion.io/x/pkg/gotypes", + "yunion.io/x/pkg/prettytable", + "yunion.io/x/pkg/trace", + "yunion.io/x/pkg/tristate", + "yunion.io/x/pkg/util/cache", + "yunion.io/x/pkg/util/compare", + "yunion.io/x/pkg/util/errors", + "yunion.io/x/pkg/util/fifoutils", + "yunion.io/x/pkg/util/fileutils", + "yunion.io/x/pkg/util/filterclause", + "yunion.io/x/pkg/util/goroutine_pool", + "yunion.io/x/pkg/util/netutils", + "yunion.io/x/pkg/util/osprofile", + "yunion.io/x/pkg/util/prometheus", + "yunion.io/x/pkg/util/reflectutils", + "yunion.io/x/pkg/util/regutils", + "yunion.io/x/pkg/util/seclib", + "yunion.io/x/pkg/util/secrules", + "yunion.io/x/pkg/util/sets", + "yunion.io/x/pkg/util/stringutils", + "yunion.io/x/pkg/util/sysutils", + "yunion.io/x/pkg/util/timeutils", + "yunion.io/x/pkg/util/trace", + "yunion.io/x/pkg/util/ttlpool", + "yunion.io/x/pkg/util/version", + "yunion.io/x/pkg/util/wait", + "yunion.io/x/pkg/util/workqueue", + "yunion.io/x/pkg/utils", + "yunion.io/x/sqlchemy", + "yunion.io/x/structarg", + ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/push/push_notice_to_android.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/push/push_notice_to_android.go deleted file mode 100644 index ef385f3a9f..0000000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/push/push_notice_to_android.go +++ /dev/null @@ -1,110 +0,0 @@ -package push - -//Licensed under the Apache License, Version 2.0 (the "License"); -//you may not use this file except in compliance with the License. -//You may obtain a copy of the License at -// -//http://www.apache.org/licenses/LICENSE-2.0 -// -//Unless required by applicable law or agreed to in writing, software -//distributed under the License is distributed on an "AS IS" BASIS, -//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -//See the License for the specific language governing permissions and -//limitations under the License. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// PushNoticeToAndroid invokes the push.PushNoticeToAndroid API synchronously -// api document: https://help.aliyun.com/api/push/pushnoticetoandroid.html -func (client *Client) PushNoticeToAndroid(request *PushNoticeToAndroidRequest) (response *PushNoticeToAndroidResponse, err error) { - response = CreatePushNoticeToAndroidResponse() - err = client.DoAction(request, response) - return -} - -// PushNoticeToAndroidWithChan invokes the push.PushNoticeToAndroid API asynchronously -// api document: https://help.aliyun.com/api/push/pushnoticetoandroid.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) PushNoticeToAndroidWithChan(request *PushNoticeToAndroidRequest) (<-chan *PushNoticeToAndroidResponse, <-chan error) { - responseChan := make(chan *PushNoticeToAndroidResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.PushNoticeToAndroid(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// PushNoticeToAndroidWithCallback invokes the push.PushNoticeToAndroid API asynchronously -// api document: https://help.aliyun.com/api/push/pushnoticetoandroid.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) PushNoticeToAndroidWithCallback(request *PushNoticeToAndroidRequest, callback func(response *PushNoticeToAndroidResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *PushNoticeToAndroidResponse - var err error - defer close(result) - response, err = client.PushNoticeToAndroid(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// PushNoticeToAndroidRequest is the request struct for api PushNoticeToAndroid -type PushNoticeToAndroidRequest struct { - *requests.RpcRequest - AppKey requests.Integer `position:"Query" name:"AppKey"` - Target string `position:"Query" name:"Target"` - TargetValue string `position:"Query" name:"TargetValue"` - Title string `position:"Query" name:"Title"` - Body string `position:"Query" name:"Body"` - JobKey string `position:"Query" name:"JobKey"` - ExtParameters string `position:"Query" name:"ExtParameters"` -} - -// PushNoticeToAndroidResponse is the response struct for api PushNoticeToAndroid -type PushNoticeToAndroidResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` - MessageId string `json:"MessageId" xml:"MessageId"` -} - -// CreatePushNoticeToAndroidRequest creates a request to invoke PushNoticeToAndroid API -func CreatePushNoticeToAndroidRequest() (request *PushNoticeToAndroidRequest) { - request = &PushNoticeToAndroidRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Push", "2016-08-01", "PushNoticeToAndroid", "", "") - return -} - -// CreatePushNoticeToAndroidResponse creates a response to parse from PushNoticeToAndroid response -func CreatePushNoticeToAndroidResponse() (response *PushNoticeToAndroidResponse) { - response = &PushNoticeToAndroidResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/push/push_notice_toi_os.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/push/push_notice_toi_os.go deleted file mode 100644 index 73d1a588e6..0000000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/push/push_notice_toi_os.go +++ /dev/null @@ -1,111 +0,0 @@ -package push - -//Licensed under the Apache License, Version 2.0 (the "License"); -//you may not use this file except in compliance with the License. -//You may obtain a copy of the License at -// -//http://www.apache.org/licenses/LICENSE-2.0 -// -//Unless required by applicable law or agreed to in writing, software -//distributed under the License is distributed on an "AS IS" BASIS, -//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -//See the License for the specific language governing permissions and -//limitations under the License. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// PushNoticeToiOS invokes the push.PushNoticeToiOS API synchronously -// api document: https://help.aliyun.com/api/push/pushnoticetoios.html -func (client *Client) PushNoticeToiOS(request *PushNoticeToiOSRequest) (response *PushNoticeToiOSResponse, err error) { - response = CreatePushNoticeToiOSResponse() - err = client.DoAction(request, response) - return -} - -// PushNoticeToiOSWithChan invokes the push.PushNoticeToiOS API asynchronously -// api document: https://help.aliyun.com/api/push/pushnoticetoios.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) PushNoticeToiOSWithChan(request *PushNoticeToiOSRequest) (<-chan *PushNoticeToiOSResponse, <-chan error) { - responseChan := make(chan *PushNoticeToiOSResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.PushNoticeToiOS(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// PushNoticeToiOSWithCallback invokes the push.PushNoticeToiOS API asynchronously -// api document: https://help.aliyun.com/api/push/pushnoticetoios.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) PushNoticeToiOSWithCallback(request *PushNoticeToiOSRequest, callback func(response *PushNoticeToiOSResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *PushNoticeToiOSResponse - var err error - defer close(result) - response, err = client.PushNoticeToiOS(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// PushNoticeToiOSRequest is the request struct for api PushNoticeToiOS -type PushNoticeToiOSRequest struct { - *requests.RpcRequest - AppKey requests.Integer `position:"Query" name:"AppKey"` - Target string `position:"Query" name:"Target"` - TargetValue string `position:"Query" name:"TargetValue"` - ApnsEnv string `position:"Query" name:"ApnsEnv"` - Title string `position:"Query" name:"Title"` - Body string `position:"Query" name:"Body"` - JobKey string `position:"Query" name:"JobKey"` - ExtParameters string `position:"Query" name:"ExtParameters"` -} - -// PushNoticeToiOSResponse is the response struct for api PushNoticeToiOS -type PushNoticeToiOSResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` - MessageId string `json:"MessageId" xml:"MessageId"` -} - -// CreatePushNoticeToiOSRequest creates a request to invoke PushNoticeToiOS API -func CreatePushNoticeToiOSRequest() (request *PushNoticeToiOSRequest) { - request = &PushNoticeToiOSRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Push", "2016-08-01", "PushNoticeToiOS", "", "") - return -} - -// CreatePushNoticeToiOSResponse creates a response to parse from PushNoticeToiOS response -func CreatePushNoticeToiOSResponse() (response *PushNoticeToiOSResponse) { - response = &PushNoticeToiOSResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/gosuri/uitable/.travis.yml b/vendor/github.com/gosuri/uitable/.travis.yml new file mode 100644 index 0000000000..2139b89ef0 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/.travis.yml @@ -0,0 +1,8 @@ +language: go +sudo: false +install: + - go get ./... +go: + - 1.4 + - 1.5.2 + - tip diff --git a/vendor/github.com/gosuri/uitable/LICENSE b/vendor/github.com/gosuri/uitable/LICENSE new file mode 100644 index 0000000000..e436d90439 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/LICENSE @@ -0,0 +1,10 @@ +MIT License +=========== + +Copyright (c) 2015, Greg Osuri + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/gosuri/uitable/Makefile b/vendor/github.com/gosuri/uitable/Makefile new file mode 100644 index 0000000000..60246a8a93 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/Makefile @@ -0,0 +1,4 @@ +test: + @go test ./... + +.PHONY: test diff --git a/vendor/github.com/gosuri/uitable/README.md b/vendor/github.com/gosuri/uitable/README.md new file mode 100644 index 0000000000..683b538d13 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/README.md @@ -0,0 +1,67 @@ +# uitable [![GoDoc](https://godoc.org/github.com/gosuri/uitable?status.svg)](https://godoc.org/github.com/gosuri/uitable) [![Build Status](https://travis-ci.org/gosuri/uitable.svg?branch=master)](https://travis-ci.org/gosuri/uitable) + +uitable is a go library for representing data as tables for terminal applications. It provides primitives for sizing and wrapping columns to improve readability. + +## Example Usage + +Full source code for the example is available at [example/main.go](example/main.go) + +```go +table := uitable.New() +table.MaxColWidth = 50 + +table.AddRow("NAME", "BIRTHDAY", "BIO") +for _, hacker := range hackers { + table.AddRow(hacker.Name, hacker.Birthday, hacker.Bio) +} +fmt.Println(table) +``` + +Will render the data as: + +```sh +NAME BIRTHDAY BIO +Ada Lovelace December 10, 1815 Ada was a British mathematician and writer, chi... +Alan Turing June 23, 1912 Alan was a British pioneering computer scientis... +``` + +For wrapping in two columns: + +```go +table = uitable.New() +table.MaxColWidth = 80 +table.Wrap = true // wrap columns + +for _, hacker := range hackers { + table.AddRow("Name:", hacker.Name) + table.AddRow("Birthday:", hacker.Birthday) + table.AddRow("Bio:", hacker.Bio) + table.AddRow("") // blank +} +fmt.Println(table) +``` + +Will render the data as: + +``` +Name: Ada Lovelace +Birthday: December 10, 1815 +Bio: Ada was a British mathematician and writer, chiefly known for her work on + Charles Babbage's early mechanical general-purpose computer, the Analytical + Engine + +Name: Alan Turing +Birthday: June 23, 1912 +Bio: Alan was a British pioneering computer scientist, mathematician, logician, + cryptanalyst and theoretical biologist +``` + +## Installation + +``` +$ go get -v github.com/gosuri/uitable +``` + + +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/gosuri/uitable/trend.png)](https://bitdeli.com/free "Bitdeli Badge") + diff --git a/vendor/github.com/gosuri/uitable/table.go b/vendor/github.com/gosuri/uitable/table.go new file mode 100644 index 0000000000..b792c88367 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/table.go @@ -0,0 +1,203 @@ +// Package uitable provides a decorator for formating data as a table +package uitable + +import ( + "fmt" + "strings" + "sync" + + "github.com/gosuri/uitable/util/strutil" + "github.com/gosuri/uitable/util/wordwrap" + "github.com/mattn/go-runewidth" +) + +// Separator is the default column seperator +var Separator = "\t" + +// Table represents a decorator that renders the data in formatted in a table +type Table struct { + // Rows is the collection of rows in the table + Rows []*Row + + // MaxColWidth is the maximum allowed width for cells in the table + MaxColWidth uint + + // Wrap when set to true wraps the contents of the columns when the length exceeds the MaxColWidth + Wrap bool + + // Separator is the seperator for columns in the table. Default is "\t" + Separator string + + mtx *sync.RWMutex + rightAlign map[int]bool +} + +// New returns a new Table with default values +func New() *Table { + return &Table{ + Separator: Separator, + mtx: new(sync.RWMutex), + rightAlign: map[int]bool{}, + } +} + +// AddRow adds a new row to the table +func (t *Table) AddRow(data ...interface{}) *Table { + t.mtx.Lock() + defer t.mtx.Unlock() + r := NewRow(data...) + t.Rows = append(t.Rows, r) + return t +} + +// Bytes returns the []byte value of table +func (t *Table) Bytes() []byte { + return []byte(t.String()) +} + +func (t *Table) RightAlign(col int) { + t.mtx.Lock() + t.rightAlign[col] = true + t.mtx.Unlock() +} + +// String returns the string value of table +func (t *Table) String() string { + t.mtx.RLock() + defer t.mtx.RUnlock() + + if len(t.Rows) == 0 { + return "" + } + + // determine the width for each column (cell in a row) + var colwidths []uint + for _, row := range t.Rows { + for i, cell := range row.Cells { + // resize colwidth array + if i+1 > len(colwidths) { + colwidths = append(colwidths, 0) + } + cellwidth := cell.LineWidth() + if t.MaxColWidth != 0 && cellwidth > t.MaxColWidth { + cellwidth = t.MaxColWidth + } + + if cellwidth > colwidths[i] { + colwidths[i] = cellwidth + } + } + } + + var lines []string + for _, row := range t.Rows { + row.Separator = t.Separator + for i, cell := range row.Cells { + cell.Width = colwidths[i] + cell.Wrap = t.Wrap + cell.RightAlign = t.rightAlign[i] + } + lines = append(lines, row.String()) + } + return strutil.Join(lines, "\n") +} + +// Row represents a row in a table +type Row struct { + // Cells is the group of cell for the row + Cells []*Cell + + // Separator for tabular columns + Separator string +} + +// NewRow returns a new Row and adds the data to the row +func NewRow(data ...interface{}) *Row { + r := &Row{Cells: make([]*Cell, len(data))} + for i, d := range data { + r.Cells[i] = &Cell{Data: d} + } + return r +} + +// String returns the string representation of the row +func (r *Row) String() string { + // get the max number of lines for each cell + var lc int // line count + for _, cell := range r.Cells { + if clc := len(strings.Split(cell.String(), "\n")); clc > lc { + lc = clc + } + } + + // allocate a two-dimentional array of cells for each line and add size them + cells := make([][]*Cell, lc) + for x := 0; x < lc; x++ { + cells[x] = make([]*Cell, len(r.Cells)) + for y := 0; y < len(r.Cells); y++ { + cells[x][y] = &Cell{Width: r.Cells[y].Width} + } + } + + // insert each line in a cell as new cell in the cells array + for y, cell := range r.Cells { + lines := strings.Split(cell.String(), "\n") + for x, line := range lines { + cells[x][y].Data = line + } + } + + // format each line + lines := make([]string, lc) + for x := range lines { + line := make([]string, len(cells[x])) + for y := range cells[x] { + line[y] = cells[x][y].String() + } + lines[x] = strutil.Join(line, r.Separator) + } + return strutil.Join(lines, "\n") +} + +// Cell represents a column in a row +type Cell struct { + // Width is the width of the cell + Width uint + + // Wrap when true wraps the contents of the cell when the lenght exceeds the width + Wrap bool + + // RightAlign when true aligns contents to the right + RightAlign bool + + // Data is the cell data + Data interface{} +} + +// LineWidth returns the max width of all the lines in a cell +func (c *Cell) LineWidth() uint { + width := 0 + for _, s := range strings.Split(c.String(), "\n") { + w := runewidth.StringWidth(s) + if w > width { + width = w + } + } + return uint(width) +} + +// String returns the string formated representation of the cell +func (c *Cell) String() string { + if c.Data == nil { + return strutil.PadLeft(" ", int(c.Width), ' ') + } + s := fmt.Sprintf("%v", c.Data) + if c.Width > 0 { + if c.Wrap && uint(len(s)) > c.Width { + return wordwrap.WrapString(s, c.Width) + } else { + return strutil.Resize(s, c.Width, c.RightAlign) + } + } + return s +} diff --git a/vendor/github.com/gosuri/uitable/util/strutil/strutil.go b/vendor/github.com/gosuri/uitable/util/strutil/strutil.go new file mode 100644 index 0000000000..cb35bce272 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/util/strutil/strutil.go @@ -0,0 +1,76 @@ +// Package strutil provides various utilities for manipulating strings +package strutil + +import ( + "bytes" + "github.com/mattn/go-runewidth" +) + +// PadRight returns a new string of a specified length in which the end of the current string is padded with spaces or with a specified Unicode character. +func PadRight(str string, length int, pad byte) string { + slen := runewidth.StringWidth(str) + if slen >= length { + return str + } + buf := bytes.NewBufferString(str) + for i := 0; i < length-slen; i++ { + buf.WriteByte(pad) + } + return buf.String() +} + +// PadLeft returns a new string of a specified length in which the beginning of the current string is padded with spaces or with a specified Unicode character. +func PadLeft(str string, length int, pad byte) string { + slen := runewidth.StringWidth(str) + if slen >= length { + return str + } + var buf bytes.Buffer + for i := 0; i < length-slen; i++ { + buf.WriteByte(pad) + } + buf.WriteString(str) + return buf.String() +} + +// Resize resizes the string with the given length. It ellipses with '...' when the string's length exceeds +// the desired length or pads spaces to the right of the string when length is smaller than desired +func Resize(s string, length uint, rightAlign bool) string { + slen := runewidth.StringWidth(s) + n := int(length) + if slen == n { + return s + } + // Pads only when length of the string smaller than len needed + if rightAlign { + s = PadLeft(s, n, ' ') + } else { + s = PadRight(s, n, ' ') + } + if slen > n { + rs := []rune(s) + var buf bytes.Buffer + w := 0 + for _, r := range rs { + buf.WriteRune(r) + rw := runewidth.RuneWidth(r) + if w+rw >= n-3 { + break + } + w += rw + } + buf.WriteString("...") + s = buf.String() + } + return s +} + +// Join joins the list of the string with the delim provided +func Join(list []string, delim string) string { + var buf bytes.Buffer + for i := 0; i < len(list)-1; i++ { + buf.WriteString(list[i] + delim) + } + buf.WriteString(list[len(list)-1]) + return buf.String() +} diff --git a/vendor/github.com/gosuri/uitable/util/wordwrap/LICENSE.md b/vendor/github.com/gosuri/uitable/util/wordwrap/LICENSE.md new file mode 100644 index 0000000000..2298515904 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/util/wordwrap/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Mitchell Hashimoto + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/github.com/gosuri/uitable/util/wordwrap/README.md b/vendor/github.com/gosuri/uitable/util/wordwrap/README.md new file mode 100644 index 0000000000..60ae311700 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/util/wordwrap/README.md @@ -0,0 +1,39 @@ +# go-wordwrap + +`go-wordwrap` (Golang package: `wordwrap`) is a package for Go that +automatically wraps words into multiple lines. The primary use case for this +is in formatting CLI output, but of course word wrapping is a generally useful +thing to do. + +## Installation and Usage + +Install using `go get github.com/mitchellh/go-wordwrap`. + +Full documentation is available at +http://godoc.org/github.com/mitchellh/go-wordwrap + +Below is an example of its usage ignoring errors: + +```go +wrapped := wordwrap.WrapString("foo bar baz", 3) +fmt.Println(wrapped) +``` + +Would output: + +``` +foo +bar +baz +``` + +## Word Wrap Algorithm + +This library doesn't use any clever algorithm for word wrapping. The wrapping +is actually very naive: whenever there is whitespace or an explicit linebreak. +The goal of this library is for word wrapping CLI output, so the input is +typically pretty well controlled human language. Because of this, the naive +approach typically works just fine. + +In the future, we'd like to make the algorithm more advanced. We would do +so without breaking the API. diff --git a/vendor/github.com/gosuri/uitable/util/wordwrap/wordwrap.go b/vendor/github.com/gosuri/uitable/util/wordwrap/wordwrap.go new file mode 100644 index 0000000000..e64dbc8016 --- /dev/null +++ b/vendor/github.com/gosuri/uitable/util/wordwrap/wordwrap.go @@ -0,0 +1,84 @@ +// Package wordwrap provides methods for wrapping the contents of a string +package wordwrap + +import ( + "bytes" + "github.com/mattn/go-runewidth" + "unicode" +) + +// WrapString wraps the given string within lim width in characters. +// +// Wrapping is currently naive and only happens at white-space. A future +// version of the library will implement smarter wrapping. This means that +// pathological cases can dramatically reach past the limit, such as a very +// long word. +func WrapString(s string, lim uint) string { + // Initialize a buffer with a slightly larger size to account for breaks + init := make([]byte, 0, len(s)) + buf := bytes.NewBuffer(init) + + var current uint + var wordBuf, spaceBuf bytes.Buffer + var wordWidth, spaceWidth int + + for _, char := range s { + if char == '\n' { + if wordBuf.Len() == 0 { + if current+uint(spaceWidth) > lim { + current = 0 + } else { + current += uint(spaceWidth) + spaceBuf.WriteTo(buf) + spaceWidth += runewidth.StringWidth(buf.String()) + } + spaceBuf.Reset() + spaceWidth = 0 + } else { + current += uint(spaceWidth + wordWidth) + spaceBuf.WriteTo(buf) + spaceBuf.Reset() + wordBuf.WriteTo(buf) + wordBuf.Reset() + spaceWidth = 0 + wordWidth = 0 + } + buf.WriteRune(char) + current = 0 + } else if unicode.IsSpace(char) { + if spaceBuf.Len() == 0 || wordBuf.Len() > 0 { + current += uint(spaceWidth + wordWidth) + spaceBuf.WriteTo(buf) + spaceBuf.Reset() + wordBuf.WriteTo(buf) + wordBuf.Reset() + spaceWidth = 0 + wordWidth = 0 + } + + spaceBuf.WriteRune(char) + spaceWidth += runewidth.RuneWidth(char) + } else { + wordBuf.WriteRune(char) + wordWidth += runewidth.RuneWidth(char) + + if current+uint(spaceWidth+wordWidth) > lim && uint(wordWidth) < lim { + buf.WriteRune('\n') + current = 0 + spaceBuf.Reset() + spaceWidth = 0 + } + } + } + + if wordBuf.Len() == 0 { + if current+uint(spaceWidth) <= lim { + spaceBuf.WriteTo(buf) + } + } else { + spaceBuf.WriteTo(buf) + wordBuf.WriteTo(buf) + } + + return buf.String() +} diff --git a/vendor/github.com/vmware/govmomi/simulator/license_manager.go b/vendor/github.com/vmware/govmomi/simulator/license_manager.go deleted file mode 100644 index 13565d32ef..0000000000 --- a/vendor/github.com/vmware/govmomi/simulator/license_manager.go +++ /dev/null @@ -1,156 +0,0 @@ -/* -Copyright (c) 2017 VMware, Inc. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Copyright 2017 VMware, Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package simulator - -import ( - "github.com/vmware/govmomi/object" - "github.com/vmware/govmomi/vim25/methods" - "github.com/vmware/govmomi/vim25/mo" - "github.com/vmware/govmomi/vim25/soap" - "github.com/vmware/govmomi/vim25/types" -) - -// EvalLicense is the default license -var EvalLicense = types.LicenseManagerLicenseInfo{ - LicenseKey: "00000-00000-00000-00000-00000", - EditionKey: "eval", - Name: "Evaluation Mode", - Properties: []types.KeyAnyValue{ - { - Key: "feature", - Value: types.KeyValue{ - Key: "serialuri:2", - Value: "Remote virtual Serial Port Concentrator", - }, - }, - { - Key: "feature", - Value: types.KeyValue{ - Key: "dvs", - Value: "vSphere Distributed Switch", - }, - }, - }, -} - -type LicenseManager struct { - mo.LicenseManager -} - -func NewLicenseManager(ref types.ManagedObjectReference) object.Reference { - m := &LicenseManager{} - m.Self = ref - m.Licenses = []types.LicenseManagerLicenseInfo{EvalLicense} - - if Map.IsVPX() { - am := Map.Put(&LicenseAssignmentManager{}).Reference() - m.LicenseAssignmentManager = &am - } - - return m -} - -func (m *LicenseManager) AddLicense(req *types.AddLicense) soap.HasFault { - body := &methods.AddLicenseBody{ - Res: &types.AddLicenseResponse{}, - } - - for _, license := range m.Licenses { - if license.LicenseKey == req.LicenseKey { - body.Res.Returnval = licenseInfo(license.LicenseKey, license.Labels) - return body - } - } - - m.Licenses = append(m.Licenses, types.LicenseManagerLicenseInfo{ - LicenseKey: req.LicenseKey, - Labels: req.Labels, - }) - - body.Res.Returnval = licenseInfo(req.LicenseKey, req.Labels) - - return body -} - -func (m *LicenseManager) RemoveLicense(req *types.RemoveLicense) soap.HasFault { - body := &methods.RemoveLicenseBody{ - Res: &types.RemoveLicenseResponse{}, - } - - for i, license := range m.Licenses { - if req.LicenseKey == license.LicenseKey { - m.Licenses = append(m.Licenses[:i], m.Licenses[i+1:]...) - return body - } - } - return body -} - -type LicenseAssignmentManager struct { - mo.LicenseAssignmentManager -} - -func (m *LicenseAssignmentManager) QueryAssignedLicenses(req *types.QueryAssignedLicenses) soap.HasFault { - body := &methods.QueryAssignedLicensesBody{ - Res: &types.QueryAssignedLicensesResponse{}, - } - - // EntityId can be a HostSystem or the vCenter InstanceUuid - if req.EntityId != "" { - if req.EntityId != Map.content().About.InstanceUuid { - id := types.ManagedObjectReference{ - Type: "HostSystem", - Value: req.EntityId, - } - - if Map.Get(id) == nil { - return body - } - } - } - - body.Res.Returnval = []types.LicenseAssignmentManagerLicenseAssignment{ - { - EntityId: req.EntityId, - AssignedLicense: EvalLicense, - }, - } - - return body -} - -func licenseInfo(key string, labels []types.KeyValue) types.LicenseManagerLicenseInfo { - info := EvalLicense - - info.LicenseKey = key - info.Labels = labels - - return info -}