Ejemplo n.º 1
0
/*
	Crates an array of VM info that can be inserted into the network graph for an entire
	project.
*/
func (p *osif_project) Get_all_info(creds *ostack.Ostack, inc_project bool) (ilist []*Net_vm, err error) {

	err = nil
	ilist = nil

	if p == nil || creds == nil {
		err = fmt.Errorf("creds were nil")
		osif_sheep.Baa(2, "lazy update: unable to get_all: nil creds")
		return
	}

	if time.Now().Unix()-p.lastfetch > 90 { // if not fresh force a reload first
		err = p.refresh_maps(creds)
		osif_sheep.Baa(2, "lazy update: data reload for: get_all")
		if err != nil {
			return
		}
	}

	found := 0
	ilist = make([]*Net_vm, len(p.ip2vmid))

	for k, _ := range p.ip2vmid {
		name := p.ip2vm[k]
		_, id, ip4, fip4, mac, gw, phost, gwmap, _, lerr := p.Get_info(&k, creds, true)
		if lerr == nil {
			if name == nil {
				n := "unknown"
				name = &n
			}
			ilist[found] = Mk_netreq_vm(name, id, ip4, nil, phost, mac, gw, fip4, gwmap)
			found++
		}
	}

	pname, _ := creds.Get_project()
	osif_sheep.Baa(1, "get all osvm info found %d VMs in %s", found, *pname)

	return
}