yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/hcs/shell/redis.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/cloudprovider"
    19  	"yunion.io/x/cloudmux/pkg/multicloud/hcs"
    20  	"yunion.io/x/onecloud/pkg/util/shellutils"
    21  )
    22  
    23  func init() {
    24  	type ElasticcacheListOptions struct {
    25  	}
    26  	shellutils.R(&ElasticcacheListOptions{}, "redis-list", "List elasticcaches", func(cli *hcs.SRegion, args *ElasticcacheListOptions) error {
    27  		instances, e := cli.GetElasticCaches()
    28  		if e != nil {
    29  			return e
    30  		}
    31  		printList(instances, len(instances), 0, 0, []string{})
    32  		return nil
    33  	})
    34  
    35  	type ElasitccacheInstanceTypeListOptions struct {
    36  	}
    37  
    38  	shellutils.R(&ElasitccacheInstanceTypeListOptions{}, "redis-instance-type-list", "List elasticcache instancetypes", func(cli *hcs.SRegion, args *ElasitccacheInstanceTypeListOptions) error {
    39  		ret, e := cli.GetRedisInstnaceTypes()
    40  		if e != nil {
    41  			return e
    42  		}
    43  		printList(ret, 0, 0, 0, []string{})
    44  		return nil
    45  	})
    46  
    47  	shellutils.R(&cloudprovider.SCloudElasticCacheInput{}, "redis-create", "Create elasticcache", func(cli *hcs.SRegion, args *cloudprovider.SCloudElasticCacheInput) error {
    48  		instance, e := cli.CreateElasticcache(args)
    49  		if e != nil {
    50  			return e
    51  		}
    52  		printObject(instance)
    53  		return nil
    54  	})
    55  
    56  	type ElasticcacheIdOptions struct {
    57  		ID string `help:"ID of instances to show"`
    58  	}
    59  	shellutils.R(&ElasticcacheIdOptions{}, "redis-show", "Show elasticcache", func(cli *hcs.SRegion, args *ElasticcacheIdOptions) error {
    60  		instance, err := cli.GetElasticCache(args.ID)
    61  		if err != nil {
    62  			return err
    63  		}
    64  		printObject(instance)
    65  		return nil
    66  	})
    67  
    68  	shellutils.R(&ElasticcacheIdOptions{}, "redis-delete", "Delete elasticcache", func(cli *hcs.SRegion, args *ElasticcacheIdOptions) error {
    69  		return cli.DeleteElasticcache(args.ID)
    70  	})
    71  
    72  	type ElasticcacheBackupsListOptions struct {
    73  		ID        string `help:"ID of instances to show"`
    74  		StartTime string `help:"backup start time. format: 20060102150405"`
    75  		EndTime   string `help:"backup end time. format: 20060102150405 "`
    76  	}
    77  
    78  	shellutils.R(&ElasticcacheBackupsListOptions{}, "redis-backup-list", "List elasticcache backups", func(cli *hcs.SRegion, args *ElasticcacheBackupsListOptions) error {
    79  		backups, err := cli.GetElasticCacheBackups(args.ID, args.StartTime, args.EndTime)
    80  		if err != nil {
    81  			return err
    82  		}
    83  		printList(backups, 0, 0, 0, []string{})
    84  		return nil
    85  	})
    86  
    87  	shellutils.R(&ElasticcacheIdOptions{}, "redis-parameter-list", "List elasticcache parameters", func(cli *hcs.SRegion, args *ElasticcacheIdOptions) error {
    88  		parameters, err := cli.GetElasticCacheParameters(args.ID)
    89  		if err != nil {
    90  			return err
    91  		}
    92  		printList(parameters, 0, 0, 0, []string{})
    93  		return nil
    94  	})
    95  }