metadata.go 1.8 KB

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