metadata.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package metadata
  2. import (
  3. "github.com/packethost/packngo"
  4. )
  5. const (
  6. metadataBasePath = "/metadata"
  7. )
  8. type Metadata struct {
  9. ApiUrl string `json:"api_url"`
  10. Id string `json:"id"`
  11. Hostname string `json:"hostname"`
  12. Iqn string `json:"iqn"`
  13. OperatingSystem OperatingSystem `json:"operating_system"`
  14. Plan string `json:"plan"`
  15. Facility string `json:"facility"`
  16. SshKeys []string `json:"ssh_keys"`
  17. Network Network `json:"network"`
  18. }
  19. type Network struct {
  20. Addresses []Address `json:"addresses"`
  21. Interfaces []Interface `json:"interfaces"`
  22. }
  23. type Address struct {
  24. Href string `json:"href"`
  25. Gateway string `json:"gateway"`
  26. Address string `json:"address"`
  27. Network string `json:"network"`
  28. Id string `json:"id"`
  29. AddressFamily int `json:"address_family"`
  30. Netmask string `json:"netmask"`
  31. Public bool `json:"public"`
  32. Cidr int `json:"cidr"`
  33. Management bool `json:"management"`
  34. Manageable bool `json:"manageable"`
  35. AssignedTo Reference `json:"assigned_to"`
  36. }
  37. type Reference struct {
  38. Href string `json:"href"`
  39. }
  40. type OperatingSystem struct {
  41. Version string `json:"version"`
  42. Distro string `json:"distro"`
  43. Slug string `json:"slug"`
  44. }
  45. type Interface struct {
  46. Mac string `json:"mac"`
  47. Name string `json:"name"`
  48. }
  49. type MetadataServiceOp struct {
  50. client *packngo.Client
  51. }
  52. func (s *MetadataServiceOp) Get() (Metadata, error) {
  53. metadata := Metadata{}
  54. req, err := s.client.NewRequest("GET", metadataBasePath, nil)
  55. if err != nil {
  56. return metadata, err
  57. }
  58. _, err = s.client.Do(req, &metadata)
  59. return metadata, err
  60. }