Commit b651c704 authored by Ryan Goodfellow's avatar Ryan Goodfellow
Browse files

support for costing out phased builds


Signed-off-by: Ryan Goodfellow's avatarRyan Goodfellow <rgoodfel@isi.edu>
parent fcdfcf20
Pipeline #167506300 passed with stage
in 31 seconds
package build
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"sort"
......@@ -64,18 +66,37 @@ func Run(net *xir.Net) {
save.Flags().BoolVarP(&stdout, "stdout", "s", false, "Write to stdout")
root.AddCommand(save)
var purchaseOrder string
cost := &cobra.Command{
Use: "cost",
Short: "Calculate testbed cost",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
if purchaseOrder != "" {
applyPO(net, purchaseOrder)
}
tb.CalculateCost(net).Print()
},
}
cost.Flags().StringVarP(
&purchaseOrder, "po", "p", "", "Apply previous purchase order")
root.AddCommand(cost)
po := &cobra.Command{
Use: "po",
Short: "Emit purchase order data",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
emitPO(net)
},
}
root.AddCommand(po)
lom := &cobra.Command{
Use: "lom",
Short: "Calculate testbed bill of materials",
......@@ -384,3 +405,106 @@ func power(net *xir.Net) {
tw.Flush()
}
type PO struct {
Nodes []POItem
Links []POItem
}
type POItem struct {
SKU string
TBID string
}
func emitPO(net *xir.Net) {
var po PO
for _, x := range net.AllNodes() {
r := tb.GetResourceSpec(x)
if r == nil {
continue
}
dev := r.System.Device
if dev.Cost == 0 {
continue
}
po.Nodes = append(po.Nodes, POItem{
SKU: dev.SKU,
TBID: x.Label(),
})
}
for _, x := range net.AllLinks() {
c := tb.GetCableSpec(x)
if c == nil || c.Cost == 0 {
continue
}
po.Links = append(po.Links, POItem{
SKU: c.SKU,
TBID: x.Id,
})
}
out, err := json.MarshalIndent(po, "", " ")
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(net.Label()+"_po.json", out, 0644)
if err != nil {
log.Fatal(err)
}
}
func applyPO(net *xir.Net, poFile string) {
in, err := ioutil.ReadFile(poFile)
if err != nil {
log.Fatal(err)
}
var po PO
err = json.Unmarshal(in, &po)
if err != nil {
log.Fatal(err)
}
for _, x := range po.Nodes {
_, _, n := net.GetNode(x.TBID)
if n == nil {
log.Printf("node not found: %s", x.TBID)
continue
}
//TODO gross ..... round trip from GetResourceSpec will not work
r := n.Props["resource"].(*tb.Resource)
r.System.Device.Cost = 0
}
for _, x := range po.Links {
_, _, l := net.GetLink(x.TBID)
if l == nil {
log.Printf("link not found: %s", x.TBID)
continue
}
//TODO gross .....
c := l.Props["cable"].(*hw.Cable)
c.Cost = 0
}
}
......@@ -30,6 +30,7 @@ func (d *Device) Node(id string) *xir.Node {
"manufacturer": d.Manufacturer,
"cpu": d.Procs,
"memory": d.Memory,
"cost": d.Cost,
//"nics": d.Nics,
},
}
......
......@@ -38,7 +38,7 @@ func OpenGearCM7132() *hw.Device {
d := &hw.Device{
Base: hw.Base{
Model: "CM7132",
Model: "CM7132 Console Server",
Manufacturer: "OpenGear",
SKU: "CM7132-2-DAC-US",
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment