Skip to content

Commit

Permalink
fix(region): refactor snapshot policy (#18996)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Dec 15, 2023
1 parent 6e9253b commit d478a8a
Show file tree
Hide file tree
Showing 76 changed files with 1,628 additions and 3,808 deletions.
112 changes: 9 additions & 103 deletions cmd/climc/shell/compute/snapshot_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,112 +15,18 @@
package compute

import (
"yunion.io/x/jsonutils"

"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/cmd/climc/shell"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
"yunion.io/x/onecloud/pkg/mcclient/options"
"yunion.io/x/onecloud/pkg/mcclient/options/compute"
)

func init() {
type SnapshotPolicyListOptions struct {
options.BaseListOptions

OrderByBindDiskCount string
}
R(&SnapshotPolicyListOptions{}, "snapshot-policy-list", "List snapshot policy", func(s *mcclient.ClientSession, args *SnapshotPolicyListOptions) error {
params, err := options.ListStructToParams(args)
if err != nil {
return err
}
result, err := modules.SnapshotPoliciy.List(s, params)
if err != nil {
return err
}
printList(result, modules.SnapshotPoliciy.GetColumns(s))
return nil
})

type SnapshotPolicyDeleteOptions struct {
ID string `help:"Delete snapshot id"`
}
R(&SnapshotPolicyDeleteOptions{}, "snapshot-policy-delete", "Delete snapshot policy", func(s *mcclient.ClientSession, args *SnapshotPolicyDeleteOptions) error {
result, err := modules.SnapshotPoliciy.Delete(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})

type SnapshotPolicyCreateOptions struct {
NAME string

RetentionDays int `help:"snapshot retention days"`
RepeatWeekdays []int `help:"snapshot create days on week"`
TimePoints []int `help:"snapshot create time points on one day"`
}

R(&SnapshotPolicyCreateOptions{}, "snapshot-policy-create", "Create snapshot policy", func(s *mcclient.ClientSession, args *SnapshotPolicyCreateOptions) error {
params := jsonutils.Marshal(args).(*jsonutils.JSONDict)
snapshot, err := modules.SnapshotPoliciy.Create(s, params)
if err != nil {
return err
}
printObject(snapshot)
return nil
})

type SnapshotPolicyBindDisksOptions struct {
ID string `help:"ID"`
Disk []string `help:"ids of disk"`
}

R(&SnapshotPolicyBindDisksOptions{}, "snapshot-policy-bind-disk", "bind snapshotpolicy to disks",
func(s *mcclient.ClientSession, opts *SnapshotPolicyBindDisksOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
sp, err := modules.SnapshotPoliciy.PerformAction(s, opts.ID, "bind-disks", params)
if err != nil {
return err
}
printObject(sp)
return nil
})

R(&SnapshotPolicyBindDisksOptions{}, "snapshot-policy-unbind-disk", "bind snapshotpolicy to disks",
func(s *mcclient.ClientSession, opts *SnapshotPolicyBindDisksOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
sp, err := modules.SnapshotPoliciy.PerformAction(s, opts.ID, "unbind-disks", params)
if err != nil {
return err
}
printObject(sp)
return nil
})

type SnapshotPolicyCacheOptions struct {
ID string `help:"SnasphotPolicy ID"`
REGIONID string `help:"Region ID"`
PROVIDER string `help:"Provider ID"`
}
R(&SnapshotPolicyCacheOptions{}, "snapshot-policy-cache", "upload local snapshotpolicy to cloud",
func(s *mcclient.ClientSession, opts *SnapshotPolicyCacheOptions) error {
params, err := options.StructToParams(opts)
if err != nil {
return err
}
sp, err := modules.SnapshotPoliciy.PerformAction(s, opts.ID, "cache", params)
if err != nil {
return err
}
printObject(sp)
return nil
},
)
cmd := shell.NewResourceCmd(&modules.SnapshotPoliciy).WithKeyword("snapshot-policy")
cmd.List(&compute.SnapshotPolicyListOptions{})
cmd.Delete(&options.BaseIdOptions{})
cmd.Create(&compute.SnapshotPolicyCreateOptions{})
cmd.Perform("bind-disks", &compute.SnapshotPolicyDisksOptions{})
cmd.Perform("unbind-disks", &compute.SnapshotPolicyDisksOptions{})
cmd.Perform("syncstatus", &options.BaseIdOptions{})
}
80 changes: 0 additions & 80 deletions cmd/climc/shell/compute/snapshotpolicy_disk.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ require (
k8s.io/client-go v0.19.3
k8s.io/cluster-bootstrap v0.19.3
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231214030208-02cfe93ac519
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231215084755-601e4d02e207
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231214030208-02cfe93ac519 h1:0LEcNL0GkI2h/Qy2st4Dc6I9nY1MgrHSD0e7Irc/8ik=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231214030208-02cfe93ac519/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231215084755-601e4d02e207 h1:p2R9I3/DNwTJrD/RDQlF9a8xWYo4nXOs+B6KLZXqNSc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231215084755-601e4d02e207/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/compute/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,7 @@ type DiskResetInput struct {
SnapshotId string `json:"snapshot_id"`
AutoStart bool `json:"auto_start"`
}

type DiskSnapshotpolicyInput struct {
SnapshotpolicyId string `json:"snapshotpolicy_id"`
}
5 changes: 3 additions & 2 deletions pkg/apis/compute/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,13 @@ type ServiceCatalogListInput struct {

type SnapshotPolicyListInput struct {
apis.VirtualResourceListInput
apis.ExternalizedResourceBaseListInput
ManagedResourceListInput
RegionalFilterListInput

// 按绑定的磁盘数量排序
// pattern:asc|desc
OrderByBindDiskCount string `json:"order_by_bind_disk_count"`
// 是否启用?
IsActivated *bool `json:"is_activated"`
}

type HostnameInput struct {
Expand Down
26 changes: 3 additions & 23 deletions pkg/apis/compute/snapshot_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package compute

import "yunion.io/x/cloudmux/pkg/apis/compute"
import (
"yunion.io/x/cloudmux/pkg/apis/compute"
)

const (
// create by
Expand All @@ -29,35 +31,13 @@ const (
SNAPSHOT_DELETING = compute.SNAPSHOT_DELETING
SNAPSHOT_UNKNOWN = compute.SNAPSHOT_UNKNOWN

SNAPSHOT_POLICY_CREATING = compute.SNAPSHOT_POLICY_CREATING

SNAPSHOT_POLICY_READY = compute.SNAPSHOT_POLICY_READY
SNAPSHOT_POLICY_UPDATING = "updating"
SNAPSHOT_POLICY_UNKNOWN = compute.SNAPSHOT_POLICY_UNKNOWN
SNAPSHOT_POLICY_DELETING = "deleting"
SNAPSHOT_POLICY_DELETE_FAILED = "delete_failed"

SNAPSHOT_POLICY_APPLY = "applying"
SNAPSHOT_POLICY_APPLY_FAILED = "apply_failed"
SNAPSHOT_POLICY_CANCEL = "canceling"
SNAPSHOT_POLICY_CANCEL_FAILED = "cancel_failed"

SNAPSHOT_POLICY_DISK_INIT = "init"
SNAPSHOT_POLICY_DISK_READY = "ready"
SNAPSHOT_POLICY_DISK_DELETING = "deleting"
SNAPSHOT_POLICY_DISK_DELETE_FAILED = "delete_failed"

INSTANCE_SNAPSHOT_READY = compute.INSTANCE_SNAPSHOT_READY
INSTANCE_SNAPSHOT_UNKNOWN = "unknown"
INSTANCE_SNAPSHOT_FAILED = "instance_snapshot_create_failed"
INSTANCE_SNAPSHOT_START_DELETE = "instance_snapshot_start_delete"
INSTANCE_SNAPSHOT_DELETE_FAILED = "instance_snapshot_delete_failed"
INSTANCE_SNAPSHOT_RESET = "instance_snapshot_reset"

SNAPSHOT_POLICY_CACHE_STATUS_READY = "ready"
SNAPSHOT_POLICY_CACHE_STATUS_DELETING = "deleting"
SNAPSHOT_POLICY_CACHE_STATUS_DELETE_FAILED = "delete_failed"

SNAPSHOT_EXIST = "exist"
SNAPSHOT_NOT_EXIST = "not_exist"
)
Loading

0 comments on commit d478a8a

Please sign in to comment.