yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/apsara/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/apsara"
    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 *apsara.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  			printList(snapshotPolicis, num, args.Offset, args.Limit, []string{})
    37  			return nil
    38  		},
    39  	)
    40  
    41  	type SSnapshotPolicyDeleteOptions struct {
    42  		ID string `help:"snapshot id"`
    43  	}
    44  	shellutils.R(&SSnapshotPolicyDeleteOptions{}, "snapshot-policy-delete", "delete snapshot policy",
    45  		func(cli *apsara.SRegion, args *SSnapshotPolicyDeleteOptions) error {
    46  			err := cli.DeleteSnapshotPolicy(args.ID)
    47  			return err
    48  		},
    49  	)
    50  
    51  	type SSnapshotPolicyCreateOptions struct {
    52  		Name string `help:"snapshot name"`
    53  
    54  		RetentionDays  int   `help:"retention days"`
    55  		RepeatWeekdays []int `help:"auto snapshot which days of the week"`
    56  		TimePoints     []int `help:"auto snapshot which hours of the day"`
    57  	}
    58  	shellutils.R(&SSnapshotPolicyCreateOptions{}, "snapshot-policy-create", "create snapshot policy",
    59  		func(cli *apsara.SRegion, args *SSnapshotPolicyCreateOptions) error {
    60  			input := cloudprovider.SnapshotPolicyInput{
    61  				RetentionDays:  args.RetentionDays,
    62  				RepeatWeekdays: args.RepeatWeekdays,
    63  				TimePoints:     args.TimePoints,
    64  				PolicyName:     args.Name,
    65  			}
    66  			_, err := cli.CreateSnapshotPolicy(&input)
    67  			if err != nil {
    68  				return err
    69  			}
    70  			return nil
    71  		},
    72  	)
    73  
    74  	type SSnapshotPolicyApplyOptions struct {
    75  		SNAPSHOTPOLICYID string `help:"snapshot policy id"`
    76  		DISKID           string `help:"disk id"`
    77  	}
    78  	shellutils.R(&SSnapshotPolicyApplyOptions{}, "snapshot-policy-apply", "apply snapshot policy",
    79  		func(cli *apsara.SRegion, args *SSnapshotPolicyApplyOptions) error {
    80  			err := cli.ApplySnapshotPolicyToDisks(args.SNAPSHOTPOLICYID, args.DISKID)
    81  			return err
    82  		},
    83  	)
    84  
    85  	type SSnapshotPolicyCancelOptions struct {
    86  		SNAPSHOTPOLICYID string `help:"snapshot policy id"`
    87  		DISKID           string `help:"disk id"`
    88  	}
    89  	shellutils.R(&SSnapshotPolicyCancelOptions{}, "snapshot-policy-cancel", "cancel snapshot policy",
    90  		func(cli *apsara.SRegion, args *SSnapshotPolicyCancelOptions) error {
    91  			err := cli.CancelSnapshotPolicyToDisks(args.SNAPSHOTPOLICYID, args.DISKID)
    92  			return err
    93  		},
    94  	)
    95  }