Merge branch 'release/2.1.0' of ssh://git.yunion.io/~qiujian/onecloud into feature/qj-elastic-ip

This commit is contained in:
Qiu Jian
2018-09-04 23:46:43 +08:00
122 changed files with 3993 additions and 893 deletions
+5 -38
View File
@@ -5,51 +5,18 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
/**
* 列出报警事件
*/
type AlarmEventListOptions struct {
BaseListOptions
NodeLabels string `help:"Service tree node labels"`
MetricName string `help:"Metric name"`
HostName string `help:"Host name"`
HostIp string `help:"Host IP address"`
AlarmLevel string `help:"Alarm level"`
AlarmCondition string `help:"Concrete alarm rule"`
Template string `help:"Template number of the alarm condition"`
AckStatus string `help:"Alarm event ack status"`
}
R(&AlarmEventListOptions{}, "alarmevent-list", "List all alarm's event", func(s *mcclient.ClientSession, args *AlarmEventListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
if len(args.NodeLabels) > 0 {
params.Add(jsonutils.NewString(args.NodeLabels), "node_labels")
R(&options.AlarmEventListOptions{}, "alarmevent-list", "List all alarm's event", func(s *mcclient.ClientSession, opts *options.AlarmEventListOptions) error {
params, err := options.ListStructToParams(opts)
if err != nil {
return err
}
if len(args.MetricName) > 0 {
params.Add(jsonutils.NewString(args.MetricName), "metric_name")
}
if len(args.HostName) > 0 {
params.Add(jsonutils.NewString(args.HostName), "host_name")
}
if len(args.HostIp) > 0 {
params.Add(jsonutils.NewString(args.HostIp), "host_ip")
}
if len(args.AlarmLevel) > 0 {
params.Add(jsonutils.NewString(args.AlarmLevel), "alarm_level")
}
if len(args.AlarmCondition) > 0 {
params.Add(jsonutils.NewString(args.AlarmCondition), "alarm_condition")
}
if len(args.Template) > 0 {
params.Add(jsonutils.NewString(args.Template), "template")
}
if len(args.AckStatus) > 0 {
params.Add(jsonutils.NewString(args.AckStatus), "ack_status")
}
result, err := modules.AlarmEvents.List(s, params)
if err != nil {
return err
+6 -2
View File
@@ -7,6 +7,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -15,7 +16,7 @@ func init() {
* 列出报警日志
*/
type AlarmLogListOptions struct {
BaseListOptions
options.BaseListOptions
Host string `help:"Name of the host"`
Id int64 `help:"ID of tree node"`
Label []string `help:"Labels to this tree node"`
@@ -26,7 +27,10 @@ func init() {
ThisTimeUntil string `help:"This time until the alarm event"`
}
R(&AlarmLogListOptions{}, "alarmlog-list", "List all alarm's event", func(s *mcclient.ClientSession, args *AlarmLogListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
params, err := args.BaseListOptions.Params()
if err != nil {
return err
}
if len(args.Host) > 0 {
params.Add(jsonutils.NewString(args.Host), "host")
}
+11 -2
View File
@@ -5,6 +5,7 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -116,10 +117,18 @@ func init() {
* 列出报警规则
*/
type AlarmListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&AlarmListOptions{}, "alarm-list", "List all alarms", func(s *mcclient.ClientSession, args *AlarmListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Alarms.List(s, params)
if err != nil {
return err
+11 -2
View File
@@ -7,6 +7,7 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -78,12 +79,20 @@ func init() {
* 列出报警模板
*/
type AlarmTemplateListOptions struct {
BaseListOptions
options.BaseListOptions
LIST_TYPE string `help:"Type of list: avaliable|applied|created "`
LABELS string `help:"Labels for node(split by comma)"`
}
R(&AlarmTemplateListOptions{}, "alarmtemplate-list", "List all alarm templates ", func(s *mcclient.ClientSession, args *AlarmTemplateListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
params.Add(jsonutils.NewString(args.LIST_TYPE), "type")
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
+11 -3
View File
@@ -2,19 +2,27 @@ package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type HostNetworkListOptions struct {
BaseListOptions
options.BaseListOptions
Host string `help:"ID or Name of Host"`
Network string `help:"ID or name of network"`
}
R(&HostNetworkListOptions{}, "host-network-list", "List baremetal network pairs", func(s *mcclient.ClientSession, args *HostNetworkListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Network) > 0 {
params.Add(jsonutils.NewString(args.Network), "network_id")
}
+12 -2
View File
@@ -1,17 +1,27 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type BaremetalStorageListOptions struct {
BaseListOptions
options.BaseListOptions
Host string `help:"ID or Name of Host"`
}
R(&BaremetalStorageListOptions{}, "baremetal-storage-list", "List baremetal storage pairs", func(s *mcclient.ClientSession, args *BaremetalStorageListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
var result *modules.ListResult
var err error
if len(args.Host) > 0 {
+12 -2
View File
@@ -1,16 +1,26 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type CachedImageListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&CachedImageListOptions{}, "cached-image-list", "List cached images", func(s *mcclient.ClientSession, args *CachedImageListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Cachedimages.List(s, params)
if err != nil {
return err
+11 -2
View File
@@ -5,15 +5,24 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type CloudproviderListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&CloudproviderListOptions{}, "cloud-provider-list", "List cloud providers", func(s *mcclient.ClientSession, args *CloudproviderListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Cloudproviders.List(s, params)
if err != nil {
return err
+11 -2
View File
@@ -5,18 +5,27 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type CloudregionListOptions struct {
BaseListOptions
options.BaseListOptions
Private bool `help:"show private cloud regions only"`
Public bool `help:"show public cloud regions only"`
Manager string `help:"Show regions belongs to the cloud provider"`
Usable bool `help:"List regions that are usable"`
}
R(&CloudregionListOptions{}, "cloud-region-list", "List cloud regions", func(s *mcclient.ClientSession, args *CloudregionListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if args.Usable {
params.Add(jsonutils.JSONTrue, "usable")
}
+12 -2
View File
@@ -1,8 +1,10 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -11,10 +13,18 @@ func init() {
* 获得一个全部通信地址组
*/
type ContactGroupsListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&ContactGroupsListOptions{}, "contact-group-list", "List all contact groups for all the domainsconta", func(s *mcclient.ClientSession, args *ContactGroupsListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.ContactGroups.List(s, params)
if err != nil {
+21 -4
View File
@@ -5,6 +5,7 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -70,10 +71,18 @@ func init() {
* 获得所有用户的所有通信地址列表
*/
type ContactsListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&ContactsListOptions{}, "contact-list", "List all contacts for all users", func(s *mcclient.ClientSession, args *ContactsListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Contacts.List(s, params)
if err != nil {
@@ -88,11 +97,19 @@ func init() {
* 获得一个用户全部通信地址
*/
type ContactsListForUserOptions struct {
BaseListOptions
options.BaseListOptions
UID string `help:"The user you wanna find contact from (Keystone User ID)"`
}
R(&ContactsListForUserOptions{}, "contact-show", "List all contacts for the users", func(s *mcclient.ClientSession, args *ContactsListForUserOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Contacts.Get(s, args.UID, params)
if err != nil {
+11 -2
View File
@@ -5,11 +5,12 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type DiskListOptions struct {
BaseListOptions
options.BaseListOptions
Unused bool `help:"Show unused disks"`
Share bool `help:"Show Share storage disks"`
Local bool `help:"Show Local storage disks"`
@@ -18,7 +19,15 @@ func init() {
Provider string `help:"Provider for disk" choices:"Aliyun|VMware"`
}
R(&DiskListOptions{}, "disk-list", "List virtual disks", func(s *mcclient.ClientSession, suboptions *DiskListOptions) error {
params := FetchPagingParams(suboptions.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = suboptions.BaseListOptions.Params()
if err != nil {
return err
}
}
if suboptions.Unused {
params.Add(jsonutils.JSONTrue, "unused")
}
+11 -2
View File
@@ -7,6 +7,7 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type DNSRecordOptions struct {
@@ -38,10 +39,18 @@ func parseDNSRecords(args *DNSRecordOptions, params *jsonutils.JSONDict) {
func init() {
type DNSListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&DNSListOptions{}, "dns-list", "List dns records", func(s *mcclient.ClientSession, suboptions *DNSListOptions) error {
params := FetchPagingParams(suboptions.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = suboptions.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.DNSRecords.List(s, params)
if err != nil {
return err
+10 -2
View File
@@ -5,6 +5,7 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -12,10 +13,17 @@ func init() {
Manager string `help:"Show servers imported from manager"`
Region string `help:"Show servers in cloudregion"`
BaseListOptions
options.BaseListOptions
}
R(&ElasticipListOptions{}, "eip-list", "List elastic IPs", func(s *mcclient.ClientSession, args *ElasticipListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Manager) > 0 {
params.Add(jsonutils.NewString(args.Manager), "manager")
}
+11 -2
View File
@@ -4,16 +4,25 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type HostCachedImageListOptions struct {
BaseListOptions
options.BaseListOptions
Host string `help:"ID or Name of Host"`
Image string `help:"ID or Name of image"`
}
R(&HostCachedImageListOptions{}, "host-cachedimage-list", "List host cached image pairs", func(s *mcclient.ClientSession, args *HostCachedImageListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
var result *modules.ListResult
var err error
if len(args.Host) > 0 {
+45 -2
View File
@@ -6,6 +6,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -26,10 +27,18 @@ func init() {
Manager string `help:"Show regions belongs to the cloud provider"`
BaseListOptions
options.BaseListOptions
}
R(&HostListOptions{}, "host-list", "List hosts", func(s *mcclient.ClientSession, args *HostListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Schedtag) > 0 {
params.Add(jsonutils.NewString(args.Schedtag), "schedtag")
}
@@ -465,4 +474,38 @@ func init() {
return nil
})
type HostCreateOptions struct {
ZONE string `help:"Zone where the host is located"`
NAME string `help:"Name of baremetal"`
MAC string `help:"Default MAC address of baremetal"`
Rack string `help:"Rack number of baremetal"`
Slots string `help:"Slots number of baremetal"`
IpmiPasswd string `help:"IPMI user password"`
IpmiAddr string `help:"IPMI IP address"`
}
R(&HostCreateOptions{}, "host-create", "Create a baremetal host", func(s *mcclient.ClientSession, args *HostCreateOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.NAME), "name")
params.Add(jsonutils.NewString(args.MAC), "access_mac")
params.Add(jsonutils.NewString("baremetal"), "host_type")
if len(args.Rack) > 0 {
params.Add(jsonutils.NewString(args.Rack), "rack")
}
if len(args.Slots) > 0 {
params.Add(jsonutils.NewString(args.Slots), "slots")
}
if len(args.IpmiPasswd) > 0 {
params.Add(jsonutils.NewString(args.IpmiPasswd), "ipmi_password")
}
if len(args.IpmiAddr) > 0 {
params.Add(jsonutils.NewString(args.IpmiAddr), "ipmi_ip_addr")
}
result, err := modules.Hosts.CreateInContext(s, params, &modules.Zones, args.ZONE)
if err != nil {
return err
}
printObject(result)
return nil
})
}
+11 -2
View File
@@ -4,16 +4,25 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type HostStorageListOptions struct {
BaseListOptions
options.BaseListOptions
Host string `help:"ID or Name of Host"`
Storage string `help:"ID or Name of Storage"`
}
R(&HostStorageListOptions{}, "host-storage-list", "List host storage pairs", func(s *mcclient.ClientSession, args *HostStorageListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
var result *modules.ListResult
var err error
if len(args.Storage) > 0 {
+11 -2
View File
@@ -4,16 +4,25 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type HostWireListOptions struct {
BaseListOptions
options.BaseListOptions
Host string `help:"ID or Name of Host"`
Wire string `help:"ID or Name of Wire"`
}
R(&HostWireListOptions{}, "host-wire-list", "List host wire", func(s *mcclient.ClientSession, args *HostWireListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
var result *modules.ListResult
var err error
if len(args.Host) > 0 {
+12 -2
View File
@@ -1,16 +1,26 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type InstanceListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&InstanceListOptions{}, "instance-list", "List instances", func(s *mcclient.ClientSession, suboptions *InstanceListOptions) error {
params := FetchPagingParams(suboptions.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = suboptions.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Instances.List(s, params)
if err != nil {
return err
+11 -2
View File
@@ -4,17 +4,26 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type DeviceListOptions struct {
BaseListOptions
options.BaseListOptions
Unused bool `help:"Only show unused devices"`
Gpu bool `help:"Only show gpu devices"`
Host string `help:"Host ID or Name"`
}
R(&DeviceListOptions{}, "isolated-device-list", "List isolated devices like GPU", func(s *mcclient.ClientSession, args *DeviceListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Host) > 0 {
params.Add(jsonutils.NewString(args.Host), "host")
}
+13 -5
View File
@@ -6,10 +6,10 @@ import (
"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"
"yunion.io/x/onecloud/pkg/mcclient/options"
"yunion.io/x/pkg/util/sets"
)
func initCluster() {
@@ -17,11 +17,19 @@ func initCluster() {
return resourceCmdN("cluster", suffix)
}
type listOpt struct {
BaseListOptions
options.BaseListOptions
}
R(&listOpt{}, cmdN("list"), "List k8s clusters", func(s *mcclient.ClientSession, args *listOpt) error {
args.Details = true
params := FetchPagingParams(args.BaseListOptions)
args.Details = options.Bool(true)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := k8s.Clusters.List(s, params)
if err != nil {
return err
+2 -1
View File
@@ -17,7 +17,8 @@ func initConfigMap() {
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())
params.Update(args.ClusterParams())
ret, err := k8s.ConfigMaps.List(s, params)
if err != nil {
return err
}
+6 -5
View File
@@ -25,7 +25,8 @@ func initDeployment() {
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())
params.Update(args.ClusterParams())
ret, err := k8s.Deployments.List(s, params)
if err != nil {
return err
}
@@ -45,7 +46,7 @@ func initDeployment() {
Net string `help:"Network config, e.g. net1, net1:10.168.222.171"`
}
R(&createOpt{}, cmdN("create"), "Create deployment resource", func(s *mcclient.ClientSession, args *createOpt) error {
params := jsonutils.NewDict()
params := args.ClusterParams()
if len(args.Image) == 0 {
return fmt.Errorf("Image must provided")
}
@@ -74,7 +75,7 @@ func initDeployment() {
}
params.Add(net, "networkConfig")
}
ret, err := k8s.Deployments.CreateInContexts(s, params, args.ClusterContext())
ret, err := k8s.Deployments.Create(s, params)
if err != nil {
return err
}
@@ -87,11 +88,11 @@ func initDeployment() {
}
R(&getOpt{}, cmdN("show"), "Get deployment details", func(s *mcclient.ClientSession, args *getOpt) error {
id := args.NAME
params := jsonutils.NewDict()
params := args.ClusterParams()
if args.Namespace != "" {
params.Add(jsonutils.NewString(args.Namespace), "namespace")
}
ret, err := k8s.Deployments.GetInContexts(s, id, params, args.ClusterContext())
ret, err := k8s.Deployments.Get(s, id, params)
if err != nil {
return err
}
+5 -10
View File
@@ -4,7 +4,6 @@ import (
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/cmd/climc/shell"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/modules/k8s"
@@ -30,14 +29,14 @@ func init() {
initService()
}
type BaseListOptions shell.BaseListOptions
type clusterBaseOptions struct {
Cluster string `default:"$K8S_CLUSTER|default" help:"Kubernetes cluster name"`
}
func (o clusterBaseOptions) ClusterContext() []modules.ManagerContext {
return []modules.ManagerContext{clusterContext(o.Cluster)}
func (o clusterBaseOptions) ClusterParams() *jsonutils.JSONDict {
ret := jsonutils.NewDict()
ret.Add(jsonutils.NewString(o.Cluster), "cluster")
return ret
}
type baseListOptions struct {
@@ -73,7 +72,7 @@ type resourceGetOptions struct {
}
func (o resourceGetOptions) ToJSON() *jsonutils.JSONDict {
params := jsonutils.NewDict()
params := o.ClusterParams()
if o.Namespace != "" {
params.Add(jsonutils.NewString(o.Namespace), "namespace")
}
@@ -99,10 +98,6 @@ var (
printBatchResults = printutils.PrintJSONBatchResults
)
func FetchPagingParams(o BaseListOptions) *jsonutils.JSONDict {
return shell.FetchPagingParams(shell.BaseListOptions(o))
}
func resourceCmdN(prefix, suffix string) string {
return fmt.Sprintf("k8s-%s-%s", prefix, suffix)
}
+11 -5
View File
@@ -7,6 +7,7 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules/k8s"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func initNode() {
@@ -14,14 +15,19 @@ func initNode() {
return resourceCmdN("node", suffix)
}
type listOpt struct {
BaseListOptions
options.BaseListOptions
Cluster string `help:"Filter by cluster"`
}
R(&listOpt{}, cmdN("list"), "List k8s node", func(s *mcclient.ClientSession, args *listOpt) error {
args.Details = true
params := FetchPagingParams(args.BaseListOptions)
if args.Cluster != "" {
params.Add(jsonutils.NewString(args.Cluster), "cluster")
args.Details = options.Bool(true)
var params *jsonutils.JSONDict
{
var err error
params, err = options.ListStructToParams(args)
if err != nil {
return err
}
}
result, err := k8s.Nodes.List(s, params)
if err != nil {
+3 -2
View File
@@ -19,7 +19,8 @@ func initPod() {
R(&listOpt{}, cmdN("list"), "List k8s pod", func(s *mcclient.ClientSession, args *listOpt) error {
params := fetchNamespaceParams(args.namespaceListOptions)
params.Update(fetchPagingParams(args.baseListOptions))
ret, err := k8s.Pods.ListInContexts(s, params, args.ClusterContext())
params.Update(args.ClusterParams())
ret, err := k8s.Pods.List(s, params)
if err != nil {
return err
}
@@ -32,7 +33,7 @@ func initPod() {
}
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())
ret, err := k8s.Pods.Delete(s, id, args.ToJSON())
if err != nil {
return err
}
+2 -2
View File
@@ -17,7 +17,7 @@ type rawDeleteOpt struct {
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())
obj, err := k8s.RawResource.Get(s, args.KIND, args.Namespace, args.NAME, args.ClusterParams())
if err != nil {
return err
}
@@ -26,7 +26,7 @@ func initRaw() {
})
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())
err := k8s.RawResource.Delete(s, args.KIND, args.Namespace, args.NAME, args.ClusterParams())
if err != nil {
return err
}
+8 -5
View File
@@ -29,6 +29,7 @@ func initRelease() {
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))
params.Update(args.ClusterParams())
if args.Filter != "" {
params.Add(json.NewString(args.Filter), "filter")
}
@@ -57,7 +58,7 @@ func initRelease() {
if args.Pending {
params.Add(json.JSONTrue, "pending")
}
ret, err := k8s.Releases.ListInContexts(s, params, args.ClusterContext())
ret, err := k8s.Releases.List(s, params)
if err != nil {
return err
}
@@ -70,7 +71,7 @@ func initRelease() {
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())
ret, err := k8s.Releases.Get(s, args.NAME, args.ClusterParams())
if err != nil {
return err
}
@@ -121,6 +122,7 @@ func initRelease() {
if err != nil {
return err
}
params.Update(args.ClusterParams())
params.Add(json.NewString(args.CHARTNAME), "chart_name")
if args.Namespace != "" {
params.Add(json.NewString(args.Namespace), "namespace")
@@ -128,7 +130,7 @@ func initRelease() {
if args.Name != "" {
params.Add(json.NewString(args.Name), "release_name")
}
ret, err := k8s.Releases.CreateInContexts(s, params, args.ClusterContext())
ret, err := k8s.Releases.Create(s, params)
if err != nil {
return err
}
@@ -149,6 +151,7 @@ func initRelease() {
if err != nil {
return err
}
params.Update(args.ClusterParams())
params.Add(json.NewString(args.CHARTNAME), "chart_name")
params.Add(json.NewString(args.NAME), "release_name")
if args.ReuseValues {
@@ -158,7 +161,7 @@ func initRelease() {
params.Add(json.JSONTrue, "reset_values")
}
res, err := k8s.Releases.PutInContexts(s, args.NAME, params, args.ClusterContext())
res, err := k8s.Releases.Put(s, args.NAME, params)
if err != nil {
return err
}
@@ -171,7 +174,7 @@ func initRelease() {
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())
_, err := k8s.Releases.Delete(s, args.NAME, args.ClusterParams())
return err
})
}
+11 -2
View File
@@ -5,6 +5,7 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules/k8s"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func initRepo() {
@@ -12,10 +13,18 @@ func initRepo() {
return resourceCmdN("repo", suffix)
}
type listOpt struct {
BaseListOptions
options.BaseListOptions
}
R(&listOpt{}, cmdN("list"), "List k8s global helm repos", func(s *mcclient.ClientSession, args *listOpt) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := k8s.Repos.List(s, params)
if err != nil {
return err
+2 -1
View File
@@ -17,7 +17,8 @@ func initService() {
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())
params.Update(args.ClusterParams())
ret, err := k8s.Services.List(s, params)
if err != nil {
return err
}
+2 -2
View File
@@ -28,7 +28,7 @@ func initTiller() {
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()
params := args.ClusterParams()
if len(args.KubeContext) > 0 {
params.Add(json.NewString(args.KubeContext), "kube_context")
}
@@ -46,7 +46,7 @@ func initTiller() {
if args.MaxHistory > 0 {
params.Add(json.NewInt(int64(args.MaxHistory)), "history_max")
}
ret, err := k8s.Tiller.CreateInContexts(s, params, args.ClusterContext())
ret, err := k8s.Tiller.Create(s, params)
if err != nil {
return err
}
+11 -2
View File
@@ -7,15 +7,24 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type KeypairList struct {
BaseListOptions
options.BaseListOptions
}
R(&KeypairList{}, "keypair-list", "List keypairs.", func(s *mcclient.ClientSession, args *KeypairList) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Keypairs.List(s, params)
if err != nil {
+11 -2
View File
@@ -4,6 +4,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -81,10 +82,18 @@ func init() {
* 列出所有的标签
*/
type LabelListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&LabelListOptions{}, "label-list", "List labels", func(s *mcclient.ClientSession, args *LabelListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Labels.List(s, params)
if err != nil {
return err
+32 -6
View File
@@ -1,8 +1,10 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -26,10 +28,18 @@ func init() {
* 列出所有监控指标
*/
type MetricsListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&MetricsListOptions{}, "metric-list", "List all metrics", func(s *mcclient.ClientSession, args *MetricsListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Metrics.List(s, params)
if err != nil {
@@ -44,11 +54,19 @@ func init() {
* 查看监控指标详情
*/
type MetricsShowOptions struct {
BaseListOptions
options.BaseListOptions
ID string `help:"The ID of the metric"`
}
R(&MetricsShowOptions{}, "metric-show", "Show metric details", func(s *mcclient.ClientSession, args *MetricsShowOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Metrics.Get(s, args.ID, params)
if err != nil {
@@ -63,11 +81,19 @@ func init() {
* 根据name查看监控指标详情
*/
type MetricsShowByNameOptions struct {
BaseListOptions
options.BaseListOptions
NAME string `help:"The NAME of the metric"`
}
R(&MetricsShowByNameOptions{}, "metric-details", "Show metric details by name", func(s *mcclient.ClientSession, args *MetricsShowByNameOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Metrics.GetSpecific(s, "", args.NAME, params)
if err != nil {
+12 -2
View File
@@ -1,8 +1,10 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -11,10 +13,18 @@ func init() {
* 列出全部的监控类型
*/
type MonitorTypesOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&MonitorTypesOptions{}, "monitortype-list", "List all monitor types", func(s *mcclient.ClientSession, args *MonitorTypesOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.MonitorTypes.List(s, params)
if err != nil {
+22 -4
View File
@@ -1,8 +1,10 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -11,10 +13,18 @@ func init() {
* 列出所有监控数据源
*/
type MonitorInputsListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&MonitorInputsListOptions{}, "monitorinputs-list", "List all monitor-inputs", func(s *mcclient.ClientSession, args *MonitorInputsListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.MonitorInputs.List(s, params)
if err != nil {
@@ -29,11 +39,19 @@ func init() {
* 查看监控数据源下的监控项
*/
type MonitorInputsShowOptions struct {
BaseListOptions
options.BaseListOptions
ID string `help:"The ID of the monitor-input"`
}
R(&MonitorInputsShowOptions{}, "monitorinputs-metrics-list", "List all metrics for the monitor-inputs", func(s *mcclient.ClientSession, args *MonitorInputsShowOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.MonitorInputs.GetSpecific(s, args.ID, "metrics", params)
if err != nil {
+21 -4
View File
@@ -6,6 +6,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -47,10 +48,18 @@ func init() {
* 列出监控模板
*/
type MonitorTemplateListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&MonitorTemplateListOptions{}, "monitortemplate-list", "List all monitor-template", func(s *mcclient.ClientSession, args *MonitorTemplateListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.MonitorTemplates.List(s, params)
if err != nil {
@@ -65,11 +74,19 @@ func init() {
* 查看监控模板详情
*/
type MonitorTemplateShowOptions struct {
BaseListOptions
options.BaseListOptions
ID string `help:"The ID of the monitor-template"`
}
R(&MonitorTemplateShowOptions{}, "monitortemplate-show", "Show monitor-template", func(s *mcclient.ClientSession, args *MonitorTemplateShowOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.MonitorTemplates.Get(s, args.ID, params)
if err != nil {
+118 -2
View File
@@ -6,18 +6,27 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type NetworkListOptions struct {
BaseListOptions
options.BaseListOptions
Ip string `help:"search networks that contain this IP"`
Zone string `help:"search networks in a zone"`
Wire string `help:"search networks belongs to a wire"`
Vpc string `help:"search networks belongs to a VPC"`
}
R(&NetworkListOptions{}, "network-list", "List networks", func(s *mcclient.ClientSession, args *NetworkListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Ip) > 0 {
params.Add(jsonutils.NewString(args.Ip), "ip")
}
@@ -133,6 +142,15 @@ func init() {
return nil
})
R(&NetworkShowOptions{}, "network-metadata", "Show metadata of a network", func(s *mcclient.ClientSession, args *NetworkShowOptions) error {
result, err := modules.Networks.GetMetadata(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
R(&NetworkShowOptions{}, "network-private", "Make a network private", func(s *mcclient.ClientSession, args *NetworkShowOptions) error {
result, err := modules.Networks.PerformAction(s, args.ID, "private", nil)
if err != nil {
@@ -279,4 +297,102 @@ func init() {
return nil
})
type NetworkStaticRoutesOptions struct {
NETWORK string `help:"ID or name of the network"`
Net []string `help:"destination network of static route"`
Gw []string `help:"gateway address for the static route"`
}
R(&NetworkStaticRoutesOptions{}, "network-set-static-routes", "Set static routes for a network", func(s *mcclient.ClientSession, args *NetworkStaticRoutesOptions) error {
params := jsonutils.NewDict()
if len(args.Net) > 0 && len(args.Gw) > 0 {
if len(args.Net) != len(args.Gw) {
return fmt.Errorf("Inconsistent network and gateway pairs")
}
routes := jsonutils.NewDict()
for i := 0; i < len(args.Net); i += 1 {
routes.Add(jsonutils.NewString(args.Gw[i]), args.Net[i])
}
params.Add(routes, "static_routes")
} else {
params.Add(jsonutils.JSONNull, "static_routes")
}
result, err := modules.Networks.PerformAction(s, args.NETWORK, "metadata", params)
if err != nil {
return err
}
printObject(result)
return nil
})
type NetworkAddDnsUpdateTargetOptions struct {
ID string `help:"Network ID or name"`
DNS string `help:"DNS server address" metavar:"DNS_SERVER"`
KEY string `help:"DNS update key name" metavar:"DNS_UPDATE_KEY"`
SECRET string `help:"DNS update key secret" metavar:"DNS_UPDATE_SECRET"`
}
R(&NetworkAddDnsUpdateTargetOptions{}, "network-add-dns-update-target", "Add a dns update target to a network", func(s *mcclient.ClientSession, args *NetworkAddDnsUpdateTargetOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.DNS), "server")
params.Add(jsonutils.NewString(args.KEY), "key")
params.Add(jsonutils.NewString(args.SECRET), "secret")
result, err := modules.Networks.PerformAction(s, args.ID, "add-dns-update-target", params)
if err != nil {
return err
}
printObject(result)
return nil
})
type NetworkRemoveDnsUpdateTargetOptions struct {
ID string `help:"Network ID or name"`
DNS string `help:"DNS server address" metavar:"DNS_SERVER"`
KEY string `help:"DNS update key name" metavar:"DNS_UPDATE_KEY"`
}
R(&NetworkRemoveDnsUpdateTargetOptions{}, "network-remove-dns-update-target", "Remove a dns update target from a network", func(s *mcclient.ClientSession, args *NetworkRemoveDnsUpdateTargetOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.DNS), "server")
params.Add(jsonutils.NewString(args.KEY), "key")
result, err := modules.Networks.PerformAction(s, args.ID, "remove-dns-update-target", params)
if err != nil {
return err
}
printObject(result)
return nil
})
type NetworkSetDnsUpdateKeyOptions struct {
ID string `help:"ID of virtual network to update"`
KEY string `help:"Key name of secret" metavar:"KEYNAME"`
SECRET string `help:"Key secret"`
SERVER string `help:"Alternate DNS update server"`
}
R(&NetworkSetDnsUpdateKeyOptions{}, "network-set-dns-update-key", "Set DNS update key info for a virtual network", func(s *mcclient.ClientSession, args *NetworkSetDnsUpdateKeyOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.KEY), "dns_update_key_name")
params.Add(jsonutils.NewString(args.SECRET), "dns_update_key_secret")
params.Add(jsonutils.NewString(args.SERVER), "dns_update_server")
result, err := modules.Networks.PerformAction(s, args.ID, "metadata", params)
if err != nil {
return err
}
printObject(result)
return nil
})
type NetworkRemoveDnsUpdateKeyOptions struct {
ID string `help:"ID of virtual network"`
}
R(&NetworkRemoveDnsUpdateKeyOptions{}, "network-remove-dns-update-key", "Set DNS update key info for a virtual network", func(s *mcclient.ClientSession, args *NetworkRemoveDnsUpdateKeyOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.JSONNull, "dns_update_key_name")
params.Add(jsonutils.JSONNull, "dns_update_key_secret")
params.Add(jsonutils.JSONNull, "dns_update_server")
result, err := modules.Networks.PerformAction(s, args.ID, "metadata", params)
if err != nil {
return err
}
printObject(result)
return nil
})
}
+11 -2
View File
@@ -6,6 +6,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -14,11 +15,19 @@ func init() {
* 查看所有的监控节点 | 列出匹配标签的节点列表
*/
type NodeListOptions struct {
BaseListOptions
options.BaseListOptions
Labels []string `help:"Node labels"`
}
R(&NodeListOptions{}, "node-list", "List all nodes", func(s *mcclient.ClientSession, args *NodeListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Labels) > 0 {
for _, f := range args.Labels {
parts := strings.Split(f, "=")
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -71,7 +72,7 @@ func init() {
* 查询已发送的通知任务
*/
type NotificationListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&NotificationListOptions{}, "notify-list", "List notification history", func(s *mcclient.ClientSession, args *NotificationListOptions) error {
result, err := modules.Notifications.List(s, nil)
+11 -2
View File
@@ -4,14 +4,23 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type OperationListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&OperationListOptions{}, "operation-list", "List operations", func(s *mcclient.ClientSession, suboptions *OperationListOptions) error {
params := FetchPagingParams(suboptions.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = suboptions.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Operations.List(s, params)
if err != nil {
return err
+12 -2
View File
@@ -1,16 +1,26 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type TaskListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&TaskListOptions{}, "process-list", "List processes", func(s *mcclient.ClientSession, suboptions *TaskListOptions) error {
params := FetchPagingParams(suboptions.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = suboptions.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Processes.List(s, params)
if err != nil {
return err
+12 -2
View File
@@ -1,16 +1,26 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type TaskListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&TaskListOptions{}, "prosesslog-list", "List processlogs", func(s *mcclient.ClientSession, suboptions *TaskListOptions) error {
params := FetchPagingParams(suboptions.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = suboptions.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Processlogs.List(s, params)
if err != nil {
return err
+12 -2
View File
@@ -1,8 +1,10 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -11,10 +13,18 @@ func init() {
* 列出所有监控指标
*/
type ProjectAdminListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&ProjectAdminListOptions{}, "projectadmin-list", "List all Project Admins", func(s *mcclient.ClientSession, args *ProjectAdminListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.ProjectAdmin.List(s, params)
if err != nil {
+12 -2
View File
@@ -1,8 +1,10 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -11,10 +13,18 @@ func init() {
* 列出所有监控指标
*/
type ProjectAdminCandidateListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&ProjectAdminCandidateListOptions{}, "projectadmincandidate-list", "List all Project Admin Candidates", func(s *mcclient.ClientSession, args *ProjectAdminCandidateListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.ProjectAdminCandidate.List(s, params)
if err != nil {
+11 -2
View File
@@ -4,6 +4,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -11,14 +12,22 @@ func init() {
* 列出列表
*/
type RateListOptions struct {
BaseListOptions
options.BaseListOptions
RESTYPE string `"help":"res_type of the rate"`
ACTION string `"help":"action of list :querygroup or queryhistory"`
SubResType string `"help":"query the subResType"`
Id string `"help":"ID of rate"`
}
R(&RateListOptions{}, "rate-list", "List all rates ", func(s *mcclient.ClientSession, args *RateListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
params.Add(jsonutils.NewString(args.RESTYPE), "res_type")
params.Add(jsonutils.NewString(args.ACTION), "action")
+11 -2
View File
@@ -4,6 +4,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -74,12 +75,20 @@ func init() {
* 查询树节点的报警接收人信息
*/
type TreeNodeRecipientsListOptions struct {
BaseListOptions
options.BaseListOptions
LIST_TYPE string `help:"Type of list: junior|senior"`
LABELS string `help:"Labels for tree-node(split by comma)"`
}
R(&TreeNodeRecipientsListOptions{}, "treenode-recipient-list", "List recipient for the tree-node ", func(s *mcclient.ClientSession, args *TreeNodeRecipientsListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
params.Add(jsonutils.NewString(args.LIST_TYPE), "type")
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
+11 -2
View File
@@ -4,6 +4,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -40,11 +41,19 @@ func init() {
})
type ReservedIPListOptions struct {
BaseListOptions
options.BaseListOptions
Network string `help:"Network filter"`
}
R(&ReservedIPListOptions{}, "reserved-ip-list", "Show all reserved IPs for any network", func(s *mcclient.ClientSession, args *ReservedIPListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Network) > 0 {
params.Add(jsonutils.NewString(args.Network), "network")
}
+11 -2
View File
@@ -4,6 +4,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -11,12 +12,20 @@ func init() {
* 列出列表
*/
type ResourceDetailListOptions struct {
BaseListOptions
options.BaseListOptions
QUERYTYPE string `"help":"query type of the resource_detail"`
ProjectId string `"help":"project id of the resource_detail"`
}
R(&ResourceDetailListOptions{}, "resourcedetail-list", "List all resource details", func(s *mcclient.ClientSession, args *ResourceDetailListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.QUERYTYPE) > 0 {
params.Add(jsonutils.NewString(args.QUERYTYPE), "query_type")
}
+11 -2
View File
@@ -4,6 +4,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -11,7 +12,7 @@ func init() {
* 列出列表
*/
type ResourceFeeListOptions struct {
BaseListOptions
options.BaseListOptions
STATTYPE string `"help":"stat type of the resource_fee"`
STATMONTH string `"help":"stat month of the resource_fee"`
ProjectId string `"help":"project id of the resource_fee"`
@@ -19,7 +20,15 @@ func init() {
EndDay string `"help":"end day of the resource_fee"`
}
R(&ResourceFeeListOptions{}, "resourcefee-list", "List all resource fees", func(s *mcclient.ClientSession, args *ResourceFeeListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.STATTYPE) > 0 {
params.Add(jsonutils.NewString(args.STATTYPE), "stat_type")
}
+12 -2
View File
@@ -1,13 +1,15 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type SchedtagHostListOptions struct {
BaseListOptions
options.BaseListOptions
Schedtag string `help:"ID or Name of schedtag"`
}
R(&SchedtagHostListOptions{}, "schedtag-host-list", "List all scheduler tag and host pairs", func(s *mcclient.ClientSession, args *SchedtagHostListOptions) error {
@@ -15,7 +17,15 @@ func init() {
if err != nil {
return err
}
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
var result *modules.ListResult
if len(args.Schedtag) > 0 {
result, err = mod.ListDescendent(s, args.Schedtag, params)
+11 -2
View File
@@ -5,14 +5,23 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type SchedtagListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&SchedtagListOptions{}, "schedtag-list", "List schedule tags", func(s *mcclient.ClientSession, suboptions *SchedtagListOptions) error {
params := FetchPagingParams(suboptions.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = suboptions.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Schedtags.List(s, params)
if err != nil {
return err
+11 -2
View File
@@ -4,11 +4,12 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type SecGroupRulesListOptions struct {
BaseListOptions
options.BaseListOptions
Secgroup string `help:"Secgroup ID or Name"`
Direction string `help:"filter Direction of rule" choices:"in|out"`
Protocol string `help:"filter Protocol of rule" choices:"any|tcp|udp|icmp"`
@@ -16,7 +17,15 @@ func init() {
}
R(&SecGroupRulesListOptions{}, "secgroup-rule-list", "List all security group", func(s *mcclient.ClientSession, args *SecGroupRulesListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Secgroup) > 0 {
params.Add(jsonutils.NewString(args.Secgroup), "secgroup")
}
+11 -2
View File
@@ -6,15 +6,24 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type SecGroupsListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&SecGroupsListOptions{}, "secgroup-list", "List all security group", func(s *mcclient.ClientSession, args *SecGroupsListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.SecGroups.List(s, params)
if err != nil {
return err
+11 -2
View File
@@ -5,15 +5,24 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type ServerDiskListOptions struct {
BaseListOptions
options.BaseListOptions
Server string `help:"ID or Name of Server"`
}
R(&ServerDiskListOptions{}, "server-disk-list", "List server disk pairs", func(s *mcclient.ClientSession, args *ServerDiskListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
var result *modules.ListResult
var err error
if len(args.Server) > 0 {
+11 -2
View File
@@ -4,18 +4,27 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type ServerNetworkListOptions struct {
BaseListOptions
options.BaseListOptions
Server string `help:"ID or Name of Server"`
Mac string `help:"search the MAC address"`
Ip string `help:"search the IP address"`
Network string `help:"Network ID or name"`
}
R(&ServerNetworkListOptions{}, "server-network-list", "List server network pairs", func(s *mcclient.ClientSession, args *ServerNetworkListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Mac) > 0 {
params.Add(jsonutils.NewString(args.Mac), "mac_addr")
}
+124 -487
View File
@@ -2,110 +2,18 @@ package shell
import (
"fmt"
"io/ioutil"
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type ServerDeployInfo struct {
Action string
Path string
Content string
}
func parseDeployInfo(info string) (ServerDeployInfo, error) {
sdi := ServerDeployInfo{}
colonPos := strings.IndexByte(info, ':')
if colonPos <= 0 {
return sdi, fmt.Errorf("Malformed deploy string")
}
if info[0] == '+' {
sdi.Action = "append"
sdi.Path = info[1:colonPos]
} else {
sdi.Action = "create"
sdi.Path = info[:colonPos]
}
content := info[colonPos+1:]
bytes, e := ioutil.ReadFile(content)
if e != nil {
sdi.Content = content
} else {
sdi.Content = string(bytes)
}
return sdi, nil
}
func parseDeployList(list []string, params *jsonutils.JSONDict) error {
for i, info := range list {
ret, e := parseDeployInfo(info)
if e != nil {
return e
}
params.Add(jsonutils.NewString(ret.Action), fmt.Sprintf("deploy.%d.action", i))
params.Add(jsonutils.NewString(ret.Path), fmt.Sprintf("deploy.%d.path", i))
params.Add(jsonutils.NewString(ret.Content), fmt.Sprintf("deploy.%d.content", i))
}
return nil
}
func init() {
type ServerListOptions struct {
Zone string `help:"Zone ID or Name"`
Wire string `help:"Wire ID or Name"`
Network string `help:"Network ID or Name"`
Disk string `help:"Disk ID or Name"`
Host string `help:"Host ID or Name"`
Baremetal bool `help:"Show baremetal servers"`
Gpu bool `help:"Show gpu servers"`
Secgroup string `help:"Secgroup ID or Name"`
AdminSecgroup string `help:"AdminSecgroup ID or Name"`
Hypervisor string `help:"Show server of hypervisor" choices:"kvm|esxi|container|baremetal|aliyun"`
Manager string `help:"Show servers imported from manager"`
Region string `help:"Show servers in cloudregion"`
BaseListOptions
}
R(&ServerListOptions{}, "server-list", "List virtual servers", func(s *mcclient.ClientSession, args *ServerListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
if len(args.Zone) > 0 {
params.Add(jsonutils.NewString(args.Zone), "zone")
}
if len(args.Disk) > 0 {
params.Add(jsonutils.NewString(args.Disk), "disk")
}
if len(args.Wire) > 0 {
params.Add(jsonutils.NewString(args.Wire), "wire")
}
if len(args.Network) > 0 {
params.Add(jsonutils.NewString(args.Network), "network")
}
if len(args.Host) > 0 {
params.Add(jsonutils.NewString(args.Host), "host")
}
if args.Baremetal {
params.Add(jsonutils.JSONTrue, "baremetal")
}
if args.Gpu {
params.Add(jsonutils.JSONTrue, "gpu")
}
if len(args.Secgroup) > 0 {
params.Add(jsonutils.NewString(args.Secgroup), "secgroup")
}
if len(args.AdminSecgroup) > 0 {
params.Add(jsonutils.NewString(args.AdminSecgroup), "admin_secgroup")
}
if len(args.Hypervisor) > 0 {
params.Add(jsonutils.NewString(args.Hypervisor), "hypervisor")
}
if len(args.Manager) > 0 {
params.Add(jsonutils.NewString(args.Manager), "manager")
}
if len(args.Region) > 0 {
params.Add(jsonutils.NewString(args.Region), "region")
R(&options.ServerListOptions{}, "server-list", "List virtual servers", func(s *mcclient.ClientSession, opts *options.ServerListOptions) error {
params, err := options.ListStructToParams(opts)
if err != nil {
return err
}
result, err := modules.Servers.List(s, params)
if err != nil {
@@ -115,16 +23,12 @@ func init() {
return nil
})
type ServerShowOptions struct {
ID string `help:"ID or name of the server"`
WithMeta bool `help:"With meta data"`
}
R(&ServerShowOptions{}, "server-show", "Show details of a server", func(s *mcclient.ClientSession, args *ServerShowOptions) error {
params := jsonutils.NewDict()
if args.WithMeta {
params.Add(jsonutils.JSONTrue, "with_meta")
R(&options.ServerShowOptions{}, "server-show", "Show details of a server", func(s *mcclient.ClientSession, opts *options.ServerShowOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
result, err := modules.Servers.Get(s, args.ID, params)
result, err := modules.Servers.Get(s, opts.ID, params)
if err != nil {
return err
}
@@ -132,8 +36,8 @@ func init() {
return nil
})
R(&ServerShowOptions{}, "server-metadata", "Show metadata of a server", func(s *mcclient.ClientSession, args *ServerShowOptions) error {
result, err := modules.Servers.GetMetadata(s, args.ID, nil)
R(&options.ServerIdOptions{}, "server-metadata", "Show metadata of a server", func(s *mcclient.ClientSession, opts *options.ServerIdOptions) error {
result, err := modules.Servers.GetMetadata(s, opts.ID, nil)
if err != nil {
return err
}
@@ -141,146 +45,25 @@ func init() {
return nil
})
type ServerCreateOptions struct {
NAME string `help:"Name of server"`
MEM string `help:"Memory size" metavar:"MEMORY"`
Disk []string `help:"Disk descriptions" nargs:"+"`
Net []string `help:"Network descriptions" metavar:"NETWORK"`
IsolatedDevice []string `help:"Isolated device model or ID" metavar:"ISOLATED_DEVICE"`
Keypair string `help:"SSH Keypair"`
Password string `help:"Default user password"`
Iso string `help:"ISO image ID" metavar:"IMAGE_ID"`
Ncpu int64 `help:"#CPU cores of VM server, default 1" default:"1" metavar:"<SERVER_CPU_COUNT>"`
Vga string `help:"VGA driver" choices:"std|vmware|cirrus|qxl"`
Vdi string `help:"VDI protocool" choices:"vnc|spice"`
Bios string `help:"BIOS" choices:"BIOS|UEFI"`
Desc string `help:"Description" metavar:"<DESCRIPTION>"`
Boot string `help:"Boot device" metavar:"<BOOT_DEVICE>" choices:"disk|cdrom"`
NoAccountInit bool `help:"Not reset account password"`
AllowDelete bool `help:"Unlock server to allow deleting"`
ShutdownBehavior string `help:"Behavior after VM server shutdown, stop or terminate server" metavar:"<SHUTDOWN_BEHAVIOR>" choices:"stop|terminate"`
AutoStart bool `help:"Auto start server after it is created"`
Zone string `help:"Preferred zone where virtual server should be created"`
Host string `help:"Preferred host where virtual server should be created"`
SchedTag []string `help:"Schedule policy, key = aggregate name, value = require|exclude|prefer|avoid" metavar:"<KEY:VALUE>"`
Deploy []string `help:"Specify deploy files in virtual server file system"`
Group []string `help:"Group of virtual server"`
Project string `help:"'Owner project ID or Name"`
User string `help:"Owner user ID or Name"`
System bool `help:"Create a system VM, sysadmin ONLY option"`
Hypervisor string `help:"Hypervisor type" choices:"kvm|esxi|baremetal|container|aliyun"`
TaskNotify bool `help:"Setup task notify"`
Count int `help:"Create multiple simultaneously" default:"1"`
DryRun bool `help:"Dry run to test scheduler"`
RaidConfig []string `help:"Baremetal raid config"`
}
R(&ServerCreateOptions{}, "server-create", "Create a server", func(s *mcclient.ClientSession, args *ServerCreateOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.NAME), "name")
params.Add(jsonutils.NewString(args.MEM), "vmem_size")
for i, d := range args.Disk {
params.Add(jsonutils.NewString(d), fmt.Sprintf("disk.%d", i))
R(&options.ServerCreateOptions{}, "server-create", "Create a server", func(s *mcclient.ClientSession, opts *options.ServerCreateOptions) error {
params, err := opts.Params()
if err != nil {
return err
}
for i, n := range args.Net {
params.Add(jsonutils.NewString(n), fmt.Sprintf("net.%d", i))
}
for i, g := range args.IsolatedDevice {
params.Add(jsonutils.NewString(g), fmt.Sprintf("isolated_device.%d", i))
}
for i, t := range args.SchedTag {
params.Add(jsonutils.NewString(t), fmt.Sprintf("schedtag.%d", i))
}
if args.Ncpu > 0 {
params.Add(jsonutils.NewInt(args.Ncpu), "vcpu_count")
}
if len(args.Iso) > 0 {
params.Add(jsonutils.NewString(args.Iso), "cdrom")
}
if len(args.Vga) > 0 {
params.Add(jsonutils.NewString(args.Vga), "vga")
}
if args.NoAccountInit {
params.Add(jsonutils.JSONFalse, "reset_password")
}
if args.Password != "" {
params.Add(jsonutils.NewString(args.Password), "password")
}
if len(args.Vdi) > 0 {
params.Add(jsonutils.NewString(args.Vdi), "vdi")
}
if len(args.Bios) > 0 {
params.Add(jsonutils.NewString(args.Bios), "bios")
}
if len(args.Deploy) > 0 {
err := parseDeployList(args.Deploy, params)
if err != nil {
return err
}
}
if len(args.Boot) > 0 {
if args.Boot == "disk" {
params.Add(jsonutils.NewString("cdn"), "boot_order")
} else {
params.Add(jsonutils.NewString("dcn"), "boot_order")
}
}
if len(args.Desc) > 0 {
params.Add(jsonutils.NewString(args.Desc), "description")
}
if args.AllowDelete {
params.Add(jsonutils.JSONFalse, "disable_delete")
}
if len(args.ShutdownBehavior) > 0 {
params.Add(jsonutils.NewString(args.ShutdownBehavior), "shutdown_behavior")
}
if args.AutoStart {
params.Add(jsonutils.JSONTrue, "auto_start")
}
if len(args.Group) > 0 {
for i, g := range args.Group {
params.Add(jsonutils.NewString(g), fmt.Sprintf("group.%d", i))
}
}
if len(args.Host) > 0 {
params.Add(jsonutils.NewString(args.Host), "prefer_host")
} else {
if len(args.Zone) > 0 {
params.Add(jsonutils.NewString(args.Zone), "prefer_zone")
}
}
if len(args.Project) > 0 {
params.Add(jsonutils.NewString(args.Project), "tenant")
}
if len(args.User) > 0 {
params.Add(jsonutils.NewString(args.User), "user")
}
if args.System {
params.Add(jsonutils.JSONTrue, "is_system")
}
if len(args.Hypervisor) > 0 {
params.Add(jsonutils.NewString(args.Hypervisor), "hypervisor")
}
if len(args.RaidConfig) > 0 {
if args.Hypervisor != "baremetal" {
return fmt.Errorf("RaidConfig is applicable to baremetal ONLY")
}
for i, conf := range args.RaidConfig {
params.Add(jsonutils.NewString(conf), fmt.Sprintf("baremetal_disk_config.%d", i))
}
}
if args.DryRun {
params.Add(jsonutils.JSONTrue, "suggestion")
results, err := modules.SchedManager.DoScheduleListResult(s, params, args.Count)
count := options.IntV(opts.Count)
if options.BoolV(opts.DryRun) {
results, err := modules.SchedManager.DoScheduleListResult(s, params, count)
if err != nil {
return err
}
printList(results, []string{"id", "name", "rank", "capacity", "error"})
} else {
if args.TaskNotify {
taskNotify := options.BoolV(opts.TaskNotify)
if taskNotify {
s.PrepareTask()
}
if args.Count > 1 {
results := modules.Servers.BatchCreate(s, params, args.Count)
if count > 1 {
results := modules.Servers.BatchCreate(s, params, count)
printBatchResults(results, modules.Servers.GetColumns(s))
} else {
server, err := modules.Servers.Create(s, params)
@@ -289,15 +72,15 @@ func init() {
}
printObject(server)
}
if args.TaskNotify {
if taskNotify {
s.WaitTaskNotify()
}
}
return nil
})
R(&ServerShowOptions{}, "server-logininfo", "Get login info of a server", func(s *mcclient.ClientSession, args *ServerShowOptions) error {
srvid, e := modules.Servers.GetId(s, args.ID, nil)
R(&options.ServerIdOptions{}, "server-logininfo", "Get login info of a server", func(s *mcclient.ClientSession, opts *options.ServerIdOptions) error {
srvid, e := modules.Servers.GetId(s, opts.ID, nil)
if e != nil {
return e
}
@@ -309,91 +92,74 @@ func init() {
return nil
})
type ServerOpsOptions struct {
ID []string `help:"ID of servers to operate" metavar:"SERVER"`
}
R(&ServerOpsOptions{}, "server-start", "Start servers", func(s *mcclient.ClientSession, args *ServerOpsOptions) error {
ret := modules.Servers.BatchPerformAction(s, args.ID, "start", nil)
R(&options.ServerIdsOptions{}, "server-start", "Start servers", func(s *mcclient.ClientSession, opts *options.ServerIdsOptions) error {
ret := modules.Servers.BatchPerformAction(s, opts.ID, "start", nil)
printBatchResults(ret, modules.Servers.GetColumns(s))
return nil
})
R(&ServerOpsOptions{}, "server-syncstatus", "Sync servers status", func(s *mcclient.ClientSession, args *ServerOpsOptions) error {
ret := modules.Servers.BatchPerformAction(s, args.ID, "syncstatus", nil)
R(&options.ServerIdsOptions{}, "server-syncstatus", "Sync servers status", func(s *mcclient.ClientSession, opts *options.ServerIdsOptions) error {
ret := modules.Servers.BatchPerformAction(s, opts.ID, "syncstatus", nil)
printBatchResults(ret, modules.Servers.GetColumns(s))
return nil
})
R(&ServerOpsOptions{}, "server-sync", "Sync servers configures", func(s *mcclient.ClientSession, args *ServerOpsOptions) error {
ret := modules.Servers.BatchPerformAction(s, args.ID, "sync", nil)
R(&options.ServerIdsOptions{}, "server-sync", "Sync servers configurations", func(s *mcclient.ClientSession, opts *options.ServerIdsOptions) error {
ret := modules.Servers.BatchPerformAction(s, opts.ID, "sync", nil)
printBatchResults(ret, modules.Servers.GetColumns(s))
return nil
})
type ServerStopOptions struct {
ID []string `help:"ID or Name of server"`
Force bool `help:"Stop server forcefully"`
}
R(&ServerStopOptions{}, "server-stop", "Stop servers", func(s *mcclient.ClientSession, args *ServerStopOptions) error {
params := jsonutils.NewDict()
if args.Force {
params.Add(jsonutils.JSONTrue, "is_force")
} else {
params.Add(jsonutils.JSONFalse, "is_force")
R(&options.ServerStopOptions{}, "server-stop", "Stop servers", func(s *mcclient.ClientSession, opts *options.ServerStopOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
ret := modules.Servers.BatchPerformAction(s, args.ID, "stop", params)
ret := modules.Servers.BatchPerformAction(s, opts.ID, "stop", params)
printBatchResults(ret, modules.Servers.GetColumns(s))
return nil
})
R(&ServerOpsOptions{}, "server-suspend", "Suspend servers", func(s *mcclient.ClientSession, args *ServerOpsOptions) error {
ret := modules.Servers.BatchPerformAction(s, args.ID, "suspend", nil)
R(&options.ServerIdsOptions{}, "server-suspend", "Suspend servers", func(s *mcclient.ClientSession, opts *options.ServerIdsOptions) error {
ret := modules.Servers.BatchPerformAction(s, opts.ID, "suspend", nil)
printBatchResults(ret, modules.Servers.GetColumns(s))
return nil
})
type ServerResetOptions struct {
ServerOpsOptions
Hard bool `help:"Hard reset or not; default soft"`
}
R(&ServerResetOptions{}, "server-reset", "Reset servers", func(s *mcclient.ClientSession, args *ServerResetOptions) error {
params := jsonutils.NewDict()
if args.Hard {
params.Add(jsonutils.JSONTrue, "is_hard")
R(&options.ServerResetOptions{}, "server-reset", "Reset servers", func(s *mcclient.ClientSession, opts *options.ServerResetOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
ret := modules.Servers.BatchPerformAction(s, args.ID, "reset", params)
ret := modules.Servers.BatchPerformAction(s, opts.ID, "reset", params)
printBatchResults(ret, modules.Servers.GetColumns(s))
return nil
})
R(&ServerOpsOptions{}, "server-purge", "Purge obsolete servers", func(s *mcclient.ClientSession, args *ServerOpsOptions) error {
ret := modules.Servers.BatchPerformAction(s, args.ID, "purge", nil)
R(&options.ServerIdsOptions{}, "server-purge", "Purge obsolete servers", func(s *mcclient.ClientSession, opts *options.ServerIdsOptions) error {
ret := modules.Servers.BatchPerformAction(s, opts.ID, "purge", nil)
printBatchResults(ret, modules.Servers.GetColumns(s))
return nil
})
type ServerDeleteOptions struct {
OverridePendingDelete bool `help:"Delete server directly instead of pending delete"`
ServerOpsOptions
}
R(&ServerDeleteOptions{}, "server-delete", "Delete servers", func(s *mcclient.ClientSession, args *ServerDeleteOptions) error {
params := jsonutils.NewDict()
if args.OverridePendingDelete {
params.Add(jsonutils.JSONTrue, "override_pending_delete")
R(&options.ServerDeleteOptions{}, "server-delete", "Delete servers", func(s *mcclient.ClientSession, opts *options.ServerDeleteOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
ret := modules.Servers.BatchDeleteWithParam(s, args.ID, params, nil)
ret := modules.Servers.BatchDeleteWithParam(s, opts.ID, params, nil)
printBatchResults(ret, modules.Servers.GetColumns(s))
return nil
})
R(&ServerOpsOptions{}, "server-cancel-delete", "Cancel pending delete servers", func(s *mcclient.ClientSession, args *ServerOpsOptions) error {
ret := modules.Servers.BatchPerformAction(s, args.ID, "cancel-delete", nil)
R(&options.ServerIdsOptions{}, "server-cancel-delete", "Cancel pending delete servers", func(s *mcclient.ClientSession, opts *options.ServerIdsOptions) error {
ret := modules.Servers.BatchPerformAction(s, opts.ID, "cancel-delete", nil)
printBatchResults(ret, modules.Servers.GetColumns(s))
return nil
})
R(&ServerShowOptions{}, "server-vnc", "Show vnc info of server", func(s *mcclient.ClientSession, args *ServerShowOptions) error {
ret, e := modules.Servers.GetSpecific(s, args.ID, "vnc", nil)
R(&options.ServerIdOptions{}, "server-vnc", "Show vnc info of server", func(s *mcclient.ClientSession, opts *options.ServerIdOptions) error {
ret, e := modules.Servers.GetSpecific(s, opts.ID, "vnc", nil)
if e != nil {
return e
}
@@ -401,8 +167,8 @@ func init() {
return nil
})
R(&ServerShowOptions{}, "server-desc", "Show desc info of server", func(s *mcclient.ClientSession, args *ServerShowOptions) error {
ret, e := modules.Servers.GetSpecific(s, args.ID, "desc", nil)
R(&options.ServerIdOptions{}, "server-desc", "Show desc info of server", func(s *mcclient.ClientSession, opts *options.ServerIdOptions) error {
ret, e := modules.Servers.GetSpecific(s, opts.ID, "desc", nil)
if e != nil {
return e
}
@@ -410,8 +176,8 @@ func init() {
return nil
})
R(&ServerShowOptions{}, "server-status", "Show status of server", func(s *mcclient.ClientSession, args *ServerShowOptions) error {
ret, e := modules.Servers.GetSpecific(s, args.ID, "status", nil)
R(&options.ServerIdOptions{}, "server-status", "Show status of server", func(s *mcclient.ClientSession, opts *options.ServerIdOptions) error {
ret, e := modules.Servers.GetSpecific(s, opts.ID, "status", nil)
if e != nil {
return e
}
@@ -419,79 +185,25 @@ func init() {
return nil
})
type ServerUpdateOptions struct {
ID []string `help:"IDs or Names of servers to update"`
Name string `help:"New name to change"`
Vmem string `help:"Memory size"`
Ncpu int64 `help:"CPU count"`
Vga string `help:"VGA driver" choices:"std|vmware|cirrus|qxl"`
Vdi string `help:"VDI protocol" choices:"vnc|spice"`
Bios string `help:"BIOS" choices:"BIOS|UEFI"`
Desc string `help:"Description"`
Boot string `help:"Boot device" choices:"disk|cdrom"`
Delete string `help:"Lock server to prevent from deleting" choices:"enable|disable"`
ShutdownBehavior string `help:"Behavior after VM server shutdown, stop or terminate server" choices:"stop|terminate"`
}
R(&ServerUpdateOptions{}, "server-update", "Update servers", func(s *mcclient.ClientSession, args *ServerUpdateOptions) error {
params := jsonutils.NewDict()
if len(args.Name) > 0 {
params.Add(jsonutils.NewString(args.Name), "name")
}
if args.Ncpu > 0 {
params.Add(jsonutils.NewInt(args.Ncpu), "vcpu_count")
}
if len(args.Vmem) > 0 {
params.Add(jsonutils.NewString(args.Vmem), "vmem_size")
}
if len(args.Vga) > 0 {
params.Add(jsonutils.NewString(args.Vga), "vga")
}
if len(args.Vdi) > 0 {
params.Add(jsonutils.NewString(args.Vdi), "vdi")
}
if len(args.Bios) > 0 {
params.Add(jsonutils.NewString(args.Bios), "bios")
}
if len(args.Desc) > 0 {
params.Add(jsonutils.NewString(args.Desc), "description")
}
if len(args.Boot) > 0 {
if args.Boot == "disk" {
params.Add(jsonutils.NewString("cdn"), "boot_order")
} else {
params.Add(jsonutils.NewString("dcn"), "boot_order")
}
}
if len(args.Delete) > 0 {
if args.Delete == "disable" {
params.Add(jsonutils.JSONTrue, "disable_delete")
} else {
params.Add(jsonutils.JSONFalse, "disable_delete")
}
}
if len(args.ShutdownBehavior) > 0 {
params.Add(jsonutils.NewString(args.ShutdownBehavior), "shutdown_behavior")
R(&options.ServerUpdateOptions{}, "server-update", "Update servers", func(s *mcclient.ClientSession, opts *options.ServerUpdateOptions) error {
params, err := opts.Params()
if err != nil {
return err
}
if params.Size() == 0 {
return InvalidUpdateError()
}
result := modules.Servers.BatchPut(s, args.ID, params)
result := modules.Servers.BatchPut(s, opts.ID, params)
printBatchResults(result, modules.Servers.GetColumns(s))
return nil
})
type ServerSendKeyOptions struct {
SERVER string `help:"ID of virtual server to get monitor info"`
KEYS string `help:"Special keys to send, eg. ctrl, alt, f12, shift, etc, separated by \"-\""`
Hold int64 `help:"Hold key for specified milliseconds"`
}
R(&ServerSendKeyOptions{}, "server-send-keys", "Send keys to server", func(s *mcclient.ClientSession, args *ServerSendKeyOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.KEYS), "keys")
if args.Hold > 0 {
params.Add(jsonutils.NewInt(args.Hold), "duration")
R(&options.ServerSendKeyOptions{}, "server-send-keys", "Send keys to server", func(s *mcclient.ClientSession, opts *options.ServerSendKeyOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
srv, err := modules.Servers.PerformAction(s, args.SERVER, "sendkeys", params)
srv, err := modules.Servers.PerformAction(s, opts.ID, "sendkeys", params)
if err != nil {
return err
}
@@ -499,34 +211,12 @@ func init() {
return nil
})
type ServerDeployOptions struct {
ID string `help:"ID or Name of server"`
Keypair string `help:"ssh Keypair used for login"`
DeleteKeypair bool `help:"Remove ssh Keypairs"`
Deploy []string `help:"Specify deploy files in virtual server file system"`
ResetPassword bool `help:"Force reset password"`
Password string `help:"Default user password"`
}
R(&ServerDeployOptions{}, "server-deploy", "Deploy hostname and keypair to a stopped virtual server", func(s *mcclient.ClientSession, args *ServerDeployOptions) error {
params := jsonutils.NewDict()
if args.DeleteKeypair {
params.Add(jsonutils.JSONTrue, "__delete_keypair__")
} else if len(args.Keypair) > 0 {
params.Add(jsonutils.NewString(args.Keypair), "keypair")
R(&options.ServerDeployOptions{}, "server-deploy", "Deploy hostname and keypair to a stopped virtual server", func(s *mcclient.ClientSession, opts *options.ServerDeployOptions) error {
params, err := opts.Params()
if err != nil {
return err
}
if len(args.Deploy) > 0 {
e := parseDeployList(args.Deploy, params)
if e != nil {
return e
}
}
if args.ResetPassword {
params.Add(jsonutils.JSONTrue, "reset_password")
}
if args.Password != "" {
params.Add(jsonutils.NewString(args.Password), "password")
}
srv, e := modules.Servers.PerformAction(s, args.ID, "deploy", params)
srv, e := modules.Servers.PerformAction(s, opts.ID, "deploy", params)
if e != nil {
return e
}
@@ -534,15 +224,12 @@ func init() {
return nil
})
type ServerSecGroupOptions struct {
ID string `help:"ID or Name of server" metavar:"Guest"`
SecGrp string `help:"ID of Security Group" metavar:"Security Group" positional:"true"`
}
R(&ServerSecGroupOptions{}, "server-assign-secgroup", "Assign security group to a VM", func(s *mcclient.ClientSession, args *ServerSecGroupOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.SecGrp), "secgrp")
srv, e := modules.Servers.PerformAction(s, args.ID, "assign-secgroup", params)
R(&options.ServerSecGroupOptions{}, "server-assign-secgroup", "Assign security group to a VM", func(s *mcclient.ClientSession, opts *options.ServerSecGroupOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
srv, e := modules.Servers.PerformAction(s, opts.ID, "assign-secgroup", params)
if e != nil {
return e
}
@@ -550,10 +237,12 @@ func init() {
return nil
})
R(&ServerSecGroupOptions{}, "server-assign-admin-secgroup", "Assign administrative security group to a VM", func(s *mcclient.ClientSession, args *ServerSecGroupOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.SecGrp), "secgrp")
srv, e := modules.Servers.PerformAction(s, args.ID, "assign-admin-secgroup", params)
R(&options.ServerSecGroupOptions{}, "server-assign-admin-secgroup", "Assign administrative security group to a VM", func(s *mcclient.ClientSession, opts *options.ServerSecGroupOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
srv, e := modules.Servers.PerformAction(s, opts.ID, "assign-admin-secgroup", params)
if e != nil {
return e
}
@@ -561,12 +250,8 @@ func init() {
return nil
})
type ServerRevokeSecGroupOptions struct {
ID string `help:"ID or Name of server" metavar:"Guest"`
}
R(&ServerRevokeSecGroupOptions{}, "server-revoke-secgroup", "Assign security group to a VM", func(s *mcclient.ClientSession, args *ServerRevokeSecGroupOptions) error {
srv, e := modules.Servers.PerformAction(s, args.ID, "revoke-secgroup", nil)
R(&options.ServerIdOptions{}, "server-revoke-secgroup", "Assign security group to a VM", func(s *mcclient.ClientSession, opts *options.ServerIdOptions) error {
srv, e := modules.Servers.PerformAction(s, opts.ID, "revoke-secgroup", nil)
if e != nil {
return e
}
@@ -574,8 +259,8 @@ func init() {
return nil
})
R(&ServerRevokeSecGroupOptions{}, "server-revoke-admin-secgroup", "Assign administrative security group to a VM", func(s *mcclient.ClientSession, args *ServerRevokeSecGroupOptions) error {
srv, e := modules.Servers.PerformAction(s, args.ID, "revoke-admin-secgroup", nil)
R(&options.ServerIdOptions{}, "server-revoke-admin-secgroup", "Assign administrative security group to a VM", func(s *mcclient.ClientSession, opts *options.ServerIdOptions) error {
srv, e := modules.Servers.PerformAction(s, opts.ID, "revoke-admin-secgroup", nil)
if e != nil {
return e
}
@@ -583,14 +268,12 @@ func init() {
return nil
})
type ServerMonitorOptions struct {
SERVER string `help:"ID or Name of server"`
CMD string `help:"Qemu Monitor command to send"`
}
R(&ServerMonitorOptions{}, "server-monitor", "Send commands to qemu monitor", func(s *mcclient.ClientSession, args *ServerMonitorOptions) error {
query := jsonutils.NewDict()
query.Add(jsonutils.NewString(args.CMD), "command")
ret, err := modules.Servers.GetSpecific(s, args.SERVER, "monitor", query)
R(&options.ServerMonitorOptions{}, "server-monitor", "Send commands to qemu monitor", func(s *mcclient.ClientSession, opts *options.ServerMonitorOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
ret, err := modules.Servers.GetSpecific(s, opts.ID, "monitor", params)
if err != nil {
return err
}
@@ -602,28 +285,12 @@ func init() {
return nil
})
type ServerSaveImageOptions struct {
SERVER string `help:"ID or name of server"`
IMAGE string `help:"Image name"`
Public bool `help:"Make the image public available"`
Format string `help:"image format" choices:"vmdk|qcow2"`
Notes string `help:"Notes about the image"`
}
R(&ServerSaveImageOptions{}, "server-save-image", "Save root disk to new image and upload to glance.", func(s *mcclient.ClientSession, args *ServerSaveImageOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.IMAGE), "name")
if args.Public {
params.Add(jsonutils.JSONTrue, "is_public")
} else {
params.Add(jsonutils.JSONFalse, "is_public")
R(&options.ServerSaveImageOptions{}, "server-save-image", "Save root disk to new image and upload to glance.", func(s *mcclient.ClientSession, opts *options.ServerSaveImageOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
if len(args.Format) > 0 {
params.Add(jsonutils.NewString(args.Format), "format")
}
if len(args.Notes) > 0 {
params.Add(jsonutils.NewString(args.Notes), "notes")
}
srv, err := modules.Servers.PerformAction(s, args.SERVER, "save-image", params)
srv, err := modules.Servers.PerformAction(s, opts.ID, "save-image", params)
if err != nil {
return err
}
@@ -632,23 +299,23 @@ func init() {
})
type ServerChangeOwnerOptions struct {
SERVER string `help:"Server to change owner"`
ID string `help:"Server to change owner"`
PROJECT string `help:"Project ID or change"`
RawId bool `help:"User raw ID, instead of name"`
}
R(&ServerChangeOwnerOptions{}, "server-change-owner", "Change owner porject of a server", func(s *mcclient.ClientSession, args *ServerChangeOwnerOptions) error {
R(&ServerChangeOwnerOptions{}, "server-change-owner", "Change owner porject of a server", func(s *mcclient.ClientSession, opts *ServerChangeOwnerOptions) error {
params := jsonutils.NewDict()
if args.RawId {
projid, err := modules.Projects.GetId(s, args.PROJECT, nil)
if opts.RawId {
projid, err := modules.Projects.GetId(s, opts.PROJECT, nil)
if err != nil {
return err
}
params.Add(jsonutils.NewString(projid), "tenant")
params.Add(jsonutils.JSONTrue, "raw_id")
} else {
params.Add(jsonutils.NewString(args.PROJECT), "tenant")
params.Add(jsonutils.NewString(opts.PROJECT), "tenant")
}
srv, err := modules.Servers.PerformAction(s, args.SERVER, "change-owner", params)
srv, err := modules.Servers.PerformAction(s, opts.ID, "change-owner", params)
if err != nil {
return err
}
@@ -656,28 +323,12 @@ func init() {
return nil
})
type ServerRebuildRootOptions struct {
SERVER string `help:"Server to rebuild root"`
AutoStart bool `help:"Auto start server after it is created"`
Image string `help:"New root Image template ID"`
Keypair string `help:"ssh Keypair used for login"`
Password string `help:"Default user password"`
}
R(&ServerRebuildRootOptions{}, "server-rebuild-root", "Rebuild VM root image with new template", func(s *mcclient.ClientSession, args *ServerRebuildRootOptions) error {
params := jsonutils.NewDict()
if len(args.Image) > 0 {
params.Add(jsonutils.NewString(args.Image), "image_id")
R(&options.ServerRebuildRootOptions{}, "server-rebuild-root", "Rebuild VM root image with new template", func(s *mcclient.ClientSession, opts *options.ServerRebuildRootOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
if args.AutoStart {
params.Add(jsonutils.JSONTrue, "auto_start")
}
if args.Keypair != "" {
params.Add(jsonutils.NewString(args.Keypair), "keypair")
}
if args.Password != "" {
params.Add(jsonutils.NewString(args.Password), "password")
}
srv, err := modules.Servers.PerformAction(s, args.SERVER, "rebuild-root", params)
srv, err := modules.Servers.PerformAction(s, opts.ID, "rebuild-root", params)
if err != nil {
return err
}
@@ -685,29 +336,15 @@ func init() {
return nil
})
type ServerChangeConfigOptions struct {
SERVER string `help:"Server to rebuild root"`
Ncpu int64 `help:"New number of Virtual CPU cores"`
Vmem string `help:"New memory size"`
Disk []string `help:"Data disk description, from the 1st data disk to the last one, empty string if no change for this data disk"`
}
R(&ServerChangeConfigOptions{}, "server-change-config", "Change configuration of VM", func(s *mcclient.ClientSession, args *ServerChangeConfigOptions) error {
params := jsonutils.NewDict()
if args.Ncpu > 0 {
params.Add(jsonutils.NewInt(args.Ncpu), "vcpu_count")
}
if len(args.Vmem) > 0 {
params.Add(jsonutils.NewString(args.Vmem), "vmem_size")
}
if len(args.Disk) > 0 {
for idx, disk := range args.Disk {
params.Add(jsonutils.NewString(disk), fmt.Sprintf("disk.%d", (idx+1)))
}
R(&options.ServerChangeConfigOptions{}, "server-change-config", "Change configuration of VM", func(s *mcclient.ClientSession, opts *options.ServerChangeConfigOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
if params.Size() == 0 {
return InvalidUpdateError()
}
srv, err := modules.Servers.PerformAction(s, args.SERVER, "change-config", params)
srv, err := modules.Servers.PerformAction(s, opts.ID, "change-config", params)
if err != nil {
return err
}
@@ -719,8 +356,8 @@ func init() {
ID string `help:"server ID or Name"`
ISO string `help:"Glance image ID of the ISO"`
}
R(&ServerInsertISOOptions{}, "server-insert-iso", "Insert an ISO image into server's cdrom", func(s *mcclient.ClientSession, args *ServerInsertISOOptions) error {
img, err := modules.Images.Get(s, args.ISO, nil)
R(&ServerInsertISOOptions{}, "server-insert-iso", "Insert an ISO image into server's cdrom", func(s *mcclient.ClientSession, opts *ServerInsertISOOptions) error {
img, err := modules.Images.Get(s, opts.ISO, nil)
if err != nil {
return err
}
@@ -730,7 +367,7 @@ func init() {
}
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(imgId), "image_id")
result, err := modules.Servers.PerformAction(s, args.ID, "insertiso", params)
result, err := modules.Servers.PerformAction(s, opts.ID, "insertiso", params)
if err != nil {
return err
}
@@ -738,8 +375,8 @@ func init() {
return nil
})
R(&ServerShowOptions{}, "server-eject-iso", "Eject iso from servers' cdrom", func(s *mcclient.ClientSession, args *ServerShowOptions) error {
result, err := modules.Servers.PerformAction(s, args.ID, "ejectiso", nil)
R(&options.ServerIdOptions{}, "server-eject-iso", "Eject iso from servers' cdrom", func(s *mcclient.ClientSession, opts *options.ServerIdOptions) error {
result, err := modules.Servers.PerformAction(s, opts.ID, "ejectiso", nil)
if err != nil {
return err
}
@@ -747,8 +384,8 @@ func init() {
return nil
})
R(&ServerShowOptions{}, "server-iso", "Show server's mounting ISO information", func(s *mcclient.ClientSession, args *ServerShowOptions) error {
results, err := modules.Servers.GetSpecific(s, args.ID, "iso", nil)
R(&options.ServerIdOptions{}, "server-iso", "Show server's mounting ISO information", func(s *mcclient.ClientSession, opts *options.ServerIdOptions) error {
results, err := modules.Servers.GetSpecific(s, opts.ID, "iso", nil)
if err != nil {
return err
}
+11 -2
View File
@@ -4,6 +4,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -72,11 +73,19 @@ func init() {
* 查看指定服务树节点的机器
*/
type ServiceHostListOptions struct {
BaseListOptions
options.BaseListOptions
Labels string `help:"Labels for tree-node(split by comma)"`
}
R(&ServiceHostListOptions{}, "servicehost-list", "List all hosts for the tree-node", func(s *mcclient.ClientSession, args *ServiceHostListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Labels) > 0 {
params.Add(jsonutils.NewString(args.Labels), "node_labels")
}
+12 -2
View File
@@ -1,8 +1,10 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -11,10 +13,18 @@ func init() {
* 列出所有监控指标
*/
type ServiceNameSuggestionListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&ServiceNameSuggestionListOptions{}, "servicenamesuggestion-list", "List all serviceNameSuggestion", func(s *mcclient.ClientSession, args *ServiceNameSuggestionListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.ServiceNameSuggestion.List(s, params)
if err != nil {
+11 -2
View File
@@ -4,6 +4,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -79,10 +80,18 @@ func init() {
* 列出服务树
*/
type ServiceTreeListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&ServiceTreeListOptions{}, "servicetree-list", "List all service tree", func(s *mcclient.ClientSession, args *ServiceTreeListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.ServiceTrees.List(s, params)
if err != nil {
return err
-101
View File
@@ -2,8 +2,6 @@ package shell
import (
"fmt"
"yunion.io/x/jsonutils"
)
type CMD struct {
@@ -19,105 +17,6 @@ func R(options interface{}, command string, desc string, callback interface{}) {
CommandTable = append(CommandTable, CMD{options, command, desc, callback})
}
type BaseListOptions struct {
Limit int `default:"20" help:"Page limit"`
Offset int `default:"0" help:"Page offset"`
OrderBy string `help:"Name of the field to be ordered by"`
Order string `help:"List order" choices:"desc|asc"`
Details bool `help:"Show more details"`
Search string `help:"Filter results by a simple keyword search"`
Meta bool `help:"Piggyback metadata information"`
Filter []string `help:"Filters"`
JointFilter []string `help:"Filters with joint table col; joint_tbl(related_key).filter_col.filter_cond(filters)"`
FilterAny bool `help:"If true, match if any of the filters matches; otherwise, match if all of the filters match"`
Admin bool `help:"Is an admin call?"`
Tenant string `help:"Tenant ID or Name"`
User string `help:"User ID or Name"`
System bool `help:"Show system resource"`
PendingDelete bool `help:"Show pending deleted resource"`
Field []string `help:"Show only specified fields"`
ShowEmulated bool `help:"Show all resources including the emulated resources"`
}
func FetchPagingParams(options BaseListOptions) *jsonutils.JSONDict {
params := jsonutils.NewDict()
if options.Limit > 0 {
params.Add(jsonutils.NewInt(int64(options.Limit)), "limit")
}
if options.Offset > 0 {
params.Add(jsonutils.NewInt(int64(options.Offset)), "offset")
}
if len(options.OrderBy) > 0 {
params.Add(jsonutils.NewString(options.OrderBy), "order_by")
}
if len(options.Order) > 0 {
params.Add(jsonutils.NewString(options.Order), "order")
}
if options.Details {
params.Add(jsonutils.JSONTrue, "details")
} else {
params.Add(jsonutils.JSONFalse, "details")
}
if len(options.Search) > 0 {
params.Add(jsonutils.NewString(options.Search), "search")
}
if options.Meta {
params.Add(jsonutils.JSONTrue, "with_meta")
}
if len(options.JointFilter) > 0 {
arr := jsonutils.NewArray()
for _, f := range options.JointFilter {
arr.Add(jsonutils.NewString(f))
}
params.Add(arr, "joint_filter")
}
if len(options.Filter) > 0 {
arr := jsonutils.NewArray()
for _, f := range options.Filter {
arr.Add(jsonutils.NewString(f))
}
params.Add(arr, "filter")
if options.FilterAny {
params.Add(jsonutils.JSONTrue, "filter_any")
}
}
if options.Admin {
params.Add(jsonutils.JSONTrue, "admin")
}
if len(options.Tenant) > 0 {
params.Add(jsonutils.NewString(options.Tenant), "tenant")
if !options.Admin {
params.Add(jsonutils.JSONTrue, "admin")
}
}
if len(options.User) > 0 {
params.Add(jsonutils.NewString(options.User), "user")
}
if options.System {
params.Add(jsonutils.JSONTrue, "system")
if !options.Admin {
params.Add(jsonutils.JSONTrue, "admin")
}
}
if options.PendingDelete {
params.Add(jsonutils.JSONTrue, "pending_delete")
if !options.Admin {
params.Add(jsonutils.JSONTrue, "admin")
}
}
if len(options.Field) > 0 {
arr := jsonutils.NewArray()
for _, f := range options.Field {
arr.Add(jsonutils.NewString(f))
}
params.Add(arr, "field")
}
if options.ShowEmulated {
params.Add(jsonutils.JSONTrue, "show_emulated")
}
return params
}
func InvalidUpdateError() error {
return fmt.Errorf("No valid update data")
}
+31 -6
View File
@@ -6,17 +6,26 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type ListOptions struct {
BaseListOptions
options.BaseListOptions
Model string `help:"Specified model specs" choices:"hosts|isolated_devices|guests"`
HostType string `help:"Host type filter" choices:"baremetal|hypervisor|esxi|kubelet|hyperv"`
Gpu bool `help:"Only show gpu devices"`
}
R(&ListOptions{}, "spec", "List all kinds of model specs", func(s *mcclient.ClientSession, args *ListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
model := ""
if len(args.Model) != 0 {
model = args.Model
@@ -36,7 +45,7 @@ func init() {
})
type HostsQueryOptions struct {
BaseListOptions
options.BaseListOptions
HostType string `help:"Host type filter" choices:"baremetal|hypervisor|esxi|kubelet|hyperv"`
Ncpu int64 `help:"#CPU count of host" metavar:"<CPU_COUNT>"`
MemSize string `help:"Memory GB size"`
@@ -61,7 +70,15 @@ func init() {
}
return keys
}
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.HostType) > 0 {
params.Add(jsonutils.NewString(args.HostType), "host_type")
}
@@ -80,7 +97,7 @@ func init() {
})
type IsoDevQueryOptions struct {
BaseListOptions
options.BaseListOptions
Model string `help:"Device model name"`
Vendor string `help:"Device vendor name"`
}
@@ -95,7 +112,15 @@ func init() {
}
return keys
}
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
resp, err := modules.Specs.SpecsQueryModelObjects(s, "isolated_devices", newSpecKeys(), params)
if err != nil {
return err
+11 -2
View File
@@ -4,16 +4,25 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type StorageCachedImageListOptions struct {
BaseListOptions
options.BaseListOptions
Storagecache string `help:"ID or Name of Storage"`
Image string `help:"ID or Name of image"`
}
R(&StorageCachedImageListOptions{}, "storage-cached-image-list", "List storage cached image pairs", func(s *mcclient.ClientSession, args *StorageCachedImageListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
var result *modules.ListResult
var err error
if len(args.Storagecache) > 0 {
+11 -2
View File
@@ -4,16 +4,25 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type StoragecacheListOptions struct {
BaseListOptions
options.BaseListOptions
Manager string `help:"Show regions belongs to the cloud provider"`
}
R(&StoragecacheListOptions{}, "storage-cache-list", "List storage caches", func(s *mcclient.ClientSession, args *StoragecacheListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Manager) > 0 {
params.Add(jsonutils.NewString(args.Manager), "manager")
+11 -2
View File
@@ -6,11 +6,12 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type StorageListOptions struct {
BaseListOptions
options.BaseListOptions
Share bool `help:"Share storage list"`
Local bool `help:"Local storage list"`
Usable bool `help:"Usable storage list"`
@@ -20,7 +21,15 @@ func init() {
Manager string `help:"Show regions belongs to the cloud provider"`
}
R(&StorageListOptions{}, "storage-list", "List storages", func(s *mcclient.ClientSession, args *StorageListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if args.Share {
params.Add(jsonutils.JSONTrue, "share")
}
+21 -3
View File
@@ -1,16 +1,26 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type TaskListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&TaskListOptions{}, "task-list", "List taskman", func(s *mcclient.ClientSession, suboptions *TaskListOptions) error {
params := FetchPagingParams(suboptions.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = suboptions.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.Tasks.List(s, params)
if err != nil {
return err
@@ -20,7 +30,15 @@ func init() {
})
R(&TaskListOptions{}, "region-task-list", "List tasks on region server", func(s *mcclient.ClientSession, suboptions *TaskListOptions) error {
params := FetchPagingParams(suboptions.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = suboptions.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.ComputeTasks.List(s, params)
if err != nil {
return err
+11 -2
View File
@@ -7,6 +7,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
@@ -58,12 +59,20 @@ func init() {
})
type ServiceTreeNodeListOptions struct {
BaseListOptions
options.BaseListOptions
Label string `help:"Label of node"`
Pid int64 `help:"Pid of node" default:"-1"`
}
R(&ServiceTreeNodeListOptions{}, "servicetree-node-list", "List servicetree nodes", func(s *mcclient.ClientSession, args *ServiceTreeNodeListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if args.Pid >= 0 {
params.Add(jsonutils.NewInt(args.Pid), "pid")
}
+11 -2
View File
@@ -4,14 +4,23 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type VCenterListOptions struct {
BaseListOptions
options.BaseListOptions
}
R(&VCenterListOptions{}, "vcenter-list", "List VMWare vcenters", func(s *mcclient.ClientSession, args *VCenterListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
result, err := modules.VCenters.List(s, params)
if err != nil {
return err
+11 -2
View File
@@ -4,16 +4,25 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type VpcListOptions struct {
BaseListOptions
options.BaseListOptions
Region string `help:"ID or Name of region"`
Manager string `help:"Show regions belongs to the cloud provider"`
}
R(&VpcListOptions{}, "vpc-list", "List VPCs", func(s *mcclient.ClientSession, args *VpcListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Manager) > 0 {
params.Add(jsonutils.NewString(args.Manager), "manager")
+11 -2
View File
@@ -4,16 +4,25 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type WireListOptions struct {
BaseListOptions
options.BaseListOptions
Zone string `help:"list wires in zone"`
Vpc string `help:"List wires in vpc"`
}
R(&WireListOptions{}, "wire-list", "List wires", func(s *mcclient.ClientSession, args *WireListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if len(args.Vpc) > 0 {
params.Add(jsonutils.NewString(args.Vpc), "vpc")
}
+11 -2
View File
@@ -4,18 +4,27 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type ZoneListOptions struct {
BaseListOptions
options.BaseListOptions
Region string `help:"cloud region ID or Name"`
Usable bool `help:"List all zones that is usable"`
Private bool `help:"show all zones in private cloud regions only"`
Public bool `help:"show all zones in public cloud regions only"`
}
R(&ZoneListOptions{}, "zone-list", "List zones", func(s *mcclient.ClientSession, args *ZoneListOptions) error {
params := FetchPagingParams(args.BaseListOptions)
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
if err != nil {
return err
}
}
if args.Usable {
params.Add(jsonutils.JSONTrue, "usable")
}