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.

42 lines
813 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["Id"] = dc.Id()
  28. m["Max"] = dc.GetMaxVolumeCount()
  29. m["Free"] = dc.FreeSpace()
  30. var racks []interface{}
  31. for _, c := range dc.Children() {
  32. rack := c.(*Rack)
  33. racks = append(racks, rack.ToMap())
  34. }
  35. m["Racks"] = racks
  36. return m
  37. }