yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/jdcloud/shell/rds.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/jdcloud"
    19  	"yunion.io/x/onecloud/pkg/util/shellutils"
    20  )
    21  
    22  func init() {
    23  	type DBInstanceListOptions struct {
    24  		PageNumber int `default:"1"`
    25  		PageSize   int `default:"100"`
    26  	}
    27  
    28  	shellutils.R(&DBInstanceListOptions{}, "dbinstance-list", "List rds", func(cli *jdcloud.SRegion, args *DBInstanceListOptions) error {
    29  		dbs, _, err := cli.GetDBInstances(args.PageNumber, args.PageSize)
    30  		if err != nil {
    31  			return err
    32  		}
    33  		printList(dbs, 0, 0, 0, nil)
    34  		return nil
    35  	})
    36  
    37  	type DBInstanceIdOptions struct {
    38  		ID string
    39  	}
    40  
    41  	shellutils.R(&DBInstanceIdOptions{}, "dbinstance-show", "Show rds", func(cli *jdcloud.SRegion, args *DBInstanceIdOptions) error {
    42  		rds, err := cli.GetDBInstance(args.ID)
    43  		if err != nil {
    44  			return err
    45  		}
    46  		printObject(rds)
    47  		return nil
    48  	})
    49  
    50  	shellutils.R(&DBInstanceIdOptions{}, "dbinstance-delete", "Delete rds", func(cli *jdcloud.SRegion, args *DBInstanceIdOptions) error {
    51  		return cli.DeleteDBInstance(args.ID)
    52  	})
    53  
    54  	type DBInstanceAccountListOptions struct {
    55  		PageNumber int `default:"1"`
    56  		PageSize   int `default:"100"`
    57  		ID         string
    58  	}
    59  
    60  	shellutils.R(&DBInstanceAccountListOptions{}, "dbinstance-account-list", "List rds account", func(cli *jdcloud.SRegion, args *DBInstanceAccountListOptions) error {
    61  		accounts, _, err := cli.GetDBInstanceAccounts(args.ID, args.PageNumber, args.PageSize)
    62  		if err != nil {
    63  			return err
    64  		}
    65  		printList(accounts, 0, 0, 0, nil)
    66  		return nil
    67  	})
    68  
    69  	type DBInstanceDatabaseListOptions struct {
    70  		PageNumber int `default:"1"`
    71  		PageSize   int `default:"100"`
    72  		ID         string
    73  	}
    74  
    75  	shellutils.R(&DBInstanceDatabaseListOptions{}, "dbinstance-database-list", "List rds database", func(cli *jdcloud.SRegion, args *DBInstanceDatabaseListOptions) error {
    76  		databases, _, err := cli.GetDBInstanceDatabases(args.ID, args.PageNumber, args.PageSize)
    77  		if err != nil {
    78  			return err
    79  		}
    80  		printList(databases, 0, 0, 0, nil)
    81  		return nil
    82  	})
    83  
    84  	type DBInstanceBackupListOptions struct {
    85  		PageNumber int `default:"1"`
    86  		PageSize   int `default:"100"`
    87  		ID         string
    88  	}
    89  
    90  	shellutils.R(&DBInstanceBackupListOptions{}, "dbinstance-backup-list", "List rds backup", func(cli *jdcloud.SRegion, args *DBInstanceBackupListOptions) error {
    91  		backups, _, err := cli.GetDBInstanceBackups(args.ID, args.PageNumber, args.PageSize)
    92  		if err != nil {
    93  			return err
    94  		}
    95  		printList(backups, 0, 0, 0, nil)
    96  		return nil
    97  	})
    98  
    99  }