Пример #1
0
func (ds *Domainslice) List(c *nuage.Connection, parentid string) error {
	var reply []byte
	var err error

	if parentid == "" { // get global list of domains
		reply, err = nuage.GetEntity(c, "domains")
	} else {
		// get the list of domains for a given enterprise ID
		reply, err = nuage.GetEntity(c, "enterprises/"+parentid+"/domains")
	}

	if err != nil {
		log.Debugf("Domain List: Unable to obtain list: %s ", err)
		return err
	}

	if len(reply) == 0 {
		log.Debugf("Domain List: Empty list")
		return nil
	}

	err = json.Unmarshal(reply, ds)

	if err != nil {
		log.Debugf("Domain List: Unable to decode JSON payload: %s ", err)
		return err
	}
	log.Debug("Domain List: done")
	return nil
}
Пример #2
0
func (ss *Subnetslice) List(c *nuage.Connection, parentid string) error {
	var reply []byte
	var err error

	if parentid == "" { // get global list of subnets
		reply, err = nuage.GetEntity(c, "subnets")
	} else {
		// get the list of subnets for a given Zone ID
		reply, err = nuage.GetEntity(c, "zones/"+parentid+"/subnets")
	}

	if err != nil {
		log.Debugf("Subnet List: Unable to obtain list: %s ", err)
		return err
	}

	if len(reply) == 0 {
		log.Debugf("Subnet List: Empty list")
		return nil
	}

	err = json.Unmarshal(reply, ss)

	if err != nil {
		log.Debugf("Subnet List: Unable to decode JSON payload: %s ", err)
		return err
	}
	log.Debug("Subnet List: done")
	return nil
}
Пример #3
0
func (zts *Zonetemplateslice) List(c *nuage.Connection, parentid string) error {
	if parentid == "" {
		err := fmt.Errorf("Zone template List: Empty ParentID, nothing to do")
		return err
	}

	reply, err := nuage.GetEntity(c, "domaintemplates/"+parentid+"/zonetemplates")

	if err != nil {
		log.Debugf("Zone templates List: Unable to obtain list: %s ", err)
		return err
	}

	if len(reply) == 0 {
		log.Debugf("Zone templates List: Empty list")
		return nil
	}

	err = json.Unmarshal(reply, zts)

	if err != nil {
		log.Debugf("Zone template List: Unable to decode JSON payload: %s ", err)
		return err
	}
	log.Debug("Zone template List: done")
	return nil
}
Пример #4
0
// VPort list for a Subnet.  Caller must initialize the Subnet ID (s.ID)
func (s *Subnet) VPortsList(c *nuage.Connection) ([]VPort, error) {

	if s.ID == "" {
		err := fmt.Errorf("Subnet VPorts List: Empty Subnet ID, nothing to do")
		return nil, err
	}

	reply, err := nuage.GetEntity(c, "subnets/"+s.ID+"/vports")

	if err != nil {
		log.Debugf("Subnet VPorts List: Error %s ", err)
		return nil, err
	}

	if len(reply) == 0 {
		log.Debugf("Subnet VPorts List: Empty list")
		return nil, nil
	}

	var vports []VPort

	err = json.Unmarshal(reply, &vports)
	if err != nil {
		log.Debugf("Subnet VPorts List:  Unable to decode JSON payload: %s ", err)
		return nil, err
	}

	log.Debug("Subnet VPorts List: done")
	return vports, nil

}
Пример #5
0
// Add VPort to Subnet / Create VPort. Caller must initialize the Subnet ID (s.ID). Additionally, the virtual Port must have:
// - A Name (vp.Name)
// - A Type (vp.Type)
func (s *Subnet) AddVPort(c *nuage.Connection, vp VPort) (VPort, error) {
	var vpa [1]VPort

	// In the worst case we return what we received
	vpa[0] = vp
	if s.ID == "" {
		err := fmt.Errorf("Subnet Add VPort: Empty Subnet ID, nothing to do")
		return vpa[0], err
	}

	//XXX -- TBD: Better sanity checks
	if vp.Name == "" || vp.Type == "" || vp.AddressSpoofing == "" {
		err := fmt.Errorf("Subnet Add VPort: Invalid VPort initialization, nothing to do")
		return vpa[0], err
	}

	jsonvport, _ := json.MarshalIndent(vp, "", "\t")
	reply, err := nuage.CreateEntity(c, "subnets/"+s.ID+"/vports", jsonvport)

	if err != nil {
		log.Debugf("Subnet Add VPort: Error: %s ", err)
		return vpa[0], err
	}

	err = json.Unmarshal(reply, &vpa)
	if err != nil {
		log.Debugf("Subnet Add VPort:  Unable to decode JSON payload: %s ", err)
		return vpa[0], err
	}
	log.Debug("Subnet Add VPort: done")
	return vpa[0], nil

}
Пример #6
0
// VMInterfaces list for a Domain.  Caller must initialize the Domain ID (d.ID)
func (d *Domain) VMInterfacesList(c *nuage.Connection) ([]VMInterface, error) {

	if d.ID == "" {
		err := fmt.Errorf("Domain VMInterfaces List: Empty Domain ID, nothing to do")
		return nil, err
	}

	reply, err := nuage.GetEntity(c, "domains/"+d.ID+"/vminterfaces")

	if err != nil {
		log.Debugf("Domain VMInterfaces List: Error %s ", err)
		return nil, err
	}

	if len(reply) == 0 {
		log.Debugf("Domain VMInterfaces List: Empty list")
		return nil, nil
	}

	var vmis []VMInterface

	err = json.Unmarshal(reply, &vmis)
	if err != nil {
		log.Debugf("Domain VMInterfaces List:  Unable to decode JSON payload: %s ", err)
		return nil, err
	}

	log.Debug("Domain VMInterfaces List: done")
	return vmis, nil

}
Пример #7
0
// enterprises list
func (orglist *EnterpriseSlice) List(c *nuage.Connection) error {

	// XXX - Alternative
	// var orgs []Enterprise

	reply, err := nuage.GetEntity(c, "enterprises")
	if err != nil {
		log.Debugf("Enterprise List: Unable to obtain Enterprise list: %s ", err)
		return err
	}

	if len(reply) == 0 {
		log.Debugf("Enterprise List: Empty list")
		return nil
	}

	// XXX - Alternative
	// err = json.Unmarshal(reply, &orgs)
	err = json.Unmarshal(reply, orglist)

	if err != nil {
		log.Debugf("Enterprise List: Unable to decode JSON payload: %s ", err)
		return err
	}

	//// var orgs []Enterprise
	////
	//// orgs = *orglist
	////
	//// for i, v := range orgs {
	//// 	jsonorg, _ := json.MarshalIndent(v, "", "\t")
	//// 	fmt.Printf("\n\n ===> Org nr [%d]: [%s] <=== \n%#s\n", i, orgs[i].Name, string(jsonorg))
	//// }

	// XXX - Alternative: This effeticvely converts "EnterpriseSlice" to "[]Enterprise"
	// *orglist = orgs

	// log.Fatal("\n\n KABOOM ?? Yes Rico, KABOOM..\n\n")

	log.Debug("Enterprise List: done")
	return nil
}
Пример #8
0
// Global list (all VMInterfaces in the Data Center)
func (vmis *VMInterfaceslice) List(c *nuage.Connection) error {

	reply, err := nuage.GetEntity(c, "vminterfaces")

	if err != nil {
		log.Debugf("VMInterface List: Unable to obtain list: %s ", err)
		return err
	}

	if len(reply) == 0 {
		log.Debugf("VMInterface List: Empty list")
		return nil
	}

	err = json.Unmarshal(reply, vmis)

	if err != nil {
		log.Debugf("VMInterface List: Unable to decode JSON payload: %s ", err)
		return err
	}
	log.Debug("VMInterface List: done")
	return nil
}