isolated_devices.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 cloudpods
  15. import (
  16. api "yunion.io/x/onecloud/pkg/apis/compute"
  17. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  18. )
  19. type SIsolatedDevice struct {
  20. api.IsolateDeviceDetails
  21. }
  22. func (d *SIsolatedDevice) GetName() string {
  23. return d.Name
  24. }
  25. func (d *SIsolatedDevice) GetGlobalId() string {
  26. return d.Id
  27. }
  28. func (d *SIsolatedDevice) GetModel() string {
  29. return d.Model
  30. }
  31. func (d *SIsolatedDevice) GetAddr() string {
  32. return d.Addr
  33. }
  34. func (d *SIsolatedDevice) GetDevType() string {
  35. return d.DevType
  36. }
  37. func (d *SIsolatedDevice) GetNumaNode() int8 {
  38. return int8(d.NumaNode)
  39. }
  40. func (d *SIsolatedDevice) GetVendorDeviceId() string {
  41. return d.VendorDeviceId
  42. }
  43. func (d *SIsolatedDevice) GetSharedProjectIds() ([]string, error) {
  44. ret := []string{}
  45. for _, p := range d.SharedProjects {
  46. ret = append(ret, p.Id)
  47. }
  48. return ret, nil
  49. }
  50. func (region *SRegion) GetIsolatedDevices(hostId string, serverId string) ([]SIsolatedDevice, error) {
  51. params := map[string]interface{}{
  52. "show_baremetal_isolated_devices": true,
  53. }
  54. if len(hostId) > 0 {
  55. params["host_id"] = hostId
  56. }
  57. if len(serverId) > 0 {
  58. params["guest_id"] = serverId
  59. }
  60. ret := []SIsolatedDevice{}
  61. err := region.list(&modules.IsolatedDevices, params, &ret)
  62. if err != nil {
  63. return nil, err
  64. }
  65. return ret, nil
  66. }
  67. func (region *SRegion) GetIsolatedDevice(id string) (*SIsolatedDevice, error) {
  68. ret := &SIsolatedDevice{}
  69. err := region.cli.get(&modules.IsolatedDevices, id, nil, ret)
  70. if err != nil {
  71. return nil, err
  72. }
  73. return ret, nil
  74. }