host.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 openstack
  15. import (
  16. "time"
  17. "github.com/pkg/errors"
  18. )
  19. type SHost struct {
  20. HostName string
  21. Zone string
  22. Service string
  23. }
  24. type SAggregate struct {
  25. AvailabilityZone string
  26. CreatedAt time.Time
  27. Deleted bool
  28. Hosts []string
  29. Id string
  30. Metadata map[string]string
  31. Name string
  32. Uuid string
  33. }
  34. func (region *SRegion) GetAggregates() ([]SAggregate, error) {
  35. resp, err := region.ecsList("/os-aggregates", nil)
  36. if err != nil {
  37. return nil, errors.Wrap(err, "ecsList")
  38. }
  39. aggregates := []SAggregate{}
  40. err = resp.Unmarshal(&aggregates, "aggregates")
  41. if err != nil {
  42. return nil, errors.Wrap(err, `resp.Unmarshal(&aggregates, "aggregates")`)
  43. }
  44. return aggregates, nil
  45. }
  46. func (region *SRegion) GetHosts() ([]SHost, error) {
  47. hosts := []SHost{}
  48. resp, err := region.ecsList("/os-hosts", nil)
  49. if err != nil {
  50. return nil, errors.Wrap(err, "ecsList(os-hosts)")
  51. }
  52. err = resp.Unmarshal(&hosts, "hosts")
  53. if err != nil {
  54. return nil, errors.Wrap(err, "resp.Unmarshal")
  55. }
  56. return hosts, nil
  57. }