yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/openstack/shell/flavor.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  	"fmt"
    19  
    20  	"yunion.io/x/cloudmux/pkg/multicloud/openstack"
    21  	"yunion.io/x/onecloud/pkg/util/shellutils"
    22  )
    23  
    24  func init() {
    25  	type FlavorkListOptions struct {
    26  	}
    27  	shellutils.R(&FlavorkListOptions{}, "flavor-list", "List flavors", func(cli *openstack.SRegion, args *FlavorkListOptions) error {
    28  		flavors, err := cli.GetFlavors()
    29  		if err != nil {
    30  			return err
    31  		}
    32  		printList(flavors, 0, 0, 0, []string{})
    33  		return nil
    34  	})
    35  
    36  	type FlavorOptions struct {
    37  		ID string `help:"ID of flavor"`
    38  	}
    39  
    40  	shellutils.R(&FlavorOptions{}, "flavor-show", "Show flavor", func(cli *openstack.SRegion, args *FlavorOptions) error {
    41  		flavor, err := cli.GetFlavor(args.ID)
    42  		if err != nil {
    43  			return err
    44  		}
    45  		printObject(flavor)
    46  		return nil
    47  	})
    48  
    49  	shellutils.R(&FlavorOptions{}, "flavor-delete", "Delete flavor", func(cli *openstack.SRegion, args *FlavorOptions) error {
    50  		return cli.DeleteFlavor(args.ID)
    51  	})
    52  
    53  	type FlavorCreateOptions struct {
    54  		NAME      string `help:"Name of flavor"`
    55  		CPU       int    `help:"Core num of cpu"`
    56  		MEMORY_MB int    `help:"Memory of flavor"`
    57  		DISK      int    `help:"Disk size of flavor"`
    58  	}
    59  
    60  	shellutils.R(&FlavorCreateOptions{}, "flavor-create", "Create flavor", func(cli *openstack.SRegion, args *FlavorCreateOptions) error {
    61  		flavor, err := cli.CreateFlavor(args.NAME, args.CPU, args.MEMORY_MB, args.DISK)
    62  		if err != nil {
    63  			return err
    64  		}
    65  		printObject(flavor)
    66  		return nil
    67  	})
    68  
    69  	shellutils.R(&FlavorCreateOptions{}, "flavor-sync", "Sync flavor", func(cli *openstack.SRegion, args *FlavorCreateOptions) error {
    70  		flavorId, err := cli.SyncFlavor(args.NAME, args.CPU, args.MEMORY_MB, args.DISK)
    71  		if err != nil {
    72  			return err
    73  		}
    74  		fmt.Println(flavorId)
    75  		return nil
    76  	})
    77  
    78  }