yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/shell/snapshot_policy.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package shell
    16  
    17  import (
    18  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    19  	"yunion.io/x/cloudmux/pkg/multicloud/qcloud"
    20  	"yunion.io/x/onecloud/pkg/util/shellutils"
    21  )
    22  
    23  func init() {
    24  	type SSnapshotPolicyListOptions struct {
    25  		PolicyId string `help:"snapshot policy id"`
    26  		Offset   int    `help:"offset"`
    27  		Limit    int    `help:"limit"`
    28  	}
    29  
    30  	shellutils.R(&SSnapshotPolicyListOptions{}, "snapshot-policy-list", "list snapshot policy",
    31  		func(cli *qcloud.SRegion, args *SSnapshotPolicyListOptions) error {
    32  			snapshotPolicis, num, err := cli.GetSnapshotPolicies(args.PolicyId, args.Offset, args.Limit)
    33  			if err != nil {
    34  				return err
    35  			}
    36  
    37  			printList(snapshotPolicis, num, args.Offset, args.Limit, []string{})
    38  			return nil
    39  		},
    40  	)
    41  
    42  	type SSnapshotPolicyDeleteOptions struct {
    43  		ID string `help:"snapshot id"`
    44  	}
    45  	shellutils.R(&SSnapshotPolicyDeleteOptions{}, "snapshot-policy-delete", "delete snapshot policy",
    46  		func(cli *qcloud.SRegion, args *SSnapshotPolicyDeleteOptions) error {
    47  			err := cli.DeleteSnapshotPolicy(args.ID)
    48  			return err
    49  		},
    50  	)
    51  
    52  	type SSnapshotPolicyCreateOptions struct {
    53  		Name string `help:"snapshot name"`
    54  
    55  		RetentionDays  int   `help:"retention days"`
    56  		RepeatWeekdays []int `help:"auto snapshot which days of the week"`
    57  		TimePoints     []int `help:"auto snapshot which hours of the day"`
    58  	}
    59  	shellutils.R(&SSnapshotPolicyCreateOptions{}, "snapshot-policy-create", "create snapshot policy",
    60  		func(cli *qcloud.SRegion, args *SSnapshotPolicyCreateOptions) error {
    61  			input := cloudprovider.SnapshotPolicyInput{
    62  				RetentionDays:  args.RetentionDays,
    63  				RepeatWeekdays: args.RepeatWeekdays,
    64  				TimePoints:     args.TimePoints,
    65  				PolicyName:     args.Name,
    66  			}
    67  			_, err := cli.CreateSnapshotPolicy(&input)
    68  			if err != nil {
    69  				return err
    70  			}
    71  			return nil
    72  		},
    73  	)
    74  
    75  	type SSnapshotPolicyApplyOptions struct {
    76  		SNAPSHOTPOLICYID string `help:"snapshot policy id"`
    77  		DISKID           string `help:"disk id"`
    78  	}
    79  	shellutils.R(&SSnapshotPolicyApplyOptions{}, "snapshot-policy-apply", "apply snapshot policy",
    80  		func(cli *qcloud.SRegion, args *SSnapshotPolicyApplyOptions) error {
    81  			err := cli.ApplySnapshotPolicyToDisks(args.SNAPSHOTPOLICYID, args.DISKID)
    82  			return err
    83  		},
    84  	)
    85  
    86  	type SSnapshotPolicyCancelOptions struct {
    87  		SNAPSHOTPOLICYID string `help:"snapshot policy id"`
    88  		DISKID           string `help:"disk id"`
    89  	}
    90  	shellutils.R(&SSnapshotPolicyCancelOptions{}, "snapshot-policy-cancel", "cancel snapshot policy",
    91  		func(cli *qcloud.SRegion, args *SSnapshotPolicyCancelOptions) error {
    92  			err := cli.CancelSnapshotPolicyToDisks(args.SNAPSHOTPOLICYID, args.DISKID)
    93  			return err
    94  		},
    95  	)
    96  }