You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
811 B

  1. package topology
  2. import (
  3. "encoding/xml"
  4. )
  5. type loc struct {
  6. dcName string
  7. rackName string
  8. }
  9. type rack struct {
  10. Name string `xml:"name,attr"`
  11. Ips []string `xml:"Ip"`
  12. }
  13. type dataCenter struct {
  14. Name string `xml:"name,attr"`
  15. Racks []rack `xml:"Rack"`
  16. }
  17. type topology struct {
  18. DataCenters []dataCenter `xml:"DataCenter"`
  19. }
  20. type Configuration struct {
  21. XMLName xml.Name `xml:"Configuration"`
  22. Topo topology `xml:"Topology"`
  23. }
  24. func (c *Configuration) String() string {
  25. if b, e := xml.MarshalIndent(c, " ", " "); e == nil {
  26. return string(b)
  27. }
  28. return ""
  29. }
  30. func (c *Configuration) Locate(ip string, dcName string, rackName string) (dc string, rack string) {
  31. if dcName == "" {
  32. dcName = "DefaultDataCenter"
  33. }
  34. if rackName == "" {
  35. rackName = "DefaultRack"
  36. }
  37. return dcName, rackName
  38. }