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.

41 lines
794 B

13 years ago
13 years ago
  1. package topology
  2. import ()
  3. type DataCenter struct {
  4. NodeImpl
  5. }
  6. func NewDataCenter(id string) *DataCenter {
  7. dc := &DataCenter{}
  8. dc.id = NodeId(id)
  9. dc.nodeType = "DataCenter"
  10. dc.children = make(map[NodeId]Node)
  11. dc.NodeImpl.value = dc
  12. return dc
  13. }
  14. func (dc *DataCenter) GetOrCreateRack(rackName string) *Rack {
  15. for _, c := range dc.Children() {
  16. rack := c.(*Rack)
  17. if string(rack.Id()) == rackName {
  18. return rack
  19. }
  20. }
  21. rack := NewRack(rackName)
  22. dc.LinkChildNode(rack)
  23. return rack
  24. }
  25. func (dc *DataCenter) ToMap() interface{} {
  26. m := make(map[string]interface{})
  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. }