From d2fa217caba6b311de315abc7a991eee9209c0f9 Mon Sep 17 00:00:00 2001 From: TangBin Date: Sat, 7 Sep 2019 18:26:13 +0800 Subject: [PATCH 1/2] mcclient module base --- cmd/climc/shell/baremetalnetworks.go | 3 +- cmd/climc/shell/baremetalstorages.go | 3 +- cmd/climc/shell/buckets.go | 3 +- cmd/climc/shell/cloudproviderregions.go | 3 +- cmd/climc/shell/cloudregions.go | 5 +- cmd/climc/shell/contacts.go | 3 +- cmd/climc/shell/credentials.go | 5 +- cmd/climc/shell/dbinstances.go | 3 +- cmd/climc/shell/events.go | 3 +- cmd/climc/shell/hostcachedimages.go | 3 +- cmd/climc/shell/hoststorages.go | 3 +- cmd/climc/shell/hostwires.go | 3 +- cmd/climc/shell/images.go | 3 +- cmd/climc/shell/k8s/k8s.go | 22 +- cmd/climc/shell/k8s/list.go | 6 +- cmd/climc/shell/labels.go | 3 +- cmd/climc/shell/loadbalanceracls.go | 3 +- cmd/climc/shell/loadbalancercachedacls.go | 3 +- cmd/climc/shell/loadbalancernetworks.go | 3 +- cmd/climc/shell/modules.go | 4 +- cmd/climc/shell/networkinterfacenetworks.go | 3 +- cmd/climc/shell/networks.go | 3 +- cmd/climc/shell/parameters.go | 3 +- cmd/climc/shell/projects.go | 17 +- cmd/climc/shell/quotas.go | 3 +- cmd/climc/shell/routetables.go | 3 +- cmd/climc/shell/schedtagresources.go | 17 +- cmd/climc/shell/schedulers.go | 7 +- cmd/climc/shell/serverdisks.go | 3 +- cmd/climc/shell/servernetworks.go | 3 +- cmd/climc/shell/servers.go | 9 +- cmd/climc/shell/specs.go | 5 +- cmd/climc/shell/storagecachedimages.go | 3 +- cmd/climc/shell/storages.go | 3 +- cmd/climc/shell/users.go | 3 +- cmd/climc/shell/utils.go | 8 +- cmd/climc/shell/vpcs.go | 3 +- cmd/climc/shell/wires.go | 3 +- cmd/climc/shell/zones.go | 3 +- pkg/apigateway/handler/auth.go | 9 +- pkg/apigateway/handler/csrfexempt.go | 14 +- pkg/apigateway/handler/request.go | 18 +- pkg/apigateway/handler/resource.go | 70 +++--- pkg/apigateway/handler/rpc.go | 4 +- pkg/apigateway/service/service.go | 4 +- pkg/appsrv/dispatcher/dispatcher.go | 6 +- pkg/appsrv/dispatcher/handlers.go | 12 +- pkg/appsrv/dispatcher/jointdispatcher.go | 9 +- pkg/baremetal/pxe/dhcp.go | 3 +- pkg/cloudcommon/db/db_dispatcher.go | 20 +- pkg/cloudcommon/db/db_joint_dispatcher.go | 8 +- pkg/cloudcommon/etcd/handler/dispatcher.go | 8 +- pkg/cloudcommon/notifyclient/notify.go | 3 +- pkg/compute/models/buckets.go | 6 +- pkg/image/models/images.go | 3 +- pkg/lbagent/models/modelset.go | 17 +- pkg/lbagent/models/reflect.go | 6 +- pkg/mcclient/{modules => modulebase}/base.go | 2 +- pkg/mcclient/modulebase/doc.go | 1 + .../{modules => modulebase}/filter.go | 3 +- pkg/mcclient/{modules => modulebase}/joint.go | 2 +- .../{modules => modulebase}/modules.go | 8 +- pkg/mcclient/modulebase/pprof.go | 34 +++ pkg/mcclient/modulebase/projectresources.go | 36 +++ .../{modules => modulebase}/resource.go | 3 +- pkg/mcclient/modulebase/utils.go | 54 +++++ pkg/mcclient/modulebase/version.go | 35 +++ pkg/mcclient/modules/cache.go | 5 +- pkg/mcclient/modules/etcd/managers.go | 3 +- .../modules/etcd/mod_service_registries.go | 7 +- pkg/mcclient/modules/k8s/base.go | 8 +- pkg/mcclient/modules/managers.go | 214 +++++++----------- pkg/mcclient/modules/mod_account_balances.go | 4 +- pkg/mcclient/modules/mod_actions.go | 4 +- pkg/mcclient/modules/mod_alarmevents.go | 5 +- pkg/mcclient/modules/mod_alarmlogs.go | 4 +- pkg/mcclient/modules/mod_alarms.go | 4 +- .../modules/mod_alarmtemplatealarms.go | 4 +- pkg/mcclient/modules/mod_alarmtemplates.go | 4 +- pkg/mcclient/modules/mod_ansibleplaybooks.go | 4 +- pkg/mcclient/modules/mod_baremetalagents.go | 4 +- pkg/mcclient/modules/mod_baremetalnetworks.go | 4 +- pkg/mcclient/modules/mod_baremetalstorages.go | 4 +- pkg/mcclient/modules/mod_bill_analysises.go | 4 +- pkg/mcclient/modules/mod_bill_balances.go | 4 +- pkg/mcclient/modules/mod_bill_cloudchecks.go | 4 +- pkg/mcclient/modules/mod_bill_conditions.go | 4 +- pkg/mcclient/modules/mod_bill_details.go | 4 +- pkg/mcclient/modules/mod_bill_resources.go | 4 +- pkg/mcclient/modules/mod_buckets.go | 5 +- pkg/mcclient/modules/mod_cachedimages.go | 4 +- pkg/mcclient/modules/mod_capabilities.go | 9 +- pkg/mcclient/modules/mod_cloud_sku_rates.go | 4 +- pkg/mcclient/modules/mod_cloudaccounts.go | 4 +- .../modules/mod_cloudproviderregions.go | 4 +- pkg/mcclient/modules/mod_cloudproviders.go | 4 +- pkg/mcclient/modules/mod_cloudregions.go | 3 +- pkg/mcclient/modules/mod_contactgroups.go | 4 +- pkg/mcclient/modules/mod_contacts.go | 7 +- pkg/mcclient/modules/mod_copyright.go | 4 +- pkg/mcclient/modules/mod_credentials.go | 3 +- .../modules/mod_dbinstanceaccounts.go | 4 +- pkg/mcclient/modules/mod_dbinstancebackups.go | 4 +- .../modules/mod_dbinstancedatabases.go | 4 +- .../modules/mod_dbinstancenetworks.go | 4 +- .../modules/mod_dbinstanceparameters.go | 4 +- .../modules/mod_dbinstanceprivileges.go | 4 +- pkg/mcclient/modules/mod_dbinstances.go | 4 +- pkg/mcclient/modules/mod_disks.go | 4 +- pkg/mcclient/modules/mod_dnsrecords.go | 4 +- pkg/mcclient/modules/mod_domains.go | 4 +- pkg/mcclient/modules/mod_dynamicschedtags.go | 4 +- pkg/mcclient/modules/mod_elasticips.go | 4 +- pkg/mcclient/modules/mod_email_configs.go | 4 +- pkg/mcclient/modules/mod_endpoints.go | 6 +- pkg/mcclient/modules/mod_externalprojects.go | 4 +- pkg/mcclient/modules/mod_groups.go | 11 +- pkg/mcclient/modules/mod_hostcachedimages.go | 4 +- pkg/mcclient/modules/mod_hosts.go | 15 +- pkg/mcclient/modules/mod_hoststorages.go | 4 +- pkg/mcclient/modules/mod_hostwires.go | 4 +- pkg/mcclient/modules/mod_identity.go | 7 +- pkg/mcclient/modules/mod_identityproviders.go | 4 +- pkg/mcclient/modules/mod_images.go | 47 ++-- pkg/mcclient/modules/mod_infos.go | 5 +- pkg/mcclient/modules/mod_instances.go | 4 +- pkg/mcclient/modules/mod_isolatedevices.go | 4 +- pkg/mcclient/modules/mod_itsm_deployments.go | 4 +- .../mod_itsm_historic_process_instances.go | 7 +- .../mod_itsm_historic_task_instances.go | 4 +- .../modules/mod_itsm_process_definitions.go | 4 +- .../modules/mod_itsm_process_instances.go | 5 +- pkg/mcclient/modules/mod_itsm_tasks.go | 5 +- pkg/mcclient/modules/mod_keypairs.go | 4 +- pkg/mcclient/modules/mod_labels.go | 4 +- pkg/mcclient/modules/mod_license.go | 5 +- pkg/mcclient/modules/mod_loadbalanceracls.go | 4 +- .../modules/mod_loadbalanceragents.go | 4 +- .../modules/mod_loadbalancerbackendgroups.go | 4 +- .../modules/mod_loadbalancerbackends.go | 4 +- .../modules/mod_loadbalancercachedacls.go | 4 +- .../mod_loadbalancercachedcertificates.go | 4 +- .../modules/mod_loadbalancercertificates.go | 4 +- .../modules/mod_loadbalancerclusters.go | 4 +- .../modules/mod_loadbalancerlistenerrules.go | 4 +- .../modules/mod_loadbalancerlisteners.go | 4 +- .../modules/mod_loadbalancernetworks.go | 4 +- pkg/mcclient/modules/mod_loadbalancers.go | 4 +- pkg/mcclient/modules/mod_logs.go | 4 +- pkg/mcclient/modules/mod_metadatas.go | 4 +- pkg/mcclient/modules/mod_meteralert.go | 4 +- pkg/mcclient/modules/mod_metrics.go | 4 +- pkg/mcclient/modules/mod_metrictypes.go | 4 +- pkg/mcclient/modules/mod_monitor_metrics.go | 4 +- pkg/mcclient/modules/mod_monitorinputs.go | 4 +- pkg/mcclient/modules/mod_monitortemplates.go | 6 +- pkg/mcclient/modules/mod_monitortypes.go | 4 +- pkg/mcclient/modules/mod_natdtables.go | 4 +- pkg/mcclient/modules/mod_natgateways.go | 4 +- pkg/mcclient/modules/mod_natstables.go | 4 +- .../modules/mod_networkinterfacenetworks.go | 4 +- pkg/mcclient/modules/mod_networkinterfaces.go | 4 +- pkg/mcclient/modules/mod_networks.go | 4 +- pkg/mcclient/modules/mod_nodealert.go | 4 +- pkg/mcclient/modules/mod_nodes.go | 17 +- pkg/mcclient/modules/mod_notices.go | 6 +- pkg/mcclient/modules/mod_notify.go | 4 +- pkg/mcclient/modules/mod_operations.go | 4 +- pkg/mcclient/modules/mod_parameters.go | 3 +- pkg/mcclient/modules/mod_performances.go | 5 +- pkg/mcclient/modules/mod_policies.go | 3 +- pkg/mcclient/modules/mod_price_infos.go | 4 +- pkg/mcclient/modules/mod_processes.go | 4 +- pkg/mcclient/modules/mod_processlogs.go | 4 +- .../modules/mod_project_admin_candidates.go | 4 +- pkg/mcclient/modules/mod_project_admins.go | 4 +- pkg/mcclient/modules/mod_projecthosts.go | 4 +- pkg/mcclient/modules/mod_projects.go | 21 +- pkg/mcclient/modules/mod_quotas.go | 15 +- pkg/mcclient/modules/mod_rates.go | 4 +- pkg/mcclient/modules/mod_recipients.go | 5 +- pkg/mcclient/modules/mod_regions.go | 4 +- pkg/mcclient/modules/mod_registers.go | 4 +- pkg/mcclient/modules/mod_res_results.go | 4 +- pkg/mcclient/modules/mod_res_tag_details.go | 4 +- pkg/mcclient/modules/mod_reservedips.go | 3 +- pkg/mcclient/modules/mod_resource_details.go | 4 +- pkg/mcclient/modules/mod_resource_fees.go | 4 +- pkg/mcclient/modules/mod_roleassignments.go | 3 +- pkg/mcclient/modules/mod_roles.go | 13 +- pkg/mcclient/modules/mod_routetables.go | 4 +- pkg/mcclient/modules/mod_schedpolicies.go | 4 +- pkg/mcclient/modules/mod_schedtaghosts.go | 10 +- pkg/mcclient/modules/mod_schedtags.go | 3 +- pkg/mcclient/modules/mod_scheduler.go | 23 +- pkg/mcclient/modules/mod_secgrouprules.go | 4 +- pkg/mcclient/modules/mod_secgroups.go | 4 +- pkg/mcclient/modules/mod_serverdisks.go | 4 +- pkg/mcclient/modules/mod_servernetworks.go | 4 +- pkg/mcclient/modules/mod_servers.go | 3 +- .../modules/mod_service_name_suggestions.go | 4 +- pkg/mcclient/modules/mod_servicehosts.go | 5 +- pkg/mcclient/modules/mod_services.go | 6 +- pkg/mcclient/modules/mod_servicetrees.go | 4 +- pkg/mcclient/modules/mod_skus.go | 11 +- pkg/mcclient/modules/mod_sms_configs.go | 4 +- pkg/mcclient/modules/mod_snapshotpolicy.go | 4 +- .../modules/mod_snapshotpolicydisk.go | 6 +- pkg/mcclient/modules/mod_snapshots.go | 4 +- pkg/mcclient/modules/mod_specs.go | 9 +- pkg/mcclient/modules/mod_sshkeypairs.go | 9 +- pkg/mcclient/modules/mod_stastics.go | 9 +- .../modules/mod_storagecachedimages.go | 4 +- pkg/mcclient/modules/mod_storagecaches.go | 4 +- pkg/mcclient/modules/mod_storages.go | 4 +- pkg/mcclient/modules/mod_tasks.go | 5 +- pkg/mcclient/modules/mod_tenants.go | 4 +- pkg/mcclient/modules/mod_treenodes.go | 5 +- .../modules/mod_underutilizedinstances.go | 4 +- pkg/mcclient/modules/mod_unused_resources.go | 4 +- pkg/mcclient/modules/mod_updates.go | 3 +- pkg/mcclient/modules/mod_usages.go | 5 +- pkg/mcclient/modules/mod_users.go | 21 +- pkg/mcclient/modules/mod_vcenters.go | 4 +- pkg/mcclient/modules/mod_verification.go | 4 +- pkg/mcclient/modules/mod_versions.go | 4 +- pkg/mcclient/modules/mod_vncproxy.go | 5 +- pkg/mcclient/modules/mod_vpcs.go | 4 +- pkg/mcclient/modules/mod_webconsole.go | 9 +- pkg/mcclient/modules/mod_websockets.go | 4 +- pkg/mcclient/modules/mod_wires.go | 4 +- pkg/mcclient/modules/mod_workers.go | 7 +- pkg/mcclient/modules/mod_zones.go | 4 +- .../modules/notify/mod_notification.go | 3 +- pkg/mcclient/modules/pprof.go | 12 +- pkg/mcclient/modules/projectresources.go | 15 +- pkg/mcclient/modules/register.go | 25 +- pkg/mcclient/modules/version.go | 15 +- pkg/multicloud/loader/doc.go | 1 + pkg/multicloud/objectstore/ceph/doc.go | 1 + .../objectstore/ceph/provider/doc.go | 1 + pkg/notify/handlers.go | 10 +- pkg/s3gateway/handlers/doc.go | 1 + pkg/s3gateway/models/doc.go | 1 + pkg/s3gateway/session/doc.go | 1 + pkg/util/printutils/printgetter.go | 5 +- pkg/util/printutils/printjson.go | 10 +- pkg/util/printutils/printobj.go | 5 +- pkg/util/s3auth/doc.go | 1 + pkg/util/validate/doc.go | 1 + 250 files changed, 1103 insertions(+), 684 deletions(-) rename pkg/mcclient/{modules => modulebase}/base.go (99%) create mode 100644 pkg/mcclient/modulebase/doc.go rename pkg/mcclient/{modules => modulebase}/filter.go (98%) rename pkg/mcclient/{modules => modulebase}/joint.go (99%) rename pkg/mcclient/{modules => modulebase}/modules.go (98%) create mode 100644 pkg/mcclient/modulebase/pprof.go create mode 100644 pkg/mcclient/modulebase/projectresources.go rename pkg/mcclient/{modules => modulebase}/resource.go (99%) create mode 100644 pkg/mcclient/modulebase/utils.go create mode 100644 pkg/mcclient/modulebase/version.go create mode 100644 pkg/multicloud/loader/doc.go create mode 100644 pkg/multicloud/objectstore/ceph/doc.go create mode 100644 pkg/multicloud/objectstore/ceph/provider/doc.go create mode 100644 pkg/s3gateway/handlers/doc.go create mode 100644 pkg/s3gateway/models/doc.go create mode 100644 pkg/s3gateway/session/doc.go create mode 100644 pkg/util/s3auth/doc.go create mode 100644 pkg/util/validate/doc.go diff --git a/cmd/climc/shell/baremetalnetworks.go b/cmd/climc/shell/baremetalnetworks.go index 601c082d05..799adb836c 100644 --- a/cmd/climc/shell/baremetalnetworks.go +++ b/cmd/climc/shell/baremetalnetworks.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -41,7 +42,7 @@ func init() { if len(args.Network) > 0 { params.Add(jsonutils.NewString(args.Network), "network_id") } - var result *modules.ListResult + var result *modulebase.ListResult var err error if len(args.Host) > 0 { result, err = modules.Baremetalnetworks.ListDescendent(s, args.Host, params) diff --git a/cmd/climc/shell/baremetalstorages.go b/cmd/climc/shell/baremetalstorages.go index 6f364e8156..e9143cce35 100644 --- a/cmd/climc/shell/baremetalstorages.go +++ b/cmd/climc/shell/baremetalstorages.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -37,7 +38,7 @@ func init() { } } - var result *modules.ListResult + var result *modulebase.ListResult var err error if len(args.Host) > 0 { result, err = modules.Baremetalstorages.ListDescendent(s, args.Host, params) diff --git a/cmd/climc/shell/buckets.go b/cmd/climc/shell/buckets.go index 060fd151e3..f17506d49f 100644 --- a/cmd/climc/shell/buckets.go +++ b/cmd/climc/shell/buckets.go @@ -20,6 +20,7 @@ import ( "os" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -119,7 +120,7 @@ func init() { } arrays, _ := result.GetArray("objects") - listResult := modules.ListResult{Data: arrays} + listResult := modulebase.ListResult{Data: arrays} printList(&listResult, []string{}) return nil }) diff --git a/cmd/climc/shell/cloudproviderregions.go b/cmd/climc/shell/cloudproviderregions.go index 10eb540989..b52003ec16 100644 --- a/cmd/climc/shell/cloudproviderregions.go +++ b/cmd/climc/shell/cloudproviderregions.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -37,7 +38,7 @@ func init() { } } - var result *modules.ListResult + var result *modulebase.ListResult var err error if len(args.Manager) > 0 { result, err = modules.CloudproviderregionManager.ListDescendent(s, args.Manager, params) diff --git a/cmd/climc/shell/cloudregions.go b/cmd/climc/shell/cloudregions.go index 8bea6e47a2..3441ee76df 100644 --- a/cmd/climc/shell/cloudregions.go +++ b/cmd/climc/shell/cloudregions.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) @@ -68,7 +69,7 @@ func init() { if err != nil { return err } - listResult := modules.ListResult{} + listResult := modulebase.ListResult{} listResult.Data, err = results.GetArray() if err != nil { return err @@ -86,7 +87,7 @@ func init() { if err != nil { return err } - listResult := modules.ListResult{} + listResult := modulebase.ListResult{} listResult.Data, err = results.GetArray() if err != nil { return err diff --git a/cmd/climc/shell/contacts.go b/cmd/climc/shell/contacts.go index 79a2a79e44..c7c957be2e 100644 --- a/cmd/climc/shell/contacts.go +++ b/cmd/climc/shell/contacts.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) @@ -145,7 +146,7 @@ func init() { return err } - printList(&modules.ListResult{Data: contacts}, nil) + printList(&modulebase.ListResult{Data: contacts}, nil) return nil }) diff --git a/cmd/climc/shell/credentials.go b/cmd/climc/shell/credentials.go index 029d182630..1ffad42c77 100644 --- a/cmd/climc/shell/credentials.go +++ b/cmd/climc/shell/credentials.go @@ -16,11 +16,12 @@ package shell import ( "fmt" + "time" "yunion.io/x/jsonutils" - "time" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" ) @@ -204,7 +205,7 @@ func init() { if err != nil { return err } - result := modules.ListResult{} + result := modulebase.ListResult{} result.Data = make([]jsonutils.JSONObject, len(secrets)) for i := range secrets { result.Data[i] = jsonutils.Marshal(secrets[i]) diff --git a/cmd/climc/shell/dbinstances.go b/cmd/climc/shell/dbinstances.go index bda7fa51d5..3c68fd0014 100644 --- a/cmd/climc/shell/dbinstances.go +++ b/cmd/climc/shell/dbinstances.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) @@ -50,7 +51,7 @@ func init() { return err } - var result *modules.ListResult + var result *modulebase.ListResult if len(opts.DBInstance) > 0 { result, err = modules.DBInstanceNetworks.ListDescendent(s, opts.DBInstance, params) } else if len(opts.Network) > 0 { diff --git a/cmd/climc/shell/events.go b/cmd/climc/shell/events.go index 804577c45d..e6e1e8338c 100644 --- a/cmd/climc/shell/events.go +++ b/cmd/climc/shell/events.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" ) @@ -66,7 +67,7 @@ func doIdentityEventList(s *mcclient.ClientSession, args *EventListOptions) erro return doEventList(modules.IdentityLogs, s, args) } -func doEventList(man modules.ResourceManager, s *mcclient.ClientSession, args *EventListOptions) error { +func doEventList(man modulebase.ResourceManager, s *mcclient.ClientSession, args *EventListOptions) error { params := jsonutils.NewDict() if len(args.Type) > 0 { params.Add(jsonutils.NewStringArray(args.Type), "obj_type") diff --git a/cmd/climc/shell/hostcachedimages.go b/cmd/climc/shell/hostcachedimages.go index 5b086c3e3f..86e70addfe 100644 --- a/cmd/climc/shell/hostcachedimages.go +++ b/cmd/climc/shell/hostcachedimages.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) @@ -38,7 +39,7 @@ func init() { } } - var result *modules.ListResult + var result *modulebase.ListResult var err error if len(args.Host) > 0 { result, err = modules.Hostcachedimages.ListDescendent(s, args.Host, params) diff --git a/cmd/climc/shell/hoststorages.go b/cmd/climc/shell/hoststorages.go index a0f0e0c08d..d8a4f9b0b7 100644 --- a/cmd/climc/shell/hoststorages.go +++ b/cmd/climc/shell/hoststorages.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -38,7 +39,7 @@ func init() { } } - var result *modules.ListResult + var result *modulebase.ListResult var err error // if len(args.Storage) > 0 { // params.Add(jsonutils.NewString(args.Storage), "storage") diff --git a/cmd/climc/shell/hostwires.go b/cmd/climc/shell/hostwires.go index a8fdc61573..827290503e 100644 --- a/cmd/climc/shell/hostwires.go +++ b/cmd/climc/shell/hostwires.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) @@ -38,7 +39,7 @@ func init() { } } - var result *modules.ListResult + var result *modulebase.ListResult var err error if len(args.Host) > 0 { result, err = modules.Hostwires.ListDescendent(s, args.Host, params) diff --git a/cmd/climc/shell/images.go b/cmd/climc/shell/images.go index c331643912..a55d62419b 100644 --- a/cmd/climc/shell/images.go +++ b/cmd/climc/shell/images.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) @@ -445,7 +446,7 @@ func init() { continue } arrays, _ := result.(*jsonutils.JSONArray).GetArray() - listResult := modules.ListResult{Data: arrays} + listResult := modulebase.ListResult{Data: arrays} printList(&listResult, []string{}) } return nil diff --git a/cmd/climc/shell/k8s/k8s.go b/cmd/climc/shell/k8s/k8s.go index 707d48385b..cf30d43921 100644 --- a/cmd/climc/shell/k8s/k8s.go +++ b/cmd/climc/shell/k8s/k8s.go @@ -21,7 +21,7 @@ import ( "yunion.io/x/onecloud/cmd/climc/shell" "yunion.io/x/onecloud/pkg/mcclient" - "yunion.io/x/onecloud/pkg/mcclient/modules" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" o "yunion.io/x/onecloud/pkg/mcclient/options/k8s" "yunion.io/x/onecloud/pkg/util/printutils" @@ -77,8 +77,8 @@ func kubeResourceCmdN(prefix, suffix string) string { return fmt.Sprintf("kube-%s-%s", prefix, suffix) } -func clusterContext(clusterId string) modules.ManagerContext { - return modules.ManagerContext{ +func clusterContext(clusterId string) modulebase.ManagerContext { + return modulebase.ManagerContext{ InstanceManager: k8s.Clusters, InstanceId: clusterId, } @@ -129,7 +129,7 @@ func (c *ShellCommands) AddR(rs ...*Cmd) *ShellCommands { return c } -func initK8sClusterResource(kind string, manager modules.Manager) *ShellCommands { +func initK8sClusterResource(kind string, manager modulebase.Manager) *ShellCommands { cmdN := NewCmdNameFactory(kind) return NewShellCommands(cmdN.Do).AddR( NewK8sResourceListCmd(cmdN, manager), @@ -138,7 +138,7 @@ func initK8sClusterResource(kind string, manager modules.Manager) *ShellCommands ) } -func NewK8sResourceListCmd(cmdN CmdNameFactory, manager modules.Manager) *Cmd { +func NewK8sResourceListCmd(cmdN CmdNameFactory, manager modulebase.Manager) *Cmd { return NewCommand( &o.ResourceListOptions{}, cmdN.Do("list"), @@ -168,7 +168,7 @@ func NewCmdNameFactory(kind string) CmdNameFactory { } } -func NewK8sNsResourceListCmd(cmdN CmdNameFactory, manager modules.Manager) *Cmd { +func NewK8sNsResourceListCmd(cmdN CmdNameFactory, manager modulebase.Manager) *Cmd { return NewCommand( &o.NamespaceResourceListOptions{}, cmdN.Do("list"), @@ -184,7 +184,7 @@ func NewK8sNsResourceListCmd(cmdN CmdNameFactory, manager modules.Manager) *Cmd ) } -func NewK8sResourceGetCmd(cmdN CmdNameFactory, manager modules.Manager) *Cmd { +func NewK8sResourceGetCmd(cmdN CmdNameFactory, manager modulebase.Manager) *Cmd { return NewCommand( &o.ResourceGetOptions{}, cmdN.Do("show"), @@ -200,7 +200,7 @@ func NewK8sResourceGetCmd(cmdN CmdNameFactory, manager modules.Manager) *Cmd { ) } -func NewK8sNsResourceGetCmd(cmdN CmdNameFactory, manager modules.Manager) *Cmd { +func NewK8sNsResourceGetCmd(cmdN CmdNameFactory, manager modulebase.Manager) *Cmd { return NewCommand( &o.NamespaceResourceGetOptions{}, cmdN.Do("show"), @@ -216,7 +216,7 @@ func NewK8sNsResourceGetCmd(cmdN CmdNameFactory, manager modules.Manager) *Cmd { ) } -func NewK8sResourceDeleteCmd(cmdN CmdNameFactory, manager modules.Manager) *Cmd { +func NewK8sResourceDeleteCmd(cmdN CmdNameFactory, manager modulebase.Manager) *Cmd { return NewCommand( &o.ResourceDeleteOptions{}, cmdN.Do("delete"), @@ -229,7 +229,7 @@ func NewK8sResourceDeleteCmd(cmdN CmdNameFactory, manager modules.Manager) *Cmd ) } -func NewK8sNsResourceDeleteCmd(cmdN CmdNameFactory, manager modules.Manager) *Cmd { +func NewK8sNsResourceDeleteCmd(cmdN CmdNameFactory, manager modulebase.Manager) *Cmd { deleteCmd := NewCommand( &o.NamespaceResourceDeleteOptions{}, cmdN.Do("delete"), @@ -243,7 +243,7 @@ func NewK8sNsResourceDeleteCmd(cmdN CmdNameFactory, manager modules.Manager) *Cm return deleteCmd } -func initK8sNamespaceResource(kind string, manager modules.Manager) *ShellCommands { +func initK8sNamespaceResource(kind string, manager modulebase.Manager) *ShellCommands { cmdN := NewCmdNameFactory(kind) return NewShellCommands(cmdN.Do).AddR( NewK8sNsResourceListCmd(cmdN, manager), diff --git a/cmd/climc/shell/k8s/list.go b/cmd/climc/shell/k8s/list.go index 111e47a0c6..b6dcc5c717 100644 --- a/cmd/climc/shell/k8s/list.go +++ b/cmd/climc/shell/k8s/list.go @@ -20,12 +20,12 @@ import ( "strings" "github.com/gosuri/uitable" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/onecloud/pkg/mcclient" - "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" ) @@ -56,7 +56,7 @@ func getPrinterRowValues(printer k8s.ListPrinter, obj jsonutils.JSONObject, cols return ret } -func ListerTable(res *modules.ListResult, printer k8s.ListPrinter, s *mcclient.ClientSession) *uitable.Table { +func ListerTable(res *modulebase.ListResult, printer k8s.ListPrinter, s *mcclient.ClientSession) *uitable.Table { min := func(x, y int) int { if x < y { return x @@ -78,7 +78,7 @@ func ListerTable(res *modules.ListResult, printer k8s.ListPrinter, s *mcclient.C return table } -func PrintListResultTable(res *modules.ListResult, printer k8s.ListPrinter, s *mcclient.ClientSession) { +func PrintListResultTable(res *modulebase.ListResult, printer k8s.ListPrinter, s *mcclient.ClientSession) { fmt.Println(ListerTable(res, printer, s)) table := uitable.New() diff --git a/cmd/climc/shell/labels.go b/cmd/climc/shell/labels.go index 965b6ee0a8..3e632a3a5e 100644 --- a/cmd/climc/shell/labels.go +++ b/cmd/climc/shell/labels.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -33,7 +34,7 @@ func init() { Remark string `help:"Remark or description of the new label"` } R(&LabelCreateOptions{}, "label-create", "Create a label", func(s *mcclient.ClientSession, args *LabelCreateOptions) error { - mod, err := modules.GetModule(s, "labels") + mod, err := modulebase.GetModule(s, "labels") if err != nil { return err } diff --git a/cmd/climc/shell/loadbalanceracls.go b/cmd/climc/shell/loadbalanceracls.go index 1306ad9a53..ca5c684c68 100644 --- a/cmd/climc/shell/loadbalanceracls.go +++ b/cmd/climc/shell/loadbalanceracls.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -51,7 +52,7 @@ func init() { } printObject(jd) } - printLbAclList := func(list *modules.ListResult, columns []string) { + printLbAclList := func(list *modulebase.ListResult, columns []string) { data := list.Data for _, jsonObj := range data { jd := jsonObj.(*jsonutils.JSONDict) diff --git a/cmd/climc/shell/loadbalancercachedacls.go b/cmd/climc/shell/loadbalancercachedacls.go index 23e1e15c18..31c6f2eecc 100644 --- a/cmd/climc/shell/loadbalancercachedacls.go +++ b/cmd/climc/shell/loadbalancercachedacls.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -51,7 +52,7 @@ func init() { } printObject(jd) } - printLbAclList := func(list *modules.ListResult, columns []string) { + printLbAclList := func(list *modulebase.ListResult, columns []string) { data := list.Data for _, jsonObj := range data { jd := jsonObj.(*jsonutils.JSONDict) diff --git a/cmd/climc/shell/loadbalancernetworks.go b/cmd/climc/shell/loadbalancernetworks.go index 36b3ee3850..568d486b94 100644 --- a/cmd/climc/shell/loadbalancernetworks.go +++ b/cmd/climc/shell/loadbalancernetworks.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -42,7 +43,7 @@ func init() { if len(args.Ip) > 0 { params.Add(jsonutils.NewString(args.Ip), "ip_addr") } - var result *modules.ListResult + var result *modulebase.ListResult var err error if len(args.Loadbalancer) > 0 { result, err = modules.Loadbalancernetworks.ListDescendent(s, args.Loadbalancer, params) diff --git a/cmd/climc/shell/modules.go b/cmd/climc/shell/modules.go index 6c23a572d3..80986aa775 100644 --- a/cmd/climc/shell/modules.go +++ b/cmd/climc/shell/modules.go @@ -18,16 +18,16 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" - "yunion.io/x/onecloud/pkg/mcclient/modules" ) func init() { type ModuleListOptions struct { } R(&ModuleListOptions{}, "module-list", "List all modules", func(s *mcclient.ClientSession, args *ModuleListOptions) error { - modules, jointModules := modules.GetRegisterdModules() + modules, jointModules := modulebase.GetRegisterdModules() json := jsonutils.Marshal(modules) fmt.Println("Modules") fmt.Println(json.PrettyString()) diff --git a/cmd/climc/shell/networkinterfacenetworks.go b/cmd/climc/shell/networkinterfacenetworks.go index 6d47e87dc0..6ab2ca0305 100644 --- a/cmd/climc/shell/networkinterfacenetworks.go +++ b/cmd/climc/shell/networkinterfacenetworks.go @@ -17,6 +17,7 @@ package shell import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" ) @@ -28,7 +29,7 @@ func init() { } R(&NetworkinterfaceNetworkListOptions{}, "networkinterface-network-list", "List server network pairs", func(s *mcclient.ClientSession, args *NetworkinterfaceNetworkListOptions) error { params := jsonutils.NewDict() - var result *modules.ListResult + var result *modulebase.ListResult var err error if len(args.Networkinterface) > 0 { result, err = modules.Networkinterfacenetworks.ListDescendent(s, args.Networkinterface, params) diff --git a/cmd/climc/shell/networks.go b/cmd/climc/shell/networks.go index b101d686fd..bb7ae8841d 100644 --- a/cmd/climc/shell/networks.go +++ b/cmd/climc/shell/networks.go @@ -18,6 +18,7 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -43,7 +44,7 @@ func init() { if err != nil { return err } - var result *modules.ListResult + var result *modulebase.ListResult if len(opts.Wire) > 0 { result, err = modules.Networks.ListInContext(s, params, &modules.Wires, opts.Wire) } else { diff --git a/cmd/climc/shell/parameters.go b/cmd/climc/shell/parameters.go index e8c6441fc2..384195cb16 100644 --- a/cmd/climc/shell/parameters.go +++ b/cmd/climc/shell/parameters.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) @@ -41,7 +42,7 @@ func init() { params.Add(jsonutils.NewString(args.Name), "name") } - var result *modules.ListResult + var result *modulebase.ListResult if len(args.NamespaceId) > 0 { params.Add(jsonutils.NewString(args.NamespaceId), "namespace_id") params.Add(jsonutils.NewString("system"), "scope") diff --git a/cmd/climc/shell/projects.go b/cmd/climc/shell/projects.go index ab54db2721..9215f300f9 100644 --- a/cmd/climc/shell/projects.go +++ b/cmd/climc/shell/projects.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" api "yunion.io/x/onecloud/pkg/apis/identity" "yunion.io/x/onecloud/pkg/mcclient" @@ -175,7 +176,7 @@ func init() { if err != nil { return err } - _, err = modules.RolesV3.PutInContexts(s, rid, nil, []modules.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.UsersV3, InstanceId: uid}}) + _, err = modules.RolesV3.PutInContexts(s, rid, nil, []modulebase.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.UsersV3, InstanceId: uid}}) if err != nil { return err } @@ -195,7 +196,7 @@ func init() { return err } - _, err = modules.RolesV3.HeadInContexts(s, rid, nil, []modules.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.UsersV3, InstanceId: uid}}) + _, err = modules.RolesV3.HeadInContexts(s, rid, nil, []modulebase.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.UsersV3, InstanceId: uid}}) if err != nil { return err } @@ -214,7 +215,7 @@ func init() { if err != nil { return err } - _, err = modules.RolesV3.DeleteInContexts(s, rid, nil, []modules.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.UsersV3, InstanceId: uid}}) + _, err = modules.RolesV3.DeleteInContexts(s, rid, nil, []modulebase.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.UsersV3, InstanceId: uid}}) if err != nil { return err } @@ -236,7 +237,7 @@ func init() { if err != nil { return err } - result, err := modules.RolesV3.ListInContexts(s, nil, []modules.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.UsersV3, InstanceId: uid}}) + result, err := modules.RolesV3.ListInContexts(s, nil, []modulebase.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.UsersV3, InstanceId: uid}}) if err != nil { return err } @@ -265,7 +266,7 @@ func init() { if err != nil { return err } - _, err = modules.RolesV3.PutInContexts(s, rid, nil, []modules.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.Groups, InstanceId: gid}}) + _, err = modules.RolesV3.PutInContexts(s, rid, nil, []modulebase.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.Groups, InstanceId: gid}}) if err != nil { return err } @@ -284,7 +285,7 @@ func init() { if err != nil { return err } - _, err = modules.RolesV3.HeadInContexts(s, rid, nil, []modules.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.Groups, InstanceId: gid}}) + _, err = modules.RolesV3.HeadInContexts(s, rid, nil, []modulebase.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.Groups, InstanceId: gid}}) if err != nil { return err } @@ -303,7 +304,7 @@ func init() { if err != nil { return err } - _, err = modules.RolesV3.DeleteInContexts(s, rid, nil, []modules.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.Groups, InstanceId: gid}}) + _, err = modules.RolesV3.DeleteInContexts(s, rid, nil, []modulebase.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.Groups, InstanceId: gid}}) if err != nil { return err } @@ -324,7 +325,7 @@ func init() { if err != nil { return err } - result, err := modules.RolesV3.ListInContexts(s, nil, []modules.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.Groups, InstanceId: gid}}) + result, err := modules.RolesV3.ListInContexts(s, nil, []modulebase.ManagerContext{{InstanceManager: &modules.Projects, InstanceId: pid}, {InstanceManager: &modules.Groups, InstanceId: gid}}) if err != nil { return err } diff --git a/cmd/climc/shell/quotas.go b/cmd/climc/shell/quotas.go index ab79cdf8d2..0b680ecb24 100644 --- a/cmd/climc/shell/quotas.go +++ b/cmd/climc/shell/quotas.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -89,7 +90,7 @@ func init() { if e != nil { return e } - printList(modules.JSON2ListResult(result), nil) + printList(modulebase.JSON2ListResult(result), nil) return nil }) diff --git a/cmd/climc/shell/routetables.go b/cmd/climc/shell/routetables.go index 0edf019084..19940b5031 100644 --- a/cmd/climc/shell/routetables.go +++ b/cmd/climc/shell/routetables.go @@ -21,12 +21,13 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) func init() { - printRouteTableList := func(list *modules.ListResult, columns []string) { + printRouteTableList := func(list *modulebase.ListResult, columns []string) { data := list.Data for _, jsonObj := range data { jd := jsonObj.(*jsonutils.JSONDict) diff --git a/cmd/climc/shell/schedtagresources.go b/cmd/climc/shell/schedtagresources.go index 46c115ebd5..96bc7e29d8 100644 --- a/cmd/climc/shell/schedtagresources.go +++ b/cmd/climc/shell/schedtagresources.go @@ -18,15 +18,16 @@ import ( "fmt" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) type schedtagModelHelper struct { - managers []modules.JointResourceManager + managers []modulebase.JointResourceManager } -func newSchedtagModelHelper(mans ...modules.JointResourceManager) *schedtagModelHelper { +func newSchedtagModelHelper(mans ...modulebase.JointResourceManager) *schedtagModelHelper { return &schedtagModelHelper{managers: mans} } @@ -39,13 +40,13 @@ func (h *schedtagModelHelper) register() { } } -func (h *schedtagModelHelper) list(slave modules.Manager, kw string) { +func (h *schedtagModelHelper) list(slave modulebase.Manager, kw string) { R( &options.SchedtagModelListOptions{}, fmt.Sprintf("schedtag-%s-list", kw), fmt.Sprintf("List all scheduler tag and %s pairs", kw), func(s *mcclient.ClientSession, args *options.SchedtagModelListOptions) error { - mod, err := modules.GetJointModule2(s, &modules.Schedtags, slave) + mod, err := modulebase.GetJointModule2(s, &modules.Schedtags, slave) if err != nil { return err } @@ -53,7 +54,7 @@ func (h *schedtagModelHelper) list(slave modules.Manager, kw string) { if err != nil { return err } - var result *modules.ListResult + var result *modulebase.ListResult if len(args.Schedtag) > 0 { result, err = mod.ListDescendent(s, args.Schedtag, params) } else { @@ -68,7 +69,7 @@ func (h *schedtagModelHelper) list(slave modules.Manager, kw string) { ) } -func (h *schedtagModelHelper) add(man modules.JointResourceManager, kw string) { +func (h *schedtagModelHelper) add(man modulebase.JointResourceManager, kw string) { R( &options.SchedtagModelPairOptions{}, fmt.Sprintf("schedtag-%s-add", kw), @@ -83,7 +84,7 @@ func (h *schedtagModelHelper) add(man modules.JointResourceManager, kw string) { }) } -func (h *schedtagModelHelper) remove(man modules.JointResourceManager, kw string) { +func (h *schedtagModelHelper) remove(man modulebase.JointResourceManager, kw string) { R( &options.SchedtagModelPairOptions{}, fmt.Sprintf("schedtag-%s-remove", kw), @@ -98,7 +99,7 @@ func (h *schedtagModelHelper) remove(man modules.JointResourceManager, kw string }) } -func (h *schedtagModelHelper) setTags(man modules.JointResourceManager, kw string) { +func (h *schedtagModelHelper) setTags(man modulebase.JointResourceManager, kw string) { R( &options.SchedtagSetOptions{}, fmt.Sprintf("%s-set-schedtag", kw), diff --git a/cmd/climc/shell/schedulers.go b/cmd/climc/shell/schedulers.go index ffc1a4325c..3184cbe264 100644 --- a/cmd/climc/shell/schedulers.go +++ b/cmd/climc/shell/schedulers.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) @@ -39,7 +40,7 @@ func init() { if err != nil { return err } - printList(modules.JSON2ListResult(result), listFields) + printList(modulebase.JSON2ListResult(result), listFields) return nil }) @@ -86,7 +87,7 @@ func init() { if err != nil { return err } - printList(modules.JSON2ListResult(result), []string{ + printList(modulebase.JSON2ListResult(result), []string{ "id", "name", "host_type", "cpu(free/reserverd/total)", "mem(free/reserverd/total)", "storage(free/reserverd/total)", "status", "host_status", "enable_status"}) @@ -145,7 +146,7 @@ func init() { if err != nil { return err } - printList(modules.JSON2ListResult(result), []string{ + printList(modulebase.JSON2ListResult(result), []string{ "session_id", "time", "status", "consuming", }) return nil diff --git a/cmd/climc/shell/serverdisks.go b/cmd/climc/shell/serverdisks.go index df86079cad..d423702f8f 100644 --- a/cmd/climc/shell/serverdisks.go +++ b/cmd/climc/shell/serverdisks.go @@ -18,6 +18,7 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -44,7 +45,7 @@ func init() { if args.Index >= 0 { params.Add(jsonutils.NewInt(args.Index), "index") } - var result *modules.ListResult + var result *modulebase.ListResult var err error if len(args.Server) > 0 { result, err = modules.Serverdisks.ListDescendent(s, args.Server, params) diff --git a/cmd/climc/shell/servernetworks.go b/cmd/climc/shell/servernetworks.go index 616b5134cc..da0aae8f24 100644 --- a/cmd/climc/shell/servernetworks.go +++ b/cmd/climc/shell/servernetworks.go @@ -19,6 +19,7 @@ import ( "strconv" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/util/regutils" "yunion.io/x/onecloud/pkg/cloudcommon/cmdline" @@ -51,7 +52,7 @@ func init() { if len(args.Ip) > 0 { params.Add(jsonutils.NewString(args.Ip), "ip_addr") } - var result *modules.ListResult + var result *modulebase.ListResult var err error if len(args.Server) > 0 { result, err = modules.Servernetworks.ListDescendent(s, args.Server, params) diff --git a/cmd/climc/shell/servers.go b/cmd/climc/shell/servers.go index e3ba90e895..17df4be0fc 100644 --- a/cmd/climc/shell/servers.go +++ b/cmd/climc/shell/servers.go @@ -22,9 +22,10 @@ import ( "os" "path/filepath" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/cmdline" @@ -88,7 +89,7 @@ func init() { if err != nil { return err } - listResult := modules.ListResult{} + listResult := modulebase.ListResult{} listResult.Data = tasks printList(&listResult, nil) return nil @@ -174,7 +175,7 @@ func init() { if err != nil { return err } - printList(modules.JSON2ListResult(result), listFields) + printList(modulebase.JSON2ListResult(result), listFields) } else { taskNotify := options.BoolV(opts.TaskNotify) if taskNotify { @@ -982,7 +983,7 @@ func init() { if err != nil { return err } - listResult := modules.ListResult{} + listResult := modulebase.ListResult{} listResult.Data, _ = result.GetArray() printList(&listResult, nil) return nil diff --git a/cmd/climc/shell/specs.go b/cmd/climc/shell/specs.go index 6c5c2bf53d..caf5e2d3db 100644 --- a/cmd/climc/shell/specs.go +++ b/cmd/climc/shell/specs.go @@ -18,6 +18,7 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -121,7 +122,7 @@ func init() { if err != nil { return err } - data := &modules.ListResult{Data: hosts, Total: len(hosts)} + data := &modulebase.ListResult{Data: hosts, Total: len(hosts)} printList(data, []string{"ID", "Name", "Mem", "CPU", "Storage_Info"}) return nil }) @@ -159,7 +160,7 @@ func init() { if err != nil { return err } - data := &modules.ListResult{Data: devs, Total: len(devs)} + data := &modulebase.ListResult{Data: devs, Total: len(devs)} printList(data, []string{"ID", "Addr", "Dev_Type", "Model", "Vendor_Device_Id"}) return nil }) diff --git a/cmd/climc/shell/storagecachedimages.go b/cmd/climc/shell/storagecachedimages.go index 7bc28de2e6..77ce0cef78 100644 --- a/cmd/climc/shell/storagecachedimages.go +++ b/cmd/climc/shell/storagecachedimages.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -38,7 +39,7 @@ func init() { } } - var result *modules.ListResult + var result *modulebase.ListResult var err error if len(args.Storagecache) > 0 { result, err = modules.Storagecachedimages.ListDescendent(s, args.Storagecache, params) diff --git a/cmd/climc/shell/storages.go b/cmd/climc/shell/storages.go index aac7cb6bde..8cf6feeb20 100644 --- a/cmd/climc/shell/storages.go +++ b/cmd/climc/shell/storages.go @@ -18,6 +18,7 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -39,7 +40,7 @@ func init() { if err != nil { return err } - var result *modules.ListResult + var result *modulebase.ListResult if len(opts.Zone) > 0 { result, err = modules.Storages.ListInContext(s, params, &modules.Zones, opts.Zone) } else { diff --git a/cmd/climc/shell/users.go b/cmd/climc/shell/users.go index b0feccfcb0..c473c5c83c 100644 --- a/cmd/climc/shell/users.go +++ b/cmd/climc/shell/users.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" api "yunion.io/x/onecloud/pkg/apis/identity" "yunion.io/x/onecloud/pkg/mcclient" @@ -143,7 +144,7 @@ func init() { if err != nil { return err } - printList(modules.JSON2ListResult(result), nil) + printList(modulebase.JSON2ListResult(result), nil) return nil }) diff --git a/cmd/climc/shell/utils.go b/cmd/climc/shell/utils.go index 0c90112e72..bbd9c70742 100644 --- a/cmd/climc/shell/utils.go +++ b/cmd/climc/shell/utils.go @@ -22,7 +22,7 @@ import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modules" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/util/excelutils" "yunion.io/x/onecloud/pkg/util/printutils" ) @@ -41,7 +41,7 @@ func OutputFormat(s string) { outputFormat = s } -func printList(list *modules.ListResult, columns []string) { +func printList(list *modulebase.ListResult, columns []string) { printutils.PrintJSONList(list, columns) } @@ -95,11 +95,11 @@ func printObjectRecursiveEx(obj jsonutils.JSONObject, cb printutils.PrintJSONObj printutils.PrintJSONObjectRecursiveEx(obj, cb) } -func printBatchResults(results []modules.SubmitResult, columns []string) { +func printBatchResults(results []modulebase.SubmitResult, columns []string) { printutils.PrintJSONBatchResults(results, columns) } -func exportList(list *modules.ListResult, file string, exportKeys string, exportTexts string, columns []string) { +func exportList(list *modulebase.ListResult, file string, exportKeys string, exportTexts string, columns []string) { var keys []string var texts []string if len(exportKeys) > 0 { diff --git a/cmd/climc/shell/vpcs.go b/cmd/climc/shell/vpcs.go index 95c5a39398..155a60bfc2 100644 --- a/cmd/climc/shell/vpcs.go +++ b/cmd/climc/shell/vpcs.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) @@ -34,7 +35,7 @@ func init() { return err } - var result *modules.ListResult + var result *modulebase.ListResult if len(opts.Region) > 0 { result, err = modules.Vpcs.ListInContext(s, params, &modules.Cloudregions, opts.Region) } else { diff --git a/cmd/climc/shell/wires.go b/cmd/climc/shell/wires.go index 56fa2fc4a0..71654e8be1 100644 --- a/cmd/climc/shell/wires.go +++ b/cmd/climc/shell/wires.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -36,7 +37,7 @@ func init() { return err } - var result *modules.ListResult + var result *modulebase.ListResult if len(opts.Zone) > 0 { result, err = modules.Wires.ListInContext(s, params, &modules.Zones, opts.Zone) } else { diff --git a/cmd/climc/shell/zones.go b/cmd/climc/shell/zones.go index 99e7415874..a98463cb2b 100644 --- a/cmd/climc/shell/zones.go +++ b/cmd/climc/shell/zones.go @@ -16,6 +16,7 @@ package shell import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -35,7 +36,7 @@ func init() { if err != nil { return err } - var result *modules.ListResult + var result *modulebase.ListResult if len(args.Region) > 0 { result, err = modules.Zones.ListInContext(s, params, &modules.Cloudregions, args.Region) } else { diff --git a/pkg/apigateway/handler/auth.go b/pkg/apigateway/handler/auth.go index 2f692ef9ba..15288ef01a 100644 --- a/pkg/apigateway/handler/auth.go +++ b/pkg/apigateway/handler/auth.go @@ -24,6 +24,7 @@ import ( "github.com/pkg/errors" "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/apigateway/clientman" "yunion.io/x/onecloud/pkg/apigateway/constants" @@ -880,17 +881,17 @@ func (h *AuthHandlers) doDeletePolicies(ctx context.Context, w http.ResponseWrit return } idStrList := jsonutils.JSONArray2StringArray(idlist) - ret := make([]modules.SubmitResult, len(idStrList)) + ret := make([]modulebase.SubmitResult, len(idStrList)) for i := range idStrList { err := policytool.PolicyDelete(s, idStrList[i]) if err != nil { - ret[i] = modules.SubmitResult{ + ret[i] = modulebase.SubmitResult{ Status: 400, Id: idStrList[i], Data: jsonutils.NewString(err.Error()), } } else { - ret[i] = modules.SubmitResult{ + ret[i] = modulebase.SubmitResult{ Status: 200, Id: idStrList[i], Data: jsonutils.NewDict(), @@ -898,7 +899,7 @@ func (h *AuthHandlers) doDeletePolicies(ctx context.Context, w http.ResponseWrit } } w.WriteHeader(207) - appsrv.SendJSON(w, modules.SubmitResults2JSON(ret)) + appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret)) } /* diff --git a/pkg/apigateway/handler/csrfexempt.go b/pkg/apigateway/handler/csrfexempt.go index 157a37d542..c98e9d3840 100644 --- a/pkg/apigateway/handler/csrfexempt.go +++ b/pkg/apigateway/handler/csrfexempt.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/util/sets" "yunion.io/x/onecloud/pkg/appctx" @@ -28,7 +29,6 @@ import ( "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" - "yunion.io/x/onecloud/pkg/mcclient/modules" ) type CSRFResourceHandler struct { @@ -64,12 +64,12 @@ func getAdminSession(ctx context.Context, apiVer string, region string, w http.R return s } -func fetchEnv3Csrf(ctx context.Context, w http.ResponseWriter, r *http.Request) (modules.Manager, modules.Manager, modules.Manager, *mcclient.ClientSession, map[string]string, jsonutils.JSONObject, jsonutils.JSONObject) { +func fetchEnv3Csrf(ctx context.Context, w http.ResponseWriter, r *http.Request) (modulebase.Manager, modulebase.Manager, modulebase.Manager, *mcclient.ClientSession, map[string]string, jsonutils.JSONObject, jsonutils.JSONObject) { module, module2, session, params, query, body := fetchEnv2Csrf(ctx, w, r) if module == nil || module2 == nil { return nil, nil, nil, nil, nil, nil, nil } - module3, e := modules.GetModule(session, params[ResName3]) + module3, e := modulebase.GetModule(session, params[ResName3]) if e != nil || module == nil { httperrors.NotFoundError(w, fmt.Sprintf("resource %s not found", params[ResName3])) return nil, nil, nil, nil, nil, nil, nil @@ -77,12 +77,12 @@ func fetchEnv3Csrf(ctx context.Context, w http.ResponseWriter, r *http.Request) return module, module2, module3, session, params, query, body } -func fetchEnv2Csrf(ctx context.Context, w http.ResponseWriter, r *http.Request) (modules.Manager, modules.Manager, *mcclient.ClientSession, map[string]string, jsonutils.JSONObject, jsonutils.JSONObject) { +func fetchEnv2Csrf(ctx context.Context, w http.ResponseWriter, r *http.Request) (modulebase.Manager, modulebase.Manager, *mcclient.ClientSession, map[string]string, jsonutils.JSONObject, jsonutils.JSONObject) { module, session, params, query, body := fetchEnvCsrf(ctx, w, r) if module == nil { return nil, nil, nil, nil, nil, nil } - module2, e := modules.GetModule(session, params[ResName2]) + module2, e := modulebase.GetModule(session, params[ResName2]) if e != nil || module == nil { httperrors.NotFoundError(w, fmt.Sprintf("resource %s not found", params[ResName2])) return nil, nil, nil, nil, nil, nil @@ -90,9 +90,9 @@ func fetchEnv2Csrf(ctx context.Context, w http.ResponseWriter, r *http.Request) return module, module2, session, params, query, body } -func fetchEnvCsrf(ctx context.Context, w http.ResponseWriter, r *http.Request) (modules.Manager, *mcclient.ClientSession, map[string]string, jsonutils.JSONObject, jsonutils.JSONObject) { +func fetchEnvCsrf(ctx context.Context, w http.ResponseWriter, r *http.Request) (modulebase.Manager, *mcclient.ClientSession, map[string]string, jsonutils.JSONObject, jsonutils.JSONObject) { session, params, query, body := fetchEnvCsrf0(ctx, w, r) - module, e := modules.GetModule(session, params[ResName]) + module, e := modulebase.GetModule(session, params[ResName]) if e != nil || module == nil { httperrors.NotFoundError(w, fmt.Sprintf("resource %s not found", params[ResName])) return nil, nil, nil, nil, nil diff --git a/pkg/apigateway/handler/request.go b/pkg/apigateway/handler/request.go index b8c42228e9..36fe057155 100644 --- a/pkg/apigateway/handler/request.go +++ b/pkg/apigateway/handler/request.go @@ -19,6 +19,7 @@ import ( "net/http" "github.com/pkg/errors" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/jsonutils" "yunion.io/x/pkg/utils" @@ -28,7 +29,6 @@ import ( "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" - "yunion.io/x/onecloud/pkg/mcclient/modules" ) type Request struct { @@ -41,9 +41,9 @@ type Request struct { params map[string]string query jsonutils.JSONObject body jsonutils.JSONObject - mod1 modules.Manager - mod2 modules.Manager - mod3 modules.Manager + mod1 modulebase.Manager + mod2 modulebase.Manager + mod3 modulebase.Manager } func newRequest(ctx context.Context, w http.ResponseWriter, r *http.Request) *Request { @@ -127,21 +127,21 @@ func (req *Request) Spec() string { return req.params[Spec] } -func (req *Request) Mod1() modules.Manager { +func (req *Request) Mod1() modulebase.Manager { return req.mod1 } -func (req *Request) Mod2() modules.Manager { +func (req *Request) Mod2() modulebase.Manager { return req.mod2 } -func (req *Request) Mod3() modules.Manager { +func (req *Request) Mod3() modulebase.Manager { return req.mod3 } -func (req Request) findMod(resKey string) (modules.Manager, error) { +func (req Request) findMod(resKey string) (modulebase.Manager, error) { resName := req.params[resKey] - module, err := modules.GetModule(req.session, resName) + module, err := modulebase.GetModule(req.session, resName) if err != nil { return nil, errors.Errorf("found module by %s: %v", resName, err) } diff --git a/pkg/apigateway/handler/resource.go b/pkg/apigateway/handler/resource.go index d29f8c3d7c..80f235ed76 100644 --- a/pkg/apigateway/handler/resource.go +++ b/pkg/apigateway/handler/resource.go @@ -22,11 +22,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" - "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/util/excelutils" ) @@ -160,7 +160,7 @@ func (f *ResourceHandlers) listHandler(ctx context.Context, w http.ResponseWrite httperrors.GeneralServerError(w, req.Error()) return } - jmod, _ := modules.GetJointModule(req.Session(), req.ResName()) + jmod, _ := modulebase.GetJointModule(req.Session(), req.ResName()) if jmod != nil { f.doList(req.Session(), jmod, req.Query(), w, r) } else { @@ -180,14 +180,14 @@ func (f *ResourceHandlers) listHandler(ctx context.Context, w http.ResponseWrite querydict.Remove("id") } ret := req.Mod1().BatchGet(req.Session(), idlist, req.Query()) - appsrv.SendJSON(w, modules.ListResult2JSON(modules.SubmitResults2ListResult(ret))) + appsrv.SendJSON(w, modulebase.ListResult2JSON(modulebase.SubmitResults2ListResult(ret))) } else { f.doList(req.Session(), req.Mod1(), req.Query(), w, r) } } } -func (f *ResourceHandlers) doList(session *mcclient.ClientSession, module modules.BaseManagerInterface, query jsonutils.JSONObject, w http.ResponseWriter, r *http.Request) { +func (f *ResourceHandlers) doList(session *mcclient.ClientSession, module modulebase.BaseManagerInterface, query jsonutils.JSONObject, w http.ResponseWriter, r *http.Request) { var exportKeys []string var exportTexts []string exportFormat, _ := query.GetString("export") @@ -227,7 +227,7 @@ func (f *ResourceHandlers) doList(session *mcclient.ClientSession, module module w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"export-%s.xlsx\"", module.KeyString())) excelutils.Export(ret.Data, exportKeys, exportTexts, w) } else { - appsrv.SendJSON(w, modules.ListResult2JSON(ret)) + appsrv.SendJSON(w, modulebase.ListResult2JSON(ret)) } } @@ -262,10 +262,10 @@ func (f *ResourceHandlers) getSpecHandler(ctx context.Context, w http.ResponseWr module := req.Mod1() query := req.Query() - module2, e := modules.GetModule(session, req.Spec()) + module2, e := modulebase.GetModule(session, req.Spec()) if e == nil { // list in 1 context - jmod, e := modules.GetJointModule2(session, module, module2) - var ret *modules.ListResult + jmod, e := modulebase.GetJointModule2(session, module, module2) + var ret *modulebase.ListResult if e == nil { // joint module ret, e = jmod.ListDescendent(session, req.ResID(), query) } else { @@ -274,7 +274,7 @@ func (f *ResourceHandlers) getSpecHandler(ctx context.Context, w http.ResponseWr if e != nil { httperrors.GeneralServerError(w, e) } else { - appsrv.SendJSON(w, modules.ListResult2JSON(ret)) + appsrv.SendJSON(w, modulebase.ListResult2JSON(ret)) } } else { obj, e := module.GetSpecific(session, req.ResID(), req.Spec(), query) @@ -299,7 +299,7 @@ func (f *ResourceHandlers) getJointHandler(ctx context.Context, w http.ResponseW module2 := req.Mod2() session := req.Session() - jmod, e := modules.GetJointModule2(session, module, module2) + jmod, e := modulebase.GetJointModule2(session, module, module2) if e != nil { httperrors.NotFoundError(w, fmt.Sprintf("resource %s-%s not exist", req.ResName(), req.ResName2())) return @@ -325,11 +325,11 @@ func (f *ResourceHandlers) listInContextsHandler(ctx context.Context, w http.Res module3 := req.Mod3() session := req.Session() query := req.Query() - obj, e := module3.ListInContexts(session, query, []modules.ManagerContext{{module, req.ResID()}, {module2, req.ResID2()}}) + obj, e := module3.ListInContexts(session, query, []modulebase.ManagerContext{{module, req.ResID()}, {module2, req.ResID2()}}) if e != nil { httperrors.GeneralServerError(w, e) } else { - appsrv.SendJSON(w, modules.ListResult2JSON(obj)) + appsrv.SendJSON(w, modulebase.ListResult2JSON(obj)) } } @@ -355,7 +355,7 @@ func (f *ResourceHandlers) createHandler(ctx context.Context, w http.ResponseWri nbody := bodyDict.Copy("__count__") ret := module.BatchCreate(session, nbody, int(count)) w.WriteHeader(207) - appsrv.SendJSON(w, modules.SubmitResults2JSON(ret)) + appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret)) } } else { obj, e := module.Create(session, body) @@ -389,7 +389,7 @@ func (f *ResourceHandlers) batchPerformActionHandler(ctx context.Context, w http } else { ret := module.BatchPerformAction(session, jsonutils.JSONArray2StringArray(idlist), req.Action(), body) w.WriteHeader(207) - appsrv.SendJSON(w, modules.SubmitResults2JSON(ret)) + appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret)) } } @@ -410,21 +410,21 @@ func (f *ResourceHandlers) performActionHandler(ctx context.Context, w http.Resp var obj jsonutils.JSONObject var idlist []string - if module2, e := modules.GetModule(session, req.Action()); e == nil { - if jmod, e := modules.GetJointModule2(session, module, module2); e == nil { + if module2, e := modulebase.GetModule(session, req.Action()); e == nil { + if jmod, e := modulebase.GetJointModule2(session, module, module2); e == nil { if idlist = fetchIdList(query, w); idlist == nil { return } ret := jmod.BatchAttach(session, req.ResID(), idlist, body) w.WriteHeader(207) - appsrv.SendJSON(w, modules.SubmitResults2JSON(ret)) - } else if jmod, e := modules.GetJointModule2(session, module2, module); e == nil { + appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret)) + } else if jmod, e := modulebase.GetJointModule2(session, module2, module); e == nil { if idlist = fetchIdList(query, w); idlist == nil { return } ret := jmod.BatchAttach2(session, req.ResID(), idlist, body) w.WriteHeader(207) - appsrv.SendJSON(w, modules.SubmitResults2JSON(ret)) + appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret)) } else { if obj, e = module2.CreateInContext(session, body, module, req.ResID()); e != nil { httperrors.GeneralServerError(w, e) @@ -454,7 +454,7 @@ func (f *ResourceHandlers) attachHandler(ctx context.Context, w http.ResponseWri session := req.Session() body := req.Body() - jmod, e := modules.GetJointModule2(session, module, module2) + jmod, e := modulebase.GetJointModule2(session, module, module2) if e != nil { httperrors.NotFoundError(w, fmt.Sprintf("resource %s-%s not exists", req.ResName(), req.ResName2())) return @@ -487,7 +487,7 @@ func (f *ResourceHandlers) batchUpdateHandler(ctx context.Context, w http.Respon ret := module.BatchUpdate(req.Session(), idlist, body) w.WriteHeader(207) - appsrv.SendJSON(w, modules.SubmitResults2JSON(ret)) + appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret)) } // batchPatch @@ -510,7 +510,7 @@ func (f *ResourceHandlers) batchPatchHandler(ctx context.Context, w http.Respons ret := module.BatchPatch(req.Session(), idlist, body) w.WriteHeader(207) - appsrv.SendJSON(w, modules.SubmitResults2JSON(ret)) + appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret)) } // put single @@ -567,7 +567,7 @@ func (f *ResourceHandlers) updateJointHandler(ctx context.Context, w http.Respon module2 := req.Mod2() body := req.Body() - jmod, e := modules.GetJointModule2(session, module, module2) + jmod, e := modulebase.GetJointModule2(session, module, module2) var obj jsonutils.JSONObject if e == nil { // update joint obj, e = jmod.Update(session, req.ResID(), req.ResID2(), nil, body) @@ -592,7 +592,7 @@ func (f *ResourceHandlers) patchJointHandler(ctx context.Context, w http.Respons module2 := req.Mod2() body := req.Body() - jmod, e := modules.GetJointModule2(session, module, module2) + jmod, e := modulebase.GetJointModule2(session, module, module2) var obj jsonutils.JSONObject if e == nil { // update joint obj, e = jmod.Patch(session, req.ResID(), req.ResID2(), nil, body) @@ -623,14 +623,14 @@ func (f *ResourceHandlers) batchUpdateJointHandler(ctx context.Context, w http.R if idlist == nil { return } - jmod, e := modules.GetJointModule2(session, module, module2) + jmod, e := modulebase.GetJointModule2(session, module, module2) if e != nil { // update joint httperrors.GeneralServerError(w, e) return } ret := jmod.BatchUpdate(session, req.ResID(), idlist, query, body) w.WriteHeader(207) - appsrv.SendJSON(w, modules.SubmitResults2JSON(ret)) + appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret)) } // update in contexts @@ -642,7 +642,7 @@ func (f *ResourceHandlers) updateInContextsHandler(ctx context.Context, w http.R return } - obj, e := req.Mod3().PutInContexts(req.Session(), req.ResID3(), req.Body(), []modules.ManagerContext{{req.Mod1(), req.ResID()}, {req.Mod2(), req.ResID2()}}) + obj, e := req.Mod3().PutInContexts(req.Session(), req.ResID3(), req.Body(), []modulebase.ManagerContext{{req.Mod1(), req.ResID()}, {req.Mod2(), req.ResID2()}}) if e != nil { httperrors.GeneralServerError(w, e) } else { @@ -662,7 +662,7 @@ func (f *ResourceHandlers) patchInContextsHandler(ctx context.Context, w http.Re session := req.Session() body := req.Body() - obj, e := module3.PatchInContexts(session, req.ResID3(), body, []modules.ManagerContext{{module, req.ResID()}, {module2, req.ResID2()}}) + obj, e := module3.PatchInContexts(session, req.ResID3(), body, []modulebase.ManagerContext{{module, req.ResID()}, {module2, req.ResID2()}}) if e != nil { httperrors.GeneralServerError(w, e) } else { @@ -685,7 +685,7 @@ func (f *ResourceHandlers) batchDeleteHandler(ctx context.Context, w http.Respon } ret := req.Mod1().BatchDeleteWithParam(req.Session(), idlist, req.Query(), req.Body()) w.WriteHeader(207) - appsrv.SendJSON(w, modules.SubmitResults2JSON(ret)) + appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret)) } // delete single @@ -719,12 +719,12 @@ func (f *ResourceHandlers) batchDetachHandler(ctx context.Context, w http.Respon session := req.Session() module := req.Mod1() module2 := req.Mod2() - jmod, e := modules.GetJointModule2(session, module, module2) - var ret []modules.SubmitResult + jmod, e := modulebase.GetJointModule2(session, module, module2) + var ret []modulebase.SubmitResult if e == nil { ret = jmod.BatchDetach(session, req.ResID(), idlist) } else { - jmod, e := modules.GetJointModule2(session, module2, module) + jmod, e := modulebase.GetJointModule2(session, module2, module) if e == nil { ret = jmod.BatchDetach2(session, req.ResID(), idlist) } else { @@ -732,7 +732,7 @@ func (f *ResourceHandlers) batchDetachHandler(ctx context.Context, w http.Respon } } w.WriteHeader(207) - appsrv.SendJSON(w, modules.SubmitResults2JSON(ret)) + appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret)) } // detach joint @@ -748,7 +748,7 @@ func (f *ResourceHandlers) detachHandle(ctx context.Context, w http.ResponseWrit module := req.Mod1() module2 := req.Mod2() - jmod, e := modules.GetJointModule2(session, module, module2) + jmod, e := modulebase.GetJointModule2(session, module, module2) var obj jsonutils.JSONObject if e == nil { // joint detach obj, e = jmod.Detach(session, req.ResID(), req.ResID2(), nil) @@ -777,7 +777,7 @@ func (f *ResourceHandlers) deleteInContextsHandler(ctx context.Context, w http.R query := req.Query() body := req.Body() - obj, e := module3.DeleteInContextsWithParam(session, req.ResID3(), query, body, []modules.ManagerContext{{module, req.ResID()}, {module2, req.ResID2()}}) + obj, e := module3.DeleteInContextsWithParam(session, req.ResID3(), query, body, []modulebase.ManagerContext{{module, req.ResID()}, {module2, req.ResID2()}}) if e != nil { httperrors.GeneralServerError(w, e) } else { diff --git a/pkg/apigateway/handler/rpc.go b/pkg/apigateway/handler/rpc.go index 4c9c648cf2..eaf5d9f179 100644 --- a/pkg/apigateway/handler/rpc.go +++ b/pkg/apigateway/handler/rpc.go @@ -22,13 +22,13 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/utils" "yunion.io/x/onecloud/pkg/appctx" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient/auth" - "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/util/httputils" ) @@ -86,7 +86,7 @@ func rpcHandler(ctx context.Context, w http.ResponseWriter, req *http.Request) { pathParams := appctx.AppContextParams(ctx) s := auth.GetSession(ctx, token, FetchRegion(req), pathParams[""]) funcname := verb + utils.Kebab2Camel(callName, "-") - mod, e := modules.GetModule(s, resType) + mod, e := modulebase.GetModule(s, resType) if e != nil || mod == nil { if e != nil { log.Debugf("module %s not found %s", resType, e) diff --git a/pkg/apigateway/service/service.go b/pkg/apigateway/service/service.go index 1fda2e1829..4c00661767 100644 --- a/pkg/apigateway/service/service.go +++ b/pkg/apigateway/service/service.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/apigateway/app" "yunion.io/x/onecloud/pkg/apigateway/clientman" @@ -28,7 +29,6 @@ import ( app_common "yunion.io/x/onecloud/pkg/cloudcommon/app" common_options "yunion.io/x/onecloud/pkg/cloudcommon/options" "yunion.io/x/onecloud/pkg/mcclient" - "yunion.io/x/onecloud/pkg/mcclient/modules" ) func StartService() { @@ -51,7 +51,7 @@ func StartService() { serviceApp := app.NewApp(app_common.InitApp(baseOpts, false)) serviceApp.InitHandlers().Bind() - mods, jmods := modules.GetRegisterdModules() + mods, jmods := modulebase.GetRegisterdModules() log.Infof("Modules: %s", jsonutils.Marshal(mods).PrettyString()) log.Infof("Modules: %s", jsonutils.Marshal(jmods).PrettyString()) diff --git a/pkg/appsrv/dispatcher/dispatcher.go b/pkg/appsrv/dispatcher/dispatcher.go index f2873d7a12..7dc31ca782 100644 --- a/pkg/appsrv/dispatcher/dispatcher.go +++ b/pkg/appsrv/dispatcher/dispatcher.go @@ -18,16 +18,16 @@ import ( "context" "fmt" "net/http" + "strings" "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/utils" - "strings" "yunion.io/x/onecloud/pkg/appctx" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/httperrors" - "yunion.io/x/onecloud/pkg/mcclient/modules" ) func AddModelDispatcher(prefix string, app *appsrv.Application, manager IModelDispatchHandler) { @@ -206,7 +206,7 @@ func handleList(ctx context.Context, w http.ResponseWriter, manager IModelDispat httperrors.GeneralServerError(w, err) return } - appsrv.SendJSON(w, modules.ListResult2JSONWithKey(listResult, manager.KeywordPlural())) + appsrv.SendJSON(w, modulebase.ListResult2JSONWithKey(listResult, manager.KeywordPlural())) } func fetchContextIds(segs []string, params map[string]string) ([]SResourceContext, []string) { diff --git a/pkg/appsrv/dispatcher/handlers.go b/pkg/appsrv/dispatcher/handlers.go index 15ffe336b8..e1aa810e6d 100644 --- a/pkg/appsrv/dispatcher/handlers.go +++ b/pkg/appsrv/dispatcher/handlers.go @@ -19,9 +19,9 @@ import ( "net/http" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/appsrv" - "yunion.io/x/onecloud/pkg/mcclient/modules" ) type IMiddlewareFilter interface { @@ -40,12 +40,12 @@ type IModelDispatchHandler interface { KeywordPlural() string ContextKeywordPlurals() [][]string - List(ctx context.Context, query jsonutils.JSONObject, ctxIds []SResourceContext) (*modules.ListResult, error) + List(ctx context.Context, query jsonutils.JSONObject, ctxIds []SResourceContext) (*modulebase.ListResult, error) Get(ctx context.Context, idstr string, query jsonutils.JSONObject, isHead bool) (jsonutils.JSONObject, error) GetSpecific(ctx context.Context, idstr string, spec string, query jsonutils.JSONObject) (jsonutils.JSONObject, error) Create(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject, ctxIds []SResourceContext) (jsonutils.JSONObject, error) - BatchCreate(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject, count int, ctxIds []SResourceContext) ([]modules.SubmitResult, error) + BatchCreate(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject, count int, ctxIds []SResourceContext) ([]modulebase.SubmitResult, error) PerformClassAction(ctx context.Context, action string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) PerformAction(ctx context.Context, idstr string, action string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) @@ -71,9 +71,9 @@ type IJointModelDispatchHandler interface { MasterKeywordPlural() string SlaveKeywordPlural() string - List(ctx context.Context, query jsonutils.JSONObject, ctxIds []SResourceContext) (*modules.ListResult, error) - ListMasterDescendent(ctx context.Context, idStr string, query jsonutils.JSONObject) (*modules.ListResult, error) - ListSlaveDescendent(ctx context.Context, idStr string, query jsonutils.JSONObject) (*modules.ListResult, error) + List(ctx context.Context, query jsonutils.JSONObject, ctxIds []SResourceContext) (*modulebase.ListResult, error) + ListMasterDescendent(ctx context.Context, idStr string, query jsonutils.JSONObject) (*modulebase.ListResult, error) + ListSlaveDescendent(ctx context.Context, idStr string, query jsonutils.JSONObject) (*modulebase.ListResult, error) Get(ctx context.Context, id1 string, id2 string, query jsonutils.JSONObject) (jsonutils.JSONObject, error) Attach(ctx context.Context, id1 string, id2 string, query jsonutils.JSONObject, body jsonutils.JSONObject) (jsonutils.JSONObject, error) Update(ctx context.Context, id1 string, id2 string, query jsonutils.JSONObject, body jsonutils.JSONObject) (jsonutils.JSONObject, error) diff --git a/pkg/appsrv/dispatcher/jointdispatcher.go b/pkg/appsrv/dispatcher/jointdispatcher.go index 962cd32d5b..dfcdba223a 100644 --- a/pkg/appsrv/dispatcher/jointdispatcher.go +++ b/pkg/appsrv/dispatcher/jointdispatcher.go @@ -18,13 +18,14 @@ import ( "context" "fmt" "net/http" + "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/appctx" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/httperrors" - "yunion.io/x/onecloud/pkg/mcclient/modules" ) func AddJointModelDispatcher(prefix string, app *appsrv.Application, manager IJointModelDispatchHandler) { @@ -120,12 +121,12 @@ func jointListHandler(ctx context.Context, w http.ResponseWriter, r *http.Reques httperrors.GeneralServerError(w, err) return } - appsrv.SendJSON(w, modules.ListResult2JSONWithKey(listResult, manager.KeywordPlural())) + appsrv.SendJSON(w, modulebase.ListResult2JSONWithKey(listResult, manager.KeywordPlural())) } func jointListDescendentHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) { manager, params, query, _ := fetchJointEnv(ctx, w, r) - var listResult *modules.ListResult + var listResult *modulebase.ListResult var err error if _, ok := params[""]; ok { listResult, err = manager.ListMasterDescendent(ctx, params[""], mergeQueryParams(params, query, "")) @@ -136,7 +137,7 @@ func jointListDescendentHandler(ctx context.Context, w http.ResponseWriter, r *h httperrors.GeneralServerError(w, err) return } - appsrv.SendJSON(w, modules.ListResult2JSONWithKey(listResult, manager.KeywordPlural())) + appsrv.SendJSON(w, modulebase.ListResult2JSONWithKey(listResult, manager.KeywordPlural())) } func jointGetHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) { diff --git a/pkg/baremetal/pxe/dhcp.go b/pkg/baremetal/pxe/dhcp.go index c13e9adad8..5e164f4553 100644 --- a/pkg/baremetal/pxe/dhcp.go +++ b/pkg/baremetal/pxe/dhcp.go @@ -27,6 +27,7 @@ import ( o "yunion.io/x/onecloud/pkg/baremetal/options" "yunion.io/x/onecloud/pkg/cloudcommon/types" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/util/dhcp" ) @@ -236,7 +237,7 @@ func (req *dhcpRequest) findNetworkConf(session *mcclient.ClientSession, filterU return &network, err } -func (req *dhcpRequest) findBaremetalsOfAnyMac(session *mcclient.ClientSession, isBaremetal bool) (*modules.ListResult, error) { +func (req *dhcpRequest) findBaremetalsOfAnyMac(session *mcclient.ClientSession, isBaremetal bool) (*modulebase.ListResult, error) { params := jsonutils.NewDict() params.Add(jsonutils.NewString(req.ClientMac.String()), "any_mac") if isBaremetal { diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index eeb1b4cf3b..8d08a0c3b5 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -37,7 +37,7 @@ import ( "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" - "yunion.io/x/onecloud/pkg/mcclient/modules" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/util/httputils" "yunion.io/x/onecloud/pkg/util/rbacutils" "yunion.io/x/onecloud/pkg/util/stringutils2" @@ -440,7 +440,7 @@ func fetchContextObject(manager IModelManager, ctx context.Context, userCred mcc return nil, httperrors.NewInternalServerError("No such context %s(%s)", ctxId.Type, ctxId.Id) } -func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, ctxIds []dispatcher.SResourceContext) (*modules.ListResult, error) { +func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, ctxIds []dispatcher.SResourceContext) (*modulebase.ListResult, error) { var err error var maxLimit int64 = 2048 limit, _ := query.Int("limit") @@ -479,7 +479,7 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok } // log.Debugf("total count %d", totalCnt) if totalCnt == 0 { - emptyList := modules.ListResult{Data: []jsonutils.JSONObject{}} + emptyList := modulebase.ListResult{Data: []jsonutils.JSONObject{}} return &emptyList, nil } } else { @@ -578,7 +578,7 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok } retList = retList[:limit] } - retResult := modules.ListResult{ + retResult := modulebase.ListResult{ Data: retList, Limit: int(limit), NextMarker: nextMarker, MarkerField: pagingConf.MarkerField, @@ -627,7 +627,7 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok return calculateListResult(retList, int64(totalCnt), limit, offset, paginate), nil } -func calculateListResult(data []jsonutils.JSONObject, total, limit, offset int64, paginate bool) *modules.ListResult { +func calculateListResult(data []jsonutils.JSONObject, total, limit, offset int64, paginate bool) *modulebase.ListResult { if paginate { // do offset first if offset > 0 { @@ -643,12 +643,12 @@ func calculateListResult(data []jsonutils.JSONObject, total, limit, offset int64 } } - retResult := modules.ListResult{Data: data, Total: int(total), Limit: int(limit), Offset: int(offset)} + retResult := modulebase.ListResult{Data: data, Total: int(total), Limit: int(limit), Offset: int(offset)} return &retResult } -func (dispatcher *DBModelDispatcher) List(ctx context.Context, query jsonutils.JSONObject, ctxIds []dispatcher.SResourceContext) (*modules.ListResult, error) { +func (dispatcher *DBModelDispatcher) List(ctx context.Context, query jsonutils.JSONObject, ctxIds []dispatcher.SResourceContext) (*modulebase.ListResult, error) { userCred := fetchUserCredential(ctx) items, err := ListItems(dispatcher.modelManager, ctx, userCred, query, ctxIds) @@ -1106,7 +1106,7 @@ func expandMultiCreateParams(data jsonutils.JSONObject, count int) ([]jsonutils. return ret, nil } -func (dispatcher *DBModelDispatcher) BatchCreate(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject, count int, ctxIds []dispatcher.SResourceContext) ([]modules.SubmitResult, error) { +func (dispatcher *DBModelDispatcher) BatchCreate(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject, count int, ctxIds []dispatcher.SResourceContext) ([]modulebase.SubmitResult, error) { userCred := fetchUserCredential(ctx) manager := dispatcher.modelManager @@ -1163,10 +1163,10 @@ func (dispatcher *DBModelDispatcher) BatchCreate(ctx context.Context, query json if err != nil { return nil, err } - results := make([]modules.SubmitResult, count) + results := make([]modulebase.SubmitResult, count) models := make([]IModel, 0) for i, res := range createResults { - result := modules.SubmitResult{} + result := modulebase.SubmitResult{} if res.err != nil { jsonErr, ok := res.err.(*httputils.JSONClientError) if ok { diff --git a/pkg/cloudcommon/db/db_joint_dispatcher.go b/pkg/cloudcommon/db/db_joint_dispatcher.go index 19a1d96964..5156432974 100644 --- a/pkg/cloudcommon/db/db_joint_dispatcher.go +++ b/pkg/cloudcommon/db/db_joint_dispatcher.go @@ -21,13 +21,13 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/cloudcommon/consts" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" - "yunion.io/x/onecloud/pkg/mcclient/modules" ) type DBJointModelDispatcher struct { @@ -59,7 +59,7 @@ func (dispatcher *DBJointModelDispatcher) SlaveKeywordPlural() string { return jointManager.GetSlaveManager().KeywordPlural() } -func (dispatcher *DBJointModelDispatcher) ListMasterDescendent(ctx context.Context, idStr string, query jsonutils.JSONObject) (*modules.ListResult, error) { +func (dispatcher *DBJointModelDispatcher) ListMasterDescendent(ctx context.Context, idStr string, query jsonutils.JSONObject) (*modulebase.ListResult, error) { //log.Debugf("ListMasterDescendent %s %s", dispatcher.JointModelManager().GetMasterManager().Keyword(), idStr) userCred := fetchUserCredential(ctx) @@ -85,7 +85,7 @@ func (dispatcher *DBJointModelDispatcher) ListMasterDescendent(ctx context.Conte return dispatcher._listJoint(ctx, userCred, model.(IStandaloneModel), queryDict) } -func (dispatcher *DBJointModelDispatcher) ListSlaveDescendent(ctx context.Context, idStr string, query jsonutils.JSONObject) (*modules.ListResult, error) { +func (dispatcher *DBJointModelDispatcher) ListSlaveDescendent(ctx context.Context, idStr string, query jsonutils.JSONObject) (*modulebase.ListResult, error) { //log.Debugf("ListSlaveDescendent %s %s", dispatcher.JointModelManager().GetMasterManager().Keyword(), idStr) userCred := fetchUserCredential(ctx) @@ -111,7 +111,7 @@ func (dispatcher *DBJointModelDispatcher) ListSlaveDescendent(ctx context.Contex return dispatcher._listJoint(ctx, userCred, model.(IStandaloneModel), queryDict) } -func (dispatcher *DBJointModelDispatcher) _listJoint(ctx context.Context, userCred mcclient.TokenCredential, ctxModel IStandaloneModel, queryDict jsonutils.JSONObject) (*modules.ListResult, error) { +func (dispatcher *DBJointModelDispatcher) _listJoint(ctx context.Context, userCred mcclient.TokenCredential, ctxModel IStandaloneModel, queryDict jsonutils.JSONObject) (*modulebase.ListResult, error) { items, err := ListItems(dispatcher.JointModelManager(), ctx, userCred, queryDict, nil) if err != nil { log.Errorf("Fail to list items: %s", err) diff --git a/pkg/cloudcommon/etcd/handler/dispatcher.go b/pkg/cloudcommon/etcd/handler/dispatcher.go index fd6eb81a47..b89792726f 100644 --- a/pkg/cloudcommon/etcd/handler/dispatcher.go +++ b/pkg/cloudcommon/etcd/handler/dispatcher.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/gotypes" "yunion.io/x/pkg/utils" @@ -32,7 +33,6 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient/auth" - "yunion.io/x/onecloud/pkg/mcclient/modules" ) func NewEtcdModelHandler(manger base.IEtcdModelManager) *SEtcdModelHandler { @@ -73,12 +73,12 @@ func (disp *SEtcdModelHandler) FetchUpdateHeaderData(ctx context.Context, header return disp.manager.FetchUpdateHeaderData(ctx, header) } -func (disp *SEtcdModelHandler) List(ctx context.Context, query jsonutils.JSONObject, ctxIds []dispatcher.SResourceContext) (*modules.ListResult, error) { +func (disp *SEtcdModelHandler) List(ctx context.Context, query jsonutils.JSONObject, ctxIds []dispatcher.SResourceContext) (*modulebase.ListResult, error) { objs, err := disp.manager.AllJson(ctx) if err != nil { return nil, httperrors.NewGeneralError(err) } - return &modules.ListResult{ + return &modulebase.ListResult{ Data: objs, Total: len(objs), Limit: 0, @@ -171,7 +171,7 @@ func (disp *SEtcdModelHandler) Create(ctx context.Context, query jsonutils.JSONO return nil, httperrors.NewNotImplementedError("not implemented") } -func (disp *SEtcdModelHandler) BatchCreate(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject, count int, ctxIds []dispatcher.SResourceContext) ([]modules.SubmitResult, error) { +func (disp *SEtcdModelHandler) BatchCreate(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject, count int, ctxIds []dispatcher.SResourceContext) ([]modulebase.SubmitResult, error) { return nil, httperrors.NewNotImplementedError("not implemented") } diff --git a/pkg/cloudcommon/notifyclient/notify.go b/pkg/cloudcommon/notifyclient/notify.go index 9b3997ce91..749df4837f 100644 --- a/pkg/cloudcommon/notifyclient/notify.go +++ b/pkg/cloudcommon/notifyclient/notify.go @@ -26,6 +26,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/cloudcommon/consts" @@ -230,7 +231,7 @@ var ( domainCache = make(map[string]string) ) -func getIdentityId(s *mcclient.ClientSession, idName string, manager modules.Manager) (string, error) { +func getIdentityId(s *mcclient.ClientSession, idName string, manager modulebase.Manager) (string, error) { domain, idName := parseIdName(idName) query := jsonutils.NewDict() diff --git a/pkg/compute/models/buckets.go b/pkg/compute/models/buckets.go index f0d4c11ebf..25fb114283 100644 --- a/pkg/compute/models/buckets.go +++ b/pkg/compute/models/buckets.go @@ -23,6 +23,7 @@ import ( "time" "github.com/minio/minio-go/pkg/s3utils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/jsonutils" "yunion.io/x/log" @@ -41,7 +42,6 @@ import ( "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" - "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/util/logclient" "yunion.io/x/onecloud/pkg/util/rbacutils" ) @@ -742,7 +742,7 @@ func (bucket *SBucket) PerformDelete( return nil, httperrors.NewInternalServerError("fail to find external bucket: %s", err) } ok := jsonutils.NewDict() - results := modules.BatchDo(keyStrs, func(key string) (jsonutils.JSONObject, error) { + results := modulebase.BatchDo(keyStrs, func(key string) (jsonutils.JSONObject, error) { if strings.HasSuffix(key, "/") { err = cloudprovider.DeletePrefix(ctx, iBucket, key) } else { @@ -760,7 +760,7 @@ func (bucket *SBucket) PerformDelete( bucket.syncWithCloudBucket(ctx, userCred, iBucket, nil, true) - return modules.SubmitResults2JSON(results), nil + return modulebase.SubmitResults2JSON(results), nil } func (bucket *SBucket) AllowPerformUpload(ctx context.Context, diff --git a/pkg/image/models/images.go b/pkg/image/models/images.go index 49df498bd6..ba1d6c250d 100644 --- a/pkg/image/models/images.go +++ b/pkg/image/models/images.go @@ -29,6 +29,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/tristate" "yunion.io/x/pkg/util/timeutils" @@ -175,7 +176,7 @@ func (manager *SImageManager) GetPropertyDetail(ctx context.Context, userCred mc log.Errorf("Fail to list items: %s", err) return nil, httperrors.NewGeneralError(err) } - return modules.ListResult2JSONWithKey(items, manager.KeywordPlural()), nil + return modulebase.ListResult2JSONWithKey(items, manager.KeywordPlural()), nil } func (manager *SImageManager) IsCustomizedGetDetailsBody() bool { diff --git a/pkg/lbagent/models/modelset.go b/pkg/lbagent/models/modelset.go index d9f325a33b..728e3d2733 100644 --- a/pkg/lbagent/models/modelset.go +++ b/pkg/lbagent/models/modelset.go @@ -18,6 +18,7 @@ import ( "sort" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/models" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -25,7 +26,7 @@ import ( type IModelSet interface { //InitializeFromJSON([]jsonutils.JSONObject) error - ModelManager() modules.Manager + ModelManager() modulebase.Manager NewModel() models.IVirtualResource //GetModel(id string) models.IVirtualResource addModelCallback(models.IVirtualResource) error @@ -39,7 +40,7 @@ type LoadbalancerBackends map[string]*LoadbalancerBackend type LoadbalancerAcls map[string]*LoadbalancerAcl type LoadbalancerCertificates map[string]*LoadbalancerCertificate -func (set Loadbalancers) ModelManager() modules.Manager { +func (set Loadbalancers) ModelManager() modulebase.Manager { return &modules.Loadbalancers } @@ -103,7 +104,7 @@ func (ms Loadbalancers) JoinBackendGroups(subEntries LoadbalancerBackendGroups) return correct } -func (set LoadbalancerListeners) ModelManager() modules.Manager { +func (set LoadbalancerListeners) ModelManager() modulebase.Manager { return &modules.LoadbalancerListeners } @@ -161,7 +162,7 @@ func (ms LoadbalancerListeners) JoinCertificates(subEntries LoadbalancerCertific return correct } -func (set LoadbalancerListenerRules) ModelManager() modules.Manager { +func (set LoadbalancerListenerRules) ModelManager() modulebase.Manager { return &modules.LoadbalancerListenerRules } @@ -214,7 +215,7 @@ func (set LoadbalancerListenerRules) OrderedEnabledList() OrderedLoadbalancerLis return rules } -func (set LoadbalancerBackendGroups) ModelManager() modules.Manager { +func (set LoadbalancerBackendGroups) ModelManager() modulebase.Manager { return &modules.LoadbalancerBackendGroups } @@ -253,7 +254,7 @@ func (ms LoadbalancerBackendGroups) JoinBackends(subEntries LoadbalancerBackends return correct } -func (set LoadbalancerBackends) ModelManager() modules.Manager { +func (set LoadbalancerBackends) ModelManager() modulebase.Manager { return &modules.LoadbalancerBackends } @@ -269,7 +270,7 @@ func (set LoadbalancerBackends) addModelCallback(i models.IVirtualResource) erro return nil } -func (set LoadbalancerAcls) ModelManager() modules.Manager { +func (set LoadbalancerAcls) ModelManager() modulebase.Manager { return &modules.LoadbalancerAcls } @@ -285,7 +286,7 @@ func (set LoadbalancerAcls) addModelCallback(i models.IVirtualResource) error { return nil } -func (set LoadbalancerCertificates) ModelManager() modules.Manager { +func (set LoadbalancerCertificates) ModelManager() modulebase.Manager { return &modules.LoadbalancerCertificates } diff --git a/pkg/lbagent/models/reflect.go b/pkg/lbagent/models/reflect.go index 26f76ba447..313611b869 100644 --- a/pkg/lbagent/models/reflect.go +++ b/pkg/lbagent/models/reflect.go @@ -21,13 +21,13 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/util/timeutils" "yunion.io/x/pkg/utils" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/models" - "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) @@ -37,7 +37,7 @@ var PseudoZeroTime = time.Time{}.Add(time.Nanosecond) type GetModelsOptions struct { ClientSession *mcclient.ClientSession - ModelManager modules.Manager + ModelManager modulebase.Manager ModelSet IModelSet BatchListSize int @@ -54,7 +54,7 @@ func GetModels(opts *GetModelsOptions) error { tstr := timeutils.MysqlTime(time) return fmt.Sprintf("updated_at.ge('%s')", tstr) } - setNextListParams := func(params *jsonutils.JSONDict, lastUpdatedAt time.Time, lastResult *modules.ListResult) (time.Time, error) { + setNextListParams := func(params *jsonutils.JSONDict, lastUpdatedAt time.Time, lastResult *modulebase.ListResult) (time.Time, error) { // NOTE: the updated_at field has second-level resolution. // If they all have the same date... var max time.Time diff --git a/pkg/mcclient/modules/base.go b/pkg/mcclient/modulebase/base.go similarity index 99% rename from pkg/mcclient/modules/base.go rename to pkg/mcclient/modulebase/base.go index 0191804ba8..9d1ded2abd 100644 --- a/pkg/mcclient/modules/base.go +++ b/pkg/mcclient/modulebase/base.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package modules +package modulebase import ( "fmt" diff --git a/pkg/mcclient/modulebase/doc.go b/pkg/mcclient/modulebase/doc.go new file mode 100644 index 0000000000..7f110dd18e --- /dev/null +++ b/pkg/mcclient/modulebase/doc.go @@ -0,0 +1 @@ +package modulebase // import "yunion.io/x/onecloud/pkg/mcclient/modulebase" diff --git a/pkg/mcclient/modules/filter.go b/pkg/mcclient/modulebase/filter.go similarity index 98% rename from pkg/mcclient/modules/filter.go rename to pkg/mcclient/modulebase/filter.go index b206d9fcb0..5e249942aa 100644 --- a/pkg/mcclient/modules/filter.go +++ b/pkg/mcclient/modulebase/filter.go @@ -12,12 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package modules +package modulebase import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/mcclient" ) diff --git a/pkg/mcclient/modules/joint.go b/pkg/mcclient/modulebase/joint.go similarity index 99% rename from pkg/mcclient/modules/joint.go rename to pkg/mcclient/modulebase/joint.go index de4b5c1fca..b160bddc9b 100644 --- a/pkg/mcclient/modules/joint.go +++ b/pkg/mcclient/modulebase/joint.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package modules +package modulebase import ( "fmt" diff --git a/pkg/mcclient/modules/modules.go b/pkg/mcclient/modulebase/modules.go similarity index 98% rename from pkg/mcclient/modules/modules.go rename to pkg/mcclient/modulebase/modules.go index fd842b89eb..5b604494f7 100644 --- a/pkg/mcclient/modules/modules.go +++ b/pkg/mcclient/modulebase/modules.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package modules +package modulebase import ( "fmt" @@ -182,7 +182,7 @@ func ensureModuleNotRegistered(mod, newMod BaseManagerInterface) { } } -func _register(version string, mod BaseManagerInterface) { +func Register(version string, mod BaseManagerInterface) { if modules == nil { modules = make(map[string]map[string][]BaseManagerInterface) } @@ -203,7 +203,7 @@ func _register(version string, mod BaseManagerInterface) { // modtable[mod.KeyString()] = append(mods, mod) } -func _registerJointModule(version string, mod BaseManagerInterface) { +func RegisterJointModule(version string, mod BaseManagerInterface) { jointMod, ok := mod.(JointManager) if ok { // also a joint manager jointKey := _getJointKey(jointMod.MasterManager(), jointMod.SlaveManager()) @@ -233,7 +233,7 @@ func registerAllJointModules() { for version := range modules { for modname := range modules[version] { for i := range modules[version][modname] { - _registerJointModule(version, modules[version][modname][i]) + RegisterJointModule(version, modules[version][modname][i]) } } } diff --git a/pkg/mcclient/modulebase/pprof.go b/pkg/mcclient/modulebase/pprof.go new file mode 100644 index 0000000000..a237185dff --- /dev/null +++ b/pkg/mcclient/modulebase/pprof.go @@ -0,0 +1,34 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package modulebase + +import ( + "fmt" + "io" + + "yunion.io/x/onecloud/pkg/mcclient" +) + +func GetPProfByType(s *mcclient.ClientSession, serviceType string, profileType string, seconds int) (io.Reader, error) { + man := &BaseManager{serviceType: serviceType} + if seconds <= 0 { + seconds = 15 + } + resp, err := man.rawBaseUrlRequest(s, "GET", fmt.Sprintf("/debug/pprof/%s?seconds=%d", profileType, seconds), nil, nil) + if err != nil { + return nil, err + } + return resp.Body, nil +} diff --git a/pkg/mcclient/modulebase/projectresources.go b/pkg/mcclient/modulebase/projectresources.go new file mode 100644 index 0000000000..01e53bef65 --- /dev/null +++ b/pkg/mcclient/modulebase/projectresources.go @@ -0,0 +1,36 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package modulebase + +import ( + "io/ioutil" + + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" +) + +func GetProjectResources(s *mcclient.ClientSession, serviceType string) (jsonutils.JSONObject, error) { + man := &BaseManager{serviceType: serviceType} + resp, err := man.rawRequest(s, "GET", "/project-resources", nil, nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + return jsonutils.Parse(body) +} diff --git a/pkg/mcclient/modules/resource.go b/pkg/mcclient/modulebase/resource.go similarity index 99% rename from pkg/mcclient/modules/resource.go rename to pkg/mcclient/modulebase/resource.go index 7f7ba4e6f2..c5d6d64ff3 100644 --- a/pkg/mcclient/modules/resource.go +++ b/pkg/mcclient/modulebase/resource.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package modules +package modulebase import ( "fmt" @@ -21,7 +21,6 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/util/httputils" diff --git a/pkg/mcclient/modulebase/utils.go b/pkg/mcclient/modulebase/utils.go new file mode 100644 index 0000000000..fd0c447b5b --- /dev/null +++ b/pkg/mcclient/modulebase/utils.go @@ -0,0 +1,54 @@ +package modulebase + +import ( + "io" + "net/http" + + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/util/httputils" +) + +func Get(manager ResourceManager, session *mcclient.ClientSession, path string, respKey string) (jsonutils.JSONObject, error) { + return manager._get(session, path, respKey) +} + +func List(manager ResourceManager, session *mcclient.ClientSession, path, respKey string) (*ListResult, error) { + return manager._list(session, path, respKey) +} + +func Head(manager ResourceManager, session *mcclient.ClientSession, path string, respKey string) (jsonutils.JSONObject, error) { + return manager._head(session, path, respKey) +} + +func Post(manager ResourceManager, session *mcclient.ClientSession, path string, body jsonutils.JSONObject, respKey string) (jsonutils.JSONObject, error) { + return manager._post(session, path, body, respKey) +} + +func Put(manager ResourceManager, session *mcclient.ClientSession, path string, body jsonutils.JSONObject, respKey string) (jsonutils.JSONObject, error) { + return manager._put(session, path, body, respKey) +} + +func Patch(manager ResourceManager, session *mcclient.ClientSession, path string, body jsonutils.JSONObject, respKey string) (jsonutils.JSONObject, error) { + return manager._patch(session, path, body, respKey) +} + +func Delete(manager ResourceManager, session *mcclient.ClientSession, path string, body jsonutils.JSONObject, respKey string) (jsonutils.JSONObject, error) { + return manager._delete(session, path, body, respKey) +} + +func RawRequest(manager ResourceManager, session *mcclient.ClientSession, + method httputils.THttpMethod, path string, + header http.Header, body io.Reader) (*http.Response, error) { + return session.RawVersionRequest(manager.serviceType, manager.endpointType, + method, manager.versionedURL(path), + header, body, manager.GetApiVersion()) +} + +func JsonRequest(manager ResourceManager, session *mcclient.ClientSession, + method httputils.THttpMethod, path string, + header http.Header, body jsonutils.JSONObject) (http.Header, jsonutils.JSONObject, error) { + return session.JSONVersionRequest(manager.serviceType, manager.endpointType, + method, manager.versionedURL(path), + header, body, manager.GetApiVersion()) +} diff --git a/pkg/mcclient/modulebase/version.go b/pkg/mcclient/modulebase/version.go new file mode 100644 index 0000000000..6a4e0bdaea --- /dev/null +++ b/pkg/mcclient/modulebase/version.go @@ -0,0 +1,35 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package modulebase + +import ( + "io/ioutil" + + "yunion.io/x/onecloud/pkg/mcclient" +) + +func GetVersion(s *mcclient.ClientSession, serviceType string) (string, error) { + man := NewBaseManager(serviceType, "", "", nil, nil) + resp, err := man.rawBaseUrlRequest(s, "GET", "/version", nil, nil) + if err != nil { + return "", err + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return "", err + } + return string(body), nil +} diff --git a/pkg/mcclient/modules/cache.go b/pkg/mcclient/modules/cache.go index 3afe4c113a..45e737bece 100644 --- a/pkg/mcclient/modules/cache.go +++ b/pkg/mcclient/modules/cache.go @@ -20,6 +20,7 @@ import ( "time" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -58,7 +59,7 @@ func init() { } } -func cacheKey(manager Manager, idstr string) string { +func cacheKey(manager modulebase.Manager, idstr string) string { return fmt.Sprintf("%s-%s", manager.KeyString(), idstr) } @@ -85,7 +86,7 @@ func (cm *sCachedResourceManager) getUnlocked(key string, alloc bool) *sCachedRe return &obj } -func (cm *sCachedResourceManager) getById(manager Manager, session *mcclient.ClientSession, idstr string) (jsonutils.JSONObject, error) { +func (cm *sCachedResourceManager) getById(manager modulebase.Manager, session *mcclient.ClientSession, idstr string) (jsonutils.JSONObject, error) { key := cacheKey(manager, idstr) cacheObj := cm.getLocked(key) diff --git a/pkg/mcclient/modules/etcd/managers.go b/pkg/mcclient/modules/etcd/managers.go index 1a81423f95..a5bc044ee3 100644 --- a/pkg/mcclient/modules/etcd/managers.go +++ b/pkg/mcclient/modules/etcd/managers.go @@ -15,10 +15,11 @@ package etcd import ( + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" ) -func NewCloudirManager(keyword, keywordPlural string, columns, adminColumns []string) modules.ResourceManager { +func NewCloudirManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { return modules.NewResourceManager( "cloudir", keyword, diff --git a/pkg/mcclient/modules/etcd/mod_service_registries.go b/pkg/mcclient/modules/etcd/mod_service_registries.go index 7525cbb579..ed47017fa0 100644 --- a/pkg/mcclient/modules/etcd/mod_service_registries.go +++ b/pkg/mcclient/modules/etcd/mod_service_registries.go @@ -14,10 +14,13 @@ package etcd -import "yunion.io/x/onecloud/pkg/mcclient/modules" +import ( + "yunion.io/x/onecloud/pkg/mcclient/modulebase" + "yunion.io/x/onecloud/pkg/mcclient/modules" +) type SServiceRegistryManager struct { - modules.ResourceManager + modulebase.ResourceManager } var ServiceRegistryManager SServiceRegistryManager diff --git a/pkg/mcclient/modules/k8s/base.go b/pkg/mcclient/modules/k8s/base.go index 041a4e015e..a3b9581a60 100644 --- a/pkg/mcclient/modules/k8s/base.go +++ b/pkg/mcclient/modules/k8s/base.go @@ -19,16 +19,16 @@ import ( "yunion.io/x/pkg/util/sets" "yunion.io/x/onecloud/pkg/mcclient" - "yunion.io/x/onecloud/pkg/mcclient/modules" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type ResourceManager struct { - *modules.ResourceManager + *modulebase.ResourceManager } func NewResourceManager(keyword, keywordPlural string, columns, adminColumns *Columns) *ResourceManager { - man := &modules.ResourceManager{ - BaseManager: *modules.NewBaseManager("k8s", "", "", columns.Array(), adminColumns.Array()), + man := &modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("k8s", "", "", columns.Array(), adminColumns.Array()), Keyword: keyword, KeywordPlural: keywordPlural, } diff --git a/pkg/mcclient/modules/managers.go b/pkg/mcclient/modules/managers.go index 364763d6b2..32eb424dec 100644 --- a/pkg/mcclient/modules/managers.go +++ b/pkg/mcclient/modules/managers.go @@ -14,189 +14,143 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + /* 添加新manager注意事项: 1. version字段 -- 在endpoint中注册的url如果携带版本。例如http://x.x.x.x/api/v1,那么必须标注对应version字段。否者可能导致yunionapi报资源not found的错误。 */ func NewResourceManager(serviceType string, keyword, keywordPlural string, - columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: serviceType}, - Keyword: keyword, KeywordPlural: keywordPlural} + columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager(serviceType, "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewComputeManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "compute"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewComputeManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("compute", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewActionManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "log"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewActionManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("log", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewMonitorManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - version: "v1", - serviceType: "servicetree"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewMonitorManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("servicetree", "", "v1", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewCloudwatcherManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - version: "v1", - serviceType: "cloudwatcher"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewCloudwatcherManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("cloudwatcher", "", "v1", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewNotifyManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - version: "v1", - serviceType: "notify"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewNotifyManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("notify", "", "v1", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewJointComputeManager(keyword, keywordPlural string, columns, adminColumns []string, master, slave Manager) JointResourceManager { - return JointResourceManager{ +func NewJointComputeManager(keyword, keywordPlural string, columns, adminColumns []string, master, slave modulebase.Manager) modulebase.JointResourceManager { + return modulebase.JointResourceManager{ ResourceManager: NewComputeManager(keyword, keywordPlural, columns, adminColumns), Master: master, Slave: slave} } -func NewJointMonitorManager(keyword, keywordPlural string, columns, adminColumns []string, master, slave Manager) JointResourceManager { - return JointResourceManager{ +func NewJointMonitorManager(keyword, keywordPlural string, columns, adminColumns []string, master, slave modulebase.Manager) modulebase.JointResourceManager { + return modulebase.JointResourceManager{ ResourceManager: NewMonitorManager(keyword, keywordPlural, columns, adminColumns), Master: master, Slave: slave} } -func NewIdentityManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - endpointType: "adminURL", - version: "v2.0", - serviceType: "identity"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewIdentityManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("identity", "adminURL", "v2.0", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewIdentityV3Manager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - endpointType: "adminURL", - version: "v3", - serviceType: "identity"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewIdentityV3Manager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("identity", "adminURL", "v3", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewImageManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - endpointType: "", - version: "v1", - serviceType: "image"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewImageManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("image", "", "v1", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewVNCProxyManager() ResourceManager { - return ResourceManager{BaseManager: BaseManager{serviceType: "vncproxy"}, +func NewVNCProxyManager() modulebase.ResourceManager { + return modulebase.ResourceManager{BaseManager: *modulebase.NewBaseManager("vncproxy", "", "", nil, nil), Keyword: "vncproxy", KeywordPlural: "vncproxy"} } -func NewITSMManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "itsm"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewITSMManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("itsm", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewSchedulerManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "scheduler"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewSchedulerManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("scheduler", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewMeterManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - version: "v1", - serviceType: "meter"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewMeterManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("meter", "", "v1", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewMeterAlertManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "meteralert"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewMeterAlertManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("meteralert", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewYunionAgentManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "yunionagent"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewYunionAgentManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("yunionagent", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewYunionConfManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "yunionconf"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewYunionConfManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("yunionconf", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewAutoUpdateManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "autoupdate"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewAutoUpdateManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("autoupdate", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewWebsocketManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "websocket"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewWebsocketManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("websocket", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewCloudmetaManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "cloudmeta"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewCloudmetaManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("cloudmeta", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } -func NewAnsibleManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { - return ResourceManager{ - BaseManager: BaseManager{columns: columns, - adminColumns: adminColumns, - serviceType: "ansible"}, - Keyword: keyword, KeywordPlural: keywordPlural} +func NewAnsibleManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("ansible", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} } diff --git a/pkg/mcclient/modules/mod_account_balances.go b/pkg/mcclient/modules/mod_account_balances.go index e0167fdc37..17c0448e4f 100644 --- a/pkg/mcclient/modules/mod_account_balances.go +++ b/pkg/mcclient/modules/mod_account_balances.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - AccountBalances ResourceManager + AccountBalances modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_actions.go b/pkg/mcclient/modules/mod_actions.go index 1a4d9ed330..50f86f0f79 100644 --- a/pkg/mcclient/modules/mod_actions.go +++ b/pkg/mcclient/modules/mod_actions.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Actions ResourceManager + Actions modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_alarmevents.go b/pkg/mcclient/modules/mod_alarmevents.go index 5e4c8bbf01..99bb6b7ccd 100644 --- a/pkg/mcclient/modules/mod_alarmevents.go +++ b/pkg/mcclient/modules/mod_alarmevents.go @@ -16,18 +16,19 @@ package modules import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type AlarmEventsManager struct { - ResourceManager + modulebase.ResourceManager } func (this *AlarmEventsManager) DoBatchUpdate(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { path := "/alarm_events" - return this._put(s, path, params, "alarm_events") + return modulebase.Put(this.ResourceManager, s, path, params, "alarm_events") } var ( diff --git a/pkg/mcclient/modules/mod_alarmlogs.go b/pkg/mcclient/modules/mod_alarmlogs.go index 0d271830fa..e38a591f85 100644 --- a/pkg/mcclient/modules/mod_alarmlogs.go +++ b/pkg/mcclient/modules/mod_alarmlogs.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - AlarmLogs ResourceManager + AlarmLogs modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_alarms.go b/pkg/mcclient/modules/mod_alarms.go index 964cf281fc..5d539b7790 100644 --- a/pkg/mcclient/modules/mod_alarms.go +++ b/pkg/mcclient/modules/mod_alarms.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Alarms ResourceManager + Alarms modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_alarmtemplatealarms.go b/pkg/mcclient/modules/mod_alarmtemplatealarms.go index 5fc17b2fcb..893441d721 100644 --- a/pkg/mcclient/modules/mod_alarmtemplatealarms.go +++ b/pkg/mcclient/modules/mod_alarmtemplatealarms.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - AlarmTemplateAlarms JointResourceManager + AlarmTemplateAlarms modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_alarmtemplates.go b/pkg/mcclient/modules/mod_alarmtemplates.go index 04495e15ce..ad29e9ded3 100644 --- a/pkg/mcclient/modules/mod_alarmtemplates.go +++ b/pkg/mcclient/modules/mod_alarmtemplates.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - AlarmTemplates ResourceManager + AlarmTemplates modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_ansibleplaybooks.go b/pkg/mcclient/modules/mod_ansibleplaybooks.go index 1f2ca8f591..187cfcb25c 100644 --- a/pkg/mcclient/modules/mod_ansibleplaybooks.go +++ b/pkg/mcclient/modules/mod_ansibleplaybooks.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type AnsiblePlaybookManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_baremetalagents.go b/pkg/mcclient/modules/mod_baremetalagents.go index e585c73dd9..ab056f707e 100644 --- a/pkg/mcclient/modules/mod_baremetalagents.go +++ b/pkg/mcclient/modules/mod_baremetalagents.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Baremetalagents ResourceManager + Baremetalagents modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_baremetalnetworks.go b/pkg/mcclient/modules/mod_baremetalnetworks.go index 6f43a96da2..7b663ed006 100644 --- a/pkg/mcclient/modules/mod_baremetalnetworks.go +++ b/pkg/mcclient/modules/mod_baremetalnetworks.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Baremetalnetworks JointResourceManager + Baremetalnetworks modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_baremetalstorages.go b/pkg/mcclient/modules/mod_baremetalstorages.go index 5adae13636..88e0c09110 100644 --- a/pkg/mcclient/modules/mod_baremetalstorages.go +++ b/pkg/mcclient/modules/mod_baremetalstorages.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Baremetalstorages JointResourceManager + Baremetalstorages modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_bill_analysises.go b/pkg/mcclient/modules/mod_bill_analysises.go index 31e2976d62..fb4bdbffc5 100644 --- a/pkg/mcclient/modules/mod_bill_analysises.go +++ b/pkg/mcclient/modules/mod_bill_analysises.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - BillAnalysises ResourceManager + BillAnalysises modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_bill_balances.go b/pkg/mcclient/modules/mod_bill_balances.go index 220357d98b..d2089040e4 100644 --- a/pkg/mcclient/modules/mod_bill_balances.go +++ b/pkg/mcclient/modules/mod_bill_balances.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - BillBalances ResourceManager + BillBalances modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_bill_cloudchecks.go b/pkg/mcclient/modules/mod_bill_cloudchecks.go index a88edf3e04..38222e82bd 100644 --- a/pkg/mcclient/modules/mod_bill_cloudchecks.go +++ b/pkg/mcclient/modules/mod_bill_cloudchecks.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - BillCloudChecks ResourceManager + BillCloudChecks modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_bill_conditions.go b/pkg/mcclient/modules/mod_bill_conditions.go index 9bf196c1ae..2ef53e7c84 100644 --- a/pkg/mcclient/modules/mod_bill_conditions.go +++ b/pkg/mcclient/modules/mod_bill_conditions.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - BillConditions ResourceManager + BillConditions modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_bill_details.go b/pkg/mcclient/modules/mod_bill_details.go index d24523ec08..d31e06e096 100644 --- a/pkg/mcclient/modules/mod_bill_details.go +++ b/pkg/mcclient/modules/mod_bill_details.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - BillDetails ResourceManager + BillDetails modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_bill_resources.go b/pkg/mcclient/modules/mod_bill_resources.go index 3e6772c500..be8f0265ad 100644 --- a/pkg/mcclient/modules/mod_bill_resources.go +++ b/pkg/mcclient/modules/mod_bill_resources.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - BillResources ResourceManager + BillResources modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_buckets.go b/pkg/mcclient/modules/mod_buckets.go index 0b80ada9f3..ef35258355 100644 --- a/pkg/mcclient/modules/mod_buckets.go +++ b/pkg/mcclient/modules/mod_buckets.go @@ -23,11 +23,12 @@ import ( "github.com/pkg/errors" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/util/httputils" ) type SBucketManager struct { - ResourceManager + modulebase.ResourceManager } func (manager *SBucketManager) Upload(s *mcclient.ClientSession, bucketId string, key string, body io.Reader, contLength int64, contType string, storageClass string, acl string) error { @@ -51,7 +52,7 @@ func (manager *SBucketManager) Upload(s *mcclient.ClientSession, bucketId string headers.Set(api.BUCKET_UPLOAD_OBJECT_ACL_HEADER, acl) } - resp, err := manager.rawRequest(s, method, path, headers, body) + resp, err := modulebase.RawRequest(manager.ResourceManager, s, method, path, headers, body) if err != nil { return errors.Wrap(err, "rawRequest") } diff --git a/pkg/mcclient/modules/mod_cachedimages.go b/pkg/mcclient/modules/mod_cachedimages.go index 20ba46dc67..506386a679 100644 --- a/pkg/mcclient/modules/mod_cachedimages.go +++ b/pkg/mcclient/modules/mod_cachedimages.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Cachedimages ResourceManager + Cachedimages modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_capabilities.go b/pkg/mcclient/modules/mod_capabilities.go index 3f4d190e0f..8821f92ed6 100644 --- a/pkg/mcclient/modules/mod_capabilities.go +++ b/pkg/mcclient/modules/mod_capabilities.go @@ -18,13 +18,14 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type SCapabilityManager struct { - ResourceManager + modulebase.ResourceManager } -func (this *SCapabilityManager) List(s *mcclient.ClientSession, params jsonutils.JSONObject) (*ListResult, error) { +func (this *SCapabilityManager) List(s *mcclient.ClientSession, params jsonutils.JSONObject) (*modulebase.ListResult, error) { url := "/capabilities" if params != nil { qs := params.QueryString() @@ -32,11 +33,11 @@ func (this *SCapabilityManager) List(s *mcclient.ClientSession, params jsonutils url += "?" + qs } } - body, err := this._get(s, url, "") + body, err := modulebase.Get(this.ResourceManager, s, url, "") if err != nil { return nil, err } - result := ListResult{Data: []jsonutils.JSONObject{body}} + result := modulebase.ListResult{Data: []jsonutils.JSONObject{body}} return &result, nil } diff --git a/pkg/mcclient/modules/mod_cloud_sku_rates.go b/pkg/mcclient/modules/mod_cloud_sku_rates.go index f53fc88ea6..561dbe34bb 100644 --- a/pkg/mcclient/modules/mod_cloud_sku_rates.go +++ b/pkg/mcclient/modules/mod_cloud_sku_rates.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - CloudSkuRates ResourceManager + CloudSkuRates modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_cloudaccounts.go b/pkg/mcclient/modules/mod_cloudaccounts.go index 2245d6ae2d..f334606206 100644 --- a/pkg/mcclient/modules/mod_cloudaccounts.go +++ b/pkg/mcclient/modules/mod_cloudaccounts.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Cloudaccounts ResourceManager + Cloudaccounts modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_cloudproviderregions.go b/pkg/mcclient/modules/mod_cloudproviderregions.go index d50b6a6730..9c92b3f75b 100644 --- a/pkg/mcclient/modules/mod_cloudproviderregions.go +++ b/pkg/mcclient/modules/mod_cloudproviderregions.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - CloudproviderregionManager JointResourceManager + CloudproviderregionManager modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_cloudproviders.go b/pkg/mcclient/modules/mod_cloudproviders.go index 4329f8b233..c4e638cc87 100644 --- a/pkg/mcclient/modules/mod_cloudproviders.go +++ b/pkg/mcclient/modules/mod_cloudproviders.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Cloudproviders ResourceManager + Cloudproviders modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_cloudregions.go b/pkg/mcclient/modules/mod_cloudregions.go index 64df1b38c7..5ef1f65eef 100644 --- a/pkg/mcclient/modules/mod_cloudregions.go +++ b/pkg/mcclient/modules/mod_cloudregions.go @@ -18,12 +18,13 @@ import ( "sort" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type SCloudregionManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_contactgroups.go b/pkg/mcclient/modules/mod_contactgroups.go index 7a178091bf..3e13bb9e73 100644 --- a/pkg/mcclient/modules/mod_contactgroups.go +++ b/pkg/mcclient/modules/mod_contactgroups.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ContactGroups ResourceManager + ContactGroups modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_contacts.go b/pkg/mcclient/modules/mod_contacts.go index 548e74661c..6f8480d440 100644 --- a/pkg/mcclient/modules/mod_contacts.go +++ b/pkg/mcclient/modules/mod_contacts.go @@ -20,10 +20,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type ContactsManager struct { - ResourceManager + modulebase.ResourceManager } func (this *ContactsManager) PerformActionWithArrayParams(s *mcclient.ClientSession, id string, action string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -34,13 +35,13 @@ func (this *ContactsManager) PerformActionWithArrayParams(s *mcclient.ClientSess body.Add(params, this.KeywordPlural) } - return this._post(s, path, body, this.Keyword) + return modulebase.Post(this.ResourceManager, s, path, body, this.Keyword) } func (this *ContactsManager) DoBatchDeleteContacts(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { path := "/contacts/delete-contact" - return this._post(s, path, params, this.Keyword) + return modulebase.Post(this.ResourceManager, s, path, params, this.Keyword) } var ( diff --git a/pkg/mcclient/modules/mod_copyright.go b/pkg/mcclient/modules/mod_copyright.go index c9da808316..9768b66e17 100644 --- a/pkg/mcclient/modules/mod_copyright.go +++ b/pkg/mcclient/modules/mod_copyright.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type CopyrightManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_credentials.go b/pkg/mcclient/modules/mod_credentials.go index fdcfcf7fe4..0b51ce4f44 100644 --- a/pkg/mcclient/modules/mod_credentials.go +++ b/pkg/mcclient/modules/mod_credentials.go @@ -20,6 +20,7 @@ import ( "time" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/util/seclib" "github.com/pkg/errors" @@ -29,7 +30,7 @@ import ( ) type SCredentialManager struct { - ResourceManager + modulebase.ResourceManager } const ( diff --git a/pkg/mcclient/modules/mod_dbinstanceaccounts.go b/pkg/mcclient/modules/mod_dbinstanceaccounts.go index a79db54bf7..c73df73a6a 100644 --- a/pkg/mcclient/modules/mod_dbinstanceaccounts.go +++ b/pkg/mcclient/modules/mod_dbinstanceaccounts.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - DBInstanceAccounts ResourceManager + DBInstanceAccounts modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_dbinstancebackups.go b/pkg/mcclient/modules/mod_dbinstancebackups.go index cea6f3a553..32f5aeb80c 100644 --- a/pkg/mcclient/modules/mod_dbinstancebackups.go +++ b/pkg/mcclient/modules/mod_dbinstancebackups.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - DBInstanceBackups ResourceManager + DBInstanceBackups modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_dbinstancedatabases.go b/pkg/mcclient/modules/mod_dbinstancedatabases.go index e1cd890ecc..47231fe89d 100644 --- a/pkg/mcclient/modules/mod_dbinstancedatabases.go +++ b/pkg/mcclient/modules/mod_dbinstancedatabases.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - DBInstanceDatabases ResourceManager + DBInstanceDatabases modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_dbinstancenetworks.go b/pkg/mcclient/modules/mod_dbinstancenetworks.go index a99acb95a4..5d0ce5c50c 100644 --- a/pkg/mcclient/modules/mod_dbinstancenetworks.go +++ b/pkg/mcclient/modules/mod_dbinstancenetworks.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - DBInstanceNetworks JointResourceManager + DBInstanceNetworks modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_dbinstanceparameters.go b/pkg/mcclient/modules/mod_dbinstanceparameters.go index 04ca39bf8a..e143f4c06c 100644 --- a/pkg/mcclient/modules/mod_dbinstanceparameters.go +++ b/pkg/mcclient/modules/mod_dbinstanceparameters.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - DBInstanceParameters ResourceManager + DBInstanceParameters modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_dbinstanceprivileges.go b/pkg/mcclient/modules/mod_dbinstanceprivileges.go index acd683e86b..802d7099e5 100644 --- a/pkg/mcclient/modules/mod_dbinstanceprivileges.go +++ b/pkg/mcclient/modules/mod_dbinstanceprivileges.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - DBInstancePrivileges ResourceManager + DBInstancePrivileges modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_dbinstances.go b/pkg/mcclient/modules/mod_dbinstances.go index 0f8ce54c6e..719c796e69 100644 --- a/pkg/mcclient/modules/mod_dbinstances.go +++ b/pkg/mcclient/modules/mod_dbinstances.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - DBInstance ResourceManager + DBInstance modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_disks.go b/pkg/mcclient/modules/mod_disks.go index dd28ae7c04..888361b1db 100644 --- a/pkg/mcclient/modules/mod_disks.go +++ b/pkg/mcclient/modules/mod_disks.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Disks ResourceManager + Disks modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_dnsrecords.go b/pkg/mcclient/modules/mod_dnsrecords.go index 185564825b..e198ffb1a9 100644 --- a/pkg/mcclient/modules/mod_dnsrecords.go +++ b/pkg/mcclient/modules/mod_dnsrecords.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - DNSRecords ResourceManager + DNSRecords modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_domains.go b/pkg/mcclient/modules/mod_domains.go index 076cf98e0e..98603458b0 100644 --- a/pkg/mcclient/modules/mod_domains.go +++ b/pkg/mcclient/modules/mod_domains.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type DomainManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_dynamicschedtags.go b/pkg/mcclient/modules/mod_dynamicschedtags.go index 1f6051f206..289215375f 100644 --- a/pkg/mcclient/modules/mod_dynamicschedtags.go +++ b/pkg/mcclient/modules/mod_dynamicschedtags.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Dynamicschedtags ResourceManager + Dynamicschedtags modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_elasticips.go b/pkg/mcclient/modules/mod_elasticips.go index 79814b10e0..9eb2068fcc 100644 --- a/pkg/mcclient/modules/mod_elasticips.go +++ b/pkg/mcclient/modules/mod_elasticips.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Elasticips ResourceManager + Elasticips modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_email_configs.go b/pkg/mcclient/modules/mod_email_configs.go index af2f8358d1..963ebf6c50 100644 --- a/pkg/mcclient/modules/mod_email_configs.go +++ b/pkg/mcclient/modules/mod_email_configs.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - EmailConfigs ResourceManager + EmailConfigs modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_endpoints.go b/pkg/mcclient/modules/mod_endpoints.go index b3f7ab85ca..51266e0509 100644 --- a/pkg/mcclient/modules/mod_endpoints.go +++ b/pkg/mcclient/modules/mod_endpoints.go @@ -14,9 +14,11 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Endpoints ResourceManager - EndpointsV3 ResourceManager + Endpoints modulebase.ResourceManager + EndpointsV3 modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_externalprojects.go b/pkg/mcclient/modules/mod_externalprojects.go index 3a31fbf9cc..28a18707d4 100644 --- a/pkg/mcclient/modules/mod_externalprojects.go +++ b/pkg/mcclient/modules/mod_externalprojects.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ExternalProjects ResourceManager + ExternalProjects modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_groups.go b/pkg/mcclient/modules/mod_groups.go index 2bdd1b973a..a2eee9ffa6 100644 --- a/pkg/mcclient/modules/mod_groups.go +++ b/pkg/mcclient/modules/mod_groups.go @@ -18,24 +18,25 @@ import ( "fmt" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type GroupManager struct { - ResourceManager + modulebase.ResourceManager } -func (this *GroupManager) GetUsers(s *mcclient.ClientSession, gid string) (*ListResult, error) { +func (this *GroupManager) GetUsers(s *mcclient.ClientSession, gid string) (*modulebase.ListResult, error) { url := fmt.Sprintf("/groups/%s/users", gid) - return this._list(s, url, "users") + return modulebase.List(this.ResourceManager, s, url, "users") } var ( Groups GroupManager ) -func (this *GroupManager) GetProjects(session *mcclient.ClientSession, uid string) (*ListResult, error) { +func (this *GroupManager) GetProjects(session *mcclient.ClientSession, uid string) (*modulebase.ListResult, error) { url := fmt.Sprintf("/groups/%s/projects?admin=true", uid) - return this._list(session, url, "projects") + return modulebase.List(this.ResourceManager, session, url, "projects") } func init() { diff --git a/pkg/mcclient/modules/mod_hostcachedimages.go b/pkg/mcclient/modules/mod_hostcachedimages.go index 7e56fad72d..ea353ef88e 100644 --- a/pkg/mcclient/modules/mod_hostcachedimages.go +++ b/pkg/mcclient/modules/mod_hostcachedimages.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Hostcachedimages JointResourceManager + Hostcachedimages modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_hosts.go b/pkg/mcclient/modules/mod_hosts.go index 64b84b3652..127b54c6d1 100644 --- a/pkg/mcclient/modules/mod_hosts.go +++ b/pkg/mcclient/modules/mod_hosts.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/utils" "yunion.io/x/onecloud/pkg/httperrors" @@ -31,7 +32,7 @@ import ( const MACAddressPattern = `(([a-fA-F0-9]{2}[:-]){5}([a-fA-F0-9]{2}))` type HostManager struct { - ResourceManager + modulebase.ResourceManager } func (this *HostManager) GetLoginInfo(s *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -150,7 +151,7 @@ func (this *HostManager) DoBatchRegister(s *mcclient.ClientSession, params jsonu return nil, httperrors.NewInputParameterError(msg) } - results := make(chan SubmitResult, len(hosts)) + results := make(chan modulebase.SubmitResult, len(hosts)) for _, host := range hosts { go func(data jsonutils.JSONObject) { ret, e := this.Create(s, data) @@ -158,23 +159,23 @@ func (this *HostManager) DoBatchRegister(s *mcclient.ClientSession, params jsonu if e != nil { ecls, ok := e.(*httputils.JSONClientError) if ok { - results <- SubmitResult{Status: ecls.Code, Id: id, Data: jsonutils.NewString(ecls.Details)} + results <- modulebase.SubmitResult{Status: ecls.Code, Id: id, Data: jsonutils.NewString(ecls.Details)} } else { - results <- SubmitResult{Status: 400, Id: id, Data: jsonutils.NewString(e.Error())} + results <- modulebase.SubmitResult{Status: 400, Id: id, Data: jsonutils.NewString(e.Error())} } } else { - results <- SubmitResult{Status: 200, Id: id, Data: ret} + results <- modulebase.SubmitResult{Status: 200, Id: id, Data: ret} } }(host) } - ret := make([]SubmitResult, len(hosts)) + ret := make([]modulebase.SubmitResult, len(hosts)) for i := 0; i < len(hosts); i++ { ret[i] = <-results } close(results) - return SubmitResults2JSON(ret), nil + return modulebase.SubmitResults2JSON(ret), nil } var ( diff --git a/pkg/mcclient/modules/mod_hoststorages.go b/pkg/mcclient/modules/mod_hoststorages.go index 6007bd165e..b0cbd986a8 100644 --- a/pkg/mcclient/modules/mod_hoststorages.go +++ b/pkg/mcclient/modules/mod_hoststorages.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Hoststorages JointResourceManager + Hoststorages modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_hostwires.go b/pkg/mcclient/modules/mod_hostwires.go index fe35854efd..f08079a396 100644 --- a/pkg/mcclient/modules/mod_hostwires.go +++ b/pkg/mcclient/modules/mod_hostwires.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Hostwires JointResourceManager + Hostwires modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_identity.go b/pkg/mcclient/modules/mod_identity.go index cc53e6c317..73a9c38afc 100644 --- a/pkg/mcclient/modules/mod_identity.go +++ b/pkg/mcclient/modules/mod_identity.go @@ -18,12 +18,13 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type SIdentityUsageManager struct { - ResourceManager + modulebase.ResourceManager } func (this *SIdentityUsageManager) GetUsage(session *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -34,12 +35,12 @@ func (this *SIdentityUsageManager) GetUsage(session *mcclient.ClientSession, par url = fmt.Sprintf("%s?%s", url, query) } } - return this._get(session, url, "usage") + return modulebase.Get(this.ResourceManager, session, url, "usage") } var ( IdentityUsages SIdentityUsageManager - IdentityLogs ResourceManager + IdentityLogs modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_identityproviders.go b/pkg/mcclient/modules/mod_identityproviders.go index 1dac345cc9..070c9b7a3a 100644 --- a/pkg/mcclient/modules/mod_identityproviders.go +++ b/pkg/mcclient/modules/mod_identityproviders.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type IdentityProviderManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_images.go b/pkg/mcclient/modules/mod_images.go index a72df037de..a9b37c9b20 100644 --- a/pkg/mcclient/modules/mod_images.go +++ b/pkg/mcclient/modules/mod_images.go @@ -19,20 +19,21 @@ import ( "io" "net/http" "net/url" + "strconv" "strings" "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/pkg/utils" - "strconv" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/util/httputils" ) type ImageManager struct { - ResourceManager + modulebase.ResourceManager } const ( @@ -80,7 +81,7 @@ func (this *ImageManager) GetById(session *mcclient.ClientSession, id string, pa path = fmt.Sprintf("%s?%s", path, qs) } } - h, _, e := this.jsonRequest(session, "HEAD", path, nil, nil) + h, _, e := modulebase.JsonRequest(this.ResourceManager, session, "HEAD", path, nil, nil) if e != nil { return nil, e } @@ -112,13 +113,13 @@ func (this *ImageManager) GetId(session *mcclient.ClientSession, id string, para return img.GetString("id") } -func (this *ImageManager) BatchGet(session *mcclient.ClientSession, idlist []string, params jsonutils.JSONObject) []SubmitResult { - return BatchDo(idlist, func(id string) (jsonutils.JSONObject, error) { +func (this *ImageManager) BatchGet(session *mcclient.ClientSession, idlist []string, params jsonutils.JSONObject) []modulebase.SubmitResult { + return modulebase.BatchDo(idlist, func(id string) (jsonutils.JSONObject, error) { return this.Get(session, id, params) }) } -func (this *ImageManager) List(session *mcclient.ClientSession, params jsonutils.JSONObject) (*ListResult, error) { +func (this *ImageManager) List(session *mcclient.ClientSession, params jsonutils.JSONObject) (*modulebase.ListResult, error) { path := fmt.Sprintf("/%s", this.URLPath()) if params != nil { details, _ := params.Bool("details") @@ -132,7 +133,7 @@ func (this *ImageManager) List(session *mcclient.ClientSession, params jsonutils path = fmt.Sprintf("%s?%s", path, qs) } } - return this._list(session, path, this.KeywordPlural) + return modulebase.List(this.ResourceManager, session, path, this.KeywordPlural) } func (this *ImageManager) GetPrivateImageCount(s *mcclient.ClientSession, ownerId string, isAdmin bool) (int, error) { @@ -159,7 +160,7 @@ func (this *ImageManager) countUsage(session *mcclient.ClientSession, deleted bo var limit int64 = 1000 var offset int64 = 0 ret := make(map[string]*ImageUsageCount) - count := func(ret map[string]*ImageUsageCount, results *ListResult) { + count := func(ret map[string]*ImageUsageCount, results *modulebase.ListResult) { for _, r := range results.Data { format, _ := r.GetString("disk_format") status, _ := r.GetString("status") @@ -254,7 +255,7 @@ func setImageMeta(params jsonutils.JSONObject) (http.Header, error) { return header, nil } -func (this *ImageManager) ListMemberProjects(s *mcclient.ClientSession, imageId string) (*ListResult, error) { +func (this *ImageManager) ListMemberProjects(s *mcclient.ClientSession, imageId string) (*modulebase.ListResult, error) { result, e := this.ListMemberProjectIds(s, imageId) if e != nil { return nil, e @@ -273,9 +274,9 @@ func (this *ImageManager) ListMemberProjects(s *mcclient.ClientSession, imageId return result, nil } -func (this *ImageManager) ListMemberProjectIds(s *mcclient.ClientSession, imageId string) (*ListResult, error) { +func (this *ImageManager) ListMemberProjectIds(s *mcclient.ClientSession, imageId string) (*modulebase.ListResult, error) { path := fmt.Sprintf("/%s/%s/members", this.URLPath(), url.PathEscape(imageId)) - return this._list(s, path, "members") + return modulebase.List(this.ResourceManager, s, path, "members") } func (this *ImageManager) AddMembership(s *mcclient.ClientSession, img string, proj string, canShare bool) error { @@ -348,7 +349,7 @@ func (this *ImageManager) _addMembership(s *mcclient.ClientSession, image_id str params.Add(jsonutils.JSONFalse, "member", "can_share") } path := fmt.Sprintf("/%s/%s/members/%s", this.URLPath(), url.PathEscape(image_id), url.PathEscape(project_id)) - _, e := this._put(s, path, params, "") + _, e := modulebase.Put(this.ResourceManager, s, path, params, "") return e } @@ -367,7 +368,7 @@ func (this *ImageManager) _addMemberships(s *mcclient.ClientSession, image_id st params := jsonutils.NewDict() params.Add(memberships, "memberships") path := fmt.Sprintf("/%s/%s/members", this.URLPath(), url.PathEscape(image_id)) - _, e := this._put(s, path, params, "") + _, e := modulebase.Put(this.ResourceManager, s, path, params, "") return e } @@ -385,17 +386,17 @@ func (this *ImageManager) RemoveMembership(s *mcclient.ClientSession, image stri func (this *ImageManager) _removeMembership(s *mcclient.ClientSession, image_id string, project_id string) error { path := fmt.Sprintf("/%s/%s/members/%s", this.URLPath(), url.PathEscape(image_id), url.PathEscape(project_id)) - _, e := this._delete(s, path, nil, "") + _, e := modulebase.Delete(this.ResourceManager, s, path, nil, "") return e } -func (this *ImageManager) ListSharedImageIds(s *mcclient.ClientSession, projectId string) (*ListResult, error) { +func (this *ImageManager) ListSharedImageIds(s *mcclient.ClientSession, projectId string) (*modulebase.ListResult, error) { path := fmt.Sprintf("/shared-images/%s", projectId) // {"shared_images": [{"image_id": "4d82c731-937e-4420-959b-de9c213efd2b", "can_share": false}]} - return this._list(s, path, "shared_images") + return modulebase.List(this.ResourceManager, s, path, "shared_images") } -func (this *ImageManager) ListSharedImages(s *mcclient.ClientSession, projectId string) (*ListResult, error) { +func (this *ImageManager) ListSharedImages(s *mcclient.ClientSession, projectId string) (*modulebase.ListResult, error) { result, e := this.ListSharedImageIds(s, projectId) if e != nil { return nil, e @@ -491,7 +492,7 @@ func (this *ImageManager) _create(s *mcclient.ClientSession, params jsonutils.JS headers.Add("Content-Length", fmt.Sprintf("%d", size)) } } - resp, err := this.rawRequest(s, method, path, headers, body) + resp, err := modulebase.RawRequest(this.ResourceManager, s, method, path, headers, body) _, json, err := s.ParseJSONResponse(resp, err) if err != nil { return nil, err @@ -531,7 +532,7 @@ func (this *ImageManager) _update(s *mcclient.ClientSession, id string, params j return nil, err } path := fmt.Sprintf("/%s/%s", this.URLPath(), url.PathEscape(id)) - resp, err := this.rawRequest(s, "PUT", path, headers, body) + resp, err := modulebase.RawRequest(this.ResourceManager, s, "PUT", path, headers, body) _, json, err := s.ParseJSONResponse(resp, err) if err != nil { return nil, err @@ -552,7 +553,7 @@ func (this *ImageManager) Download(s *mcclient.ClientSession, id string, format if len(queryString) > 0 { path = fmt.Sprintf("%s?%s", path, queryString) } - resp, err := this.rawRequest(s, "GET", path, nil, nil) + resp, err := modulebase.RawRequest(this.ResourceManager, s, "GET", path, nil, nil) if err == nil && resp.StatusCode >= 200 && resp.StatusCode < 300 { sizeBytes, err := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64) if err != nil { @@ -584,7 +585,7 @@ func init() { } type SImageUsageManager struct { - ResourceManager + modulebase.ResourceManager } func (this *SImageUsageManager) GetUsage(session *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -595,12 +596,12 @@ func (this *SImageUsageManager) GetUsage(session *mcclient.ClientSession, params url = fmt.Sprintf("%s?%s", url, query) } } - return this._get(session, url, "usage") + return modulebase.Get(this.ResourceManager, session, url, "usage") } var ( ImageUsages SImageUsageManager - ImageLogs ResourceManager + ImageLogs modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_infos.go b/pkg/mcclient/modules/mod_infos.go index 8bc3cd0bdb..98baa48d98 100644 --- a/pkg/mcclient/modules/mod_infos.go +++ b/pkg/mcclient/modules/mod_infos.go @@ -22,10 +22,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type InfoManager struct { - ResourceManager + modulebase.ResourceManager } var ( @@ -34,7 +35,7 @@ var ( func (this *InfoManager) Update(s *mcclient.ClientSession, header http.Header, body io.Reader) (jsonutils.JSONObject, error) { path := fmt.Sprintf("/%s", this.URLPath()) - resp, err := this.rawRequest(s, "POST", path, header, body) + resp, err := modulebase.RawRequest(this.ResourceManager, s, "POST", path, header, body) _, json, err := s.ParseJSONResponse(resp, err) if err != nil { return nil, err diff --git a/pkg/mcclient/modules/mod_instances.go b/pkg/mcclient/modules/mod_instances.go index 4adc135cc7..7f6205f9be 100644 --- a/pkg/mcclient/modules/mod_instances.go +++ b/pkg/mcclient/modules/mod_instances.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Instances ResourceManager + Instances modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_isolatedevices.go b/pkg/mcclient/modules/mod_isolatedevices.go index a9ef2e1095..e287bce883 100644 --- a/pkg/mcclient/modules/mod_isolatedevices.go +++ b/pkg/mcclient/modules/mod_isolatedevices.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - IsolatedDevices ResourceManager + IsolatedDevices modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_itsm_deployments.go b/pkg/mcclient/modules/mod_itsm_deployments.go index a6b9045370..0d485b6efa 100644 --- a/pkg/mcclient/modules/mod_itsm_deployments.go +++ b/pkg/mcclient/modules/mod_itsm_deployments.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ProcessDeployments ResourceManager + ProcessDeployments modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_itsm_historic_process_instances.go b/pkg/mcclient/modules/mod_itsm_historic_process_instances.go index 29d8e767a5..100ccf9933 100644 --- a/pkg/mcclient/modules/mod_itsm_historic_process_instances.go +++ b/pkg/mcclient/modules/mod_itsm_historic_process_instances.go @@ -20,10 +20,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type HiProcInstManager struct { - ResourceManager + modulebase.ResourceManager } func (this *HiProcInstManager) GetStatistics(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -32,12 +33,12 @@ func (this *HiProcInstManager) GetStatistics(s *mcclient.ClientSession, params j hiProcInstPath := fmt.Sprintf("/historic-process-instances?status=unfinished&user_id=%s", userId) procTaskPath := fmt.Sprintf("/process-tasks?user_id=%s", userId) - hiProcInstObj, err := this._list(s, hiProcInstPath, "historic-process-instances") + hiProcInstObj, err := modulebase.List(this.ResourceManager, s, hiProcInstPath, "historic-process-instances") if err != nil { return nil, err } - procTaskObj, err := this._list(s, procTaskPath, "process-tasks") + procTaskObj, err := modulebase.List(this.ResourceManager, s, procTaskPath, "process-tasks") if err != nil { return nil, err } diff --git a/pkg/mcclient/modules/mod_itsm_historic_task_instances.go b/pkg/mcclient/modules/mod_itsm_historic_task_instances.go index 317d0b2d08..03288d4de7 100644 --- a/pkg/mcclient/modules/mod_itsm_historic_task_instances.go +++ b/pkg/mcclient/modules/mod_itsm_historic_task_instances.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - HistoricTaskInstances ResourceManager + HistoricTaskInstances modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_itsm_process_definitions.go b/pkg/mcclient/modules/mod_itsm_process_definitions.go index 3774e54039..7adf6ebab3 100644 --- a/pkg/mcclient/modules/mod_itsm_process_definitions.go +++ b/pkg/mcclient/modules/mod_itsm_process_definitions.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ProcessDefinitions ResourceManager + ProcessDefinitions modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_itsm_process_instances.go b/pkg/mcclient/modules/mod_itsm_process_instances.go index 8924f559fe..c249eb34d6 100644 --- a/pkg/mcclient/modules/mod_itsm_process_instances.go +++ b/pkg/mcclient/modules/mod_itsm_process_instances.go @@ -21,10 +21,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type ProcessInstanceManager struct { - ResourceManager + modulebase.ResourceManager } var ( @@ -33,7 +34,7 @@ var ( func (self *ProcessInstanceManager) Upload(s *mcclient.ClientSession, header http.Header, body io.Reader) (jsonutils.JSONObject, error) { path := fmt.Sprintf("/%s", self.URLPath()) - resp, err := self.rawRequest(s, "POST", path, header, body) + resp, err := modulebase.RawRequest(self.ResourceManager, s, "POST", path, header, body) _, json, err := s.ParseJSONResponse(resp, err) if err != nil { return nil, err diff --git a/pkg/mcclient/modules/mod_itsm_tasks.go b/pkg/mcclient/modules/mod_itsm_tasks.go index 9b05759d4b..ac0813697b 100644 --- a/pkg/mcclient/modules/mod_itsm_tasks.go +++ b/pkg/mcclient/modules/mod_itsm_tasks.go @@ -19,10 +19,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type SProcessTasksManager struct { - ResourceManager + modulebase.ResourceManager } var ( @@ -46,6 +47,6 @@ func (this *SProcessTasksManager) QuickComplete(s *mcclient.ClientSession, param path = fmt.Sprintf("%s?%s", path, qs) } } - _, err := this._get(s, path, "") + _, err := modulebase.Get(this.ResourceManager, s, path, "") return err } diff --git a/pkg/mcclient/modules/mod_keypairs.go b/pkg/mcclient/modules/mod_keypairs.go index b76974f8f6..7d9a9a728a 100644 --- a/pkg/mcclient/modules/mod_keypairs.go +++ b/pkg/mcclient/modules/mod_keypairs.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type KeypairManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_labels.go b/pkg/mcclient/modules/mod_labels.go index 0551771ca2..a0828a5c62 100644 --- a/pkg/mcclient/modules/mod_labels.go +++ b/pkg/mcclient/modules/mod_labels.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Labels ResourceManager + Labels modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_license.go b/pkg/mcclient/modules/mod_license.go index 0897b3fc10..4ddf713534 100644 --- a/pkg/mcclient/modules/mod_license.go +++ b/pkg/mcclient/modules/mod_license.go @@ -20,12 +20,13 @@ import ( "net/http" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type LicenseManager struct { - ResourceManager + modulebase.ResourceManager } var ( @@ -34,7 +35,7 @@ var ( func (this *LicenseManager) Upload(s *mcclient.ClientSession, header http.Header, body io.Reader) (jsonutils.JSONObject, error) { path := fmt.Sprintf("/%s", this.URLPath()) - resp, err := this.rawRequest(s, "POST", path, header, body) + resp, err := modulebase.RawRequest(this.ResourceManager, s, "POST", path, header, body) _, json, err := s.ParseJSONResponse(resp, err) if err != nil { return nil, err diff --git a/pkg/mcclient/modules/mod_loadbalanceracls.go b/pkg/mcclient/modules/mod_loadbalanceracls.go index 4eb688bd7f..a0ada2aa0a 100644 --- a/pkg/mcclient/modules/mod_loadbalanceracls.go +++ b/pkg/mcclient/modules/mod_loadbalanceracls.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerAclManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_loadbalanceragents.go b/pkg/mcclient/modules/mod_loadbalanceragents.go index 0190592bce..f4438e75e3 100644 --- a/pkg/mcclient/modules/mod_loadbalanceragents.go +++ b/pkg/mcclient/modules/mod_loadbalanceragents.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerAgentManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_loadbalancerbackendgroups.go b/pkg/mcclient/modules/mod_loadbalancerbackendgroups.go index 71d87bc0b0..7ce06e061e 100644 --- a/pkg/mcclient/modules/mod_loadbalancerbackendgroups.go +++ b/pkg/mcclient/modules/mod_loadbalancerbackendgroups.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerBackendGroupManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_loadbalancerbackends.go b/pkg/mcclient/modules/mod_loadbalancerbackends.go index 58a5c69a7b..2f1e981af4 100644 --- a/pkg/mcclient/modules/mod_loadbalancerbackends.go +++ b/pkg/mcclient/modules/mod_loadbalancerbackends.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerBackendManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_loadbalancercachedacls.go b/pkg/mcclient/modules/mod_loadbalancercachedacls.go index 593def8163..4846c797e1 100644 --- a/pkg/mcclient/modules/mod_loadbalancercachedacls.go +++ b/pkg/mcclient/modules/mod_loadbalancercachedacls.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerCachedAclManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_loadbalancercachedcertificates.go b/pkg/mcclient/modules/mod_loadbalancercachedcertificates.go index c635875f41..76a0499e4b 100644 --- a/pkg/mcclient/modules/mod_loadbalancercachedcertificates.go +++ b/pkg/mcclient/modules/mod_loadbalancercachedcertificates.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerCachedCertificateManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_loadbalancercertificates.go b/pkg/mcclient/modules/mod_loadbalancercertificates.go index 2622f8b63e..2a9dd853d9 100644 --- a/pkg/mcclient/modules/mod_loadbalancercertificates.go +++ b/pkg/mcclient/modules/mod_loadbalancercertificates.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerCertificateManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_loadbalancerclusters.go b/pkg/mcclient/modules/mod_loadbalancerclusters.go index 7c24d74722..4f6f5b92b6 100644 --- a/pkg/mcclient/modules/mod_loadbalancerclusters.go +++ b/pkg/mcclient/modules/mod_loadbalancerclusters.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerClusterManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_loadbalancerlistenerrules.go b/pkg/mcclient/modules/mod_loadbalancerlistenerrules.go index eb50293f39..bf7195b58e 100644 --- a/pkg/mcclient/modules/mod_loadbalancerlistenerrules.go +++ b/pkg/mcclient/modules/mod_loadbalancerlistenerrules.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerListenerRuleManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_loadbalancerlisteners.go b/pkg/mcclient/modules/mod_loadbalancerlisteners.go index da5565a48b..316a75cf5d 100644 --- a/pkg/mcclient/modules/mod_loadbalancerlisteners.go +++ b/pkg/mcclient/modules/mod_loadbalancerlisteners.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerListenerManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_loadbalancernetworks.go b/pkg/mcclient/modules/mod_loadbalancernetworks.go index 7ee5493c9a..a319430e39 100644 --- a/pkg/mcclient/modules/mod_loadbalancernetworks.go +++ b/pkg/mcclient/modules/mod_loadbalancernetworks.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Loadbalancernetworks JointResourceManager + Loadbalancernetworks modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_loadbalancers.go b/pkg/mcclient/modules/mod_loadbalancers.go index ac91ecf8e8..278bfebd15 100644 --- a/pkg/mcclient/modules/mod_loadbalancers.go +++ b/pkg/mcclient/modules/mod_loadbalancers.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type LoadbalancerManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_logs.go b/pkg/mcclient/modules/mod_logs.go index faf69fa354..02faae5df5 100644 --- a/pkg/mcclient/modules/mod_logs.go +++ b/pkg/mcclient/modules/mod_logs.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Logs ResourceManager + Logs modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_metadatas.go b/pkg/mcclient/modules/mod_metadatas.go index 18746e3e83..b6986f1c40 100644 --- a/pkg/mcclient/modules/mod_metadatas.go +++ b/pkg/mcclient/modules/mod_metadatas.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Metadatas ResourceManager + Metadatas modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_meteralert.go b/pkg/mcclient/modules/mod_meteralert.go index 84f738603d..5b95dbb656 100644 --- a/pkg/mcclient/modules/mod_meteralert.go +++ b/pkg/mcclient/modules/mod_meteralert.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - MeterAlert ResourceManager + MeterAlert modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_metrics.go b/pkg/mcclient/modules/mod_metrics.go index dbb58db0c5..cb88b7baf2 100644 --- a/pkg/mcclient/modules/mod_metrics.go +++ b/pkg/mcclient/modules/mod_metrics.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Metrics ResourceManager + Metrics modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_metrictypes.go b/pkg/mcclient/modules/mod_metrictypes.go index 9ac670ad23..ac70d64e7d 100644 --- a/pkg/mcclient/modules/mod_metrictypes.go +++ b/pkg/mcclient/modules/mod_metrictypes.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - MetricsTypes ResourceManager + MetricsTypes modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_monitor_metrics.go b/pkg/mcclient/modules/mod_monitor_metrics.go index 2da67712ea..02f1f6a24b 100644 --- a/pkg/mcclient/modules/mod_monitor_metrics.go +++ b/pkg/mcclient/modules/mod_monitor_metrics.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type MonitorMetricManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_monitorinputs.go b/pkg/mcclient/modules/mod_monitorinputs.go index 93cc6109b7..ea6ad5c540 100644 --- a/pkg/mcclient/modules/mod_monitorinputs.go +++ b/pkg/mcclient/modules/mod_monitorinputs.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - MonitorInputs ResourceManager + MonitorInputs modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_monitortemplates.go b/pkg/mcclient/modules/mod_monitortemplates.go index fab1cd4f35..6dadd5856e 100644 --- a/pkg/mcclient/modules/mod_monitortemplates.go +++ b/pkg/mcclient/modules/mod_monitortemplates.go @@ -14,9 +14,11 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - MonitorTemplates ResourceManager - MonitorTemplateInputs JointResourceManager + MonitorTemplates modulebase.ResourceManager + MonitorTemplateInputs modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_monitortypes.go b/pkg/mcclient/modules/mod_monitortypes.go index cdafb87d5c..1eea48e809 100644 --- a/pkg/mcclient/modules/mod_monitortypes.go +++ b/pkg/mcclient/modules/mod_monitortypes.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - MonitorTypes ResourceManager + MonitorTypes modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_natdtables.go b/pkg/mcclient/modules/mod_natdtables.go index 06a349d149..8c18410f25 100644 --- a/pkg/mcclient/modules/mod_natdtables.go +++ b/pkg/mcclient/modules/mod_natdtables.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - NatDTable ResourceManager + NatDTable modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_natgateways.go b/pkg/mcclient/modules/mod_natgateways.go index 84c10d4800..33ef81a5b8 100644 --- a/pkg/mcclient/modules/mod_natgateways.go +++ b/pkg/mcclient/modules/mod_natgateways.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - NatGateways ResourceManager + NatGateways modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_natstables.go b/pkg/mcclient/modules/mod_natstables.go index bcfba837fd..87b1e34578 100644 --- a/pkg/mcclient/modules/mod_natstables.go +++ b/pkg/mcclient/modules/mod_natstables.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - NatSTable ResourceManager + NatSTable modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_networkinterfacenetworks.go b/pkg/mcclient/modules/mod_networkinterfacenetworks.go index f5bb01f012..91002f1769 100644 --- a/pkg/mcclient/modules/mod_networkinterfacenetworks.go +++ b/pkg/mcclient/modules/mod_networkinterfacenetworks.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Networkinterfacenetworks JointResourceManager + Networkinterfacenetworks modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_networkinterfaces.go b/pkg/mcclient/modules/mod_networkinterfaces.go index 26a1098173..aeba1ecc64 100644 --- a/pkg/mcclient/modules/mod_networkinterfaces.go +++ b/pkg/mcclient/modules/mod_networkinterfaces.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Networkinterfaces ResourceManager + Networkinterfaces modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_networks.go b/pkg/mcclient/modules/mod_networks.go index e5bf851290..8cc81c997f 100644 --- a/pkg/mcclient/modules/mod_networks.go +++ b/pkg/mcclient/modules/mod_networks.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Networks ResourceManager + Networks modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_nodealert.go b/pkg/mcclient/modules/mod_nodealert.go index c56bab1046..e8283fec70 100644 --- a/pkg/mcclient/modules/mod_nodealert.go +++ b/pkg/mcclient/modules/mod_nodealert.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - NodeAlert ResourceManager + NodeAlert modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_nodes.go b/pkg/mcclient/modules/mod_nodes.go index 3c145737ab..817c0b4ec6 100644 --- a/pkg/mcclient/modules/mod_nodes.go +++ b/pkg/mcclient/modules/mod_nodes.go @@ -19,16 +19,17 @@ import ( "net/url" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type NodeManager struct { - ResourceManager + modulebase.ResourceManager } -func _genSubtmitResults(idlist []string, status int, err error) []SubmitResult { - results := make([]SubmitResult, len(idlist)) +func _genSubtmitResults(idlist []string, status int, err error) []modulebase.SubmitResult { + results := make([]modulebase.SubmitResult, len(idlist)) var data jsonutils.JSONObject if err != nil { data = jsonutils.NewString(err.Error()) @@ -36,12 +37,12 @@ func _genSubtmitResults(idlist []string, status int, err error) []SubmitResult { data = jsonutils.JSONNull } for i := 0; i < len(results); i++ { - results[i] = SubmitResult{Id: idlist[i], Status: status, Data: data} + results[i] = modulebase.SubmitResult{Id: idlist[i], Status: status, Data: data} } return results } -func (this *NodeManager) _batchPerformInContexts(s *mcclient.ClientSession, idlist []string, action string, params jsonutils.JSONObject, ctxs []ManagerContext) []SubmitResult { +func (this *NodeManager) _batchPerformInContexts(s *mcclient.ClientSession, idlist []string, action string, params jsonutils.JSONObject, ctxs []modulebase.ManagerContext) []modulebase.SubmitResult { labels, err := params.Get("labels") if err != nil { return _genSubtmitResults(idlist, 406, fmt.Errorf("Missing labels")) @@ -55,14 +56,14 @@ func (this *NodeManager) _batchPerformInContexts(s *mcclient.ClientSession, idli body.Add(node, "node") path := fmt.Sprintf("/%s/%s", this.ContextPath(ctxs), url.PathEscape(action)) - _, err = this._post(s, path, body, this.KeywordPlural) + _, err = modulebase.Post(this.ResourceManager, s, path, body, this.KeywordPlural) if err != nil { return _genSubtmitResults(idlist, 400, err) } return _genSubtmitResults(idlist, 200, nil) } -func (this *NodeManager) BatchPerformActionInContexts(s *mcclient.ClientSession, idlist []string, action string, params jsonutils.JSONObject, ctxs []ManagerContext) []SubmitResult { +func (this *NodeManager) BatchPerformActionInContexts(s *mcclient.ClientSession, idlist []string, action string, params jsonutils.JSONObject, ctxs []modulebase.ManagerContext) []modulebase.SubmitResult { switch action { case "remove-labels": return this._batchPerformInContexts(s, idlist, action, params, ctxs) @@ -84,7 +85,7 @@ func (this *NodeManager) NewNode(s *mcclient.ClientSession, name string, ip stri arr.Add(data) params := jsonutils.NewDict() params.Add(arr, "nodes") - res, err := this._post(s, "/nodes", params, "nodes") + res, err := modulebase.Post(this.ResourceManager, s, "/nodes", params, "nodes") if err != nil { return nil, err } diff --git a/pkg/mcclient/modules/mod_notices.go b/pkg/mcclient/modules/mod_notices.go index bda930da37..90eb49b0d6 100644 --- a/pkg/mcclient/modules/mod_notices.go +++ b/pkg/mcclient/modules/mod_notices.go @@ -14,12 +14,14 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type NoticeManager struct { - ResourceManager + modulebase.ResourceManager } type NoticeReadMarkManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_notify.go b/pkg/mcclient/modules/mod_notify.go index 0b009f1607..6552269f60 100644 --- a/pkg/mcclient/modules/mod_notify.go +++ b/pkg/mcclient/modules/mod_notify.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type ConfigsManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_operations.go b/pkg/mcclient/modules/mod_operations.go index 5430bc9e79..a9170e382d 100644 --- a/pkg/mcclient/modules/mod_operations.go +++ b/pkg/mcclient/modules/mod_operations.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Operations ResourceManager + Operations modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_parameters.go b/pkg/mcclient/modules/mod_parameters.go index 1dc3e0cae4..69ae1d7d65 100644 --- a/pkg/mcclient/modules/mod_parameters.go +++ b/pkg/mcclient/modules/mod_parameters.go @@ -18,6 +18,7 @@ import ( "context" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" @@ -25,7 +26,7 @@ import ( ) type ParametersManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_performances.go b/pkg/mcclient/modules/mod_performances.go index a56580ca55..67770e80b7 100644 --- a/pkg/mcclient/modules/mod_performances.go +++ b/pkg/mcclient/modules/mod_performances.go @@ -18,12 +18,13 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type PerformanceManager struct { - ResourceManager + modulebase.ResourceManager } var ( @@ -39,7 +40,7 @@ func (this *PerformanceManager) GetTop5(s *mcclient.ClientSession, params jsonut path := fmt.Sprintf("/%s/top5?node_labels=%s", this.KeywordPlural, node_labels) - return this._get(s, path, this.Keyword) + return modulebase.Get(this.ResourceManager, s, path, this.Keyword) } func init() { diff --git a/pkg/mcclient/modules/mod_policies.go b/pkg/mcclient/modules/mod_policies.go index 4cc018b5d0..1e51fb28d6 100644 --- a/pkg/mcclient/modules/mod_policies.go +++ b/pkg/mcclient/modules/mod_policies.go @@ -16,13 +16,14 @@ package modules import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/util/rbacutils" ) type SPolicyManager struct { - ResourceManager + modulebase.ResourceManager } var Policies SPolicyManager diff --git a/pkg/mcclient/modules/mod_price_infos.go b/pkg/mcclient/modules/mod_price_infos.go index b1b1856bb3..2275de2f7f 100644 --- a/pkg/mcclient/modules/mod_price_infos.go +++ b/pkg/mcclient/modules/mod_price_infos.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - PriceInfos ResourceManager + PriceInfos modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_processes.go b/pkg/mcclient/modules/mod_processes.go index 636429dfc8..55ef487f34 100644 --- a/pkg/mcclient/modules/mod_processes.go +++ b/pkg/mcclient/modules/mod_processes.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Processes ResourceManager + Processes modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_processlogs.go b/pkg/mcclient/modules/mod_processlogs.go index 60aa217410..2c35a11e21 100644 --- a/pkg/mcclient/modules/mod_processlogs.go +++ b/pkg/mcclient/modules/mod_processlogs.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Processlogs ResourceManager + Processlogs modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_project_admin_candidates.go b/pkg/mcclient/modules/mod_project_admin_candidates.go index 876d27df58..0ef62a949e 100644 --- a/pkg/mcclient/modules/mod_project_admin_candidates.go +++ b/pkg/mcclient/modules/mod_project_admin_candidates.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ProjectAdminCandidate ResourceManager + ProjectAdminCandidate modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_project_admins.go b/pkg/mcclient/modules/mod_project_admins.go index a553f8bdde..b43ac5ef69 100644 --- a/pkg/mcclient/modules/mod_project_admins.go +++ b/pkg/mcclient/modules/mod_project_admins.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ProjectAdmin ResourceManager + ProjectAdmin modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_projecthosts.go b/pkg/mcclient/modules/mod_projecthosts.go index 4376f7815d..fd7ac0f147 100644 --- a/pkg/mcclient/modules/mod_projecthosts.go +++ b/pkg/mcclient/modules/mod_projecthosts.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type ProjectNodeManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_projects.go b/pkg/mcclient/modules/mod_projects.go index ce36c94e06..d679252a1d 100644 --- a/pkg/mcclient/modules/mod_projects.go +++ b/pkg/mcclient/modules/mod_projects.go @@ -21,10 +21,11 @@ import ( "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type ProjectManagerV3 struct { - ResourceManager + modulebase.ResourceManager } var ( @@ -33,12 +34,12 @@ var ( func (this *ProjectManagerV3) _join(s *mcclient.ClientSession, pid, uid, rid, resource string) error { if resource == "users" { - _, err := RolesV3.PutInContexts(s, rid, nil, []ManagerContext{{&Projects, pid}, {&UsersV3, uid}}) + _, err := RolesV3.PutInContexts(s, rid, nil, []modulebase.ManagerContext{{&Projects, pid}, {&UsersV3, uid}}) if err != nil { return err } } else if resource == "groups" { - _, err := RolesV3.PutInContexts(s, rid, nil, []ManagerContext{{&Projects, pid}, {&Groups, uid}}) + _, err := RolesV3.PutInContexts(s, rid, nil, []modulebase.ManagerContext{{&Projects, pid}, {&Groups, uid}}) if err != nil { return err } @@ -49,9 +50,9 @@ func (this *ProjectManagerV3) _join(s *mcclient.ClientSession, pid, uid, rid, re func (this *ProjectManagerV3) _leave(s *mcclient.ClientSession, pid string, resource string, uid string, rid string) error { var err error if resource == "users" { - _, err = RolesV3.DeleteInContexts(s, rid, nil, []ManagerContext{{&Projects, pid}, {&UsersV3, uid}}) + _, err = RolesV3.DeleteInContexts(s, rid, nil, []modulebase.ManagerContext{{&Projects, pid}, {&UsersV3, uid}}) } else if resource == "groups" { - _, err = RolesV3.DeleteInContexts(s, rid, nil, []ManagerContext{{&Projects, pid}, {&Groups, uid}}) + _, err = RolesV3.DeleteInContexts(s, rid, nil, []modulebase.ManagerContext{{&Projects, pid}, {&Groups, uid}}) } if err != nil { return err @@ -190,7 +191,7 @@ func (this *ProjectManagerV3) DoProjectBatchJoin(s *mcclient.ClientSession, para s, rid, nil, - []ManagerContext{ + []modulebase.ManagerContext{ {&Projects, pid}, {&UsersV3, id}}) @@ -202,7 +203,7 @@ func (this *ProjectManagerV3) DoProjectBatchJoin(s *mcclient.ClientSession, para s, rid, nil, - []ManagerContext{ + []modulebase.ManagerContext{ {&Projects, pid}, {&Groups, id}}) @@ -240,12 +241,12 @@ func (this *ProjectManagerV3) DoProjectBatchDeleteUserGroup(s *mcclient.ClientSe res_type, _ := item.GetString("res_type") if res_type == "user" { - _, err := RolesV3.DeleteInContexts(s, role_id, nil, []ManagerContext{{&Projects, pid}, {&UsersV3, id}}) + _, err := RolesV3.DeleteInContexts(s, role_id, nil, []modulebase.ManagerContext{{&Projects, pid}, {&UsersV3, id}}) if err != nil { return nil, err } } else if res_type == "group" { - _, err := RolesV3.DeleteInContexts(s, role_id, nil, []ManagerContext{{&Projects, pid}, {&Groups, id}}) + _, err := RolesV3.DeleteInContexts(s, role_id, nil, []modulebase.ManagerContext{{&Projects, pid}, {&Groups, id}}) if err != nil { return nil, err } @@ -259,7 +260,7 @@ func (this *ProjectManagerV3) AddTags(session *mcclient.ClientSession, id string path := fmt.Sprintf("/projects/%s/tags", id) body := jsonutils.NewDict() body.Add(jsonutils.NewStringArray(tags), "tags") - _, err := this._put(session, path, body, "") + _, err := modulebase.Put(this.ResourceManager, session, path, body, "") if err != nil { return err } diff --git a/pkg/mcclient/modules/mod_quotas.go b/pkg/mcclient/modules/mod_quotas.go index 47261559ae..7225053509 100644 --- a/pkg/mcclient/modules/mod_quotas.go +++ b/pkg/mcclient/modules/mod_quotas.go @@ -19,12 +19,13 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type QuotaManager struct { - ResourceManager + modulebase.ResourceManager } func (this *QuotaManager) getURL(params jsonutils.JSONObject) string { @@ -44,11 +45,11 @@ func (this *QuotaManager) getURL(params jsonutils.JSONObject) string { } func (this *QuotaManager) GetQuota(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { - computeQuota, err := this._get(s, this.getURL(params), this.KeywordPlural) + computeQuota, err := modulebase.Get(this.ResourceManager, s, this.getURL(params), this.KeywordPlural) if err != nil { return nil, err } - imageQuota, err := ImageQuotas._get(s, ImageQuotas.getURL(params), ImageQuotas.KeywordPlural) + imageQuota, err := modulebase.Get(ImageQuotas.ResourceManager, s, ImageQuotas.getURL(params), ImageQuotas.KeywordPlural) if err != nil { return nil, err } @@ -92,11 +93,11 @@ func (this *QuotaManager) GetQuotaList(s *mcclient.ClientSession, params jsonuti } else { reqUrl = "/quotas/domains" } - computeQuotaList, err := this._list(s, reqUrl, this.KeywordPlural) + computeQuotaList, err := modulebase.List(this.ResourceManager, s, reqUrl, this.KeywordPlural) if err != nil { return nil, err } - imageQuotaList, err := ImageQuotas._list(s, reqUrl, this.KeywordPlural) + imageQuotaList, err := modulebase.List(ImageQuotas.ResourceManager, s, reqUrl, this.KeywordPlural) if err != nil { return nil, err } @@ -117,7 +118,7 @@ func (this *QuotaManager) doPost(s *mcclient.ClientSession, params jsonutils.JSO body := jsonutils.NewDict() body.Add(data, this.KeywordPlural) log.Debugf("set compute quota %s", body) - _, err = this._post(s, url, body, this.KeywordPlural) + _, err = modulebase.Post(this.ResourceManager, s, url, body, this.KeywordPlural) if err != nil { log.Errorf("set compute quota fail %s %s", data, err) return nil, err @@ -128,7 +129,7 @@ func (this *QuotaManager) doPost(s *mcclient.ClientSession, params jsonutils.JSO body := jsonutils.NewDict() body.Add(data, ImageQuotas.KeywordPlural) log.Debugf("set image quota %s", body) - _, err = ImageQuotas._post(s, url, body, ImageQuotas.KeywordPlural) + _, err = modulebase.Post(ImageQuotas.ResourceManager, s, url, body, ImageQuotas.KeywordPlural) if err != nil { log.Errorf("set quota fail %s %s", data, err) return nil, err diff --git a/pkg/mcclient/modules/mod_rates.go b/pkg/mcclient/modules/mod_rates.go index c4e55aaf77..73e1b545d4 100644 --- a/pkg/mcclient/modules/mod_rates.go +++ b/pkg/mcclient/modules/mod_rates.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Rates ResourceManager + Rates modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_recipients.go b/pkg/mcclient/modules/mod_recipients.go index 3315631bfd..eb37888771 100644 --- a/pkg/mcclient/modules/mod_recipients.go +++ b/pkg/mcclient/modules/mod_recipients.go @@ -20,10 +20,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type RecipientsManager struct { - ResourceManager + modulebase.ResourceManager } func (this *RecipientsManager) DoDeleteRecipient(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -34,7 +35,7 @@ func (this *RecipientsManager) DoDeleteRecipient(s *mcclient.ClientSession, para body.Add(params, this.Keyword) } - return this._delete(s, path, body, this.Keyword) + return modulebase.Delete(this.ResourceManager, s, path, body, this.Keyword) } var ( diff --git a/pkg/mcclient/modules/mod_regions.go b/pkg/mcclient/modules/mod_regions.go index 0a2cc9c985..f6a0b46488 100644 --- a/pkg/mcclient/modules/mod_regions.go +++ b/pkg/mcclient/modules/mod_regions.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type RegionManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_registers.go b/pkg/mcclient/modules/mod_registers.go index dc179fb6cb..d71c38540b 100644 --- a/pkg/mcclient/modules/mod_registers.go +++ b/pkg/mcclient/modules/mod_registers.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type RegisterManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_res_results.go b/pkg/mcclient/modules/mod_res_results.go index 992ef75f27..931a8b499e 100644 --- a/pkg/mcclient/modules/mod_res_results.go +++ b/pkg/mcclient/modules/mod_res_results.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ResResults ResourceManager + ResResults modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_res_tag_details.go b/pkg/mcclient/modules/mod_res_tag_details.go index 058ab7ed45..eca0a0d963 100644 --- a/pkg/mcclient/modules/mod_res_tag_details.go +++ b/pkg/mcclient/modules/mod_res_tag_details.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ResTagDetails ResourceManager + ResTagDetails modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_reservedips.go b/pkg/mcclient/modules/mod_reservedips.go index 8b8715c2c2..035126fccd 100644 --- a/pkg/mcclient/modules/mod_reservedips.go +++ b/pkg/mcclient/modules/mod_reservedips.go @@ -19,12 +19,13 @@ import ( "sync" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type ReservedIPManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_resource_details.go b/pkg/mcclient/modules/mod_resource_details.go index 8bf5b2b8b9..a29d423b9f 100644 --- a/pkg/mcclient/modules/mod_resource_details.go +++ b/pkg/mcclient/modules/mod_resource_details.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ResourceDetails ResourceManager + ResourceDetails modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_resource_fees.go b/pkg/mcclient/modules/mod_resource_fees.go index 466c87793e..fd6ba832d7 100644 --- a/pkg/mcclient/modules/mod_resource_fees.go +++ b/pkg/mcclient/modules/mod_resource_fees.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ResourceFees ResourceManager + ResourceFees modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_roleassignments.go b/pkg/mcclient/modules/mod_roleassignments.go index 0943a3bba2..138497b2b7 100644 --- a/pkg/mcclient/modules/mod_roleassignments.go +++ b/pkg/mcclient/modules/mod_roleassignments.go @@ -18,12 +18,13 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type RoleAssignmentManagerV3 struct { - ResourceManager + modulebase.ResourceManager } type role struct { diff --git a/pkg/mcclient/modules/mod_roles.go b/pkg/mcclient/modules/mod_roles.go index 90a4301f0e..f61d1438c1 100644 --- a/pkg/mcclient/modules/mod_roles.go +++ b/pkg/mcclient/modules/mod_roles.go @@ -20,11 +20,12 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/util/httputils" ) type RolesManager struct { - ResourceManager + modulebase.ResourceManager } var ( @@ -36,7 +37,7 @@ func (this *RolesManager) Delete(session *mcclient.ClientSession, id string, bod return this.DeleteInContexts(session, id, body, nil) } -func (this *RolesManager) DeleteInContexts(session *mcclient.ClientSession, id string, body jsonutils.JSONObject, ctxs []ManagerContext) (jsonutils.JSONObject, error) { +func (this *RolesManager) DeleteInContexts(session *mcclient.ClientSession, id string, body jsonutils.JSONObject, ctxs []modulebase.ManagerContext) (jsonutils.JSONObject, error) { if ctxs == nil { err := httputils.JSONClientError{} err.Code = 403 @@ -57,15 +58,15 @@ func (this *RolesManager) DeleteInContexts(session *mcclient.ClientSession, id s } } - return this.deleteInContexts(session, id, nil, body, ctxs) + return this.ResourceManager.DeleteInContexts(session, id, body, ctxs) } -func (this *RolesManager) BatchDelete(session *mcclient.ClientSession, idlist []string, body jsonutils.JSONObject) []SubmitResult { +func (this *RolesManager) BatchDelete(session *mcclient.ClientSession, idlist []string, body jsonutils.JSONObject) []modulebase.SubmitResult { return this.BatchDeleteInContexts(session, idlist, body, nil) } -func (this *RolesManager) BatchDeleteInContexts(session *mcclient.ClientSession, idlist []string, body jsonutils.JSONObject, ctxs []ManagerContext) []SubmitResult { - return BatchDo(idlist, func(id string) (jsonutils.JSONObject, error) { +func (this *RolesManager) BatchDeleteInContexts(session *mcclient.ClientSession, idlist []string, body jsonutils.JSONObject, ctxs []modulebase.ManagerContext) []modulebase.SubmitResult { + return modulebase.BatchDo(idlist, func(id string) (jsonutils.JSONObject, error) { return this.DeleteInContexts(session, id, body, ctxs) }) } diff --git a/pkg/mcclient/modules/mod_routetables.go b/pkg/mcclient/modules/mod_routetables.go index da62c80438..902cd0c673 100644 --- a/pkg/mcclient/modules/mod_routetables.go +++ b/pkg/mcclient/modules/mod_routetables.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type RouteTableManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_schedpolicies.go b/pkg/mcclient/modules/mod_schedpolicies.go index d91f2aabc3..91e4171009 100644 --- a/pkg/mcclient/modules/mod_schedpolicies.go +++ b/pkg/mcclient/modules/mod_schedpolicies.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Schedpolicies ResourceManager + Schedpolicies modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_schedtaghosts.go b/pkg/mcclient/modules/mod_schedtaghosts.go index f971dac6b9..502dd31fa7 100644 --- a/pkg/mcclient/modules/mod_schedtaghosts.go +++ b/pkg/mcclient/modules/mod_schedtaghosts.go @@ -14,13 +14,15 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Schedtaghosts JointResourceManager - Schedtagstorages JointResourceManager - Schedtagnetworks JointResourceManager + Schedtaghosts modulebase.JointResourceManager + Schedtagstorages modulebase.JointResourceManager + Schedtagnetworks modulebase.JointResourceManager ) -func newSchedtagJointManager(keyword, keywordPlural string, columns, adminColumns []string, slave Manager) JointResourceManager { +func newSchedtagJointManager(keyword, keywordPlural string, columns, adminColumns []string, slave modulebase.Manager) modulebase.JointResourceManager { columns = append(columns, "Schedtag_ID", "Schedtag") return NewJointComputeManager(keyword, keywordPlural, columns, adminColumns, &Schedtags, slave) diff --git a/pkg/mcclient/modules/mod_schedtags.go b/pkg/mcclient/modules/mod_schedtags.go index 94b6405cea..f31d57e20a 100644 --- a/pkg/mcclient/modules/mod_schedtags.go +++ b/pkg/mcclient/modules/mod_schedtags.go @@ -20,10 +20,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type SchedtagManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_scheduler.go b/pkg/mcclient/modules/mod_scheduler.go index 49e2f8fb48..0159ac980b 100644 --- a/pkg/mcclient/modules/mod_scheduler.go +++ b/pkg/mcclient/modules/mod_scheduler.go @@ -19,6 +19,7 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" @@ -37,7 +38,7 @@ func init() { } type SchedulerManager struct { - ResourceManager + modulebase.ResourceManager } func (this *SchedulerManager) DoSchedule(s *mcclient.ClientSession, input *api.ScheduleInput, count int) (*api.ScheduleOutput, error) { @@ -47,7 +48,7 @@ func (this *SchedulerManager) DoSchedule(s *mcclient.ClientSession, input *api.S } input.Count = count body := input.JSON(input) - ret, err := this._post(s, url, body, "") + ret, err := modulebase.Post(this.ResourceManager, s, url, body, "") if err != nil { return nil, err } @@ -82,7 +83,7 @@ func newSchedIdentURL(action, ident string) string { func (this *SchedulerManager) Test(s *mcclient.ClientSession, params *api.ScheduleInput) (jsonutils.JSONObject, error) { url := newSchedURL("test") - _, obj, err := this.jsonRequest(s, "POST", url, nil, params.JSON(params)) + _, obj, err := modulebase.JsonRequest(this.ResourceManager, s, "POST", url, nil, params.JSON(params)) if err != nil { return nil, err } @@ -109,7 +110,7 @@ func (this *SchedulerManager) DoForecast(s *mcclient.ClientSession, params jsonu data.Set("domain_id", jsonutils.NewString(domainId)) data.Set("project_id", jsonutils.NewString(projectId)) url := newSchedURL("forecast") - _, obj, err := this.jsonRequest(s, "POST", url, nil, data) + _, obj, err := modulebase.JsonRequest(this.ResourceManager, s, "POST", url, nil, data) if err != nil { return nil, err } @@ -118,14 +119,14 @@ func (this *SchedulerManager) DoForecast(s *mcclient.ClientSession, params jsonu func (this *SchedulerManager) Cleanup(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { url := newSchedURL("cleanup") - return this._post(s, url, params, "") + return modulebase.Post(this.ResourceManager, s, url, params, "") } func (this *SchedulerManager) SyncSku(s *mcclient.ClientSession, wait bool) (jsonutils.JSONObject, error) { params := jsonutils.NewDict() params.Add(jsonutils.NewBool(wait), "wait") url := newSchedURL("sync-sku") - return this._post(s, url, params, "") + return modulebase.Post(this.ResourceManager, s, url, params, "") } func (this *SchedulerManager) Kill(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -134,7 +135,7 @@ func (this *SchedulerManager) Kill(s *mcclient.ClientSession, params jsonutils.J func (this *SchedulerManager) CandidateList(s *mcclient.ClientSession, params jsonutils.JSONObject) (obj jsonutils.JSONObject, err error) { url := newSchedURL("candidate-list") - _, obj, err = this.jsonRequest(s, "POST", url, nil, params) + _, obj, err = modulebase.JsonRequest(this.ResourceManager, s, "POST", url, nil, params) if err != nil { return } @@ -188,12 +189,12 @@ func (this *SchedulerManager) CandidateList(s *mcclient.ClientSession, params js func (this *SchedulerManager) CandidateDetail(s *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { url := newSchedIdentURL("candidate-detail", id) - return this._post(s, url, params, "candidate") + return modulebase.Post(this.ResourceManager, s, url, params, "candidate") } func (this *SchedulerManager) HistoryList(s *mcclient.ClientSession, params jsonutils.JSONObject) (obj jsonutils.JSONObject, err error) { url := newSchedURL("history-list") - _, obj, err = this.jsonRequest(s, "POST", url, nil, params) + _, obj, err = modulebase.JsonRequest(this.ResourceManager, s, "POST", url, nil, params) if err != nil { return } @@ -202,7 +203,7 @@ func (this *SchedulerManager) HistoryList(s *mcclient.ClientSession, params json func (this *SchedulerManager) HistoryShow(s *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { url := newSchedIdentURL("history-detail", id) - return this._post(s, url, params, "history") + return modulebase.Post(this.ResourceManager, s, url, params, "history") } func (this *SchedulerManager) CleanCache(s *mcclient.ClientSession, hostId, sessionId string) error { @@ -213,7 +214,7 @@ func (this *SchedulerManager) CleanCache(s *mcclient.ClientSession, hostId, sess if len(sessionId) > 0 { url = fmt.Sprintf("%s?session=%s", url, sessionId) } - resp, err := this.rawRequest(s, "POST", url, nil, nil) + resp, err := modulebase.RawRequest(this.ResourceManager, s, "POST", url, nil, nil) if err != nil { return err } diff --git a/pkg/mcclient/modules/mod_secgrouprules.go b/pkg/mcclient/modules/mod_secgrouprules.go index e3c1f9c3ac..ef8c740db6 100644 --- a/pkg/mcclient/modules/mod_secgrouprules.go +++ b/pkg/mcclient/modules/mod_secgrouprules.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - SecGroupRules ResourceManager + SecGroupRules modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_secgroups.go b/pkg/mcclient/modules/mod_secgroups.go index cf869a5ae8..e11e5b1b9a 100644 --- a/pkg/mcclient/modules/mod_secgroups.go +++ b/pkg/mcclient/modules/mod_secgroups.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - SecGroups ResourceManager + SecGroups modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_serverdisks.go b/pkg/mcclient/modules/mod_serverdisks.go index 38a162f309..afcd382d57 100644 --- a/pkg/mcclient/modules/mod_serverdisks.go +++ b/pkg/mcclient/modules/mod_serverdisks.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Serverdisks JointResourceManager + Serverdisks modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_servernetworks.go b/pkg/mcclient/modules/mod_servernetworks.go index da3bb64129..6ae8cd1cd1 100644 --- a/pkg/mcclient/modules/mod_servernetworks.go +++ b/pkg/mcclient/modules/mod_servernetworks.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Servernetworks JointResourceManager + Servernetworks modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_servers.go b/pkg/mcclient/modules/mod_servers.go index d4bec5050e..ae12e8ad11 100644 --- a/pkg/mcclient/modules/mod_servers.go +++ b/pkg/mcclient/modules/mod_servers.go @@ -19,6 +19,7 @@ import ( "strings" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/gotypes" "yunion.io/x/pkg/utils" @@ -27,7 +28,7 @@ import ( ) type ServerManager struct { - ResourceManager + modulebase.ResourceManager } func (this *ServerManager) GetLoginInfo(s *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { diff --git a/pkg/mcclient/modules/mod_service_name_suggestions.go b/pkg/mcclient/modules/mod_service_name_suggestions.go index be78d5eb87..d7c4418282 100644 --- a/pkg/mcclient/modules/mod_service_name_suggestions.go +++ b/pkg/mcclient/modules/mod_service_name_suggestions.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ServiceNameSuggestion ResourceManager + ServiceNameSuggestion modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_servicehosts.go b/pkg/mcclient/modules/mod_servicehosts.go index 57d0f0830d..b19ff8055f 100644 --- a/pkg/mcclient/modules/mod_servicehosts.go +++ b/pkg/mcclient/modules/mod_servicehosts.go @@ -18,12 +18,13 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type ServiceNodeManager struct { - ResourceManager + modulebase.ResourceManager } func (this *ServiceNodeManager) DoDeleteServiceHost(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -34,7 +35,7 @@ func (this *ServiceNodeManager) DoDeleteServiceHost(s *mcclient.ClientSession, p body.Add(params, this.Keyword) } - return this._delete(s, path, body, this.Keyword) + return modulebase.Delete(this.ResourceManager, s, path, body, this.Keyword) } var ( diff --git a/pkg/mcclient/modules/mod_services.go b/pkg/mcclient/modules/mod_services.go index b0a537ba14..9ff1ec34c3 100644 --- a/pkg/mcclient/modules/mod_services.go +++ b/pkg/mcclient/modules/mod_services.go @@ -14,9 +14,11 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Services ResourceManager - ServicesV3 ResourceManager + Services modulebase.ResourceManager + ServicesV3 modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_servicetrees.go b/pkg/mcclient/modules/mod_servicetrees.go index ee282ed0a1..1a874e8256 100644 --- a/pkg/mcclient/modules/mod_servicetrees.go +++ b/pkg/mcclient/modules/mod_servicetrees.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - ServiceTrees ResourceManager + ServiceTrees modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_skus.go b/pkg/mcclient/modules/mod_skus.go index 2b13bae13f..746177f504 100644 --- a/pkg/mcclient/modules/mod_skus.go +++ b/pkg/mcclient/modules/mod_skus.go @@ -19,14 +19,15 @@ import ( "strings" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type SkusManager struct { - ResourceManager + modulebase.ResourceManager } type ServerSkusManager struct { - ResourceManager + modulebase.ResourceManager } var ( @@ -52,14 +53,14 @@ func init() { registerCompute(&ServerSkus) } -func (self *SkusManager) GetSkus(s *mcclient.ClientSession, providerId, regionId, zoneId string, limit, offset int) (*ListResult, error) { +func (self *SkusManager) GetSkus(s *mcclient.ClientSession, providerId, regionId, zoneId string, limit, offset int) (*modulebase.ListResult, error) { p := strings.ToLower(providerId) r := strings.ToLower(regionId) z := strings.ToLower(zoneId) url := fmt.Sprintf("/providers/%s/regions/%s/zones/%s/skus?limit=%d&offset=%d", p, r, z, limit, offset) - ret, err := self._list(s, url, self.KeywordPlural) + ret, err := modulebase.List(self.ResourceManager, s, url, self.KeywordPlural) if err != nil { - return &ListResult{}, err + return &modulebase.ListResult{}, err } return ret, nil diff --git a/pkg/mcclient/modules/mod_sms_configs.go b/pkg/mcclient/modules/mod_sms_configs.go index 4f8a2a22bd..1e57093f8d 100644 --- a/pkg/mcclient/modules/mod_sms_configs.go +++ b/pkg/mcclient/modules/mod_sms_configs.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - SmsConfigs ResourceManager + SmsConfigs modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_snapshotpolicy.go b/pkg/mcclient/modules/mod_snapshotpolicy.go index 8c85641448..8f9498fbbe 100644 --- a/pkg/mcclient/modules/mod_snapshotpolicy.go +++ b/pkg/mcclient/modules/mod_snapshotpolicy.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - SnapshotPoliciy ResourceManager + SnapshotPoliciy modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_snapshotpolicydisk.go b/pkg/mcclient/modules/mod_snapshotpolicydisk.go index 3794ff06e9..d9653f22c8 100644 --- a/pkg/mcclient/modules/mod_snapshotpolicydisk.go +++ b/pkg/mcclient/modules/mod_snapshotpolicydisk.go @@ -14,9 +14,11 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - SnapshotPolicyDisk JointResourceManager - SnapshotPolicyDisk1 JointResourceManager + SnapshotPolicyDisk modulebase.JointResourceManager + SnapshotPolicyDisk1 modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_snapshots.go b/pkg/mcclient/modules/mod_snapshots.go index 5227640356..bd9e459eab 100644 --- a/pkg/mcclient/modules/mod_snapshots.go +++ b/pkg/mcclient/modules/mod_snapshots.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Snapshots ResourceManager + Snapshots modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_specs.go b/pkg/mcclient/modules/mod_specs.go index 468cbdfd91..63f93ef51c 100644 --- a/pkg/mcclient/modules/mod_specs.go +++ b/pkg/mcclient/modules/mod_specs.go @@ -24,10 +24,11 @@ import ( "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type SpecsManager struct { - ResourceManager + modulebase.ResourceManager } func generateSpecURL(model, ident, action string, params jsonutils.JSONObject) string { @@ -63,7 +64,7 @@ func (this *SpecsManager) GetAllSpecs(s *mcclient.ClientSession, params jsonutil func (this *SpecsManager) GetModelSpecs(s *mcclient.ClientSession, model string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { url := newSpecURL(model, params) - return this._get(s, url, this.Keyword) + return modulebase.Get(this.ResourceManager, s, url, this.Keyword) } func (this *SpecsManager) GetObjects(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -79,7 +80,7 @@ func (this *SpecsManager) GetObjects(s *mcclient.ClientSession, params jsonutils } dict.Remove("key") url := newSpecActionURL(model, specKey, "resource", dict) - return this._get(s, url, this.Keyword) + return modulebase.Get(this.ResourceManager, s, url, this.Keyword) } func (this *SpecsManager) SpecsQueryModelObjects(s *mcclient.ClientSession, model string, specKeys []string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -88,7 +89,7 @@ func (this *SpecsManager) SpecsQueryModelObjects(s *mcclient.ClientSession, mode } specKey := url.QueryEscape(strings.Join(specKeys, "/")) url := newSpecActionURL(model, specKey, "resource", params) - return this._get(s, url, this.Keyword) + return modulebase.Get(this.ResourceManager, s, url, this.Keyword) } var ( diff --git a/pkg/mcclient/modules/mod_sshkeypairs.go b/pkg/mcclient/modules/mod_sshkeypairs.go index 39995773c7..bb388cf839 100644 --- a/pkg/mcclient/modules/mod_sshkeypairs.go +++ b/pkg/mcclient/modules/mod_sshkeypairs.go @@ -20,24 +20,25 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type SSshkeypairManager struct { - ResourceManager + modulebase.ResourceManager } -func (this *SSshkeypairManager) List(s *mcclient.ClientSession, params jsonutils.JSONObject) (*ListResult, error) { +func (this *SSshkeypairManager) List(s *mcclient.ClientSession, params jsonutils.JSONObject) (*modulebase.ListResult, error) { url := "/sshkeypairs" if params != nil { if queryStr := params.QueryString(); queryStr != "" { url = fmt.Sprintf("%s?%s", url, queryStr) } } - body, err := this._get(s, url, "sshkeypair") + body, err := modulebase.Get(this.ResourceManager, s, url, "sshkeypair") if err != nil { return nil, err } - result := ListResult{Data: []jsonutils.JSONObject{body}} + result := modulebase.ListResult{Data: []jsonutils.JSONObject{body}} return &result, nil } diff --git a/pkg/mcclient/modules/mod_stastics.go b/pkg/mcclient/modules/mod_stastics.go index 713edb6221..092cce8e79 100644 --- a/pkg/mcclient/modules/mod_stastics.go +++ b/pkg/mcclient/modules/mod_stastics.go @@ -18,12 +18,13 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type StatisticsManager struct { - ResourceManager + modulebase.ResourceManager } var ( @@ -38,7 +39,7 @@ func (this *StatisticsManager) GetByEnv(s *mcclient.ClientSession, params jsonut } path := fmt.Sprintf("/%s/env?node_labels=%s", this.KeywordPlural, node_labels) - return this._get(s, path, this.Keyword) + return modulebase.Get(this.ResourceManager, s, path, this.Keyword) } func (this *StatisticsManager) GetByResType(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -49,7 +50,7 @@ func (this *StatisticsManager) GetByResType(s *mcclient.ClientSession, params js } path := fmt.Sprintf("/%s/res_type?node_labels=%s", this.KeywordPlural, node_labels) - return this._get(s, path, this.Keyword) + return modulebase.Get(this.ResourceManager, s, path, this.Keyword) } func (this *StatisticsManager) GetHardware(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -60,7 +61,7 @@ func (this *StatisticsManager) GetHardware(s *mcclient.ClientSession, params jso } path := fmt.Sprintf("/%s/hardware?node_labels=%s", this.KeywordPlural, node_labels) - return this._get(s, path, this.Keyword) + return modulebase.Get(this.ResourceManager, s, path, this.Keyword) } func init() { diff --git a/pkg/mcclient/modules/mod_storagecachedimages.go b/pkg/mcclient/modules/mod_storagecachedimages.go index cf8ff2e1bf..9bf60f6e4c 100644 --- a/pkg/mcclient/modules/mod_storagecachedimages.go +++ b/pkg/mcclient/modules/mod_storagecachedimages.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Storagecachedimages JointResourceManager + Storagecachedimages modulebase.JointResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_storagecaches.go b/pkg/mcclient/modules/mod_storagecaches.go index 467fa3306a..02d3030ee8 100644 --- a/pkg/mcclient/modules/mod_storagecaches.go +++ b/pkg/mcclient/modules/mod_storagecaches.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Storagecaches ResourceManager + Storagecaches modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_storages.go b/pkg/mcclient/modules/mod_storages.go index ad4274a536..40b2a6627a 100644 --- a/pkg/mcclient/modules/mod_storages.go +++ b/pkg/mcclient/modules/mod_storages.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Storages ResourceManager + Storages modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_tasks.go b/pkg/mcclient/modules/mod_tasks.go index 7cb3492097..c86a9cb2a8 100644 --- a/pkg/mcclient/modules/mod_tasks.go +++ b/pkg/mcclient/modules/mod_tasks.go @@ -21,16 +21,17 @@ import ( "yunion.io/x/log" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) var ( - Tasks ResourceManager + Tasks modulebase.ResourceManager ComputeTasks ComputeTasksManager ) type ComputeTasksManager struct { - ResourceManager + modulebase.ResourceManager } func init() { diff --git a/pkg/mcclient/modules/mod_tenants.go b/pkg/mcclient/modules/mod_tenants.go index 3185ed03e1..84595df2eb 100644 --- a/pkg/mcclient/modules/mod_tenants.go +++ b/pkg/mcclient/modules/mod_tenants.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Tenants ResourceManager + Tenants modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_treenodes.go b/pkg/mcclient/modules/mod_treenodes.go index 2d997bce82..22510ed757 100644 --- a/pkg/mcclient/modules/mod_treenodes.go +++ b/pkg/mcclient/modules/mod_treenodes.go @@ -18,12 +18,13 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type TreenodeManager struct { - ResourceManager + modulebase.ResourceManager } var ( @@ -32,7 +33,7 @@ var ( func (this *TreenodeManager) GetMap(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { path := fmt.Sprintf("/%s/getMap", this.KeywordPlural) - return this._get(s, path, this.KeywordPlural) + return modulebase.Get(this.ResourceManager, s, path, this.KeywordPlural) } func (this *TreenodeManager) GetNodeIDByLabels(s *mcclient.ClientSession, labels []string) (int64, error) { diff --git a/pkg/mcclient/modules/mod_underutilizedinstances.go b/pkg/mcclient/modules/mod_underutilizedinstances.go index b216c8b818..7cc665e57f 100644 --- a/pkg/mcclient/modules/mod_underutilizedinstances.go +++ b/pkg/mcclient/modules/mod_underutilizedinstances.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - UnderutilizedInstances ResourceManager + UnderutilizedInstances modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_unused_resources.go b/pkg/mcclient/modules/mod_unused_resources.go index 0c11094154..d4809fb800 100644 --- a/pkg/mcclient/modules/mod_unused_resources.go +++ b/pkg/mcclient/modules/mod_unused_resources.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - UnusedResources ResourceManager + UnusedResources modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_updates.go b/pkg/mcclient/modules/mod_updates.go index 774266ef1d..fc2994207d 100644 --- a/pkg/mcclient/modules/mod_updates.go +++ b/pkg/mcclient/modules/mod_updates.go @@ -18,10 +18,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type SUpdateManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_usages.go b/pkg/mcclient/modules/mod_usages.go index ca6571dbcf..edda1f15dd 100644 --- a/pkg/mcclient/modules/mod_usages.go +++ b/pkg/mcclient/modules/mod_usages.go @@ -18,12 +18,13 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type UsageManager struct { - ResourceManager + modulebase.ResourceManager } func (this *UsageManager) GetGeneralUsage(session *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -42,7 +43,7 @@ func (this *UsageManager) GetGeneralUsage(session *mcclient.ClientSession, param url = fmt.Sprintf("%s?%s", url, qs) } } - return this._get(session, url, this.Keyword) + return modulebase.Get(this.ResourceManager, session, url, this.Keyword) } var ( diff --git a/pkg/mcclient/modules/mod_users.go b/pkg/mcclient/modules/mod_users.go index a373d8c4eb..9c5d64b090 100644 --- a/pkg/mcclient/modules/mod_users.go +++ b/pkg/mcclient/modules/mod_users.go @@ -18,20 +18,21 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" ) type UserManager struct { - ResourceManager + modulebase.ResourceManager } -func (this *UserManager) GetTenantRoles(session *mcclient.ClientSession, uid string, tenantId string) (*ListResult, error) { +func (this *UserManager) GetTenantRoles(session *mcclient.ClientSession, uid string, tenantId string) (*modulebase.ListResult, error) { url := fmt.Sprintf("/users/%s/roles", uid) if len(tenantId) > 0 { url = fmt.Sprintf("/tenants/%s/%s", tenantId, url) } - return this._list(session, url, "roles") + return modulebase.List(this.ResourceManager, session, url, "roles") } func (this *UserManager) GetTenantRoleList(session *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -44,21 +45,21 @@ func (this *UserManager) GetTenantRoleList(session *mcclient.ClientSession, para if e != nil { return nil, e } - return ListResult2JSON(ret), nil + return modulebase.ListResult2JSON(ret), nil } type UserManagerV3 struct { - ResourceManager + modulebase.ResourceManager } -func (this *UserManagerV3) GetProjects(session *mcclient.ClientSession, uid string) (*ListResult, error) { +func (this *UserManagerV3) GetProjects(session *mcclient.ClientSession, uid string) (*modulebase.ListResult, error) { url := fmt.Sprintf("/users/%s/projects?admin=true", uid) - return this._list(session, url, "projects") + return modulebase.List(this.ResourceManager, session, url, "projects") } -func (this *UserManagerV3) GetGroups(session *mcclient.ClientSession, uid string) (*ListResult, error) { +func (this *UserManagerV3) GetGroups(session *mcclient.ClientSession, uid string) (*modulebase.ListResult, error) { url := fmt.Sprintf("/users/%s/groups?admin=true", uid) - return this._list(session, url, "groups") + return modulebase.List(this.ResourceManager, session, url, "groups") } func (this *UserManagerV3) GetProjectsRPC(s *mcclient.ClientSession, uid string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -66,7 +67,7 @@ func (this *UserManagerV3) GetProjectsRPC(s *mcclient.ClientSession, uid string, if e != nil { return nil, e } - return ListResult2JSON(ret), nil + return modulebase.ListResult2JSON(ret), nil } /* diff --git a/pkg/mcclient/modules/mod_vcenters.go b/pkg/mcclient/modules/mod_vcenters.go index f381627d2b..24e21e0c70 100644 --- a/pkg/mcclient/modules/mod_vcenters.go +++ b/pkg/mcclient/modules/mod_vcenters.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - VCenters ResourceManager + VCenters modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_verification.go b/pkg/mcclient/modules/mod_verification.go index caaa937e04..f3c38553b7 100644 --- a/pkg/mcclient/modules/mod_verification.go +++ b/pkg/mcclient/modules/mod_verification.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Verifications ResourceManager + Verifications modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_versions.go b/pkg/mcclient/modules/mod_versions.go index be6ee92a41..ca11dac575 100644 --- a/pkg/mcclient/modules/mod_versions.go +++ b/pkg/mcclient/modules/mod_versions.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type VersionManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_vncproxy.go b/pkg/mcclient/modules/mod_vncproxy.go index 58184c28d6..fd804e7981 100644 --- a/pkg/mcclient/modules/mod_vncproxy.go +++ b/pkg/mcclient/modules/mod_vncproxy.go @@ -20,10 +20,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type VNCProxyManager struct { - ResourceManager + modulebase.ResourceManager } func (this *VNCProxyManager) DoConnect(s *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -33,7 +34,7 @@ func (this *VNCProxyManager) DoConnect(s *mcclient.ClientSession, id string, par url = fmt.Sprintf("%s/%s", url, objtype) } url = fmt.Sprintf("%s/%s", url, id) - return this._post(s, url, nil, "vncproxy") + return modulebase.Post(this.ResourceManager, s, url, nil, "vncproxy") } var ( diff --git a/pkg/mcclient/modules/mod_vpcs.go b/pkg/mcclient/modules/mod_vpcs.go index 6338758c27..006bac35b0 100644 --- a/pkg/mcclient/modules/mod_vpcs.go +++ b/pkg/mcclient/modules/mod_vpcs.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Vpcs ResourceManager + Vpcs modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_webconsole.go b/pkg/mcclient/modules/mod_webconsole.go index 7e306ad0da..963ea9c3e2 100644 --- a/pkg/mcclient/modules/mod_webconsole.go +++ b/pkg/mcclient/modules/mod_webconsole.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) var ( @@ -33,11 +34,11 @@ func init() { } type WebConsoleManager struct { - ResourceManager + modulebase.ResourceManager } -func NewWebConsoleManager() ResourceManager { - return ResourceManager{BaseManager: BaseManager{serviceType: "webconsole"}, +func NewWebConsoleManager() modulebase.ResourceManager { + return modulebase.ResourceManager{BaseManager: *modulebase.NewBaseManager("webconsole", "", "", nil, nil), Keyword: "webconsole", KeywordPlural: "webconsole"} } @@ -52,7 +53,7 @@ func (m WebConsoleManager) DoConnect(s *mcclient.ClientSession, connType, id, ac if action != "" { url = fmt.Sprintf("%s/%s", url, action) } - return m._post(s, url, params, "webconsole") + return modulebase.Post(m.ResourceManager, s, url, params, "webconsole") } func (m WebConsoleManager) DoK8sConnect(s *mcclient.ClientSession, id, action string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { diff --git a/pkg/mcclient/modules/mod_websockets.go b/pkg/mcclient/modules/mod_websockets.go index a80f774d4a..5963878356 100644 --- a/pkg/mcclient/modules/mod_websockets.go +++ b/pkg/mcclient/modules/mod_websockets.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + type SWebsocketManager struct { - ResourceManager + modulebase.ResourceManager } var ( diff --git a/pkg/mcclient/modules/mod_wires.go b/pkg/mcclient/modules/mod_wires.go index 63baf95dd2..0eedfffb20 100644 --- a/pkg/mcclient/modules/mod_wires.go +++ b/pkg/mcclient/modules/mod_wires.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Wires ResourceManager + Wires modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/mod_workers.go b/pkg/mcclient/modules/mod_workers.go index 89cb8ee9d7..72feda33a4 100644 --- a/pkg/mcclient/modules/mod_workers.go +++ b/pkg/mcclient/modules/mod_workers.go @@ -17,18 +17,19 @@ package modules import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type WorkerManager struct { - ResourceManager + modulebase.ResourceManager } var ( Workers WorkerManager ) -func (this *WorkerManager) List(s *mcclient.ClientSession, params jsonutils.JSONObject) (*ListResult, error) { - return this._list(s, this.KeywordPlural, this.Keyword) +func (this *WorkerManager) List(s *mcclient.ClientSession, params jsonutils.JSONObject) (*modulebase.ListResult, error) { + return modulebase.List(this.ResourceManager, s, this.KeywordPlural, this.Keyword) } func init() { diff --git a/pkg/mcclient/modules/mod_zones.go b/pkg/mcclient/modules/mod_zones.go index c203294879..57152a8e39 100644 --- a/pkg/mcclient/modules/mod_zones.go +++ b/pkg/mcclient/modules/mod_zones.go @@ -14,8 +14,10 @@ package modules +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + var ( - Zones ResourceManager + Zones modulebase.ResourceManager ) func init() { diff --git a/pkg/mcclient/modules/notify/mod_notification.go b/pkg/mcclient/modules/notify/mod_notification.go index 6d9efe38be..f042177aeb 100644 --- a/pkg/mcclient/modules/notify/mod_notification.go +++ b/pkg/mcclient/modules/notify/mod_notification.go @@ -16,6 +16,7 @@ package notify import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -37,7 +38,7 @@ type SNotifyMessage struct { } type NotificationManager struct { - modules.ResourceManager + modulebase.ResourceManager } func (manager *NotificationManager) Send(s *mcclient.ClientSession, msg SNotifyMessage) error { diff --git a/pkg/mcclient/modules/pprof.go b/pkg/mcclient/modules/pprof.go index 4bc7e90242..f2182d5d93 100644 --- a/pkg/mcclient/modules/pprof.go +++ b/pkg/mcclient/modules/pprof.go @@ -15,20 +15,12 @@ package modules import ( - "fmt" "io" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) func GetPProfByType(s *mcclient.ClientSession, serviceType string, profileType string, seconds int) (io.Reader, error) { - man := &BaseManager{serviceType: serviceType} - if seconds <= 0 { - seconds = 15 - } - resp, err := man.rawBaseUrlRequest(s, "GET", fmt.Sprintf("/debug/pprof/%s?seconds=%d", profileType, seconds), nil, nil) - if err != nil { - return nil, err - } - return resp.Body, nil + return modulebase.GetPProfByType(s, serviceType, profileType, seconds) } diff --git a/pkg/mcclient/modules/projectresources.go b/pkg/mcclient/modules/projectresources.go index 62f13bac47..faa1069381 100644 --- a/pkg/mcclient/modules/projectresources.go +++ b/pkg/mcclient/modules/projectresources.go @@ -15,23 +15,12 @@ package modules import ( - "io/ioutil" - "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) func GetProjectResources(s *mcclient.ClientSession, serviceType string) (jsonutils.JSONObject, error) { - man := &BaseManager{serviceType: serviceType} - resp, err := man.rawRequest(s, "GET", "/project-resources", nil, nil) - if err != nil { - return nil, err - } - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - return jsonutils.Parse(body) + return modulebase.GetProjectResources(s, serviceType) } diff --git a/pkg/mcclient/modules/register.go b/pkg/mcclient/modules/register.go index 755a28b730..2b93c874a1 100644 --- a/pkg/mcclient/modules/register.go +++ b/pkg/mcclient/modules/register.go @@ -14,30 +14,33 @@ package modules -import "yunion.io/x/onecloud/pkg/mcclient" +import ( + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" +) -func registerCompute(mod BaseManagerInterface) { +func registerCompute(mod modulebase.BaseManagerInterface) { registerComputeV1(mod) registerComputeV2(mod) } -func registerComputeV1(mod BaseManagerInterface) { - _register("v1", mod) +func registerComputeV1(mod modulebase.BaseManagerInterface) { + modulebase.Register("v1", mod) } -func registerComputeV2(mod BaseManagerInterface) { +func registerComputeV2(mod modulebase.BaseManagerInterface) { mod.SetApiVersion(mcclient.V2_API_VERSION) - _register("v2", mod) + modulebase.Register("v2", mod) } -func register(mod BaseManagerInterface) { - _register("v1", mod) +func register(mod modulebase.BaseManagerInterface) { + modulebase.Register("v1", mod) } -func registerV2(mod BaseManagerInterface) { - _register("v2", mod) +func registerV2(mod modulebase.BaseManagerInterface) { + modulebase.Register("v2", mod) } -func Register(mod BaseManagerInterface) { +func Register(mod modulebase.BaseManagerInterface) { register(mod) } diff --git a/pkg/mcclient/modules/version.go b/pkg/mcclient/modules/version.go index b209142cb2..4af1a8c1ac 100644 --- a/pkg/mcclient/modules/version.go +++ b/pkg/mcclient/modules/version.go @@ -15,21 +15,10 @@ package modules import ( - "io/ioutil" - "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) func GetVersion(s *mcclient.ClientSession, serviceType string) (string, error) { - man := &BaseManager{serviceType: serviceType} - resp, err := man.rawBaseUrlRequest(s, "GET", "/version", nil, nil) - if err != nil { - return "", err - } - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return "", err - } - return string(body), nil + return modulebase.GetVersion(s, serviceType) } diff --git a/pkg/multicloud/loader/doc.go b/pkg/multicloud/loader/doc.go new file mode 100644 index 0000000000..94832e0bbf --- /dev/null +++ b/pkg/multicloud/loader/doc.go @@ -0,0 +1 @@ +package loader // import "yunion.io/x/onecloud/pkg/multicloud/loader" diff --git a/pkg/multicloud/objectstore/ceph/doc.go b/pkg/multicloud/objectstore/ceph/doc.go new file mode 100644 index 0000000000..b78bf2eaab --- /dev/null +++ b/pkg/multicloud/objectstore/ceph/doc.go @@ -0,0 +1 @@ +package ceph // import "yunion.io/x/onecloud/pkg/multicloud/objectstore/ceph" diff --git a/pkg/multicloud/objectstore/ceph/provider/doc.go b/pkg/multicloud/objectstore/ceph/provider/doc.go new file mode 100644 index 0000000000..05d330d80e --- /dev/null +++ b/pkg/multicloud/objectstore/ceph/provider/doc.go @@ -0,0 +1 @@ +package provider // import "yunion.io/x/onecloud/pkg/multicloud/objectstore/ceph/provider" diff --git a/pkg/notify/handlers.go b/pkg/notify/handlers.go index 1205aea068..4894a616fa 100644 --- a/pkg/notify/handlers.go +++ b/pkg/notify/handlers.go @@ -21,12 +21,12 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/errors" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/httperrors" - "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/notify/models" "yunion.io/x/onecloud/pkg/notify/utils" ) @@ -281,7 +281,7 @@ func listManyHandler(ctx context.Context, w http.ResponseWriter, r *http.Request return } listResult = arrangeList(listResult) - appsrv.SendJSON(w, modules.ListResult2JSONWithKey(listResult, manager.KeywordPlural())) + appsrv.SendJSON(w, modulebase.ListResult2JSONWithKey(listResult, manager.KeywordPlural())) } // list handler for all resource in notify module @@ -292,7 +292,7 @@ func listHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) { httperrors.GeneralServerError(w, err) return } - appsrv.SendJSON(w, modules.ListResult2JSONWithKey(listResult, manager.KeywordPlural())) + appsrv.SendJSON(w, modulebase.ListResult2JSONWithKey(listResult, manager.KeywordPlural())) } func listOneHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) { @@ -314,7 +314,7 @@ func wrap(data jsonutils.JSONObject, key string) jsonutils.JSONObject { // For limit option, there is a bug but don't fix it for now. // This limit point to contact record, but these contact records whose uid are same // are considered as one record. -func arrangeList(listResult *modules.ListResult) *modules.ListResult { +func arrangeList(listResult *modulebase.ListResult) *modulebase.ListResult { ret := make(map[string]*jsonutils.JSONArray) for _, data := range listResult.Data { uid, _ := data.GetString("uid") @@ -336,7 +336,7 @@ func arrangeList(listResult *modules.ListResult) *modules.ListResult { return listResult } -func arrangeOne(listResult *modules.ListResult) jsonutils.JSONObject { +func arrangeOne(listResult *modulebase.ListResult) jsonutils.JSONObject { if len(listResult.Data) == 0 { return jsonutils.NewDict() } diff --git a/pkg/s3gateway/handlers/doc.go b/pkg/s3gateway/handlers/doc.go new file mode 100644 index 0000000000..90381b7885 --- /dev/null +++ b/pkg/s3gateway/handlers/doc.go @@ -0,0 +1 @@ +package handlers // import "yunion.io/x/onecloud/pkg/s3gateway/handlers" diff --git a/pkg/s3gateway/models/doc.go b/pkg/s3gateway/models/doc.go new file mode 100644 index 0000000000..34a9313299 --- /dev/null +++ b/pkg/s3gateway/models/doc.go @@ -0,0 +1 @@ +package models // import "yunion.io/x/onecloud/pkg/s3gateway/models" diff --git a/pkg/s3gateway/session/doc.go b/pkg/s3gateway/session/doc.go new file mode 100644 index 0000000000..d3a0ee0c7b --- /dev/null +++ b/pkg/s3gateway/session/doc.go @@ -0,0 +1 @@ +package session // import "yunion.io/x/onecloud/pkg/s3gateway/session" diff --git a/pkg/util/printutils/printgetter.go b/pkg/util/printutils/printgetter.go index 18362b1e17..496e429baa 100644 --- a/pkg/util/printutils/printgetter.go +++ b/pkg/util/printutils/printgetter.go @@ -20,10 +20,9 @@ import ( "strings" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/gotypes" "yunion.io/x/pkg/utils" - - "yunion.io/x/onecloud/pkg/mcclient/modules" ) func getter2json(obj interface{}) jsonutils.JSONObject { @@ -69,7 +68,7 @@ func PrintGetterList(data interface{}, columns []string) { for i := 0; i < dataValue.Len(); i += 1 { jsonList[i] = getter2json(dataValue.Index(i).Interface()) } - list := &modules.ListResult{ + list := &modulebase.ListResult{ Data: jsonList, Total: dataValue.Len(), Limit: 0, diff --git a/pkg/util/printutils/printjson.go b/pkg/util/printutils/printjson.go index 72d07b0bd6..c1311796fe 100644 --- a/pkg/util/printutils/printjson.go +++ b/pkg/util/printutils/printjson.go @@ -21,10 +21,10 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/prettytable" - "yunion.io/x/onecloud/pkg/mcclient/modules" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) -func PrintJSONList(list *modules.ListResult, columns []string) { +func PrintJSONList(list *modulebase.ListResult, columns []string) { colsWithData := make([]string, 0) if columns == nil || len(columns) == 0 { colsWithDataMap := make(map[string]bool) @@ -179,7 +179,7 @@ func PrintJSONObjectRecursiveEx(obj jsonutils.JSONObject, cb PrintJSONObjectRecu printJSONObjectRecursive_(obj, cb) } -func PrintJSONBatchResults(results []modules.SubmitResult, columns []string) { +func PrintJSONBatchResults(results []modulebase.SubmitResult, columns []string) { objs := make([]jsonutils.JSONObject, 0) errs := make([]jsonutils.JSONObject, 0) for _, r := range results { @@ -194,9 +194,9 @@ func PrintJSONBatchResults(results []modules.SubmitResult, columns []string) { } } if len(objs) > 0 { - PrintJSONList(&modules.ListResult{Data: objs}, columns) + PrintJSONList(&modulebase.ListResult{Data: objs}, columns) } if len(errs) > 0 { - PrintJSONList(&modules.ListResult{Data: errs}, []string{"status", "id", "error"}) + PrintJSONList(&modulebase.ListResult{Data: errs}, []string{"status", "id", "error"}) } } diff --git a/pkg/util/printutils/printobj.go b/pkg/util/printutils/printobj.go index 5363e11edd..d209884cce 100644 --- a/pkg/util/printutils/printobj.go +++ b/pkg/util/printutils/printobj.go @@ -19,8 +19,7 @@ import ( "reflect" "yunion.io/x/jsonutils" - - "yunion.io/x/onecloud/pkg/mcclient/modules" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) func PrintInterfaceList(data interface{}, total, offset, limit int, columns []string) { @@ -36,7 +35,7 @@ func PrintInterfaceList(data interface{}, total, offset, limit int, columns []st if total == 0 { total = dataValue.Len() } - list := &modules.ListResult{ + list := &modulebase.ListResult{ Data: jsonList, Total: total, Limit: limit, diff --git a/pkg/util/s3auth/doc.go b/pkg/util/s3auth/doc.go new file mode 100644 index 0000000000..d1c1879eb1 --- /dev/null +++ b/pkg/util/s3auth/doc.go @@ -0,0 +1 @@ +package s3auth // import "yunion.io/x/onecloud/pkg/util/s3auth" diff --git a/pkg/util/validate/doc.go b/pkg/util/validate/doc.go new file mode 100644 index 0000000000..7d64ed9535 --- /dev/null +++ b/pkg/util/validate/doc.go @@ -0,0 +1 @@ +package validate // import "yunion.io/x/onecloud/pkg/util/validate" From 59461ce09780633f3ba11de344b80c57c6b340d7 Mon Sep 17 00:00:00 2001 From: TangBin Date: Sat, 7 Sep 2019 19:03:24 +0800 Subject: [PATCH 2/2] reformat import --- cmd/climc/shell/baremetalnetworks.go | 2 +- cmd/climc/shell/baremetalstorages.go | 2 +- cmd/climc/shell/buckets.go | 2 +- cmd/climc/shell/cloudproviderregions.go | 2 +- cmd/climc/shell/hoststorages.go | 2 +- cmd/climc/shell/k8s/list.go | 2 +- cmd/climc/shell/labels.go | 2 +- cmd/climc/shell/loadbalanceracls.go | 2 +- cmd/climc/shell/loadbalancercachedacls.go | 2 +- cmd/climc/shell/loadbalancernetworks.go | 2 +- cmd/climc/shell/modules.go | 2 +- cmd/climc/shell/networks.go | 2 +- cmd/climc/shell/projects.go | 2 +- cmd/climc/shell/quotas.go | 2 +- cmd/climc/shell/serverdisks.go | 2 +- cmd/climc/shell/servernetworks.go | 2 +- cmd/climc/shell/servers.go | 2 +- cmd/climc/shell/specs.go | 2 +- cmd/climc/shell/storagecachedimages.go | 2 +- cmd/climc/shell/storages.go | 2 +- cmd/climc/shell/users.go | 2 +- cmd/climc/shell/wires.go | 2 +- cmd/climc/shell/zones.go | 2 +- pkg/appsrv/dispatcher/dispatcher.go | 2 +- pkg/appsrv/dispatcher/handlers.go | 2 +- pkg/appsrv/dispatcher/jointdispatcher.go | 2 +- pkg/image/models/images.go | 2 +- pkg/mcclient/modules/mod_alarmevents.go | 2 +- pkg/mcclient/modules/mod_cloudregions.go | 2 +- pkg/mcclient/modules/mod_nodes.go | 2 +- pkg/mcclient/modules/mod_policies.go | 2 +- pkg/mcclient/modules/mod_roleassignments.go | 2 +- pkg/mcclient/modules/mod_servicehosts.go | 2 +- pkg/mcclient/modules/mod_treenodes.go | 2 +- pkg/mcclient/modules/mod_usages.go | 2 +- pkg/mcclient/modules/mod_workers.go | 1 + pkg/util/printutils/printobj.go | 1 + 37 files changed, 37 insertions(+), 35 deletions(-) diff --git a/cmd/climc/shell/baremetalnetworks.go b/cmd/climc/shell/baremetalnetworks.go index 799adb836c..3ee0205f88 100644 --- a/cmd/climc/shell/baremetalnetworks.go +++ b/cmd/climc/shell/baremetalnetworks.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/baremetalstorages.go b/cmd/climc/shell/baremetalstorages.go index e9143cce35..707f3e354d 100644 --- a/cmd/climc/shell/baremetalstorages.go +++ b/cmd/climc/shell/baremetalstorages.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/buckets.go b/cmd/climc/shell/buckets.go index f17506d49f..044622acbd 100644 --- a/cmd/climc/shell/buckets.go +++ b/cmd/climc/shell/buckets.go @@ -20,9 +20,9 @@ import ( "os" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/cloudproviderregions.go b/cmd/climc/shell/cloudproviderregions.go index b52003ec16..097cd3a8ba 100644 --- a/cmd/climc/shell/cloudproviderregions.go +++ b/cmd/climc/shell/cloudproviderregions.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/hoststorages.go b/cmd/climc/shell/hoststorages.go index d8a4f9b0b7..eb680fad01 100644 --- a/cmd/climc/shell/hoststorages.go +++ b/cmd/climc/shell/hoststorages.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/k8s/list.go b/cmd/climc/shell/k8s/list.go index b6dcc5c717..55aa9928c2 100644 --- a/cmd/climc/shell/k8s/list.go +++ b/cmd/climc/shell/k8s/list.go @@ -20,12 +20,12 @@ import ( "strings" "github.com/gosuri/uitable" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules/k8s" ) diff --git a/cmd/climc/shell/labels.go b/cmd/climc/shell/labels.go index 3e632a3a5e..21bf69359d 100644 --- a/cmd/climc/shell/labels.go +++ b/cmd/climc/shell/labels.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/loadbalanceracls.go b/cmd/climc/shell/loadbalanceracls.go index ca5c684c68..0871380731 100644 --- a/cmd/climc/shell/loadbalanceracls.go +++ b/cmd/climc/shell/loadbalanceracls.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/loadbalancercachedacls.go b/cmd/climc/shell/loadbalancercachedacls.go index 31c6f2eecc..c9b56fba5f 100644 --- a/cmd/climc/shell/loadbalancercachedacls.go +++ b/cmd/climc/shell/loadbalancercachedacls.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/loadbalancernetworks.go b/cmd/climc/shell/loadbalancernetworks.go index 568d486b94..62905e35f8 100644 --- a/cmd/climc/shell/loadbalancernetworks.go +++ b/cmd/climc/shell/loadbalancernetworks.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/modules.go b/cmd/climc/shell/modules.go index 80986aa775..9a8385eb16 100644 --- a/cmd/climc/shell/modules.go +++ b/cmd/climc/shell/modules.go @@ -18,9 +18,9 @@ import ( "fmt" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) func init() { diff --git a/cmd/climc/shell/networks.go b/cmd/climc/shell/networks.go index bb7ae8841d..300d724c8a 100644 --- a/cmd/climc/shell/networks.go +++ b/cmd/climc/shell/networks.go @@ -18,9 +18,9 @@ import ( "fmt" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/projects.go b/cmd/climc/shell/projects.go index 9215f300f9..d1e748251b 100644 --- a/cmd/climc/shell/projects.go +++ b/cmd/climc/shell/projects.go @@ -16,10 +16,10 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" api "yunion.io/x/onecloud/pkg/apis/identity" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/quotas.go b/cmd/climc/shell/quotas.go index 0b680ecb24..9c8c1ed0b3 100644 --- a/cmd/climc/shell/quotas.go +++ b/cmd/climc/shell/quotas.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" ) diff --git a/cmd/climc/shell/serverdisks.go b/cmd/climc/shell/serverdisks.go index d423702f8f..f4cacec793 100644 --- a/cmd/climc/shell/serverdisks.go +++ b/cmd/climc/shell/serverdisks.go @@ -18,9 +18,9 @@ import ( "fmt" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/servernetworks.go b/cmd/climc/shell/servernetworks.go index da0aae8f24..6050ed96ae 100644 --- a/cmd/climc/shell/servernetworks.go +++ b/cmd/climc/shell/servernetworks.go @@ -19,11 +19,11 @@ import ( "strconv" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/util/regutils" "yunion.io/x/onecloud/pkg/cloudcommon/cmdline" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/servers.go b/cmd/climc/shell/servers.go index 17df4be0fc..5e668a5bff 100644 --- a/cmd/climc/shell/servers.go +++ b/cmd/climc/shell/servers.go @@ -25,11 +25,11 @@ import ( "gopkg.in/yaml.v2" "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/cmdline" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/specs.go b/cmd/climc/shell/specs.go index caf5e2d3db..8641841056 100644 --- a/cmd/climc/shell/specs.go +++ b/cmd/climc/shell/specs.go @@ -18,9 +18,9 @@ import ( "fmt" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/storagecachedimages.go b/cmd/climc/shell/storagecachedimages.go index 77ce0cef78..b89ae49239 100644 --- a/cmd/climc/shell/storagecachedimages.go +++ b/cmd/climc/shell/storagecachedimages.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/storages.go b/cmd/climc/shell/storages.go index 8cf6feeb20..1b5db06cd1 100644 --- a/cmd/climc/shell/storages.go +++ b/cmd/climc/shell/storages.go @@ -18,9 +18,9 @@ import ( "fmt" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/users.go b/cmd/climc/shell/users.go index c473c5c83c..fef2fe0f2a 100644 --- a/cmd/climc/shell/users.go +++ b/cmd/climc/shell/users.go @@ -16,10 +16,10 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" api "yunion.io/x/onecloud/pkg/apis/identity" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/wires.go b/cmd/climc/shell/wires.go index 71654e8be1..5df820e294 100644 --- a/cmd/climc/shell/wires.go +++ b/cmd/climc/shell/wires.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/cmd/climc/shell/zones.go b/cmd/climc/shell/zones.go index a98463cb2b..0b23c7d63f 100644 --- a/cmd/climc/shell/zones.go +++ b/cmd/climc/shell/zones.go @@ -16,9 +16,9 @@ package shell import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" ) diff --git a/pkg/appsrv/dispatcher/dispatcher.go b/pkg/appsrv/dispatcher/dispatcher.go index 7dc31ca782..a9db162c05 100644 --- a/pkg/appsrv/dispatcher/dispatcher.go +++ b/pkg/appsrv/dispatcher/dispatcher.go @@ -22,12 +22,12 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/utils" "yunion.io/x/onecloud/pkg/appctx" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/httperrors" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) func AddModelDispatcher(prefix string, app *appsrv.Application, manager IModelDispatchHandler) { diff --git a/pkg/appsrv/dispatcher/handlers.go b/pkg/appsrv/dispatcher/handlers.go index e1aa810e6d..3a6962e4dd 100644 --- a/pkg/appsrv/dispatcher/handlers.go +++ b/pkg/appsrv/dispatcher/handlers.go @@ -19,8 +19,8 @@ import ( "net/http" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/appsrv" ) diff --git a/pkg/appsrv/dispatcher/jointdispatcher.go b/pkg/appsrv/dispatcher/jointdispatcher.go index dfcdba223a..67a26cb15b 100644 --- a/pkg/appsrv/dispatcher/jointdispatcher.go +++ b/pkg/appsrv/dispatcher/jointdispatcher.go @@ -21,11 +21,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/appctx" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/httperrors" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) func AddJointModelDispatcher(prefix string, app *appsrv.Application, manager IJointModelDispatchHandler) { diff --git a/pkg/image/models/images.go b/pkg/image/models/images.go index ba1d6c250d..0ead8d9486 100644 --- a/pkg/image/models/images.go +++ b/pkg/image/models/images.go @@ -29,7 +29,6 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/tristate" "yunion.io/x/pkg/util/timeutils" @@ -44,6 +43,7 @@ import ( "yunion.io/x/onecloud/pkg/image/options" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/util/fileutils2" "yunion.io/x/onecloud/pkg/util/logclient" diff --git a/pkg/mcclient/modules/mod_alarmevents.go b/pkg/mcclient/modules/mod_alarmevents.go index 99bb6b7ccd..a952a56218 100644 --- a/pkg/mcclient/modules/mod_alarmevents.go +++ b/pkg/mcclient/modules/mod_alarmevents.go @@ -16,9 +16,9 @@ package modules import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type AlarmEventsManager struct { diff --git a/pkg/mcclient/modules/mod_cloudregions.go b/pkg/mcclient/modules/mod_cloudregions.go index 5ef1f65eef..3326eccacb 100644 --- a/pkg/mcclient/modules/mod_cloudregions.go +++ b/pkg/mcclient/modules/mod_cloudregions.go @@ -18,9 +18,9 @@ import ( "sort" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type SCloudregionManager struct { diff --git a/pkg/mcclient/modules/mod_nodes.go b/pkg/mcclient/modules/mod_nodes.go index 817c0b4ec6..94e56ed7de 100644 --- a/pkg/mcclient/modules/mod_nodes.go +++ b/pkg/mcclient/modules/mod_nodes.go @@ -19,9 +19,9 @@ import ( "net/url" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type NodeManager struct { diff --git a/pkg/mcclient/modules/mod_policies.go b/pkg/mcclient/modules/mod_policies.go index 1e51fb28d6..f540bb7cef 100644 --- a/pkg/mcclient/modules/mod_policies.go +++ b/pkg/mcclient/modules/mod_policies.go @@ -16,9 +16,9 @@ package modules import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/util/rbacutils" ) diff --git a/pkg/mcclient/modules/mod_roleassignments.go b/pkg/mcclient/modules/mod_roleassignments.go index 138497b2b7..cb47147c26 100644 --- a/pkg/mcclient/modules/mod_roleassignments.go +++ b/pkg/mcclient/modules/mod_roleassignments.go @@ -18,9 +18,9 @@ import ( "fmt" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type RoleAssignmentManagerV3 struct { diff --git a/pkg/mcclient/modules/mod_servicehosts.go b/pkg/mcclient/modules/mod_servicehosts.go index b19ff8055f..44c179c2ba 100644 --- a/pkg/mcclient/modules/mod_servicehosts.go +++ b/pkg/mcclient/modules/mod_servicehosts.go @@ -18,9 +18,9 @@ import ( "fmt" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type ServiceNodeManager struct { diff --git a/pkg/mcclient/modules/mod_treenodes.go b/pkg/mcclient/modules/mod_treenodes.go index 22510ed757..c41b3383d7 100644 --- a/pkg/mcclient/modules/mod_treenodes.go +++ b/pkg/mcclient/modules/mod_treenodes.go @@ -18,9 +18,9 @@ import ( "fmt" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type TreenodeManager struct { diff --git a/pkg/mcclient/modules/mod_usages.go b/pkg/mcclient/modules/mod_usages.go index edda1f15dd..9cd8706674 100644 --- a/pkg/mcclient/modules/mod_usages.go +++ b/pkg/mcclient/modules/mod_usages.go @@ -18,9 +18,9 @@ import ( "fmt" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) type UsageManager struct { diff --git a/pkg/mcclient/modules/mod_workers.go b/pkg/mcclient/modules/mod_workers.go index 72feda33a4..3c84ba6b90 100644 --- a/pkg/mcclient/modules/mod_workers.go +++ b/pkg/mcclient/modules/mod_workers.go @@ -16,6 +16,7 @@ package modules import ( "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modulebase" ) diff --git a/pkg/util/printutils/printobj.go b/pkg/util/printutils/printobj.go index d209884cce..38320405ef 100644 --- a/pkg/util/printutils/printobj.go +++ b/pkg/util/printutils/printobj.go @@ -19,6 +19,7 @@ import ( "reflect" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient/modulebase" )