yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/esxi/shell/host.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/esxi" 19 "yunion.io/x/onecloud/pkg/util/shellutils" 20 ) 21 22 func init() { 23 type HostListOptions struct { 24 DATACENTER string `help:"List hosts in datacenter"` 25 } 26 shellutils.R(&HostListOptions{}, "host-list", "List hosts in datacenter", func(cli *esxi.SESXiClient, args *HostListOptions) error { 27 dc, err := cli.FindDatacenterByMoId(args.DATACENTER) 28 if err != nil { 29 return err 30 } 31 hosts, err := dc.GetIHosts() 32 if err != nil { 33 return err 34 } 35 printList(hosts, nil) 36 return nil 37 }) 38 39 type HostShowOptions struct { 40 IP string `help:"Host IP"` 41 42 Debug bool `help:"show debug info"` 43 } 44 shellutils.R(&HostShowOptions{}, "host-show", "Show details of a host by IP", func(cli *esxi.SESXiClient, args *HostShowOptions) error { 45 host, err := cli.FindHostByIp(args.IP) 46 if err != nil { 47 return err 48 } 49 printObject(host) 50 return nil 51 }) 52 53 shellutils.R(&HostShowOptions{}, "host-storages", "Show all storages of a given host", func(cli *esxi.SESXiClient, args *HostShowOptions) error { 54 host, err := cli.FindHostByIp(args.IP) 55 if err != nil { 56 return err 57 } 58 storages, err := host.GetIStorages() 59 if err != nil { 60 return err 61 } 62 printList(storages, nil) 63 return nil 64 }) 65 66 shellutils.R(&HostShowOptions{}, "host-nics", "Show all nics of a given host", func(cli *esxi.SESXiClient, args *HostShowOptions) error { 67 host, err := cli.FindHostByIp(args.IP) 68 if err != nil { 69 return err 70 } 71 nics, err := host.GetIHostNicsInternal(args.Debug) 72 if err != nil { 73 return err 74 } 75 printList(nics, nil) 76 return nil 77 }) 78 79 shellutils.R(&HostShowOptions{}, "host-network", "Show all network of a given host", func(cli *esxi.SESXiClient, 80 args *HostShowOptions) error { 81 host, err := cli.FindHostByIp(args.IP) 82 if err != nil { 83 return err 84 } 85 networks, err := host.GetNetworks() 86 if err != nil { 87 return err 88 } 89 printList(networks, nil) 90 return nil 91 }) 92 93 shellutils.R(&HostShowOptions{}, "host-cluster", "Show host cluster", func(cli *esxi.SESXiClient, 94 args *HostShowOptions) error { 95 host, err := cli.FindHostByIp(args.IP) 96 if err != nil { 97 return err 98 } 99 cluster, err := host.GetCluster() 100 if err != nil { 101 return err 102 } 103 printObject(cluster) 104 return nil 105 }) 106 107 shellutils.R(&HostShowOptions{}, "host-pool-list", "List host pools", func(cli *esxi.SESXiClient, 108 args *HostShowOptions) error { 109 host, err := cli.FindHostByIp(args.IP) 110 if err != nil { 111 return err 112 } 113 pool, err := host.GetResourcePool() 114 if err != nil { 115 return err 116 } 117 printObject(pool) 118 return nil 119 }) 120 }