| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- // Copyright 2019 Yunion
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package shell
- import (
- "context"
- "fmt"
- "time"
- "yunion.io/x/jsonutils"
- "yunion.io/x/pkg/util/printutils"
- "yunion.io/x/pkg/util/shellutils"
- "yunion.io/x/pkg/util/timeutils"
- "yunion.io/x/onecloud/pkg/util/fileutils2"
- "yunion.io/x/onecloud/pkg/util/redfish"
- )
- func init() {
- type LanConfigGetOptions struct {
- }
- shellutils.R(&LanConfigGetOptions{}, "lan-get", "Get configuration of BMC lan", func(cli redfish.IRedfishDriver, args *LanConfigGetOptions) error {
- confs, err := cli.GetLanConfigs(context.Background())
- if err != nil {
- return err
- }
- printutils.PrintInterfaceList(confs, 0, 0, 0, nil)
- return nil
- })
- type VirtualMediaGetOptions struct {
- }
- shellutils.R(&VirtualMediaGetOptions{}, "cdrom-get", "Get details of manager virtual media", func(cli redfish.IRedfishDriver, args *VirtualMediaGetOptions) error {
- path, image, err := cli.GetVirtualCdromInfo(context.Background())
- if err != nil {
- return err
- }
- fmt.Println("Path:", path)
- fmt.Println("Image:", image.Image)
- fmt.Println("ApiSupport:", image.SupportAction)
- return nil
- })
- type VirtualMediaMountOptions struct {
- URL string `help:"cdrom http URL"`
- Boot bool `help:"set boot from virtualmedia on next boot"`
- }
- shellutils.R(&VirtualMediaMountOptions{}, "cdrom-insert", "Insert iso into virtual CD-ROM", func(cli redfish.IRedfishDriver, args *VirtualMediaMountOptions) error {
- ctx := context.Background()
- err := redfish.MountVirtualCdrom(ctx, cli, args.URL, args.Boot)
- if err != nil {
- return err
- }
- fmt.Println("Success!")
- return nil
- })
- type VirtualMediaUmountOptions struct {
- }
- shellutils.R(&VirtualMediaUmountOptions{}, "cdrom-eject", "Eject iso from virtual CD-ROM", func(cli redfish.IRedfishDriver, args *VirtualMediaUmountOptions) error {
- ctx := context.Background()
- err := redfish.UmountVirtualCdrom(ctx, cli)
- if err != nil {
- return err
- }
- fmt.Println("Success!")
- return nil
- })
- type ReadLogsOptions struct {
- Since string `help:"read logs after, format: YYYY-MM-DD"`
- }
- shellutils.R(&ReadLogsOptions{}, "system-logs", "Read system logs", func(cli redfish.IRedfishDriver, args *ReadLogsOptions) error {
- var sinceTm time.Time
- var err error
- if len(args.Since) > 0 {
- sinceTm, err = timeutils.ParseTimeStr(args.Since)
- if err != nil {
- return err
- }
- }
- events, err := cli.ReadSystemLogs(context.Background(), sinceTm)
- if err != nil {
- return err
- }
- printutils.PrintInterfaceList(events, 0, 0, 0, nil)
- return nil
- })
- shellutils.R(&ReadLogsOptions{}, "manager-logs", "Read manager logs", func(cli redfish.IRedfishDriver, args *ReadLogsOptions) error {
- var sinceTm time.Time
- var err error
- if len(args.Since) > 0 {
- sinceTm, err = timeutils.ParseTimeStr(args.Since)
- if err != nil {
- return err
- }
- }
- events, err := cli.ReadManagerLogs(context.Background(), sinceTm)
- if err != nil {
- return err
- }
- printutils.PrintInterfaceList(events, 0, 0, 0, nil)
- return nil
- })
- shellutils.R(&ReadLogsOptions{}, "system-logs-clear", "Clear system logs", func(cli redfish.IRedfishDriver, args *ReadLogsOptions) error {
- err := cli.ClearSystemLogs(context.Background())
- if err != nil {
- return err
- }
- return nil
- })
- shellutils.R(&ReadLogsOptions{}, "manager-logs-clear", "Clear manager logs", func(cli redfish.IRedfishDriver, args *ReadLogsOptions) error {
- err := cli.ClearManagerLogs(context.Background())
- if err != nil {
- return err
- }
- return nil
- })
- shellutils.R(&ReadLogsOptions{}, "bmc-reset", "reset bmc", func(cli redfish.IRedfishDriver, args *ReadLogsOptions) error {
- err := cli.BmcReset(context.Background())
- if err != nil {
- return err
- }
- fmt.Println("Success!")
- return nil
- })
- type NtpConfGetOptions struct {
- }
- shellutils.R(&NtpConfGetOptions{}, "ntp-get", "Get ntp configuration", func(cli redfish.IRedfishDriver, args *NtpConfGetOptions) error {
- conf, err := cli.GetNTPConf(context.Background())
- if err != nil {
- return err
- }
- fmt.Println(jsonutils.Marshal(conf).PrettyString())
- return nil
- })
- type NtpConfSetOptions struct {
- SERVER []string `help:"ntp servers"`
- TimeZone string `help:"time zone, e.g. Asia/Shanghai"`
- }
- shellutils.R(&NtpConfSetOptions{}, "ntp-set", "Set ntp configuration", func(cli redfish.IRedfishDriver, args *NtpConfSetOptions) error {
- ntpConf := redfish.SNTPConf{}
- ntpConf.ProtocolEnabled = true
- ntpConf.NTPServers = args.SERVER
- ntpConf.TimeZone = args.TimeZone
- err := cli.SetNTPConf(context.Background(), ntpConf)
- if err != nil {
- return err
- }
- fmt.Println("Success!")
- return nil
- })
- type JNLPGetOptions struct {
- Save string `help:"save to file"`
- }
- shellutils.R(&JNLPGetOptions{}, "jnlp-get", "Get Java Console JNLP file", func(cli redfish.IRedfishDriver, args *JNLPGetOptions) error {
- jnlp, err := cli.GetConsoleJNLP(context.Background())
- if err != nil {
- return err
- }
- if len(args.Save) > 0 {
- return fileutils2.FilePutContents(args.Save, jnlp, false)
- } else {
- fmt.Println(jnlp)
- return nil
- }
- })
- }
|