本文整理匯總了Golang中github.com/FlorianOtel/gonuageshell/Godeps/_workspace/src/github.com/Sirupsen/logrus.Debugf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Debugf函數的具體用法?Golang Debugf怎麽用?Golang Debugf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Debugf函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: List
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: DeleteEntity
// Delete Entity. Up to the caller to provide a correct ID for the given API entity -- e.g. "enterprises"
func DeleteEntity(c *Connection, entity string, id string) ([]byte, error) {
reply, statuscode, err := nuagetransaction(c, "DELETE", c.Url+"/nuage/api/"+c.Apivers+"/"+entity+"/"+id, []byte(""))
Reeval:
if err != nil {
log.Debugf("Nuage DELETE: Unable to delete: %s with ID: %s", entity, id)
return nil, err
}
log.Debugf("Nuage DELETE: Assessing HTTP status code: %d", statuscode)
switch statuscode {
case 300: // Used for Enterprise delete, must confirm deletion
// XXX -- This works when "entity" is "enterprises"
// XXX -- Check if there are other delete methods (i.e. "entity") for which the HTTP status code is "300"
reply, statuscode, err = nuagetransaction(c, "DELETE", c.Url+"/nuage/api/"+c.Apivers+"/"+entity+"/"+id+"/?responseChoice=1", []byte(""))
// The reply from this should be a "204" with No content. Need to check again.
goto Reeval
case 204: // Deleted
return reply, nil
default:
log.Debugf("Nuage DELETE: Unable to delete: %s with ID: %s. HTTP status code: %d", entity, id, statuscode)
err = fmt.Errorf("HTTP status code: %d", statuscode)
return nil, err
}
return reply, err
}
示例3: Get
// 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
}
示例4: AddVPort
// 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
}
示例5: VPortsList
// 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
}
示例6: VMInterfacesList
// 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: GetEntity
func GetEntity(c *Connection, endpoint string) ([]byte, error) {
// if len(args) < 1 || len(args) > 3 {
// // log.Debugf("Nuage generic GET: len(args): %d", len(args))
// log.Debugf("Nuage GET entity: Malformed requst, invalid entity: %s", strings.Join(args, "/"))
// err := fmt.Errorf("Nuage GET entity: Malformed requst, invalid entity: %s", strings.Join(args, "/"))
// return nil, err
// }
reply, statuscode, err := nuagetransaction(c, "GET", c.Url+"/nuage/api/"+c.Apivers+"/"+endpoint, []byte(""))
if err != nil {
log.Debugf("Nuage GET entity: Error: %s", err)
return nil, err
}
if statuscode != 200 {
log.Debugf("Nuage GET entity: HTTP status code: %d", statuscode)
err = fmt.Errorf("HTTP status code: %d", statuscode)
return nil, err
}
return reply, nil
}
示例8: Create
// Assumes the method receiver was allocated using "new(Subnet)"
// Caller must populate:
// - Name (s.Name)
// - Parent Zone ID (s.ParentID)
// - Subnet Tempate ID (s.TemplateID)
// - Address (s.Address) -- e.g. "10.24.24.0"
// - Netmask (s.Netmask) -- e.g. "255.255.255.0"
// - Optionally: Subnet Template ID (s.TemplateID)
func (s *Subnet) Create(c *nuage.Connection) error {
if s == nil {
err := fmt.Errorf("Subnet Create: Empty method receiver, nothing to do")
return err
}
if s.Name == "" {
err := fmt.Errorf("Subnet Create: Empty Name, nothing to do")
return err
}
if s.ParentID == "" {
err := fmt.Errorf("Subnet Create: Empty ParentID, nothing to do")
return err
}
if s.TemplateID == "" && (s.Address == "" || s.Netmask == "") {
err := fmt.Errorf("Subnet Create: Need either Subnet Template ID or Subnet Address & Netmask. Nothing to do")
return err
}
// XXX - Do not insist on it being present
// if s.TemplateID == "" {
// err := fmt.Errorf("Subnet Create: Empty subnet template ID, nothing to do")
// return err
// }
// It has to be an array since the reply from the server is as an array of JSON objects, and we use it for decoding as well
var subneta [1]Subnet
// XXX - This copies the supplied Name, ParentID and TemplateID
subneta[0] = *s
jsonsubnet, _ := json.MarshalIndent(subneta[0], "", "\t")
reply, err := nuage.CreateEntity(c, "zones/"+s.ParentID+"/subnets", jsonsubnet)
if err != nil {
log.Debugf("Subnet Create: Unable to create Subnet with name: [%s] . Error: %s ", s.Name, err)
return err
}
err = json.Unmarshal(reply, &subneta)
if err != nil {
log.Debugf("Subnet Create: Unable to decode JSON payload: %s ", err)
return err
}
// XXX - Mutate the receiver
*s = subneta[0]
log.Debugf("Subnet Create: Created Subnet with ID: [%s]", s.ID)
return nil
}
示例9: CreateEntity
// Create Entity. Up to the caller to encode it as a valid "payload []byte" and select an appropriate API entity -- e.g. "enterprises"
func CreateEntity(c *Connection, entity string, payload []byte) ([]byte, error) {
reply, statuscode, err := nuagetransaction(c, "POST", c.Url+"/nuage/api/"+c.Apivers+"/"+entity, payload)
if err != nil {
log.Debugf("Nuage CREATE entity: Unable to create entity. Error: %s", err)
return nil, err
}
if statuscode != 201 {
log.Debugf("Nuage CREATE entity: Unable to create entity. HTTP status code: %d", statuscode)
err = fmt.Errorf("HTTP status code: %d", statuscode)
return nil, err
}
return reply, nil
}
示例10: Delete
// VMInterface Delete. Caller must initialize the VMInterface ID (vmi.ID)
func (vmi *VMInterface) Delete(c *nuage.Connection) error {
if vmi.ID == "" {
err := fmt.Errorf("VMInterface Delete: Empty VMInterface ID, nothing to do")
return err
}
_, err := nuage.DeleteEntity(c, "vminterfaces", vmi.ID)
if err != nil {
log.Debugf("VMInterface Delete: Unable to delete VMInterface with ID: [%s] . Error: %s ", vmi.ID, err)
return err
}
log.Debugf("VMInterface Delete: Deleted VMInterface with ID: [%s]", vmi.ID)
return nil
}
示例11: nuagetransaction
// Basic Nuage API transaction. Returns the response body (empty), HTTP response code and any errors. Up to the caller to check HTTP error codes. Unexported.
func nuagetransaction(c *Connection, method string, url string, jsonpayload []byte) ([]byte, int, error) {
if c.token == nil {
log.Debugf("Invalid connection: %s", c)
return []byte(""), -1, errors.New("Invalid Nuage API connection")
}
// Still TBD: Additional sanity checks for the connection e.g. is token still valid ?
req, err := http.NewRequest(method, url, nil)
req.Header.Set("X-Nuage-Organization", c.token.EnterpriseName)
req.Header.Set("Authorization", "XREST "+base64.URLEncoding.EncodeToString([]byte(c.token.UserName+":"+c.token.Apikey)))
req.Header.Set("Content-Type", "application/json")
// "POST" methods require a valid payload.
if method == "POST" && len(jsonpayload) != 0 {
// If we are passed a payload, encode that
req.Body = ioutil.NopCloser(bytes.NewBuffer(jsonpayload))
// log.Debugf("Request payload: %s", string(jsonpayload))
defer req.Body.Close()
}
// Skip TLS security check
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
log.Debugf("Nuage API connection: %s to/from: %s with payload: %s", method, url, string(jsonpayload))
resp, err := client.Do(req)
if err != nil {
return []byte(""), -1, err
}
log.Debugf("Response Status: %s", resp.Status)
log.Debugf("Response Headers: %s", resp.Header)
body, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
log.Debugf("Response Body: %s", string(body))
return body, resp.StatusCode, nil
}