Пример #1
0
func populateGroupMembers(c *ln.Context, groups groupMap) {
	_ = c.ForEachGuest(func(guest *ln.Guest) error {
		group, ok := groups[guest.FWGroupID]
		if !ok {
			// not a FWGroup referenced by any guest's FWGroup
			return nil
		}

		ips := group.ips
		ips = append(ips, guest.IP.String())
		group.ips = ips
		groups[guest.FWGroupID] = group
		return nil
	})
}
Пример #2
0
func getHV(hn string, e *etcd.Client, c *ln.Context) *ln.Hypervisor {
	var err error
	hn, err = ln.SetHypervisorID(hn)
	if err != nil {
		log.WithFields(log.Fields{
			"error": err,
			"func":  "lochness.SetHypervisorID",
		}).Fatal("failed")
	}

	log.WithField("hypervisor_id", hn).Info("using id")

	hv, err := c.Hypervisor(hn)
	if err != nil {
		log.WithFields(log.Fields{
			"error": err,
			"func":  "context.Hypervisor",
		}).Fatal("failed to fetch hypervisor info")
	}
	return hv
}
Пример #3
0
func getGuestsFWGroups(c *ln.Context, hv *ln.Hypervisor) (groupMap, guestMap) {
	guests := guestMap{}
	groups := groupMap{}
	n := len(groups)

	_ = hv.ForEachGuest(func(guest *ln.Guest) error {
		// check if in cache
		g, ok := groups[guest.FWGroupID]
		if ok {
			// link the guest to the FWGroup, via the FWGroup's index
			guests[guest.IP.String()] = g.num
			return nil
		}

		// nope not cached
		fw, err := c.FWGroup(guest.FWGroupID)
		if err != nil {
			log.WithFields(log.Fields{
				"error": err,
				"func":  "context.FWGroup",
				"group": guest.FWGroupID,
			}).Error("failed to get firewall group")
			return err
		}

		g = groupVal{
			num:   n,
			id:    fw.ID,
			rules: genNFRules(groups, fw.Rules),
		}
		n++
		groups[guest.FWGroupID] = g

		// link the guest to the FWGroup, via the FWGroup's index
		guests[guest.IP.String()] = g.num
		return nil
	})
	return groups, guests
}