lxd/db/networks.go
func (c *Cluster) NetworkGet(name string) (int64, *api.Network, error) {
	description := sql.NullString{}
	id := int64(-1)
	state := 0

	q := "SELECT id, description, state FROM networks WHERE name=?"
	arg1 := []interface{}{name}
	arg2 := []interface{}{&id, &description, &state}
	err := dbQueryRowScan(c.db, q, arg1, arg2)
	if err != nil {
		if err == sql.ErrNoRows {
			return -1, nil, ErrNoSuchObject
		}

		return -1, nil, err
	}

	config, err := c.NetworkConfigGet(id)
	if err != nil {
		return -1, nil, err
	}

	network := api.Network{
		Name:    name,
		Managed: true,
		Type:    "bridge",
	}
	network.Description = description.String
	network.Config = config

	switch state {
	case networkPending:
		network.Status = "Pending"
	case networkCreated:
		network.Status = "Created"
	default:
		network.Status = "Unknown"
	}

	nodes, err := c.networkNodes(id)
	if err != nil {
		return -1, nil, err
	}
	network.Locations = nodes

	return id, &network, nil
}
func (c *Cluster) NetworkGet(name string) (int64, *api.Network, error) {
	description := sql.NullString{}
	id := int64(-1)
	state := 0

	q := "SELECT id, description, state FROM networks WHERE name=?"
	arg1 := []interface{}{name}
	arg2 := []interface{}{&id, &description, &state}
	err := dbQueryRowScan(c.db, q, arg1, arg2)
	if err != nil {
		if err == sql.ErrNoRows {
			return -1, nil, ErrNoSuchObject
		}

		return -1, nil, err
	}

	config, err := c.NetworkConfigGet(id)
	if err != nil {
		return -1, nil, err
	}

	network := api.Network{
		Name:    name,
		Managed: true,
		Type:    "bridge",
	}
	network.Description = description.String
	network.Config = config

	switch state {
	case networkPending:
		network.Status = "Pending"
	case networkCreated:
		network.Status = "Created"
	default:
		network.Status = "Unknown"
	}

	nodes, err := c.networkNodes(id)
	if err != nil {
		return -1, nil, err
	}
	network.Locations = nodes

	return id, &network, nil
}
func ( c * Cluster ) NetworkGet ( name string ) ( int64 , * api . Network , error ) { description := sql . NullString { } id := int64 ( - 1 ) state := 0 q := " " arg1 := [ ] interface { } { name } arg2 := [ ] interface { } { & id , & description , & state } err := dbQueryRowScan ( c . db , q , arg1 , arg2 ) if err != nil { if err == sql . ErrNoRows { return - 1 , nil , ErrNoSuchObject } return - 1 , nil , err } config , err := c . NetworkConfigGet ( id ) if err != nil { return - 1 , nil , err } network := api . Network { Name : name , Managed : true , Type : " " , } network . Description = description . String network . Config = config switch state { case networkPending : network . Status = " " case networkCreated : network . Status = " " default : network . Status = " " } nodes , err := c . networkNodes ( id ) if err != nil { return - 1 , nil , err } network . Locations = nodes return id , & network , nil }
// NetworkGet returns the network with the given name.
NetworkGet returns the network with the given name .