hardware.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright Joyent, Inc.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. package main
  7. //lint:file-ignore U1000 WIP
  8. import (
  9. // "bytes"
  10. // "errors"
  11. "fmt"
  12. "net/url"
  13. // "sort"
  14. // "strconv"
  15. // "strings"
  16. "time"
  17. "github.com/gofrs/uuid"
  18. // "github.com/jawher/mow.cli"
  19. // "github.com/olekukonko/tablewriter"
  20. )
  21. type Hardware struct {
  22. *Conch
  23. }
  24. func (c *Conch) Hardware() *Hardware {
  25. return &Hardware{c}
  26. }
  27. type HardwareProductProfile struct {
  28. ID uuid.UUID `json:"id"`
  29. BiosFirmware string `json:"bios_firmware"`
  30. CpuNum int `json:"cpu_num"`
  31. CpuType string `json:"cpu_type"`
  32. DimmsNum int `json:"dimms_num"`
  33. HbaFirmware string `json:"hba_firmware,omitempty"`
  34. NicsNum int `json:"nics_num"`
  35. Purpose string `json:"purpose"`
  36. RamTotal int `json:"ram_total"`
  37. SasHddSlots string `json:"sas_hdd_slots,omitempty"`
  38. SataHddSlots string `json:"sata_hdd_slots,omitempty"`
  39. SataSsdSlots string `json:"sata_ssd_slots,omitempty"`
  40. SasSsdSlots string `json:"sas_ssd_slots,omitempty"`
  41. NvmeSsdSlots string `json:"nvme_ssd_slots,omitempty"`
  42. UsbNum int `json:"usb_num"`
  43. // NOTE the pointers. 0 is a valid value so zero values aren't
  44. PsuTotal *int `json:"psu_total,omitempty"`
  45. RaidLunNum *int `json:"raid_lun_num,omitempty"`
  46. SasHddNum *int `json:"sas_hdd_num,omitempty"`
  47. SasHddSize *int `json:"sas_hdd_size,omitempty"`
  48. SataHddNum *int `json:"sata_hdd_num,omitempty"`
  49. SataHddSize *int `json:"sata_hdd_size,omitempty"`
  50. SataSsdNum *int `json:"sata_ssd_num,omitempty"`
  51. SataSsdSize *int `json:"sata_ssd_size,omitempty"`
  52. SasSsdNum *int `json:"sas_ssd_num,omitempty"`
  53. SasSsdSize *int `json:"sas_ssd_size,omitempty"`
  54. NvmeSsdNum *int `json:"nvme_ssd_num,omitempty"`
  55. NvmeSsdSize *int `json:"nvme_ssd_size,omitempty"`
  56. }
  57. type HardwareProducts []HardwareProduct
  58. type HardwareProduct struct {
  59. ID uuid.UUID `json:"id"`
  60. Name string `json:"name"`
  61. Alias string `json:"alias"`
  62. Prefix string `json:"prefix,omitempty"`
  63. HardwareVendorID uuid.UUID `json:"hardware_vendor_id"`
  64. GenerationName string `json:"generate_name,omitempty"`
  65. LegacyProductName string `json:"legacy_product_name,omitempty"`
  66. SKU string `json:"sku,omitempty"`
  67. Specification string `json:"specification,omitempty"`
  68. RackUnitSize int `json:"rack_unit_size"`
  69. HardwareProductProfile HardwareProductProfile `json:"hardware_product_profile,omitempty"`
  70. Created time.Time `json:"created"`
  71. Updated time.Time `json:"updated"`
  72. }
  73. func (h *Hardware) GetProduct(id uuid.UUID) (hp HardwareProduct) {
  74. uri := fmt.Sprintf("/hardware_product/%s", url.PathEscape(id.String()))
  75. res := h.Do(h.Sling().New().Get(uri))
  76. if ok := res.Parse(&hp); !ok {
  77. panic(res)
  78. }
  79. return hp
  80. }
  81. // There are three string identifiers currently accepted by the API: name,
  82. // alias, sku. The calls all look exactly the same where we stick the string in
  83. // the url and hope for the best.
  84. func (h *Hardware) GetProductByString(wat string) (hp HardwareProduct) {
  85. uri := fmt.Sprintf("/hardware_product/%s", url.PathEscape(wat))
  86. res := h.Do(h.Sling().New().Get(uri))
  87. if ok := res.Parse(&hp); !ok {
  88. panic(res)
  89. }
  90. return hp
  91. }
  92. func (h *Hardware) GetProductByName(name string) HardwareProduct {
  93. return h.GetProductByString(name)
  94. }
  95. func (h *Hardware) GetProductByAlias(alias string) HardwareProduct {
  96. return h.GetProductByString(alias)
  97. }
  98. func (h *Hardware) GetProductBySku(sku string) HardwareProduct {
  99. return h.GetProductByString(sku)
  100. }