diff --git a/cmd/climc/climc.go b/cmd/climc/climc.go index c67c4832c5..bfaf17a378 100644 --- a/cmd/climc/climc.go +++ b/cmd/climc/climc.go @@ -6,13 +6,13 @@ import ( "strings" "github.com/c-bata/go-prompt" + "github.com/yunionio/log" "github.com/yunionio/mcclient" - "github.com/yunionio/pkg/util/version" - "github.com/yunionio/structarg" - "github.com/yunionio/onecloud/cmd/climc/promputils" "github.com/yunionio/onecloud/cmd/climc/shell" + "github.com/yunionio/pkg/util/version" + "github.com/yunionio/structarg" ) type BaseOptions struct { diff --git a/cmd/climc/shell/cachedimages.go b/cmd/climc/shell/cachedimages.go index f9f7e9392e..6607240e9c 100644 --- a/cmd/climc/shell/cachedimages.go +++ b/cmd/climc/shell/cachedimages.go @@ -1,6 +1,7 @@ package shell import ( + // "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" "github.com/yunionio/mcclient/modules" ) diff --git a/cmd/climc/shell/cloudproviders.go b/cmd/climc/shell/cloudproviders.go index b6a69f0af2..2785f097c7 100644 --- a/cmd/climc/shell/cloudproviders.go +++ b/cmd/climc/shell/cloudproviders.go @@ -28,6 +28,7 @@ func init() { PROVIDER string `help:"Driver for cloud provider" choices:"VMware|Aliyun"` AccessUrl string `help:"Access url"` Desc string `help:"Description"` + Enabled bool `help:"Enabled the provider automatically"` } R(&CloudproviderCreateOptions{}, "cloud-provider-create", "Create a cloud provider", func(s *mcclient.ClientSession, args *CloudproviderCreateOptions) error { params := jsonutils.NewDict() @@ -35,6 +36,9 @@ func init() { params.Add(jsonutils.NewString(args.ACCOUNT), "account") params.Add(jsonutils.NewString(args.SECRET), "secret") params.Add(jsonutils.NewString(args.PROVIDER), "provider") + if args.Enabled { + params.Add(jsonutils.JSONTrue, "enabled") + } if len(args.AccessUrl) > 0 { params.Add(jsonutils.NewString(args.AccessUrl), "access_url") } @@ -98,6 +102,24 @@ func init() { return nil }) + R(&CloudproviderShowOptions{}, "cloud-provider-enable", "Enable cloud provider", func(s *mcclient.ClientSession, args *CloudproviderShowOptions) error { + result, err := modules.Cloudproviders.PerformAction(s, args.ID, "enable", nil) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&CloudproviderShowOptions{}, "cloud-provider-disable", "Disable cloud provider", func(s *mcclient.ClientSession, args *CloudproviderShowOptions) error { + result, err := modules.Cloudproviders.PerformAction(s, args.ID, "disable", nil) + if err != nil { + return err + } + printObject(result) + return nil + }) + type CloudproviderUpdateCredentialOptions struct { ID string `help:"ID or Name of cloud provider"` ACCOUNT string `help:"new account"` diff --git a/cmd/climc/shell/cloudregions.go b/cmd/climc/shell/cloudregions.go index 81e74f1e18..1ef32b02da 100644 --- a/cmd/climc/shell/cloudregions.go +++ b/cmd/climc/shell/cloudregions.go @@ -9,9 +9,25 @@ import ( func init() { type CloudregionListOptions struct { BaseListOptions + Private bool `help:"show private cloud regions only"` + Public bool `help:"show public cloud regions only"` + Manager string `help:"Show regions belongs to the cloud provider"` + Usable bool `help:"List regions that are usable"` } R(&CloudregionListOptions{}, "cloud-region-list", "List cloud regions", func(s *mcclient.ClientSession, args *CloudregionListOptions) error { params := FetchPagingParams(args.BaseListOptions) + if args.Usable { + params.Add(jsonutils.JSONTrue, "usable") + } + if args.Private { + params.Add(jsonutils.JSONTrue, "is_private") + } + if args.Public { + params.Add(jsonutils.JSONTrue, "is_public") + } + if len(args.Manager) > 0 { + params.Add(jsonutils.NewString(args.Manager), "manager") + } result, err := modules.Cloudregions.List(s, params) if err != nil { return err diff --git a/cmd/climc/shell/events.go b/cmd/climc/shell/events.go index 55a27b5b08..df4f80cad1 100644 --- a/cmd/climc/shell/events.go +++ b/cmd/climc/shell/events.go @@ -80,6 +80,31 @@ func init() { return doComputeEventList(s, &nargs) }) + R(&TypeEventListOptions{}, "vpc-event", "Show operation event logs of vpc", func(s *mcclient.ClientSession, args *TypeEventListOptions) error { + nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"vpc"}} + return doComputeEventList(s, &nargs) + }) + + R(&TypeEventListOptions{}, "zone-event", "Show operation event logs of zone", func(s *mcclient.ClientSession, args *TypeEventListOptions) error { + nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"zone"}} + return doComputeEventList(s, &nargs) + }) + + R(&TypeEventListOptions{}, "region-event", "Show operation event logs of region", func(s *mcclient.ClientSession, args *TypeEventListOptions) error { + nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"cloudregion"}} + return doComputeEventList(s, &nargs) + }) + + R(&TypeEventListOptions{}, "wire-event", "Show operation event logs of wire", func(s *mcclient.ClientSession, args *TypeEventListOptions) error { + nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"wire"}} + return doComputeEventList(s, &nargs) + }) + + R(&TypeEventListOptions{}, "network-event", "Show operation event logs of network", func(s *mcclient.ClientSession, args *TypeEventListOptions) error { + nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"network"}} + return doComputeEventList(s, &nargs) + }) + R(&TypeEventListOptions{}, "vcenter-event", "Show operation event logs of vcenter", func(s *mcclient.ClientSession, args *TypeEventListOptions) error { nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"vcenter"}} return doComputeEventList(s, &nargs) diff --git a/cmd/climc/shell/hosts.go b/cmd/climc/shell/hosts.go index 539de5091a..455a386397 100644 --- a/cmd/climc/shell/hosts.go +++ b/cmd/climc/shell/hosts.go @@ -23,6 +23,9 @@ func init() { Disabled bool `help:"Show disabled host only"` HostType string `help:"Host type filter" choices:"baremetal|hypervisor|esxi|kubelet|hyperv"` AnyMac string `help:"Mac matches one of the host's interface"` + + Manager string `help:"Show regions belongs to the cloud provider"` + BaseListOptions } R(&HostListOptions{}, "host-list", "List hosts", func(s *mcclient.ClientSession, args *HostListOptions) error { @@ -51,6 +54,11 @@ func init() { if len(args.HostType) > 0 { params.Add(jsonutils.NewString(args.HostType), "host_type") } + + if len(args.Manager) > 0 { + params.Add(jsonutils.NewString(args.Manager), "manager") + } + if args.Empty { params.Add(jsonutils.JSONTrue, "is_empty") } else if args.Occupied { @@ -169,6 +177,18 @@ func init() { return nil }) + type HostPropertyOptions struct { + } + + R(&HostPropertyOptions{}, "baremetal-register-script", "Get online baremetal register script", func(s *mcclient.ClientSession, args *HostPropertyOptions) error { + result, err := modules.Hosts.Get(s, "bm-start-register-script", nil) + if err != nil { + return err + } + printObject(result) + return nil + }) + type HostUpdateOptions struct { ID string `help:"ID or Name of Host"` Name string `help:"New name of the host"` diff --git a/cmd/climc/shell/hostwires.go b/cmd/climc/shell/hostwires.go index a69ea7011b..167a05560b 100644 --- a/cmd/climc/shell/hostwires.go +++ b/cmd/climc/shell/hostwires.go @@ -10,6 +10,7 @@ func init() { type HostWireListOptions struct { BaseListOptions Host string `help:"ID or Name of Host"` + Wire string `help:"ID or Name of Wire"` } R(&HostWireListOptions{}, "host-wire-list", "List host wire", func(s *mcclient.ClientSession, args *HostWireListOptions) error { params := FetchPagingParams(args.BaseListOptions) @@ -17,6 +18,8 @@ func init() { var err error if len(args.Host) > 0 { result, err = modules.Hostwires.ListDescendent(s, args.Host, params) + } else if len(args.Wire) > 0 { + result, err = modules.Hostwires.ListDescendent2(s, args.Wire, params) } else { result, err = modules.Hostwires.List(s, params) } diff --git a/cmd/climc/shell/images.go b/cmd/climc/shell/images.go index 37c399d28b..3b11caae5f 100644 --- a/cmd/climc/shell/images.go +++ b/cmd/climc/shell/images.go @@ -136,13 +136,10 @@ func init() { if args.PendingDelete { params.Add(jsonutils.JSONTrue, "pending_delete") } - if !args.Admin && len(args.Tenant) == 0 { - if s.IsSystemAdmin() { - params.Add(jsonutils.NewString(s.GetTenantId()), "owner") - } - } else if !s.IsSystemAdmin() { - return fmt.Errorf("System admin ONLY options") - } else if len(args.Tenant) > 0 { + if args.Admin { + params.Add(jsonutils.JSONTrue, "admin") + } + if len(args.Tenant) > 0 { tid, e := modules.Projects.GetId(s, args.Tenant, nil) if e != nil { return e diff --git a/cmd/climc/shell/monitortemplates.go b/cmd/climc/shell/monitortemplates.go index 2de270e59f..248a0f2bbc 100644 --- a/cmd/climc/shell/monitortemplates.go +++ b/cmd/climc/shell/monitortemplates.go @@ -2,6 +2,7 @@ package shell import ( "strings" + "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" "github.com/yunionio/mcclient/modules" diff --git a/cmd/climc/shell/networks.go b/cmd/climc/shell/networks.go index bc1a17239e..57f948fc82 100644 --- a/cmd/climc/shell/networks.go +++ b/cmd/climc/shell/networks.go @@ -1,6 +1,8 @@ package shell import ( + "fmt" + "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" "github.com/yunionio/mcclient/modules" @@ -9,14 +11,29 @@ import ( func init() { type NetworkListOptions struct { BaseListOptions - Ip string `help:"search networks that contain this IP"` + Ip string `help:"search networks that contain this IP"` + Zone string `help:"search networks in a zone"` + Wire string `help:"search networks belongs to a wire"` + Vpc string `help:"search networks belongs to a VPC"` } R(&NetworkListOptions{}, "network-list", "List networks", func(s *mcclient.ClientSession, args *NetworkListOptions) error { params := FetchPagingParams(args.BaseListOptions) if len(args.Ip) > 0 { params.Add(jsonutils.NewString(args.Ip), "ip") } - result, err := modules.Networks.List(s, params) + if len(args.Zone) > 0 { + params.Add(jsonutils.NewString(args.Zone), "zone") + } + if len(args.Vpc) > 0 { + params.Add(jsonutils.NewString(args.Vpc), "vpc") + } + var result *modules.ListResult + var err error + if len(args.Wire) > 0 { + result, err = modules.Networks.ListInContext(s, params, &modules.Wires, args.Wire) + } else { + result, err = modules.Networks.List(s, params) + } if err != nil { return err } @@ -143,6 +160,15 @@ func init() { return nil }) + R(&NetworkShowOptions{}, "network-purge", "Purge a managed network, not delete the remote entity", func(s *mcclient.ClientSession, args *NetworkShowOptions) error { + result, err := modules.Networks.PerformAction(s, args.ID, "purge", nil) + if err != nil { + return err + } + printObject(result) + return nil + }) + type NetworkCreateOptions struct { WIRE string `help:"ID or Name of wire in wihich the network is created"` NETWORK string `help:"Name of new network"` @@ -184,6 +210,41 @@ func init() { return nil }) + type NetworkCreateOptions2 struct { + Wire string `help:"ID or Name of wire in which the network is created"` + Vpc string `help:"ID or Name of vpc in which the network is created"` + Zone string `help:"ID or Name of zone in which the network is created"` + NETWORK string `help:"Name of new network"` + PREFIX string `help:"Start of IPv4 address range"` + Desc string `help:"Description" metavar:"DESCRIPTION"` + } + R(&NetworkCreateOptions2{}, "network-create2", "Create a virtual network", func(s *mcclient.ClientSession, args *NetworkCreateOptions2) error { + params := jsonutils.NewDict() + params.Add(jsonutils.NewString(args.NETWORK), "name") + params.Add(jsonutils.NewString(args.PREFIX), "guest_ip_prefix") + if len(args.Desc) > 0 { + params.Add(jsonutils.NewString(args.Desc), "description") + } + if len(args.Wire) > 0 { + params.Add(jsonutils.NewString(args.Wire), "wire") + } else if len(args.Vpc) > 0 { + if len(args.Zone) > 0 { + params.Add(jsonutils.NewString(args.Zone), "zone") + params.Add(jsonutils.NewString(args.Vpc), "vpc") + } else { + return fmt.Errorf("Either wire or VPC/Zone must be provided") + } + } else { + return fmt.Errorf("Either wire or VPC/Zone must be provided") + } + net, e := modules.Networks.Create(s, params) + if e != nil { + return e + } + printObject(net) + return nil + }) + type NetworkSplitOptions struct { NETWORK string `help:"ID or name of network to split"` IP string `help:"Start ip of the split network"` diff --git a/cmd/climc/shell/nodes.go b/cmd/climc/shell/nodes.go index 52da799c3b..b6746edb66 100644 --- a/cmd/climc/shell/nodes.go +++ b/cmd/climc/shell/nodes.go @@ -2,6 +2,7 @@ package shell import ( "strings" + "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" "github.com/yunionio/mcclient/modules" diff --git a/cmd/climc/shell/servers.go b/cmd/climc/shell/servers.go index d5166d11aa..9876c942cc 100644 --- a/cmd/climc/shell/servers.go +++ b/cmd/climc/shell/servers.go @@ -678,4 +678,44 @@ func init() { return nil }) + type ServerInsertISOOptions struct { + ID string `help:"server ID or Name"` + ISO string `help:"Glance image ID of the ISO"` + } + R(&ServerInsertISOOptions{}, "server-insert-iso", "Insert an ISO image into server's cdrom", func(s *mcclient.ClientSession, args *ServerInsertISOOptions) error { + img, err := modules.Images.Get(s, args.ISO, nil) + if err != nil { + return err + } + imgId, err := img.GetString("id") + if err != nil { + return err + } + params := jsonutils.NewDict() + params.Add(jsonutils.NewString(imgId), "image_id") + result, err := modules.Servers.PerformAction(s, args.ID, "insertiso", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&ServerShowOptions{}, "server-eject-iso", "Eject iso from servers' cdrom", func(s *mcclient.ClientSession, args *ServerShowOptions) error { + result, err := modules.Servers.PerformAction(s, args.ID, "ejectiso", nil) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&ServerShowOptions{}, "server-iso", "Show server's mounting ISO information", func(s *mcclient.ClientSession, args *ServerShowOptions) error { + results, err := modules.Servers.GetSpecific(s, args.ID, "iso", nil) + if err != nil { + return err + } + printObject(results) + return nil + }) } diff --git a/cmd/climc/shell/shell.go b/cmd/climc/shell/shell.go index 6d131513c3..7d3d47da2d 100644 --- a/cmd/climc/shell/shell.go +++ b/cmd/climc/shell/shell.go @@ -34,6 +34,7 @@ type BaseListOptions struct { System bool `help:"Show system resource"` PendingDelete bool `help:"Show pending deleted resource"` Field []string `help:"Show only specified fields"` + ShowEmulated bool `help:"Show all resources including the emulated resources"` } func FetchPagingParams(options BaseListOptions) *jsonutils.JSONDict { @@ -102,6 +103,9 @@ func FetchPagingParams(options BaseListOptions) *jsonutils.JSONDict { } params.Add(arr, "field") } + if options.ShowEmulated { + params.Add(jsonutils.JSONTrue, "show_emulated") + } return params } diff --git a/cmd/climc/shell/storagecaches.go b/cmd/climc/shell/storagecaches.go index 0f2e817a94..4068a8a2e8 100644 --- a/cmd/climc/shell/storagecaches.go +++ b/cmd/climc/shell/storagecaches.go @@ -1,6 +1,7 @@ package shell import ( + "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" "github.com/yunionio/mcclient/modules" ) @@ -8,9 +9,16 @@ import ( func init() { type StoragecacheListOptions struct { BaseListOptions + + Manager string `help:"Show regions belongs to the cloud provider"` } R(&StoragecacheListOptions{}, "storage-cache-list", "List storage caches", func(s *mcclient.ClientSession, args *StoragecacheListOptions) error { params := FetchPagingParams(args.BaseListOptions) + + if len(args.Manager) > 0 { + params.Add(jsonutils.NewString(args.Manager), "manager") + } + result, err := modules.Storagecaches.List(s, params) if err != nil { return err @@ -31,4 +39,50 @@ func init() { return nil }) + R(&StoragecacheShowptions{}, "storage-cache-delete", "Delete storage cache", func(s *mcclient.ClientSession, args *StoragecacheShowptions) error { + result, err := modules.Storagecaches.Delete(s, args.ID, nil) + if err != nil { + return err + } + printObject(result) + return nil + }) + + type StorageCacheImageActionOptions struct { + ID string `help:"ID or name of storage"` + IMAGE string `help:"ID or name of image"` + Force bool `help:"Force refresh cache, even if the image exists in cache"` + } + R(&StorageCacheImageActionOptions{}, "storagecache-cache-image", "Ask a storage cache to cache a image", func(s *mcclient.ClientSession, args *StorageCacheImageActionOptions) error { + params := jsonutils.NewDict() + params.Add(jsonutils.NewString(args.IMAGE), "image") + if args.Force { + params.Add(jsonutils.JSONTrue, "is_force") + } + storage, err := modules.Storagecaches.PerformAction(s, args.ID, "cache-image", params) + if err != nil { + return err + } + printObject(storage) + return nil + }) + + type StorageUncacheImageActionOptions struct { + ID string `help:"ID or name of storage"` + IMAGE string `help:"ID or name of image"` + Force bool `help:"Force uncache, even if the image exists in cache"` + } + R(&StorageUncacheImageActionOptions{}, "storagecache-uncache-image", "Ask a storage cache to remove image from its cache", func(s *mcclient.ClientSession, args *StorageUncacheImageActionOptions) error { + params := jsonutils.NewDict() + params.Add(jsonutils.NewString(args.IMAGE), "image") + if args.Force { + params.Add(jsonutils.JSONTrue, "is_force") + } + storage, err := modules.Storagecaches.PerformAction(s, args.ID, "uncache-image", params) + if err != nil { + return err + } + printObject(storage) + return nil + }) } diff --git a/cmd/climc/shell/storages.go b/cmd/climc/shell/storages.go index 6c4d229d83..23e8453bff 100644 --- a/cmd/climc/shell/storages.go +++ b/cmd/climc/shell/storages.go @@ -11,9 +11,13 @@ import ( func init() { type StorageListOptions struct { BaseListOptions - Share bool `help:"Share storage list"` - Local bool `help:"Local storage list"` - Usable bool `help:"Usable storage list"` + Share bool `help:"Share storage list"` + Local bool `help:"Local storage list"` + Usable bool `help:"Usable storage list"` + Zone string `help:"List storages in zone"` + Region string `help:"List storages in region"` + + Manager string `help:"Show regions belongs to the cloud provider"` } R(&StorageListOptions{}, "storage-list", "List storages", func(s *mcclient.ClientSession, args *StorageListOptions) error { params := FetchPagingParams(args.BaseListOptions) @@ -26,7 +30,21 @@ func init() { if args.Usable { params.Add(jsonutils.JSONTrue, "usable") } - result, err := modules.Storages.List(s, params) + if len(args.Region) > 0 { + params.Add(jsonutils.NewString(args.Region), "region") + } + + if len(args.Manager) > 0 { + params.Add(jsonutils.NewString(args.Manager), "manager") + } + + var result *modules.ListResult + var err error + if len(args.Zone) > 0 { + result, err = modules.Storages.ListInContext(s, params, &modules.Zones, args.Zone) + } else { + result, err = modules.Storages.List(s, params) + } if err != nil { return err } @@ -181,10 +199,14 @@ func init() { type StorageUncacheImageActionOptions struct { ID string `help:"ID or name of storage"` IMAGE string `help:"ID or name of image"` + Force bool `help:"Force uncache, even if the image exists in cache"` } R(&StorageUncacheImageActionOptions{}, "storage-uncache-image", "Ask a storage to remove image from its cache", func(s *mcclient.ClientSession, args *StorageUncacheImageActionOptions) error { params := jsonutils.NewDict() params.Add(jsonutils.NewString(args.IMAGE), "image") + if args.Force { + params.Add(jsonutils.JSONTrue, "is_force") + } storage, err := modules.Storages.PerformAction(s, args.ID, "uncache-image", params) if err != nil { return err diff --git a/cmd/climc/shell/vpcs.go b/cmd/climc/shell/vpcs.go index 81516ca28e..e725969b54 100644 --- a/cmd/climc/shell/vpcs.go +++ b/cmd/climc/shell/vpcs.go @@ -9,10 +9,16 @@ import ( func init() { type VpcListOptions struct { BaseListOptions - Region string `help:"ID or Name of region"` + Region string `help:"ID or Name of region"` + Manager string `help:"Show regions belongs to the cloud provider"` } R(&VpcListOptions{}, "vpc-list", "List VPCs", func(s *mcclient.ClientSession, args *VpcListOptions) error { params := FetchPagingParams(args.BaseListOptions) + + if len(args.Manager) > 0 { + params.Add(jsonutils.NewString(args.Manager), "manager") + } + var result *modules.ListResult var err error if len(args.Region) > 0 { @@ -23,25 +29,36 @@ func init() { if err != nil { return err } + printList(result, modules.Vpcs.GetColumns(s)) return nil }) type VpcCreateOptions struct { - REGION string `help:"ID or name of the region where the VPC is created"` - Id string `help:"ID of the new VPC"` - NAME string `help:"Name of the VPC"` - Desc string `help:"Description of the VPC"` + REGION string `help:"ID or name of the region where the VPC is created"` + Id string `help:"ID of the new VPC"` + NAME string `help:"Name of the VPC"` + CIDR string `help:"CIDR block"` + Default bool `help:"default VPC for the region" default:"false"` + Desc string `help:"Description of the VPC"` + Manager string `help:"ID or Name of Cloud provider"` } R(&VpcCreateOptions{}, "vpc-create", "Create a VPC", func(s *mcclient.ClientSession, args *VpcCreateOptions) error { params := jsonutils.NewDict() params.Add(jsonutils.NewString(args.NAME), "name") + params.Add(jsonutils.NewString(args.CIDR), "cidr_block") if len(args.Id) > 0 { params.Add(jsonutils.NewString(args.Id), "id") } if len(args.Desc) > 0 { params.Add(jsonutils.NewString(args.Desc), "description") } + if args.Default { + params.Add(jsonutils.JSONTrue, "is_default") + } + if len(args.Manager) > 0 { + params.Add(jsonutils.NewString(args.Manager), "manager") + } results, err := modules.Vpcs.CreateInContext(s, params, &modules.Cloudregions, args.REGION) if err != nil { return err @@ -116,4 +133,13 @@ func init() { printObject(result) return nil }) + + R(&VpcUpdateStatusOptions{}, "vpc-purge", "Purge a managed VPC, not delete the remote entity", func(s *mcclient.ClientSession, args *VpcUpdateStatusOptions) error { + result, err := modules.Vpcs.PerformAction(s, args.ID, "purge", nil) + if err != nil { + return err + } + printObject(result) + return nil + }) } diff --git a/cmd/climc/shell/wires.go b/cmd/climc/shell/wires.go index 60588d922b..385064cd37 100644 --- a/cmd/climc/shell/wires.go +++ b/cmd/climc/shell/wires.go @@ -9,10 +9,21 @@ import ( func init() { type WireListOptions struct { BaseListOptions + Zone string `help:"list wires in zone"` + Vpc string `help:"List wires in vpc"` } R(&WireListOptions{}, "wire-list", "List wires", func(s *mcclient.ClientSession, args *WireListOptions) error { params := FetchPagingParams(args.BaseListOptions) - result, err := modules.Wires.List(s, params) + if len(args.Vpc) > 0 { + params.Add(jsonutils.NewString(args.Vpc), "vpc") + } + var result *modules.ListResult + var err error + if len(args.Zone) > 0 { + result, err = modules.Wires.ListInContext(s, params, &modules.Zones, args.Zone) + } else { + result, err = modules.Wires.List(s, params) + } if err != nil { return err } @@ -59,7 +70,9 @@ func init() { params := jsonutils.NewDict() params.Add(jsonutils.NewString(args.NAME), "name") params.Add(jsonutils.NewInt(args.BW), "bandwidth") - params.Add(jsonutils.NewString(args.Vpc), "vpc") + if len(args.Vpc) > 0 { + params.Add(jsonutils.NewString(args.Vpc), "vpc") + } if len(args.Desc) > 0 { params.Add(jsonutils.NewString(args.Desc), "description") } diff --git a/cmd/climc/shell/zones.go b/cmd/climc/shell/zones.go index b633fd7a3f..848643bc36 100644 --- a/cmd/climc/shell/zones.go +++ b/cmd/climc/shell/zones.go @@ -9,10 +9,29 @@ import ( func init() { type ZoneListOptions struct { BaseListOptions + Region string `help:"cloud region ID or Name"` + Usable bool `help:"List zones that is usable"` + Private bool `help:"show zones in private cloud regions only"` + Public bool `help:"show zones in public cloud regions only"` } - R(&ZoneListOptions{}, "zone-list", "List zones", func(s *mcclient.ClientSession, suboptions *ZoneListOptions) error { - params := FetchPagingParams(suboptions.BaseListOptions) - result, err := modules.Zones.List(s, params) + R(&ZoneListOptions{}, "zone-list", "List zones", func(s *mcclient.ClientSession, args *ZoneListOptions) error { + params := FetchPagingParams(args.BaseListOptions) + if args.Usable { + params.Add(jsonutils.JSONTrue, "usable") + } + if args.Private { + params.Add(jsonutils.JSONTrue, "is_private") + } + if args.Public { + params.Add(jsonutils.JSONTrue, "is_public") + } + var err error + var result *modules.ListResult + if len(args.Region) > 0 { + result, err = modules.Zones.ListInContext(s, params, &modules.Cloudregions, args.Region) + } else { + result, err = modules.Zones.List(s, params) + } if err != nil { return err } @@ -73,6 +92,15 @@ func init() { return nil }) + R(&ZoneShowOptions{}, "zone-capabilities", "Show zone's capacibilities", func(s *mcclient.ClientSession, args *ZoneShowOptions) error { + result, err := modules.Zones.GetSpecific(s, args.ID, "capabilities", nil) + if err != nil { + return err + } + printObject(result) + return nil + }) + type ZoneCreateOptions struct { NAME string `help:"Name of zone"` NameCN string `help:"Name in Chinese"` diff --git a/cmd/scheduler/app/server.go b/cmd/scheduler/app/server.go index 4e36e11d17..fc0c9e023f 100644 --- a/cmd/scheduler/app/server.go +++ b/cmd/scheduler/app/server.go @@ -10,9 +10,9 @@ import ( "gopkg.in/gin-gonic/gin.v1" - o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/log" "github.com/yunionio/mcclient/auth" + o "github.com/yunionio/onecloud/cmd/scheduler/options" _ "github.com/yunionio/onecloud/pkg/scheduler/algorithmprovider" "github.com/yunionio/onecloud/pkg/scheduler/db/models" schedhandler "github.com/yunionio/onecloud/pkg/scheduler/handler" diff --git a/cmd/scheduler/options/options.go b/cmd/scheduler/options/options.go index 498c9342a2..e089d1ab40 100644 --- a/cmd/scheduler/options/options.go +++ b/cmd/scheduler/options/options.go @@ -7,8 +7,8 @@ import ( "gopkg.in/gin-gonic/gin.v1" "github.com/yunionio/log" - "github.com/yunionio/structarg" "github.com/yunionio/pkg/util/version" + "github.com/yunionio/structarg" ) type SchedulerOptions struct { diff --git a/pkg/cloudcommon/db/adminsharablevirtual.go b/pkg/cloudcommon/db/adminsharablevirtual.go index ceccae05f8..9cb61b4864 100644 --- a/pkg/cloudcommon/db/adminsharablevirtual.go +++ b/pkg/cloudcommon/db/adminsharablevirtual.go @@ -3,9 +3,9 @@ package db import ( "strings" - "github.com/yunionio/pkg/httperrors" "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/utils" ) diff --git a/pkg/cloudcommon/db/resourcebase.go b/pkg/cloudcommon/db/resourcebase.go index c0336e9953..7acdca00eb 100644 --- a/pkg/cloudcommon/db/resourcebase.go +++ b/pkg/cloudcommon/db/resourcebase.go @@ -5,8 +5,8 @@ import ( "time" "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" "github.com/yunionio/pkg/util/timeutils" + "github.com/yunionio/sqlchemy" ) type SResourceBase struct { diff --git a/pkg/cloudcommon/db/standalone.go b/pkg/cloudcommon/db/standalone.go index bd650079d6..dc840a25f3 100644 --- a/pkg/cloudcommon/db/standalone.go +++ b/pkg/cloudcommon/db/standalone.go @@ -5,14 +5,14 @@ import ( "database/sql" "fmt" - "github.com/yunionio/pkg/httperrors" "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/util/regutils" "github.com/yunionio/pkg/util/stringutils" "github.com/yunionio/pkg/utils" + "github.com/yunionio/sqlchemy" ) type SStandaloneResourceBase struct { @@ -109,7 +109,7 @@ func (manager *SStandaloneResourceBaseManager) ListItemFilter(ctx context.Contex } showEmulated := jsonutils.QueryBoolean(query, "show_emulated", false) - if ! showEmulated { + if !showEmulated { q = q.Filter(sqlchemy.IsFalse(q.Field("is_emulated"))) } diff --git a/pkg/cloudcommon/options.go b/pkg/cloudcommon/options.go index 4fbdc10f96..7dd07e76d4 100644 --- a/pkg/cloudcommon/options.go +++ b/pkg/cloudcommon/options.go @@ -6,9 +6,9 @@ import ( "path" "github.com/yunionio/log" - "github.com/yunionio/structarg" - "github.com/yunionio/pkg/utils" "github.com/yunionio/pkg/util/version" + "github.com/yunionio/pkg/utils" + "github.com/yunionio/structarg" ) type Options struct { diff --git a/pkg/cloudprovider/resources.go b/pkg/cloudprovider/resources.go index c8b1aacc3d..466dc77ed1 100644 --- a/pkg/cloudprovider/resources.go +++ b/pkg/cloudprovider/resources.go @@ -2,6 +2,7 @@ package cloudprovider import ( "time" + "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" ) diff --git a/pkg/compute/guestdrivers/aliyun.go b/pkg/compute/guestdrivers/aliyun.go index 744d186633..4d7d54a314 100644 --- a/pkg/compute/guestdrivers/aliyun.go +++ b/pkg/compute/guestdrivers/aliyun.go @@ -101,7 +101,7 @@ func (self *SAliyunGuestDriver) GetJsonDescAtHost(ctx context.Context, guest *mo imageId := disk.GetTemplateId() scimg := models.StoragecachedimageManager.GetStoragecachedimage(cache.Id, imageId) config.ExternalImageId = scimg.ExternalId - config.SysDiskSize = disk.DiskSize + config.SysDiskSize = disk.DiskSize / 1024 // MB => GB } else { config.DataDisks[i-1] = disk.DiskSize / 1024 // MB => GB } diff --git a/pkg/compute/models/cloudregions.go b/pkg/compute/models/cloudregions.go index fa6bc7161e..dd854a28a2 100644 --- a/pkg/compute/models/cloudregions.go +++ b/pkg/compute/models/cloudregions.go @@ -305,8 +305,15 @@ func (manager *SCloudregionManager) ListItemFilter(ctx context.Context, q *sqlch q = q.Equals("provider", manager.Provider) } if jsonutils.QueryBoolean(query, "usable", false) { + networks := NetworkManager.Query().SubQuery() + wires := WireManager.Query().SubQuery() vpcs := VpcManager.Query().SubQuery() - sq := vpcs.Query(sqlchemy.DISTINCT("cloudregion_id", vpcs.Field("cloudregion_id"))).Equals("status", VPC_STATUS_AVAILABLE) + + sq := vpcs.Query(sqlchemy.DISTINCT("cloudregion_id", vpcs.Field("cloudregion_id"))) + sq = sq.Join(wires, sqlchemy.Equals(vpcs.Field("id"), wires.Field("vpc_id"))) + sq = sq.Join(networks, sqlchemy.Equals(wires.Field("id"), networks.Field("wire_id"))) + sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), NETWORK_STATUS_AVAILABLE)) + q = q.Filter(sqlchemy.In(q.Field("id"), sq.SubQuery())) } return q, nil diff --git a/pkg/compute/models/guestdrivers.go b/pkg/compute/models/guestdrivers.go index 9e62cb00bc..c0a9a45ed3 100644 --- a/pkg/compute/models/guestdrivers.go +++ b/pkg/compute/models/guestdrivers.go @@ -2,11 +2,12 @@ package models import ( "context" - "github.com/yunionio/onecloud/pkg/cloudcommon/db/quotas" - "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" + "github.com/yunionio/onecloud/pkg/cloudcommon/db/quotas" + "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" ) type IGuestDriver interface { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 89d1f66fc9..7c5dc84719 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -1942,7 +1942,7 @@ func (self *SGuest) DoPendingDelete(ctx context.Context, userCred mcclient.Token for _, guestdisk := range self.GetDisks() { disk := guestdisk.GetDisk() storage := disk.GetStorage() - if utils.IsInStringArray(storage.StorageType, sysutils.LOCAL_STORAGE_TYPES) { + if utils.IsInStringArray(storage.StorageType, sysutils.LOCAL_STORAGE_TYPES) || disk.DiskType == DISK_TYPE_SYS || disk.DiskType == DISK_TYPE_SWAP { disk.DoPendingDelete(ctx, userCred) } else { self.detachDisk(ctx, disk, userCred) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 900362f4d3..82b1d2c8d6 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -3,26 +3,26 @@ package models import ( "context" "fmt" + "net/http" "net/url" "strconv" - "net/http" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/onecloud/pkg/compute/options" - "github.com/yunionio/pkg/httperrors" "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" "github.com/yunionio/mcclient/auth" "github.com/yunionio/mcclient/modules" - "github.com/yunionio/sqlchemy" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/onecloud/pkg/compute/options" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/tristate" "github.com/yunionio/pkg/util/compare" "github.com/yunionio/pkg/util/netutils" "github.com/yunionio/pkg/util/regutils" "github.com/yunionio/pkg/util/sysutils" "github.com/yunionio/pkg/utils" + "github.com/yunionio/sqlchemy" ) const ( @@ -147,7 +147,6 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu } var scopeQuery *sqlchemy.SSubQuery - schedTagStr := jsonutils.GetAnyString(query, []string{"schedtag", "schedtag_id"}) if len(schedTagStr) > 0 { schedTag, _ := SchedtagManager.FetchByIdOrName("", schedTagStr) @@ -158,7 +157,7 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu scopeQuery = hostschedtags.Query(hostschedtags.Field("host_id")).Equals("schedtag_id", schedTag.GetId()).SubQuery() } - wireStr :=jsonutils.GetAnyString(query, []string{"wire", "wire_id"}) + wireStr := jsonutils.GetAnyString(query, []string{"wire", "wire_id"}) if len(wireStr) > 0 { wire, _ := WireManager.FetchByIdOrName("", wireStr) if wire == nil { diff --git a/pkg/compute/models/hostschedtags.go b/pkg/compute/models/hostschedtags.go index 7f35ed1313..63e8659a3c 100644 --- a/pkg/compute/models/hostschedtags.go +++ b/pkg/compute/models/hostschedtags.go @@ -2,10 +2,11 @@ package models import ( "context" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" ) type SHostschedtagManager struct { diff --git a/pkg/compute/models/hoststorages.go b/pkg/compute/models/hoststorages.go index 24ff22dcc4..3bb0964974 100644 --- a/pkg/compute/models/hoststorages.go +++ b/pkg/compute/models/hoststorages.go @@ -3,12 +3,13 @@ package models import ( "context" "fmt" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/pkg/httperrors" + "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/tristate" + "github.com/yunionio/sqlchemy" ) type SHoststorageManager struct { diff --git a/pkg/compute/models/hostwires.go b/pkg/compute/models/hostwires.go index 62b9eccfa0..2e4e0300b1 100644 --- a/pkg/compute/models/hostwires.go +++ b/pkg/compute/models/hostwires.go @@ -2,10 +2,11 @@ package models import ( "context" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/pkg/httperrors" + "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/sqlchemy" ) diff --git a/pkg/compute/models/initdb.go b/pkg/compute/models/initdb.go index 0e6c514539..c6a401a233 100644 --- a/pkg/compute/models/initdb.go +++ b/pkg/compute/models/initdb.go @@ -1,8 +1,8 @@ package models import ( - "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" ) func InitDB() error { diff --git a/pkg/compute/models/isolated_devices.go b/pkg/compute/models/isolated_devices.go index 2e6acb37f6..b6f43b0228 100644 --- a/pkg/compute/models/isolated_devices.go +++ b/pkg/compute/models/isolated_devices.go @@ -5,14 +5,14 @@ import ( "fmt" "strings" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/pkg/httperrors" "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/util/regutils" "github.com/yunionio/pkg/utils" + "github.com/yunionio/sqlchemy" ) const ( diff --git a/pkg/compute/models/keypairs.go b/pkg/compute/models/keypairs.go index 2eca5e9a19..db184d4907 100644 --- a/pkg/compute/models/keypairs.go +++ b/pkg/compute/models/keypairs.go @@ -2,10 +2,11 @@ package models import ( "context" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/pkg/httperrors" + "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/sqlchemy" ) diff --git a/pkg/compute/models/netinterfaces.go b/pkg/compute/models/netinterfaces.go index 0bf701a36c..017d46aa86 100644 --- a/pkg/compute/models/netinterfaces.go +++ b/pkg/compute/models/netinterfaces.go @@ -3,10 +3,11 @@ package models import ( "context" "database/sql" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/pkg/util/regutils" ) diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index 24754a0bc1..5097840fab 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -6,21 +6,21 @@ import ( "fmt" "strings" + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" + "github.com/yunionio/mcclient" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/onecloud/pkg/compute/options" "github.com/yunionio/pkg/httperrors" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" - "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" "github.com/yunionio/pkg/tristate" "github.com/yunionio/pkg/util/compare" "github.com/yunionio/pkg/util/fileutils" "github.com/yunionio/pkg/util/netutils" "github.com/yunionio/pkg/util/regutils" "github.com/yunionio/pkg/utils" + "github.com/yunionio/sqlchemy" ) const ( diff --git a/pkg/compute/models/quotas.go b/pkg/compute/models/quotas.go index 44c51ca231..79344b4c37 100644 --- a/pkg/compute/models/quotas.go +++ b/pkg/compute/models/quotas.go @@ -3,9 +3,10 @@ package models import ( "errors" "fmt" + + "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/cloudcommon/db/quotas" "github.com/yunionio/onecloud/pkg/compute/options" - "github.com/yunionio/jsonutils" "github.com/yunionio/pkg/tristate" ) diff --git a/pkg/compute/models/reservedips.go b/pkg/compute/models/reservedips.go index ac99f30f3f..3ef5f8d309 100644 --- a/pkg/compute/models/reservedips.go +++ b/pkg/compute/models/reservedips.go @@ -3,11 +3,12 @@ package models import ( "context" "fmt" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/pkg/httperrors" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/sqlchemy" ) diff --git a/pkg/compute/models/schedtags.go b/pkg/compute/models/schedtags.go index 6e2c1fc95b..725e0b14fb 100644 --- a/pkg/compute/models/schedtags.go +++ b/pkg/compute/models/schedtags.go @@ -4,13 +4,14 @@ import ( "context" "database/sql" "strings" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/pkg/httperrors" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/utils" + "github.com/yunionio/sqlchemy" ) type SchedStrategyType string diff --git a/pkg/compute/models/secgrouprules.go b/pkg/compute/models/secgrouprules.go index 8513780d2e..cd73e8fe32 100644 --- a/pkg/compute/models/secgrouprules.go +++ b/pkg/compute/models/secgrouprules.go @@ -6,14 +6,14 @@ import ( "strconv" "strings" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/pkg/httperrors" "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/util/secrules" "github.com/yunionio/pkg/util/stringutils" + "github.com/yunionio/sqlchemy" ) type SSecurityGroupRuleManager struct { diff --git a/pkg/compute/models/secgroups.go b/pkg/compute/models/secgroups.go index 3a95f7a9a7..332077df82 100644 --- a/pkg/compute/models/secgroups.go +++ b/pkg/compute/models/secgroups.go @@ -4,11 +4,11 @@ import ( "context" "strings" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/pkg/httperrors" "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/sqlchemy" ) diff --git a/pkg/compute/models/storagecachedimages.go b/pkg/compute/models/storagecachedimages.go index abfaec97a2..01389a1bc4 100644 --- a/pkg/compute/models/storagecachedimages.go +++ b/pkg/compute/models/storagecachedimages.go @@ -4,14 +4,15 @@ import ( "context" "fmt" "time" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/onecloud/pkg/cloudcommon/db/lockman" - "github.com/yunionio/pkg/httperrors" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/onecloud/pkg/cloudcommon/db/lockman" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/utils" + "github.com/yunionio/sqlchemy" ) const ( diff --git a/pkg/compute/models/storagecaches.go b/pkg/compute/models/storagecaches.go index 5eb0b6ce04..cab681a24a 100644 --- a/pkg/compute/models/storagecaches.go +++ b/pkg/compute/models/storagecaches.go @@ -3,14 +3,15 @@ package models import ( "context" "database/sql" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" - "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" + "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/pkg/httperrors" + "github.com/yunionio/sqlchemy" ) type SStoragecacheManager struct { @@ -165,7 +166,7 @@ func (self *SStoragecache) StartImageCacheTask(ctx context.Context, userCred mcc } func (self *SStoragecache) StartImageUncacheTask(ctx context.Context, userCred mcclient.TokenCredential, imageId string, isForce bool, parentTaskId string) error { - if ! isForce { + if !isForce { err := self.ValidateDeleteCondition(ctx) if err != nil { return err @@ -219,7 +220,6 @@ func (self *SStoragecache) ValidateDeleteCondition(ctx context.Context) error { return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx) } - func (self *SStoragecache) AllowPerformUncacheImage(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { return userCred.IsSystemAdmin() } diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index e4a6d05665..78f2ad7e63 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -2,16 +2,17 @@ package models import ( "context" + + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" + "github.com/yunionio/mcclient" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/onecloud/pkg/compute/options" "github.com/yunionio/pkg/httperrors" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" - "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" "github.com/yunionio/pkg/tristate" "github.com/yunionio/pkg/util/compare" + "github.com/yunionio/sqlchemy" ) const ( diff --git a/pkg/compute/models/usage.go b/pkg/compute/models/usage.go index b9a2f0dcde..28c619a0cd 100644 --- a/pkg/compute/models/usage.go +++ b/pkg/compute/models/usage.go @@ -1,8 +1,8 @@ package models import ( - "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/sqlchemy" ) diff --git a/pkg/compute/models/vcenters.go b/pkg/compute/models/vcenters.go index 6f8612c585..62d107604c 100644 --- a/pkg/compute/models/vcenters.go +++ b/pkg/compute/models/vcenters.go @@ -3,9 +3,10 @@ package models import ( "context" "time" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" ) type SVCenterManager struct { diff --git a/pkg/compute/models/vpcs.go b/pkg/compute/models/vpcs.go index 1e256d5fa6..5fb11aaa95 100644 --- a/pkg/compute/models/vpcs.go +++ b/pkg/compute/models/vpcs.go @@ -3,18 +3,18 @@ package models import ( "context" "database/sql" - "fmt" + + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" + "github.com/yunionio/mcclient" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/pkg/httperrors" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" - "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" "github.com/yunionio/pkg/util/compare" "github.com/yunionio/pkg/util/netutils" + "github.com/yunionio/sqlchemy" ) const ( @@ -461,4 +461,4 @@ func (manager *SVpcManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQue } return q, nil -} \ No newline at end of file +} diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index 33f3d04b6f..cccbaebb74 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -2,17 +2,17 @@ package models import ( "context" - "fmt" "database/sql" + "fmt" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/pkg/httperrors" "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/util/compare" + "github.com/yunionio/sqlchemy" ) type SWireManager struct { diff --git a/pkg/compute/models/zones.go b/pkg/compute/models/zones.go index 96cdc37c87..7ae7a7f128 100644 --- a/pkg/compute/models/zones.go +++ b/pkg/compute/models/zones.go @@ -2,17 +2,17 @@ package models import ( "context" - "fmt" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/pkg/httperrors" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" - "github.com/yunionio/sqlchemy" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/tristate" "github.com/yunionio/pkg/util/compare" + "github.com/yunionio/sqlchemy" ) const ( @@ -57,7 +57,7 @@ func (manager *SZoneManager) AllowListItems(ctx context.Context, userCred mcclie func (zone *SZone) ValidateDeleteCondition(ctx context.Context) error { usage := zone.GeneralUsage() - if ! usage.isEmpty() { + if !usage.isEmpty() { return httperrors.NewNotEmptyError("not empty zone") } return zone.SStandaloneResourceBase.ValidateDeleteCondition(ctx) diff --git a/pkg/compute/service/service.go b/pkg/compute/service/service.go index e739df8cf6..59792888ed 100644 --- a/pkg/compute/service/service.go +++ b/pkg/compute/service/service.go @@ -5,12 +5,12 @@ import ( _ "github.com/go-sql-driver/mysql" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/compute" "github.com/yunionio/onecloud/pkg/compute/models" "github.com/yunionio/onecloud/pkg/compute/options" - "github.com/yunionio/log" _ "github.com/yunionio/onecloud/pkg/compute/tasks" diff --git a/pkg/compute/tasks/baremetal_convert_hypervisor_task.go b/pkg/compute/tasks/baremetal_convert_hypervisor_task.go index ebc8f28a0d..e69cf75222 100644 --- a/pkg/compute/tasks/baremetal_convert_hypervisor_task.go +++ b/pkg/compute/tasks/baremetal_convert_hypervisor_task.go @@ -3,11 +3,11 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" ) const ( diff --git a/pkg/compute/tasks/cloud_provider_sync_info_task.go b/pkg/compute/tasks/cloud_provider_sync_info_task.go index ccf0ca4ec8..ba0b27e77b 100644 --- a/pkg/compute/tasks/cloud_provider_sync_info_task.go +++ b/pkg/compute/tasks/cloud_provider_sync_info_task.go @@ -4,12 +4,12 @@ import ( "context" "fmt" + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" "github.com/yunionio/pkg/utils" ) diff --git a/pkg/compute/tasks/disk_delete_task.go b/pkg/compute/tasks/disk_delete_task.go index d26191aebb..015ebf9345 100644 --- a/pkg/compute/tasks/disk_delete_task.go +++ b/pkg/compute/tasks/disk_delete_task.go @@ -3,9 +3,9 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" - "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/compute/models" "github.com/yunionio/onecloud/pkg/compute/options" ) @@ -27,7 +27,7 @@ func (self *DiskDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, db.OpsLog.LogEvent(disk, db.ACT_DELOCATE_FAIL, reason, self.UserCred) return } - if options.Options.EnablePendingDelete && ! disk.PendingDeleted && ! jsonutils.QueryBoolean(self.Params, "purge", false) && ! jsonutils.QueryBoolean(self.Params, "override_pending_delete", false) { + if options.Options.EnablePendingDelete && !disk.PendingDeleted && !jsonutils.QueryBoolean(self.Params, "purge", false) && !jsonutils.QueryBoolean(self.Params, "override_pending_delete", false) { self.startPendingDeleteDisk(ctx, disk) } else { self.startDeleteDisk(ctx, disk) @@ -43,7 +43,7 @@ func (self *DiskDeleteTask) startDeleteDisk(ctx context.Context, disk *models.SD storage := disk.GetStorage() host := storage.GetMasterHost() isPurge := false - if (host == nil || ! host.Enabled) && jsonutils.QueryBoolean(self.Params, "purge", false) { + if (host == nil || !host.Enabled) && jsonutils.QueryBoolean(self.Params, "purge", false) { isPurge = true } disk.SetStatus(self.UserCred, models.DISK_DEALLOC, "") diff --git a/pkg/compute/tasks/guest_batch_create_task.go b/pkg/compute/tasks/guest_batch_create_task.go index eaee667d25..e99d8bf622 100644 --- a/pkg/compute/tasks/guest_batch_create_task.go +++ b/pkg/compute/tasks/guest_batch_create_task.go @@ -4,16 +4,16 @@ import ( "context" "fmt" + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" + "github.com/yunionio/mcclient/auth" + "github.com/yunionio/mcclient/modules" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/lockman" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudcommon/notifyclient" "github.com/yunionio/onecloud/pkg/compute/models" "github.com/yunionio/onecloud/pkg/compute/options" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" - "github.com/yunionio/mcclient/auth" - "github.com/yunionio/mcclient/modules" ) type GuestBatchCreateTask struct { diff --git a/pkg/compute/tasks/guest_create_task.go b/pkg/compute/tasks/guest_create_task.go index a58f30a1c6..26f64ae64e 100644 --- a/pkg/compute/tasks/guest_create_task.go +++ b/pkg/compute/tasks/guest_create_task.go @@ -5,12 +5,12 @@ import ( "fmt" "time" + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudcommon/notifyclient" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" ) type GuestCreateTask struct { diff --git a/pkg/compute/tasks/guest_delete_task.go b/pkg/compute/tasks/guest_delete_task.go index d23dc39fa7..6c18a50058 100644 --- a/pkg/compute/tasks/guest_delete_task.go +++ b/pkg/compute/tasks/guest_delete_task.go @@ -3,12 +3,12 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudcommon/notifyclient" "github.com/yunionio/onecloud/pkg/compute/models" "github.com/yunionio/onecloud/pkg/compute/options" - "github.com/yunionio/jsonutils" "github.com/yunionio/pkg/utils" ) diff --git a/pkg/compute/tasks/guest_deploy_task.go b/pkg/compute/tasks/guest_deploy_task.go index 390d89558d..230f82640f 100644 --- a/pkg/compute/tasks/guest_deploy_task.go +++ b/pkg/compute/tasks/guest_deploy_task.go @@ -4,11 +4,11 @@ import ( "context" "fmt" + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" ) type GuestDeployTask struct { diff --git a/pkg/compute/tasks/guest_detach_all_disks_task.go b/pkg/compute/tasks/guest_detach_all_disks_task.go index a959bb6892..cfc6465322 100644 --- a/pkg/compute/tasks/guest_detach_all_disks_task.go +++ b/pkg/compute/tasks/guest_detach_all_disks_task.go @@ -3,10 +3,10 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" ) type GuestDetachAllDisksTask struct { diff --git a/pkg/compute/tasks/guest_detach_disk_task.go b/pkg/compute/tasks/guest_detach_disk_task.go index 3ab8ce75af..2dff6ca781 100644 --- a/pkg/compute/tasks/guest_detach_disk_task.go +++ b/pkg/compute/tasks/guest_detach_disk_task.go @@ -3,9 +3,9 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" - "github.com/yunionio/jsonutils" ) type GuestDetachDiskTask struct { diff --git a/pkg/compute/tasks/guest_insert_iso_task.go b/pkg/compute/tasks/guest_insert_iso_task.go index 46543dc2d1..59926cfd73 100644 --- a/pkg/compute/tasks/guest_insert_iso_task.go +++ b/pkg/compute/tasks/guest_insert_iso_task.go @@ -3,9 +3,9 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" - "github.com/yunionio/jsonutils" ) type GuestInsertIsoTask struct { diff --git a/pkg/compute/tasks/guest_start_task.go b/pkg/compute/tasks/guest_start_task.go index ae2d1e3b30..b54f6e916d 100644 --- a/pkg/compute/tasks/guest_start_task.go +++ b/pkg/compute/tasks/guest_start_task.go @@ -3,10 +3,10 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" ) type GuestStartTask struct { diff --git a/pkg/compute/tasks/guest_stop_task.go b/pkg/compute/tasks/guest_stop_task.go index 9e3f7d0736..b2843cc377 100644 --- a/pkg/compute/tasks/guest_stop_task.go +++ b/pkg/compute/tasks/guest_stop_task.go @@ -4,11 +4,11 @@ import ( "context" "fmt" + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" ) type GuestStopTask struct { diff --git a/pkg/compute/tasks/guest_syncstatus_task.go b/pkg/compute/tasks/guest_syncstatus_task.go index be34c78c20..201c20cd66 100644 --- a/pkg/compute/tasks/guest_syncstatus_task.go +++ b/pkg/compute/tasks/guest_syncstatus_task.go @@ -3,12 +3,12 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" ) type GuestSyncstatusTask struct { diff --git a/pkg/compute/tasks/guest_undeploy_task.go b/pkg/compute/tasks/guest_undeploy_task.go index 066dfbb1da..4d4a3d8957 100644 --- a/pkg/compute/tasks/guest_undeploy_task.go +++ b/pkg/compute/tasks/guest_undeploy_task.go @@ -3,10 +3,10 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" "github.com/yunionio/pkg/util/httputils" ) diff --git a/pkg/compute/tasks/network_create_task.go b/pkg/compute/tasks/network_create_task.go index 5670cdbd99..57a0151ae4 100644 --- a/pkg/compute/tasks/network_create_task.go +++ b/pkg/compute/tasks/network_create_task.go @@ -2,15 +2,15 @@ package tasks import ( "context" - "fmt" "time" + + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" ) type NetworkCreateTask struct { diff --git a/pkg/compute/tasks/network_delete_task.go b/pkg/compute/tasks/network_delete_task.go index 0e35627c63..38d5c7f28d 100644 --- a/pkg/compute/tasks/network_delete_task.go +++ b/pkg/compute/tasks/network_delete_task.go @@ -3,12 +3,12 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" ) type NetworkDeleteTask struct { diff --git a/pkg/compute/tasks/storage_cache_image_task.go b/pkg/compute/tasks/storage_cache_image_task.go index ce39064db4..0a9346d410 100644 --- a/pkg/compute/tasks/storage_cache_image_task.go +++ b/pkg/compute/tasks/storage_cache_image_task.go @@ -4,10 +4,10 @@ import ( "context" "fmt" + "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" ) type StorageCacheImageTask struct { diff --git a/pkg/compute/tasks/storage_uncache_image_task.go b/pkg/compute/tasks/storage_uncache_image_task.go index e0a56650b4..2099097481 100644 --- a/pkg/compute/tasks/storage_uncache_image_task.go +++ b/pkg/compute/tasks/storage_uncache_image_task.go @@ -3,9 +3,9 @@ package tasks import ( "context" + "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" - "github.com/yunionio/jsonutils" "github.com/yunionio/onecloud/pkg/compute/models" ) diff --git a/pkg/compute/tasks/vpc_create_task.go b/pkg/compute/tasks/vpc_create_task.go index ce1d71e44d..e6eaac0bf1 100644 --- a/pkg/compute/tasks/vpc_create_task.go +++ b/pkg/compute/tasks/vpc_create_task.go @@ -2,14 +2,14 @@ package tasks import ( "context" - "time" + + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" ) type VpcCreateTask struct { diff --git a/pkg/compute/tasks/vpc_delete_task.go b/pkg/compute/tasks/vpc_delete_task.go index df461a6f32..d2e2d96b8c 100644 --- a/pkg/compute/tasks/vpc_delete_task.go +++ b/pkg/compute/tasks/vpc_delete_task.go @@ -2,14 +2,14 @@ package tasks import ( "context" - "time" + + "github.com/yunionio/jsonutils" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudcommon/db" "github.com/yunionio/onecloud/pkg/cloudcommon/db/taskman" "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/jsonutils" - "github.com/yunionio/log" ) type VpcDeleteTask struct { diff --git a/pkg/compute/usages/handler.go b/pkg/compute/usages/handler.go index 83a52b5b10..b84101adbf 100644 --- a/pkg/compute/usages/handler.go +++ b/pkg/compute/usages/handler.go @@ -5,15 +5,15 @@ import ( "fmt" "net/http" - "github.com/yunionio/pkg/appctx" - "github.com/yunionio/pkg/appsrv" - "github.com/yunionio/onecloud/pkg/cloudcommon/db" - "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/pkg/httperrors" json "github.com/yunionio/jsonutils" "github.com/yunionio/log" "github.com/yunionio/mcclient" "github.com/yunionio/mcclient/auth" + "github.com/yunionio/onecloud/pkg/cloudcommon/db" + "github.com/yunionio/onecloud/pkg/compute/models" + "github.com/yunionio/pkg/appctx" + "github.com/yunionio/pkg/appsrv" + "github.com/yunionio/pkg/httperrors" "github.com/yunionio/pkg/tristate" "github.com/yunionio/pkg/utils" ) diff --git a/pkg/scheduler/api/sched.go b/pkg/scheduler/api/sched.go index ab71f318dc..9b277a229e 100644 --- a/pkg/scheduler/api/sched.go +++ b/pkg/scheduler/api/sched.go @@ -8,8 +8,8 @@ import ( "github.com/bitly/go-simplejson" - o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/log" + o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/pkg/utils" ) diff --git a/pkg/scheduler/cache/candidate/default.go b/pkg/scheduler/cache/candidate/default.go index d6a23106c6..4cd5a6a016 100644 --- a/pkg/scheduler/cache/candidate/default.go +++ b/pkg/scheduler/cache/candidate/default.go @@ -6,8 +6,8 @@ import ( gosync "sync" "time" - "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/log" + "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/onecloud/pkg/scheduler/cache" "github.com/yunionio/onecloud/pkg/scheduler/db/models" u "github.com/yunionio/pkg/utils" diff --git a/pkg/scheduler/cache/candidate/hosts.go b/pkg/scheduler/cache/candidate/hosts.go index 9551fd499f..ed36a9e0e9 100644 --- a/pkg/scheduler/cache/candidate/hosts.go +++ b/pkg/scheduler/cache/candidate/hosts.go @@ -8,15 +8,15 @@ import ( "sync/atomic" "time" - o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/log" + o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/onecloud/pkg/scheduler/cache" "github.com/yunionio/onecloud/pkg/scheduler/cache/db" "github.com/yunionio/onecloud/pkg/scheduler/db/models" "github.com/yunionio/pkg/util/errors" "github.com/yunionio/pkg/util/sets" - "github.com/yunionio/pkg/utils" "github.com/yunionio/pkg/util/workqueue" + "github.com/yunionio/pkg/utils" "github.com/yunionio/onecloud/pkg/scheduler/core" ) diff --git a/pkg/scheduler/core/generic_scheduler.go b/pkg/scheduler/core/generic_scheduler.go index d3b73d1db0..a840dd66ae 100644 --- a/pkg/scheduler/core/generic_scheduler.go +++ b/pkg/scheduler/core/generic_scheduler.go @@ -8,8 +8,8 @@ import ( "sync/atomic" "time" - o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/log" + o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/pkg/util/errors" gp "github.com/yunionio/pkg/util/goroutine_pool" utiltrace "github.com/yunionio/pkg/util/trace" diff --git a/pkg/scheduler/handler/ping.go b/pkg/scheduler/handler/ping.go index 205cde490d..1be4267b8a 100644 --- a/pkg/scheduler/handler/ping.go +++ b/pkg/scheduler/handler/ping.go @@ -6,8 +6,8 @@ import ( "gopkg.in/gin-gonic/gin.v1" - o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/log" + o "github.com/yunionio/onecloud/cmd/scheduler/options" schedman "github.com/yunionio/onecloud/pkg/scheduler/manager" ) diff --git a/pkg/scheduler/manager/completed_queue.go b/pkg/scheduler/manager/completed_queue.go index abda1adaed..af56f1d313 100644 --- a/pkg/scheduler/manager/completed_queue.go +++ b/pkg/scheduler/manager/completed_queue.go @@ -3,8 +3,8 @@ package manager import ( "time" - o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/log" + o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/onecloud/pkg/scheduler/api" "github.com/yunionio/pkg/utils" ) diff --git a/pkg/scheduler/manager/expire_queue.go b/pkg/scheduler/manager/expire_queue.go index 0732caa333..b6e587b1ba 100644 --- a/pkg/scheduler/manager/expire_queue.go +++ b/pkg/scheduler/manager/expire_queue.go @@ -4,8 +4,8 @@ import ( "sync" "time" - o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/log" + o "github.com/yunionio/onecloud/cmd/scheduler/options" "github.com/yunionio/onecloud/pkg/scheduler/api" u "github.com/yunionio/pkg/utils" ) diff --git a/pkg/scheduler/manager/task_history.go b/pkg/scheduler/manager/task_history.go index eb9faed5ec..e8c9731351 100644 --- a/pkg/scheduler/manager/task_history.go +++ b/pkg/scheduler/manager/task_history.go @@ -6,8 +6,8 @@ import ( "time" o "github.com/yunionio/onecloud/cmd/scheduler/options" - u "github.com/yunionio/pkg/utils" "github.com/yunionio/pkg/util/wait" + u "github.com/yunionio/pkg/utils" ) type HistoryItem struct { diff --git a/pkg/util/aliyun/aliyun.go b/pkg/util/aliyun/aliyun.go index f66b967b7e..7a126d723e 100644 --- a/pkg/util/aliyun/aliyun.go +++ b/pkg/util/aliyun/aliyun.go @@ -3,9 +3,9 @@ package aliyun import ( "github.com/aliyun/alibaba-cloud-sdk-go/sdk" "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/jsonutils" "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudprovider" ) const ( diff --git a/pkg/util/aliyun/disk.go b/pkg/util/aliyun/disk.go index ec0cb617be..d25c0b3134 100644 --- a/pkg/util/aliyun/disk.go +++ b/pkg/util/aliyun/disk.go @@ -3,10 +3,11 @@ package aliyun import ( "fmt" "time" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/onecloud/pkg/compute/models" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/onecloud/pkg/compute/models" "github.com/yunionio/pkg/utils" ) diff --git a/pkg/util/aliyun/host.go b/pkg/util/aliyun/host.go index 03c569d306..680b99b388 100644 --- a/pkg/util/aliyun/host.go +++ b/pkg/util/aliyun/host.go @@ -4,15 +4,15 @@ import ( "fmt" "strconv" "strings" - "time" "github.com/aokoli/goutils" "golang.org/x/crypto/ssh" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/onecloud/pkg/compute/models" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/onecloud/pkg/compute/models" ) type SHost struct { diff --git a/pkg/util/aliyun/image.go b/pkg/util/aliyun/image.go index 486958c27d..9aff086711 100644 --- a/pkg/util/aliyun/image.go +++ b/pkg/util/aliyun/image.go @@ -4,10 +4,11 @@ import ( "fmt" "strings" "time" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/onecloud/pkg/compute/models" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/onecloud/pkg/compute/models" ) type ImageStatusType string diff --git a/pkg/util/aliyun/instance.go b/pkg/util/aliyun/instance.go index 2a3525f48c..31c0e2b17b 100644 --- a/pkg/util/aliyun/instance.go +++ b/pkg/util/aliyun/instance.go @@ -3,10 +3,11 @@ package aliyun import ( "fmt" "time" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/onecloud/pkg/compute/models" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/onecloud/pkg/compute/models" "github.com/yunionio/pkg/util/osprofile" "github.com/yunionio/pkg/util/seclib" "github.com/yunionio/pkg/utils" diff --git a/pkg/util/aliyun/provider/provider.go b/pkg/util/aliyun/provider/provider.go index faa15c0eb9..363837606c 100644 --- a/pkg/util/aliyun/provider/provider.go +++ b/pkg/util/aliyun/provider/provider.go @@ -1,8 +1,8 @@ package provider import ( - "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/jsonutils" + "github.com/yunionio/onecloud/pkg/cloudprovider" // "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/util/aliyun" ) @@ -80,4 +80,4 @@ func (self *SAliyunProvider) GetIStorageById(id string) (cloudprovider.ICloudSto func (self *SAliyunProvider) GetIStoragecacheById(id string) (cloudprovider.ICloudStoragecache, error) { return self.client.GetIStoragecacheById(id) -} \ No newline at end of file +} diff --git a/pkg/util/aliyun/region.go b/pkg/util/aliyun/region.go index 1aeeba0fba..78de885024 100644 --- a/pkg/util/aliyun/region.go +++ b/pkg/util/aliyun/region.go @@ -2,13 +2,15 @@ package aliyun import ( "fmt" + "strings" + "github.com/aliyun/alibaba-cloud-sdk-go/sdk" "github.com/aliyun/aliyun-oss-go-sdk/oss" - "strings" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/onecloud/pkg/compute/models" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/onecloud/pkg/compute/models" "github.com/yunionio/pkg/utils" ) @@ -404,7 +406,6 @@ func (self *SRegion) GetMatchInstanceTypes(cpu int, memMB int, gpu int, zoneId s return ret, nil } - func (self *SRegion) CreateInstanceSimple(name string, imgId string, cpu int, memGB int, storageType string, dataDiskSizesGB []int, vswitchId string, passwd string, publicKey string) (*SInstance, error) { izones, err := self.GetIZones() if err != nil { @@ -534,8 +535,9 @@ func (self *SRegion) GetIStorageById(id string) (cloudprovider.ICloudStorage, er } func (self *SRegion) GetIStoragecacheById(id string) (cloudprovider.ICloudStoragecache, error) { - if self.storageCache.GetGlobalId() == id { + storageCache := self.getStoragecache() + if storageCache.GetGlobalId() == id { return self.storageCache, nil } return nil, cloudprovider.ErrNotFound -} \ No newline at end of file +} diff --git a/pkg/util/aliyun/securitygroup.go b/pkg/util/aliyun/securitygroup.go index a461afb776..0f3f55e7ad 100644 --- a/pkg/util/aliyun/securitygroup.go +++ b/pkg/util/aliyun/securitygroup.go @@ -3,6 +3,7 @@ package aliyun import ( "fmt" "time" + "github.com/yunionio/log" "github.com/yunionio/pkg/util/secrules" "github.com/yunionio/pkg/utils" diff --git a/pkg/util/aliyun/shell/instance.go b/pkg/util/aliyun/shell/instance.go index 9195459234..181e078d8c 100644 --- a/pkg/util/aliyun/shell/instance.go +++ b/pkg/util/aliyun/shell/instance.go @@ -22,15 +22,15 @@ func init() { }) type InstanceCrateOptions struct { - NAME string `help:"name of instance"` - IMAGE string `help:"image ID"` - CPU int `help:"CPU count"` - MEMORYGB int `help:"MemoryGB"` - Disk []int `help:"Data disk sizes int GB"` - STORAGE string `help:"Storage type"` - VSWITCH string `help:"Vswitch ID"` - PASSWD string `help:"password"` - PublicKey string `help:"PublicKey"` + NAME string `help:"name of instance"` + IMAGE string `help:"image ID"` + CPU int `help:"CPU count"` + MEMORYGB int `help:"MemoryGB"` + Disk []int `help:"Data disk sizes int GB"` + STORAGE string `help:"Storage type"` + VSWITCH string `help:"Vswitch ID"` + PASSWD string `help:"password"` + PublicKey string `help:"PublicKey"` } R(&InstanceCrateOptions{}, "instance-create", "Create a instance", func(cli *aliyun.SRegion, args *InstanceCrateOptions) error { instance, e := cli.CreateInstanceSimple(args.NAME, args.IMAGE, args.CPU, args.MEMORYGB, args.STORAGE, args.Disk, args.VSWITCH, args.PASSWD, args.PublicKey) diff --git a/pkg/util/aliyun/shell/utils.go b/pkg/util/aliyun/shell/utils.go index b2d705d8cd..df2a3c5614 100644 --- a/pkg/util/aliyun/shell/utils.go +++ b/pkg/util/aliyun/shell/utils.go @@ -3,6 +3,7 @@ package shell import ( "fmt" "reflect" + "github.com/yunionio/jsonutils" "github.com/yunionio/mcclient/modules" "github.com/yunionio/pkg/util/printjson" diff --git a/pkg/util/aliyun/storage.go b/pkg/util/aliyun/storage.go index cffb6b27c4..f51b397530 100644 --- a/pkg/util/aliyun/storage.go +++ b/pkg/util/aliyun/storage.go @@ -3,10 +3,11 @@ package aliyun import ( "fmt" "strings" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/onecloud/pkg/compute/models" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/onecloud/pkg/compute/models" ) type SStorage struct { diff --git a/pkg/util/aliyun/storagecache.go b/pkg/util/aliyun/storagecache.go index 8ead26d5cb..7f3aed1dca 100644 --- a/pkg/util/aliyun/storagecache.go +++ b/pkg/util/aliyun/storagecache.go @@ -4,12 +4,13 @@ import ( "fmt" "strings" "time" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/onecloud/pkg/compute/options" + "github.com/yunionio/log" "github.com/yunionio/mcclient" "github.com/yunionio/mcclient/auth" "github.com/yunionio/mcclient/modules" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/onecloud/pkg/compute/options" ) type SStoragecache struct { diff --git a/pkg/util/aliyun/task.go b/pkg/util/aliyun/task.go index 251ce2a9ba..2c048630d4 100644 --- a/pkg/util/aliyun/task.go +++ b/pkg/util/aliyun/task.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" "time" + "github.com/yunionio/log" ) diff --git a/pkg/util/aliyun/vpc.go b/pkg/util/aliyun/vpc.go index dddf9d0a48..6ac1dc68c2 100644 --- a/pkg/util/aliyun/vpc.go +++ b/pkg/util/aliyun/vpc.go @@ -3,8 +3,9 @@ package aliyun import ( "strings" "time" - "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/jsonutils" + "github.com/yunionio/onecloud/pkg/cloudprovider" ) const ( diff --git a/pkg/util/aliyun/vswitch.go b/pkg/util/aliyun/vswitch.go index d4f2dbd32b..c26aef7eca 100644 --- a/pkg/util/aliyun/vswitch.go +++ b/pkg/util/aliyun/vswitch.go @@ -3,10 +3,11 @@ package aliyun import ( "strings" "time" - "github.com/yunionio/onecloud/pkg/cloudprovider" - "github.com/yunionio/onecloud/pkg/compute/models" + "github.com/yunionio/jsonutils" "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/onecloud/pkg/compute/models" "github.com/yunionio/pkg/util/netutils" "github.com/yunionio/pkg/utils" ) diff --git a/pkg/util/aliyun/wire.go b/pkg/util/aliyun/wire.go index 2b7b2ee012..352573e99e 100644 --- a/pkg/util/aliyun/wire.go +++ b/pkg/util/aliyun/wire.go @@ -2,8 +2,9 @@ package aliyun import ( "fmt" - "github.com/yunionio/onecloud/pkg/cloudprovider" + "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/cloudprovider" ) type SWire struct { diff --git a/pkg/util/aliyun/zone.go b/pkg/util/aliyun/zone.go index e8c1ba72eb..3278fbd5a8 100644 --- a/pkg/util/aliyun/zone.go +++ b/pkg/util/aliyun/zone.go @@ -3,9 +3,9 @@ package aliyun import ( "fmt" + "github.com/yunionio/log" "github.com/yunionio/onecloud/pkg/cloudprovider" "github.com/yunionio/onecloud/pkg/compute/models" - "github.com/yunionio/log" ) type InstanceChargeType string