lan.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. package shell
  15. import (
  16. "yunion.io/x/pkg/util/printutils"
  17. "yunion.io/x/pkg/util/shellutils"
  18. "yunion.io/x/onecloud/pkg/baremetal/utils/ipmitool"
  19. )
  20. func init() {
  21. type LanOptions struct {
  22. CHANNEL uint8 `help:"lan channel"`
  23. }
  24. shellutils.R(&LanOptions{}, "set-lan-dhcp", "Set lan channel DHCP", func(client ipmitool.IPMIExecutor, args *LanOptions) error {
  25. return ipmitool.SetLanDHCP(client, args.CHANNEL)
  26. })
  27. shellutils.R(&LanOptions{}, "get-lan-config", "Get lan channel config", func(cli ipmitool.IPMIExecutor, args *LanOptions) error {
  28. config, err := ipmitool.GetLanConfig(cli, args.CHANNEL)
  29. if err != nil {
  30. return err
  31. }
  32. printutils.PrintInterfaceObject(config)
  33. return nil
  34. })
  35. type SetLanStaticIpOptions struct {
  36. LanOptions
  37. IP string
  38. MASK string
  39. GATEWAY string
  40. }
  41. shellutils.R(&SetLanStaticIpOptions{}, "set-lan-static", "Set lan static network", func(cli ipmitool.IPMIExecutor, args *SetLanStaticIpOptions) error {
  42. return ipmitool.SetLanStatic(cli, args.CHANNEL, args.IP, args.MASK, args.GATEWAY)
  43. })
  44. }