Beispiel #1
0
func ReadHostInterfaces(host_id int) (*map[string]addie.Interface, error) {

	q := fmt.Sprintf(
		"SELECT name, packet_conductor_id FROM interfaces WHERE host_id = %d", host_id)

	rows, err := runQ(q)
	defer safeClose(rows)
	if err != nil {
		return nil, selectFailure(err)
	}
	result := make(map[string]addie.Interface)
	for rows.Next() {
		var name string
		var pkt_key int
		err = rows.Scan(&name, &pkt_key)
		if err != nil {
			return nil, scanFailure(err)
		}

		pkt, err := ReadPacketConductor(pkt_key)
		if err != nil {
			return nil, readFailure(err)
		}

		ifx := addie.Interface{}
		ifx.Name = name
		ifx.PacketConductor = *pkt

		result[name] = ifx

	}

	return &result, nil
}
Beispiel #2
0
func ReadInterface(id int) (*addie.Interface, error) {

	q := fmt.Sprintf(
		"SELECT name, host_id, packet_conductor_id FROM interfaces WHERE id = %d", id)

	rows, err := runQ(q)
	defer safeClose(rows)
	if err != nil {
		return nil, selectFailure(err)
	}
	if !rows.Next() {
		return nil, emptyReadFailure()
	}
	var name string
	var host_key, pkt_key int
	err = rows.Scan(&name, &host_key, &pkt_key)
	if err != nil {
		return nil, scanFailure(err)
	}

	pkt, err := ReadPacketConductor(pkt_key)
	if err != nil {
		return nil, readFailure(err)
	}

	ifx := addie.Interface{}
	ifx.Name = name
	ifx.PacketConductor = *pkt

	return &ifx, nil

}