Пример #1
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
}
Пример #2
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
}
Пример #3
0
// Virtual Machhine  Get.  Caller must initialize the VirtualMachine ID (vm.ID)
func (vm *VirtualMachine) Get(c *nuage.Connection) error {

	if vm.ID == "" {
		err := fmt.Errorf("VirtualMachine Get: Empty VirtualMachine ID, nothing to do")
		return err
	}

	reply, err := nuage.GetEntity(c, "vms/"+vm.ID)

	if err != nil {
		log.Debugf("VirtualMachine Get. Unable to find VirtualMachine with ID: [%s] . Error: %s ", vm.ID, err)
		return err
	}

	var vma [1]VirtualMachine

	err = json.Unmarshal(reply, &vma)
	if err != nil {
		log.Debugf("VirtualMachine Get: Unable to decode JSON payload: %s ", err)
		return err
	}

	// XXX - Mutate the receiver
	*vm = vma[0]
	log.Debugf("VirtualMachine Get: Found VirtualMachine with Name: [%s] and ID: [%s]", vm.Name, vm.ID)
	return nil

}
Пример #4
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
}
Пример #5
0
// GET by ID (zt.ID)
func (zt *Zonetemplate) Get(c *nuage.Connection) error {
	if zt.ID == "" {
		err := fmt.Errorf("Zone template Get: Empty ID, nothing to do")
		return err
	}

	reply, err := nuage.GetEntity(c, "zonetemplates/"+zt.ID)

	if err != nil {
		log.Debugf("Zone template Get: Unable to get zone template with ID: [%s]. Error: %s ", zt.ID, err)
		return err
	}

	var zta [1]Zonetemplate
	err = json.Unmarshal(reply, &zta)
	if err != nil {
		log.Debugf("Zone template Get: Unable to decode JSON payload: %s ", err)
		return err
	}

	// XXX - Mutate the receiver
	*zt = zta[0]
	log.Debugf("Zone template Get: Found Zone template with Name: [%s] and ID: [%s]", zt.Name, zt.ID)
	return nil
}
Пример #6
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

}
Пример #7
0
// VPort Get.  Caller must initialize the VPort ID (vp.ID)
func (vp *VPort) Get(c *nuage.Connection) error {

	if vp.ID == "" {
		err := fmt.Errorf("VPort Get: Empty VPort ID, nothing to do")
		return err
	}

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

	if err != nil {
		log.Debugf("VPort Get: Error %s ", err)
		return err
	}

	var vpa [1]VPort

	err = json.Unmarshal(reply, &vpa)
	if err != nil {
		log.Debugf("VPort Get: Unable to decode JSON payload: %s ", err)
		return err
	}

	// XXX - Mutate the receiver
	*vp = vpa[0]
	log.Debugf("VPort Get: Found VPort with Name: [%s] and ID: [%s]", vp.Name, vp.ID)
	return nil

}
Пример #8
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

}
Пример #9
0
// GET enterprise by ID (org.ID)
func (org *Enterprise) Get(c *nuage.Connection) error {
	if org.ID == "" {
		err := fmt.Errorf("Enterprise Get: Empty ID, nothing to do")
		return err
	}

	reply, err := nuage.GetEntity(c, "enterprises/"+org.ID)

	if err != nil {
		log.Debugf("Enterprise Get: Unable to find Enterprise with ID: [%s] . Error: %s ", org.ID, err)
		return err
	}

	var orga [1]Enterprise
	err = json.Unmarshal(reply, &orga)

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

	// XXX - Mutate the receiver
	*org = orga[0]

	log.Debugf("Enterprise Get: Found Enterprise with Name: [%s] and ID: [%s]", org.Name, org.ID)
	return nil

}
Пример #10
0
// GET by ID (dt.ID)
func (dt *Domaintemplate) Get(c *nuage.Connection) error {
	if dt.ID == "" {
		err := fmt.Errorf("Domain template Get: Empty ID, nothing to do")
		return err
	}

	reply, err := nuage.GetEntity(c, "domaintemplates/"+dt.ID)

	if err != nil {
		log.Debugf("Domain template Get: Unable to get domain template with ID: [%s] . Error: %s ", dt.ID, err)
		return err
	}

	var dta [1]Domaintemplate
	err = json.Unmarshal(reply, &dta)
	if err != nil {
		log.Debugf("Domain template Get: Unable to decode JSON payload: %s ", err)
		return err
	}

	// XXX - Mutate the receiver
	*dt = dta[0]
	log.Debugf("Domain template Get: Found Domain template with Name: [%s] and ID: [%s]", dt.Name, dt.ID)
	return nil
}
Пример #11
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
}
Пример #12
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
}
Пример #13
0
// Get by Subnet ID (s.ID)
func (s *Subnet) Get(c *nuage.Connection) error {
	if s.ID == "" {
		err := fmt.Errorf("Subnet Get: Empty ID, nothing to do")
		return err
	}
	reply, err := nuage.GetEntity(c, "subnets/"+s.ID)

	if err != nil {
		log.Debugf("Subnet Get: Unable to get subnet with ID: [%s]. Error: %s ", s.ID, err)
		return err
	}

	var subneta [1]Subnet
	err = json.Unmarshal(reply, &subneta)
	if err != nil {
		log.Debugf("Subnet Get: Unable to decode JSON payload: %s ", err)
		return err
	}

	// XXX - Mutate the receiver
	*s = subneta[0]
	log.Debugf("Subnet Get: Found Subnet with Name: [%s] and ID: [%s]", s.Name, s.ID)
	return nil
}