yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/shell/disk.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/multicloud/google"
    19  	"yunion.io/x/onecloud/pkg/util/shellutils"
    20  )
    21  
    22  func init() {
    23  	type DiskListOptions struct {
    24  		ZONE        string
    25  		StorageType string
    26  		MaxResults  int
    27  		PageToken   string
    28  	}
    29  	shellutils.R(&DiskListOptions{}, "disk-list", "List disks", func(cli *google.SRegion, args *DiskListOptions) error {
    30  		disks, err := cli.GetDisks(args.ZONE, args.StorageType, args.MaxResults, args.PageToken)
    31  		if err != nil {
    32  			return err
    33  		}
    34  		printList(disks, 0, 0, 0, nil)
    35  		return nil
    36  	})
    37  
    38  	type DiskIdOptions struct {
    39  		ID string
    40  	}
    41  	shellutils.R(&DiskIdOptions{}, "disk-show", "Show disk", func(cli *google.SRegion, args *DiskIdOptions) error {
    42  		disk, err := cli.GetDisk(args.ID)
    43  		if err != nil {
    44  			return err
    45  		}
    46  		printObject(disk)
    47  		return nil
    48  	})
    49  
    50  	shellutils.R(&DiskIdOptions{}, "disk-delete", "Delete disk", func(cli *google.SRegion, args *DiskIdOptions) error {
    51  		return cli.Delete(args.ID)
    52  	})
    53  
    54  	type DiskCreateOptions struct {
    55  		NAME         string
    56  		Desc         string
    57  		ZONE         string
    58  		SIZE_GB      int
    59  		Image        string
    60  		STORAGE_TYPE string `choices:"pd-standard|pd-ssd"`
    61  	}
    62  
    63  	shellutils.R(&DiskCreateOptions{}, "disk-create", "Create disks", func(cli *google.SRegion, args *DiskCreateOptions) error {
    64  		disk, err := cli.CreateDisk(args.NAME, args.SIZE_GB, args.ZONE, args.STORAGE_TYPE, args.Image, args.Desc)
    65  		if err != nil {
    66  			return err
    67  		}
    68  		printObject(disk)
    69  		return nil
    70  	})
    71  
    72  	type DiskResizeOptions struct {
    73  		ID      string
    74  		SIZE_GB int
    75  	}
    76  
    77  	shellutils.R(&DiskResizeOptions{}, "disk-resize", "Resize disk", func(cli *google.SRegion, args *DiskResizeOptions) error {
    78  		return cli.ResizeDisk(args.ID, args.SIZE_GB)
    79  	})
    80  
    81  	type RegionDiskListOptions struct {
    82  		StorageType string
    83  		MaxResults  int
    84  		PageToken   string
    85  	}
    86  	shellutils.R(&RegionDiskListOptions{}, "region-disk-list", "List region disks", func(cli *google.SRegion, args *RegionDiskListOptions) error {
    87  		disks, err := cli.GetRegionDisks(args.StorageType, args.MaxResults, args.PageToken)
    88  		if err != nil {
    89  			return err
    90  		}
    91  		printList(disks, 0, 0, 0, nil)
    92  		return nil
    93  	})
    94  
    95  	type RegionDiskShowOptions struct {
    96  		ID string
    97  	}
    98  	shellutils.R(&RegionDiskShowOptions{}, "region-disk-show", "Show region disk", func(cli *google.SRegion, args *RegionDiskShowOptions) error {
    99  		disk, err := cli.GetRegionDisk(args.ID)
   100  		if err != nil {
   101  			return err
   102  		}
   103  		printObject(disk)
   104  		return nil
   105  	})
   106  
   107  }