yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aliyun/shell/mongodb.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  	"time"
    19  
    20  	"yunion.io/x/pkg/errors"
    21  
    22  	"yunion.io/x/cloudmux/pkg/multicloud/aliyun"
    23  	"yunion.io/x/onecloud/pkg/util/shellutils"
    24  )
    25  
    26  func init() {
    27  	type MongoDBListOptions struct {
    28  		MongoType string `choices:"sharding|replicate|serverless"`
    29  		Offset    int
    30  		Limit     int
    31  	}
    32  	shellutils.R(&MongoDBListOptions{}, "mongodb-list", "List mongodb", func(cli *aliyun.SRegion, args *MongoDBListOptions) error {
    33  		dbs, _, err := cli.GetMongoDBs(args.MongoType, args.Limit, args.Offset)
    34  		if err != nil {
    35  			return err
    36  		}
    37  		printList(dbs, 0, 0, 0, []string{})
    38  		return nil
    39  	})
    40  
    41  	type MongoDBIdOptions struct {
    42  		ID string
    43  	}
    44  
    45  	shellutils.R(&MongoDBIdOptions{}, "mongodb-show", "Show mongodb", func(cli *aliyun.SRegion, args *MongoDBIdOptions) error {
    46  		db, err := cli.GetMongoDB(args.ID)
    47  		if err != nil {
    48  			return errors.Wrapf(err, "GetMongoDB(%s)", args.ID)
    49  		}
    50  		printObject(db)
    51  		return nil
    52  
    53  	})
    54  
    55  	shellutils.R(&MongoDBIdOptions{}, "mongodb-delete", "Delete mongodb", func(cli *aliyun.SRegion, args *MongoDBIdOptions) error {
    56  		return cli.DeleteMongoDB(args.ID)
    57  	})
    58  
    59  	type MongoDBBackupListOptions struct {
    60  		ID         string
    61  		START      time.Time
    62  		END        time.Time
    63  		PageSize   int
    64  		PageNumber int
    65  	}
    66  
    67  	shellutils.R(&MongoDBBackupListOptions{}, "mongodb-backup-list", "List mongodb backups", func(cli *aliyun.SRegion, args *MongoDBBackupListOptions) error {
    68  		backups, _, err := cli.GetMongoDBBackups(args.ID, args.START, args.END, args.PageSize, args.PageNumber)
    69  		if err != nil {
    70  			return err
    71  		}
    72  		printList(backups, 0, 0, 0, nil)
    73  		return nil
    74  	})
    75  
    76  	type MongoDBSkuListOptions struct {
    77  	}
    78  
    79  	shellutils.R(&MongoDBSkuListOptions{}, "mongodb-sku-list", "List mongodb skus", func(cli *aliyun.SRegion, args *MongoDBSkuListOptions) error {
    80  		skus, err := cli.GetchMongoSkus()
    81  		if err != nil {
    82  			return err
    83  		}
    84  		printObject(skus)
    85  		return nil
    86  	})
    87  
    88  }