data_center.go 802 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package topology
  2. type DataCenter struct {
  3. NodeImpl
  4. }
  5. func NewDataCenter(id string) *DataCenter {
  6. dc := &DataCenter{}
  7. dc.id = NodeId(id)
  8. dc.nodeType = "DataCenter"
  9. dc.children = make(map[NodeId]Node)
  10. dc.NodeImpl.value = dc
  11. return dc
  12. }
  13. func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack {
  14. for _, c := range dc.Children() {
  15. rack := c.(*Rack)
  16. if string(rack.Id()) == rackName {
  17. return rack
  18. }
  19. }
  20. rack := NewRack(rackName)
  21. dc.LinkChildNode(rack)
  22. return rack
  23. }
  24. func (dc *DataCenter) ToMap() interface{} {
  25. m := make(map[string]interface{})
  26. m["Id"] = dc.Id()
  27. m["Max"] = dc.GetMaxVolumeCount()
  28. m["Free"] = dc.FreeSpace()
  29. var racks []interface{}
  30. for _, c := range dc.Children() {
  31. rack := c.(*Rack)
  32. racks = append(racks, rack.ToMap())
  33. }
  34. m["Racks"] = racks
  35. return m
  36. }