yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/huawei/shell/dbinstance.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/huawei"
    19  	"yunion.io/x/onecloud/pkg/util/shellutils"
    20  )
    21  
    22  func init() {
    23  	type DBInstanceListOptions struct {
    24  	}
    25  	shellutils.R(&DBInstanceListOptions{}, "dbinstance-list", "List dbinstances", func(cli *huawei.SRegion, args *DBInstanceListOptions) error {
    26  		dbinstances, err := cli.GetDBInstances()
    27  		if err != nil {
    28  			return err
    29  		}
    30  		printList(dbinstances, 0, 0, 0, nil)
    31  		return nil
    32  	})
    33  
    34  	type DBInstanceIdOptions struct {
    35  		ID string `help:"DBInstance ID"`
    36  	}
    37  
    38  	shellutils.R(&DBInstanceIdOptions{}, "dbinstance-open-public-connection", "Open dbinstance public connection", func(cli *huawei.SRegion, args *DBInstanceIdOptions) error {
    39  		return cli.PublicConnectionAction(args.ID, "openRC")
    40  	})
    41  
    42  	shellutils.R(&DBInstanceIdOptions{}, "dbinstance-close-public-connection", "Close dbinstance public connection", func(cli *huawei.SRegion, args *DBInstanceIdOptions) error {
    43  		return cli.PublicConnectionAction(args.ID, "closeRC")
    44  	})
    45  
    46  	shellutils.R(&DBInstanceIdOptions{}, "dbinstance-show", "Show dbinstance", func(cli *huawei.SRegion, args *DBInstanceIdOptions) error {
    47  		dbinstance, err := cli.GetDBInstance(args.ID)
    48  		if err != nil {
    49  			return err
    50  		}
    51  		printObject(dbinstance)
    52  		return nil
    53  	})
    54  
    55  	shellutils.R(&DBInstanceIdOptions{}, "dbinstance-parameter-list", "Show dbinstance parameters", func(cli *huawei.SRegion, args *DBInstanceIdOptions) error {
    56  		parameters, err := cli.GetDBInstanceParameters(args.ID)
    57  		if err != nil {
    58  			return err
    59  		}
    60  		printList(parameters, 0, 0, 0, nil)
    61  		return nil
    62  	})
    63  
    64  	shellutils.R(&DBInstanceIdOptions{}, "dbinstance-backup-list", "Show dbinstance backups", func(cli *huawei.SRegion, args *DBInstanceIdOptions) error {
    65  		backups, err := cli.GetDBInstanceBackups(args.ID, "")
    66  		if err != nil {
    67  			return err
    68  		}
    69  		printList(backups, 0, 0, 0, nil)
    70  		return nil
    71  	})
    72  
    73  	type DBInstanceFlavorListOption struct {
    74  		ENGINE  string `help:"DBInstance engine" choices:"MySQL|SQLServer|PostgreSQL"`
    75  		VERSION string `help:"DBInstance engine version" choices:"5.6|5.7|9.5|9.6|10.0|2014 SE|2014 EE|2016 SE|2016 EE|2008 R2 EE|2008 R2 WEB|2014 WEB|2016 WEB"`
    76  	}
    77  
    78  	shellutils.R(&DBInstanceFlavorListOption{}, "dbinstance-flavor-list", "Show dbinstance backups", func(cli *huawei.SRegion, args *DBInstanceFlavorListOption) error {
    79  		flavors, err := cli.GetDBInstanceFlavors(args.ENGINE, args.VERSION)
    80  		if err != nil {
    81  			return err
    82  		}
    83  		printList(flavors, 0, 0, 0, nil)
    84  		return nil
    85  	})
    86  
    87  	type DBInstanceChangeConfigOptions struct {
    88  		INSTANCE     string
    89  		InstanceType string
    90  		DiskSizeGB   int
    91  	}
    92  
    93  	shellutils.R(&DBInstanceChangeConfigOptions{}, "dbinstance-change-config", "Change dbinstance config", func(cli *huawei.SRegion, args *DBInstanceChangeConfigOptions) error {
    94  		return cli.ChangeDBInstanceConfig(args.INSTANCE, args.InstanceType, args.DiskSizeGB)
    95  	})
    96  
    97  }