yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/shell/snapshot.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  	"fmt"
    19  
    20  	"yunion.io/x/cloudmux/pkg/multicloud/azure"
    21  	"yunion.io/x/onecloud/pkg/util/shellutils"
    22  )
    23  
    24  func init() {
    25  	type SnapshotListOptions struct {
    26  	}
    27  	shellutils.R(&SnapshotListOptions{}, "snapshot-list", "List snapshot", func(cli *azure.SRegion, args *SnapshotListOptions) error {
    28  		snapshots, err := cli.ListSnapshots()
    29  		if err != nil {
    30  			return err
    31  		}
    32  		printList(snapshots, len(snapshots), 0, 0, []string{})
    33  		return nil
    34  	})
    35  
    36  	type SnapshotCreateOptions struct {
    37  		DISK string `help:"SourceID"`
    38  		NAME string `help:"Snapshot name"`
    39  		Desc string `help:"Snapshot description"`
    40  	}
    41  
    42  	shellutils.R(&SnapshotCreateOptions{}, "snapshot-create", "Create snapshot", func(cli *azure.SRegion, args *SnapshotCreateOptions) error {
    43  		snapshot, err := cli.CreateSnapshot(args.DISK, args.NAME, args.Desc)
    44  		if err != nil {
    45  			return err
    46  		}
    47  		printObject(snapshot)
    48  		return nil
    49  	})
    50  
    51  	type SnapshotOptions struct {
    52  		ID string `help:"Snapshot ID"`
    53  	}
    54  
    55  	shellutils.R(&SnapshotOptions{}, "snapshot-delete", "Delete snapshot", func(cli *azure.SRegion, args *SnapshotOptions) error {
    56  		return cli.DeleteSnapshot(args.ID)
    57  	})
    58  
    59  	shellutils.R(&SnapshotOptions{}, "snapshot-show", "List snapshot", func(cli *azure.SRegion, args *SnapshotOptions) error {
    60  		snapshot, err := cli.GetSnapshot(args.ID)
    61  		if err != nil {
    62  			return err
    63  		}
    64  		printObject(snapshot)
    65  		return nil
    66  	})
    67  
    68  	shellutils.R(&SnapshotOptions{}, "snapshot-grant-access", "Grant access for snapshot", func(cli *azure.SRegion, args *SnapshotOptions) error {
    69  		if uri, err := cli.GrantAccessSnapshot(args.ID); err != nil {
    70  			return err
    71  		} else {
    72  			fmt.Printf("download link %s", uri)
    73  			return nil
    74  		}
    75  	})
    76  
    77  }