configuration.go 811 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. }