dynamic

package
v0.0.0-...-b27ac56 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Example
template := NewTemplate()

// Main
template.AddValue("cpu", 1)
template.AddValue("memory", "64")
template.AddValue("vcpu", "2")

// Disk
vector := template.NewVector("disk")
vector.AddValue("image_id", "119")
vector.AddValue("dev_prefix", "vd")

// NIC
vector = template.NewVector("nic")
vector.AddValue("network_id", "3")
vector.AddValue("model", "virtio")

fmt.Println(template)
Output:

CPU="1"
MEMORY="64"
VCPU="2"
DISK=[
    IMAGE_ID="119",
    DEV_PREFIX="vd" ]
NIC=[
    NETWORK_ID="3",
    MODEL="virtio" ]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element interface {
	String() string
	Key() string
}

Element is an interface that must implement the String function

type Pair

type Pair struct {
	XMLName xml.Name
	Value   string `xml:",innerxml"`
}

Pair is a key / value pair

func MakePair

func MakePair(key string, v interface{}) (*Pair, error)

func (*Pair) Key

func (t *Pair) Key() string

Key return the pair key

func (*Pair) String

func (p *Pair) String() string

String prints a Pair in OpenNebula syntax

type Template

type Template struct {
	Elements []Element
}

Template represents an OpenNebula syntax template

func NewTemplate

func NewTemplate() *Template

NewTemplate returns a new Template object

func (*Template) AddPair

func (t *Template) AddPair(key string, v interface{}) error

AddPair adds a new pair to a Template objects

func (*Template) AddPairToVec

func (t *Template) AddPairToVec(vecKey, key string, value interface{}) error

func (*Template) AddVector

func (t *Template) AddVector(key string) *Vector

AddVector creates a new vector in the template

func (*Template) Del

func (t *Template) Del(key string)

Del remove an element from Template objects

func (*Template) GetFloat

func (t *Template) GetFloat(key string) (float64, error)

GetFloat returns a pair value as an float

func (*Template) GetInt

func (t *Template) GetInt(key string) (int, error)

GetInt returns a pair value as an int

func (*Template) GetInts

func (t *Template) GetInts(key string) []int

GetInts allow to retrieve a slice of int from pairs with the same key

func (*Template) GetPair

func (t *Template) GetPair(key string) (*Pair, error)

GetPair retrieve a pair by key

func (*Template) GetPairs

func (t *Template) GetPairs(key string) []*Pair

GetPair retrieve a pair by it's key

func (*Template) GetStr

func (t *Template) GetStr(key string) (string, error)

GetStr allow to retrieve the value of a pair

func (*Template) GetStrFromVec

func (t *Template) GetStrFromVec(vecKey, key string) (string, error)

GetStrFromVec returns a pair value contained from a vector

func (*Template) GetStrs

func (t *Template) GetStrs(key string) []string

GetStrs allow to retrieve a slice of string from pairs with the same key

func (*Template) GetVector

func (t *Template) GetVector(key string) (*Vector, error)

GetVector retrieve a vector by key

func (*Template) GetVectors

func (t *Template) GetVectors(key string) []*Vector

GetVectors retrieve slice of vectors by key

func (*Template) String

func (t *Template) String() string

String prints the Template in OpenNebula syntax

func (*Template) UnmarshalXML

func (t *Template) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML parse dynamically a template under the TEMPLATE token

type TemplateAny

type TemplateAny struct {
	Template
}

type Vector

type Vector struct {
	XMLName xml.Name
	Pairs   []Pair
}

Vector contains an array of keyvalue pairs

func (*Vector) AddPair

func (t *Vector) AddPair(key string, v interface{}) error

AddPair adds a new pair to a Template

func (*Vector) Del

func (t *Vector) Del(key string)

Del remove a pair from Template

func (*Vector) GetFloat

func (t *Vector) GetFloat(key string) (float64, error)

GetFloat returns a pair value as an float

func (*Vector) GetInt

func (t *Vector) GetInt(key string) (int, error)

GetInt returns a pair value as an int

func (*Vector) GetInts

func (v *Vector) GetInts(key string) []int

GetInts allow to retrieve a slice of int from pairs with the same key

func (*Vector) GetPair

func (v *Vector) GetPair(key string) (*Pair, error)

GetPair retrieve a pair by it's key

func (*Vector) GetPairs

func (v *Vector) GetPairs(key string) []*Pair

GetPair retrieve a pair by it's key

func (*Vector) GetStr

func (t *Vector) GetStr(key string) (string, error)

GetStr allow to retrieve the value of a pair

func (*Vector) GetStrs

func (v *Vector) GetStrs(key string) []string

GetStrs allow to retrieve a slice of string from pairs with the same key

func (*Vector) Key

func (t *Vector) Key() string

Key return the vector key

func (*Vector) String

func (v *Vector) String() string

func (*Vector) UnmarshalXML

func (t *Vector) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML parse dynamically a vector. Either a single vector, or inside of a TEMPLATE.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL