id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
146,100
apcera/libretto
virtualmachine/virtualbox/util.go
GetBridgedDeviceNameIPMap
func GetBridgedDeviceNameIPMap() (map[string]string, error) { m := map[string]string{} kvs, err := getBridgedDeviceKV("Name", "IPAddress") if err != nil { return m, err } for _, kv := range kvs { if kv.k != "" { m[kv.k] = kv.v } } return m, nil }
go
func GetBridgedDeviceNameIPMap() (map[string]string, error) { m := map[string]string{} kvs, err := getBridgedDeviceKV("Name", "IPAddress") if err != nil { return m, err } for _, kv := range kvs { if kv.k != "" { m[kv.k] = kv.v } } return m, nil }
[ "func", "GetBridgedDeviceNameIPMap", "(", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "m", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "kvs", ",", "err", ":=", "getBridgedDeviceKV", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "m", ",", "err", "\n", "}", "\n", "for", "_", ",", "kv", ":=", "range", "kvs", "{", "if", "kv", ".", "k", "!=", "\"", "\"", "{", "m", "[", "kv", ".", "k", "]", "=", "kv", ".", "v", "\n", "}", "\n", "}", "\n", "return", "m", ",", "nil", "\n", "}" ]
// GetBridgedDeviceNameIPMap returns a map of network device // name and its IP address from the list of bridgedifs reported // by VirtualBox manager.
[ "GetBridgedDeviceNameIPMap", "returns", "a", "map", "of", "network", "device", "name", "and", "its", "IP", "address", "from", "the", "list", "of", "bridgedifs", "reported", "by", "VirtualBox", "manager", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/util.go#L60-L72
146,101
apcera/libretto
virtualmachine/virtualbox/util.go
GetBridgedDeviceName
func GetBridgedDeviceName(macAddr string) (string, error) { stdout, _, err := runner.Run("list", "bridgedifs") if err != nil { return "", err } if matches := networkRegexp.FindAllString(stdout, -1); len(matches) > 0 { // Each match is a device for _, device := range matches { var mac, name string // Find the mac address and the name for _, line := range strings.Split(device, "\n") { if strings.Contains(line, "HardwareAddress") { mac = strings.TrimSpace(strings.TrimPrefix(line, "HardwareAddress:")) } if strings.Contains(line, "Name:") { name = strings.TrimSpace(strings.TrimPrefix(line, "Name:")) } } if strings.Contains(macAddr, mac) { return name, nil } } } return "", nil }
go
func GetBridgedDeviceName(macAddr string) (string, error) { stdout, _, err := runner.Run("list", "bridgedifs") if err != nil { return "", err } if matches := networkRegexp.FindAllString(stdout, -1); len(matches) > 0 { // Each match is a device for _, device := range matches { var mac, name string // Find the mac address and the name for _, line := range strings.Split(device, "\n") { if strings.Contains(line, "HardwareAddress") { mac = strings.TrimSpace(strings.TrimPrefix(line, "HardwareAddress:")) } if strings.Contains(line, "Name:") { name = strings.TrimSpace(strings.TrimPrefix(line, "Name:")) } } if strings.Contains(macAddr, mac) { return name, nil } } } return "", nil }
[ "func", "GetBridgedDeviceName", "(", "macAddr", "string", ")", "(", "string", ",", "error", ")", "{", "stdout", ",", "_", ",", "err", ":=", "runner", ".", "Run", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "if", "matches", ":=", "networkRegexp", ".", "FindAllString", "(", "stdout", ",", "-", "1", ")", ";", "len", "(", "matches", ")", ">", "0", "{", "// Each match is a device", "for", "_", ",", "device", ":=", "range", "matches", "{", "var", "mac", ",", "name", "string", "\n", "// Find the mac address and the name", "for", "_", ",", "line", ":=", "range", "strings", ".", "Split", "(", "device", ",", "\"", "\\n", "\"", ")", "{", "if", "strings", ".", "Contains", "(", "line", ",", "\"", "\"", ")", "{", "mac", "=", "strings", ".", "TrimSpace", "(", "strings", ".", "TrimPrefix", "(", "line", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "if", "strings", ".", "Contains", "(", "line", ",", "\"", "\"", ")", "{", "name", "=", "strings", ".", "TrimSpace", "(", "strings", ".", "TrimPrefix", "(", "line", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "}", "\n", "if", "strings", ".", "Contains", "(", "macAddr", ",", "mac", ")", "{", "return", "name", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", ",", "nil", "\n", "}" ]
// GetBridgedDeviceName takes the mac address of a network device as a string // and returns the name of the network device corresponding to it as seen by // Virtualbox
[ "GetBridgedDeviceName", "takes", "the", "mac", "address", "of", "a", "network", "device", "as", "a", "string", "and", "returns", "the", "name", "of", "the", "network", "device", "corresponding", "to", "it", "as", "seen", "by", "Virtualbox" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/util.go#L77-L101
146,102
apcera/libretto
virtualmachine/virtualbox/util.go
GetBridgedDevices
func GetBridgedDevices() ([]string, error) { deviceNames := []string{} ifAndMac, err := getBridgedDeviceKV("Name", "HardwareAddress") if err != nil { return deviceNames, err } for _, kv := range ifAndMac { if kv.k != "" && kv.v != "" { deviceNames = append(deviceNames, kv.k) } } return deviceNames, nil }
go
func GetBridgedDevices() ([]string, error) { deviceNames := []string{} ifAndMac, err := getBridgedDeviceKV("Name", "HardwareAddress") if err != nil { return deviceNames, err } for _, kv := range ifAndMac { if kv.k != "" && kv.v != "" { deviceNames = append(deviceNames, kv.k) } } return deviceNames, nil }
[ "func", "GetBridgedDevices", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "deviceNames", ":=", "[", "]", "string", "{", "}", "\n", "ifAndMac", ",", "err", ":=", "getBridgedDeviceKV", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "deviceNames", ",", "err", "\n", "}", "\n", "for", "_", ",", "kv", ":=", "range", "ifAndMac", "{", "if", "kv", ".", "k", "!=", "\"", "\"", "&&", "kv", ".", "v", "!=", "\"", "\"", "{", "deviceNames", "=", "append", "(", "deviceNames", ",", "kv", ".", "k", ")", "\n", "}", "\n", "}", "\n", "return", "deviceNames", ",", "nil", "\n", "}" ]
// GetBridgedDevices returns a slice of network devices that can be connected to VMs in bridged mode
[ "GetBridgedDevices", "returns", "a", "slice", "of", "network", "devices", "that", "can", "be", "connected", "to", "VMs", "in", "bridged", "mode" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/util.go#L104-L116
146,103
apcera/libretto
virtualmachine/virtualbox/util.go
DeleteNIC
func DeleteNIC(vm *VM, nic NIC) error { if nic.Backing == Disabled { return lvm.ErrNICAlreadyDisabled } _, _, err := runner.Run("modifyvm", vm.Name, fmt.Sprintf("--nic%d", nic.Idx), "null") return err }
go
func DeleteNIC(vm *VM, nic NIC) error { if nic.Backing == Disabled { return lvm.ErrNICAlreadyDisabled } _, _, err := runner.Run("modifyvm", vm.Name, fmt.Sprintf("--nic%d", nic.Idx), "null") return err }
[ "func", "DeleteNIC", "(", "vm", "*", "VM", ",", "nic", "NIC", ")", "error", "{", "if", "nic", ".", "Backing", "==", "Disabled", "{", "return", "lvm", ".", "ErrNICAlreadyDisabled", "\n", "}", "\n", "_", ",", "_", ",", "err", ":=", "runner", ".", "Run", "(", "\"", "\"", ",", "vm", ".", "Name", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "nic", ".", "Idx", ")", ",", "\"", "\"", ")", "\n", "return", "err", "\n", "}" ]
// DeleteNIC deletes the specified network interface on the vm.
[ "DeleteNIC", "deletes", "the", "specified", "network", "interface", "on", "the", "vm", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/util.go#L228-L234
146,104
apcera/libretto
virtualmachine/virtualbox/util.go
AddNIC
func AddNIC(vm *VM, nic NIC) error { var err error switch nic.Backing { case Nat: _, _, err = runner.Run("modifyvm", vm.Name, fmt.Sprintf("--nic%d", nic.Idx), getStringFromBacking(nic.Backing)) case Bridged: _, _, err = runner.Run("modifyvm", vm.Name, fmt.Sprintf("--nic%d", nic.Idx), getStringFromBacking(nic.Backing), fmt.Sprintf("--bridgeadapter%d", nic.Idx), nic.BackingDevice) } return err }
go
func AddNIC(vm *VM, nic NIC) error { var err error switch nic.Backing { case Nat: _, _, err = runner.Run("modifyvm", vm.Name, fmt.Sprintf("--nic%d", nic.Idx), getStringFromBacking(nic.Backing)) case Bridged: _, _, err = runner.Run("modifyvm", vm.Name, fmt.Sprintf("--nic%d", nic.Idx), getStringFromBacking(nic.Backing), fmt.Sprintf("--bridgeadapter%d", nic.Idx), nic.BackingDevice) } return err }
[ "func", "AddNIC", "(", "vm", "*", "VM", ",", "nic", "NIC", ")", "error", "{", "var", "err", "error", "\n", "switch", "nic", ".", "Backing", "{", "case", "Nat", ":", "_", ",", "_", ",", "err", "=", "runner", ".", "Run", "(", "\"", "\"", ",", "vm", ".", "Name", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "nic", ".", "Idx", ")", ",", "getStringFromBacking", "(", "nic", ".", "Backing", ")", ")", "\n", "case", "Bridged", ":", "_", ",", "_", ",", "err", "=", "runner", ".", "Run", "(", "\"", "\"", ",", "vm", ".", "Name", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "nic", ".", "Idx", ")", ",", "getStringFromBacking", "(", "nic", ".", "Backing", ")", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "nic", ".", "Idx", ")", ",", "nic", ".", "BackingDevice", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// AddNIC adds a NIC to the VM.
[ "AddNIC", "adds", "a", "NIC", "to", "the", "VM", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/util.go#L247-L256
146,105
apcera/libretto
virtualmachine/virtualbox/util.go
DeleteNICs
func DeleteNICs(vm *VM) error { nics, err := vm.GetInterfaces() if err != nil { return lvm.ErrFailedToGetNICS } for _, nic := range nics { if nic.Backing != Disabled { err := DeleteNIC(vm, nic) if err != nil { return err } } } return nil }
go
func DeleteNICs(vm *VM) error { nics, err := vm.GetInterfaces() if err != nil { return lvm.ErrFailedToGetNICS } for _, nic := range nics { if nic.Backing != Disabled { err := DeleteNIC(vm, nic) if err != nil { return err } } } return nil }
[ "func", "DeleteNICs", "(", "vm", "*", "VM", ")", "error", "{", "nics", ",", "err", ":=", "vm", ".", "GetInterfaces", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "lvm", ".", "ErrFailedToGetNICS", "\n", "}", "\n", "for", "_", ",", "nic", ":=", "range", "nics", "{", "if", "nic", ".", "Backing", "!=", "Disabled", "{", "err", ":=", "DeleteNIC", "(", "vm", ",", "nic", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteNICs disables all the network interfaces on the vm.
[ "DeleteNICs", "disables", "all", "the", "network", "interfaces", "on", "the", "vm", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/util.go#L259-L273
146,106
apcera/libretto
ssh/keys.go
NewKeyPair
func NewKeyPair() (keyPair *KeyPair, err error) { priv, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { return nil, ErrKeyGeneration } if err := priv.Validate(); err != nil { return nil, ErrValidation } privDer := x509.MarshalPKCS1PrivateKey(priv) privateKey := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Headers: nil, Bytes: privDer}) pubSSH, err := gossh.NewPublicKey(&priv.PublicKey) if err != nil { return nil, ErrPublicKey } return &KeyPair{ PrivateKey: privateKey, PublicKey: gossh.MarshalAuthorizedKey(pubSSH), }, nil }
go
func NewKeyPair() (keyPair *KeyPair, err error) { priv, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { return nil, ErrKeyGeneration } if err := priv.Validate(); err != nil { return nil, ErrValidation } privDer := x509.MarshalPKCS1PrivateKey(priv) privateKey := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Headers: nil, Bytes: privDer}) pubSSH, err := gossh.NewPublicKey(&priv.PublicKey) if err != nil { return nil, ErrPublicKey } return &KeyPair{ PrivateKey: privateKey, PublicKey: gossh.MarshalAuthorizedKey(pubSSH), }, nil }
[ "func", "NewKeyPair", "(", ")", "(", "keyPair", "*", "KeyPair", ",", "err", "error", ")", "{", "priv", ",", "err", ":=", "rsa", ".", "GenerateKey", "(", "rand", ".", "Reader", ",", "2048", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "ErrKeyGeneration", "\n", "}", "\n\n", "if", "err", ":=", "priv", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "ErrValidation", "\n", "}", "\n\n", "privDer", ":=", "x509", ".", "MarshalPKCS1PrivateKey", "(", "priv", ")", "\n", "privateKey", ":=", "pem", ".", "EncodeToMemory", "(", "&", "pem", ".", "Block", "{", "Type", ":", "\"", "\"", ",", "Headers", ":", "nil", ",", "Bytes", ":", "privDer", "}", ")", "\n", "pubSSH", ",", "err", ":=", "gossh", ".", "NewPublicKey", "(", "&", "priv", ".", "PublicKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "ErrPublicKey", "\n", "}", "\n\n", "return", "&", "KeyPair", "{", "PrivateKey", ":", "privateKey", ",", "PublicKey", ":", "gossh", ".", "MarshalAuthorizedKey", "(", "pubSSH", ")", ",", "}", ",", "nil", "\n", "}" ]
// NewKeyPair generates a new SSH keypair. This will return a private & public key encoded as DER.
[ "NewKeyPair", "generates", "a", "new", "SSH", "keypair", ".", "This", "will", "return", "a", "private", "&", "public", "key", "encoded", "as", "DER", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/keys.go#L22-L43
146,107
apcera/libretto
ssh/keys.go
ReadFromFile
func (kp *KeyPair) ReadFromFile(privateKeyPath string, publicKeyPath string) error { b, err := ioutil.ReadFile(privateKeyPath) if err != nil { return err } kp.PrivateKey = b b, err = ioutil.ReadFile(publicKeyPath) if err != nil { return err } kp.PublicKey = b return nil }
go
func (kp *KeyPair) ReadFromFile(privateKeyPath string, publicKeyPath string) error { b, err := ioutil.ReadFile(privateKeyPath) if err != nil { return err } kp.PrivateKey = b b, err = ioutil.ReadFile(publicKeyPath) if err != nil { return err } kp.PublicKey = b return nil }
[ "func", "(", "kp", "*", "KeyPair", ")", "ReadFromFile", "(", "privateKeyPath", "string", ",", "publicKeyPath", "string", ")", "error", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "privateKeyPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "kp", ".", "PrivateKey", "=", "b", "\n\n", "b", ",", "err", "=", "ioutil", ".", "ReadFile", "(", "publicKeyPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "kp", ".", "PublicKey", "=", "b", "\n\n", "return", "nil", "\n", "}" ]
// ReadFromFile reads a keypair from files.
[ "ReadFromFile", "reads", "a", "keypair", "from", "files", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/keys.go#L52-L66
146,108
apcera/libretto
ssh/keys.go
WriteToFile
func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) error { files := []struct { File string Type string Value []byte }{ { File: privateKeyPath, Value: kp.PrivateKey, }, { File: publicKeyPath, Value: kp.PublicKey, }, } for _, v := range files { f, err := os.Create(v.File) if err != nil { return ErrUnableToWriteFile } if _, err := f.Write(v.Value); err != nil { return ErrUnableToWriteFile } // windows does not support chmod switch runtime.GOOS { case "darwin", "linux": if err := f.Chmod(0600); err != nil { return err } } } return nil }
go
func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) error { files := []struct { File string Type string Value []byte }{ { File: privateKeyPath, Value: kp.PrivateKey, }, { File: publicKeyPath, Value: kp.PublicKey, }, } for _, v := range files { f, err := os.Create(v.File) if err != nil { return ErrUnableToWriteFile } if _, err := f.Write(v.Value); err != nil { return ErrUnableToWriteFile } // windows does not support chmod switch runtime.GOOS { case "darwin", "linux": if err := f.Chmod(0600); err != nil { return err } } } return nil }
[ "func", "(", "kp", "*", "KeyPair", ")", "WriteToFile", "(", "privateKeyPath", "string", ",", "publicKeyPath", "string", ")", "error", "{", "files", ":=", "[", "]", "struct", "{", "File", "string", "\n", "Type", "string", "\n", "Value", "[", "]", "byte", "\n", "}", "{", "{", "File", ":", "privateKeyPath", ",", "Value", ":", "kp", ".", "PrivateKey", ",", "}", ",", "{", "File", ":", "publicKeyPath", ",", "Value", ":", "kp", ".", "PublicKey", ",", "}", ",", "}", "\n\n", "for", "_", ",", "v", ":=", "range", "files", "{", "f", ",", "err", ":=", "os", ".", "Create", "(", "v", ".", "File", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ErrUnableToWriteFile", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "f", ".", "Write", "(", "v", ".", "Value", ")", ";", "err", "!=", "nil", "{", "return", "ErrUnableToWriteFile", "\n", "}", "\n\n", "// windows does not support chmod", "switch", "runtime", ".", "GOOS", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "if", "err", ":=", "f", ".", "Chmod", "(", "0600", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// WriteToFile writes a keypair to files
[ "WriteToFile", "writes", "a", "keypair", "to", "files" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/keys.go#L69-L105
146,109
apcera/libretto
virtualmachine/aws/wait.go
Error
func (e ReadyError) Error() string { return fmt.Sprintf( "failed waiting for instance (%s) to be ready, reason was: %s", e.InstanceID, e.StateReason, ) }
go
func (e ReadyError) Error() string { return fmt.Sprintf( "failed waiting for instance (%s) to be ready, reason was: %s", e.InstanceID, e.StateReason, ) }
[ "func", "(", "e", "ReadyError", ")", "Error", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "InstanceID", ",", "e", ".", "StateReason", ",", ")", "\n", "}" ]
// Error returns a summarized string version of ReadyError. More details about // the failed instance can be accessed through the struct.
[ "Error", "returns", "a", "summarized", "string", "version", "of", "ReadyError", ".", "More", "details", "about", "the", "failed", "instance", "can", "be", "accessed", "through", "the", "struct", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/wait.go#L31-L37
146,110
apcera/libretto
util/util.go
Random
func Random(min, max int) int { if min == max { return min } if max < min { panic("max cannot be less than min") } rand.Seed(time.Now().UTC().UnixNano()) return rand.Intn(max-min+1) + min }
go
func Random(min, max int) int { if min == max { return min } if max < min { panic("max cannot be less than min") } rand.Seed(time.Now().UTC().UnixNano()) return rand.Intn(max-min+1) + min }
[ "func", "Random", "(", "min", ",", "max", "int", ")", "int", "{", "if", "min", "==", "max", "{", "return", "min", "\n", "}", "\n", "if", "max", "<", "min", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "rand", ".", "Seed", "(", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ".", "UnixNano", "(", ")", ")", "\n", "return", "rand", ".", "Intn", "(", "max", "-", "min", "+", "1", ")", "+", "min", "\n", "}" ]
// Random generates a random number in between min and max // If min equals max then min is returned. If max is less than min // then the function panics.
[ "Random", "generates", "a", "random", "number", "in", "between", "min", "and", "max", "If", "min", "equals", "max", "then", "min", "is", "returned", ".", "If", "max", "is", "less", "than", "min", "then", "the", "function", "panics", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/util/util.go#L19-L28
146,111
apcera/libretto
util/util.go
GetVMIPs
func GetVMIPs(vm lvm.VirtualMachine, options ssh.Options) ([]net.IP, error) { ips := options.IPs if len(ips) == 0 { var err error ips, err = vm.GetIPs() if err != nil { return nil, fmt.Errorf("Error getting IPs for the VM: %s", err) } if len(ips) == 0 { return nil, lvm.ErrVMNoIP } } return ips, nil }
go
func GetVMIPs(vm lvm.VirtualMachine, options ssh.Options) ([]net.IP, error) { ips := options.IPs if len(ips) == 0 { var err error ips, err = vm.GetIPs() if err != nil { return nil, fmt.Errorf("Error getting IPs for the VM: %s", err) } if len(ips) == 0 { return nil, lvm.ErrVMNoIP } } return ips, nil }
[ "func", "GetVMIPs", "(", "vm", "lvm", ".", "VirtualMachine", ",", "options", "ssh", ".", "Options", ")", "(", "[", "]", "net", ".", "IP", ",", "error", ")", "{", "ips", ":=", "options", ".", "IPs", "\n", "if", "len", "(", "ips", ")", "==", "0", "{", "var", "err", "error", "\n", "ips", ",", "err", "=", "vm", ".", "GetIPs", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "len", "(", "ips", ")", "==", "0", "{", "return", "nil", ",", "lvm", ".", "ErrVMNoIP", "\n", "}", "\n", "}", "\n", "return", "ips", ",", "nil", "\n", "}" ]
// GetVMIPs returns the IPs associated with the given VM. If the IPs are present // in options, they will be returned. Otherwise, an API call will be made to // get the list of IPs. An error is returned if the API call fails or returns // nothing.
[ "GetVMIPs", "returns", "the", "IPs", "associated", "with", "the", "given", "VM", ".", "If", "the", "IPs", "are", "present", "in", "options", "they", "will", "be", "returned", ".", "Otherwise", "an", "API", "call", "will", "be", "made", "to", "get", "the", "list", "of", "IPs", ".", "An", "error", "is", "returned", "if", "the", "API", "call", "fails", "or", "returns", "nothing", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/util/util.go#L34-L47
146,112
apcera/libretto
util/util.go
CombineErrors
func CombineErrors(delimiter string, errs ...error) error { var formatStrs = []string{} for _, e := range errs { if e == nil { continue } formatStrs = append(formatStrs, e.Error()) } return fmt.Errorf(strings.Join(formatStrs, delimiter)) }
go
func CombineErrors(delimiter string, errs ...error) error { var formatStrs = []string{} for _, e := range errs { if e == nil { continue } formatStrs = append(formatStrs, e.Error()) } return fmt.Errorf(strings.Join(formatStrs, delimiter)) }
[ "func", "CombineErrors", "(", "delimiter", "string", ",", "errs", "...", "error", ")", "error", "{", "var", "formatStrs", "=", "[", "]", "string", "{", "}", "\n\n", "for", "_", ",", "e", ":=", "range", "errs", "{", "if", "e", "==", "nil", "{", "continue", "\n", "}", "\n", "formatStrs", "=", "append", "(", "formatStrs", ",", "e", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "return", "fmt", ".", "Errorf", "(", "strings", ".", "Join", "(", "formatStrs", ",", "delimiter", ")", ")", "\n", "}" ]
// CombineErrors converts all the errors from slice into a single error
[ "CombineErrors", "converts", "all", "the", "errors", "from", "slice", "into", "a", "single", "error" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/util/util.go#L50-L61
146,113
apcera/libretto
virtualmachine/vsphere/vm.go
Progress
func (v VMwareLease) Progress(p int) { v.Lease.Progress(v.Ctx, int32(p)) }
go
func (v VMwareLease) Progress(p int) { v.Lease.Progress(v.Ctx, int32(p)) }
[ "func", "(", "v", "VMwareLease", ")", "Progress", "(", "p", "int", ")", "{", "v", ".", "Lease", ".", "Progress", "(", "v", ".", "Ctx", ",", "int32", "(", "p", ")", ")", "\n", "}" ]
// Progress takes a percentage as an int and sets that percentage as the // completed percent.
[ "Progress", "takes", "a", "percentage", "as", "an", "int", "and", "sets", "that", "percentage", "as", "the", "completed", "percent", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L51-L53
146,114
apcera/libretto
virtualmachine/vsphere/vm.go
Wait
func (v VMwareLease) Wait() (*nfc.LeaseInfo, error) { return v.Lease.Wait(v.Ctx, nil) }
go
func (v VMwareLease) Wait() (*nfc.LeaseInfo, error) { return v.Lease.Wait(v.Ctx, nil) }
[ "func", "(", "v", "VMwareLease", ")", "Wait", "(", ")", "(", "*", "nfc", ".", "LeaseInfo", ",", "error", ")", "{", "return", "v", ".", "Lease", ".", "Wait", "(", "v", ".", "Ctx", ",", "nil", ")", "\n", "}" ]
// Wait waits for the underlying lease to finish.
[ "Wait", "waits", "for", "the", "underlying", "lease", "to", "finish", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L56-L58
146,115
apcera/libretto
virtualmachine/vsphere/vm.go
Read
func (r ReadProgress) Read(p []byte) (n int, err error) { n, err = r.Reader.Read(p) if err != nil { return } r.ch <- int64(n) return }
go
func (r ReadProgress) Read(p []byte) (n int, err error) { n, err = r.Reader.Read(p) if err != nil { return } r.ch <- int64(n) return }
[ "func", "(", "r", "ReadProgress", ")", "Read", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "n", ",", "err", "=", "r", ".", "Reader", ".", "Read", "(", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "r", ".", "ch", "<-", "int64", "(", "n", ")", "\n", "return", "\n", "}" ]
// Read implements the Reader interface.
[ "Read", "implements", "the", "Reader", "interface", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L96-L103
146,116
apcera/libretto
virtualmachine/vsphere/vm.go
StartProgress
func (r ReadProgress) StartProgress() { r.wg.Add(1) go func() { var bytesReceived int64 var percent int tick := time.NewTicker(5 * time.Second) defer tick.Stop() defer r.wg.Done() for { select { case b := <-r.ch: bytesReceived += b percent = int((float32(bytesReceived) / float32(r.TotalBytes)) * 100) case <-tick.C: // TODO: Preet This can return an error as well, should return it r.Lease.Progress(percent) if percent == 100 { return } } } }() }
go
func (r ReadProgress) StartProgress() { r.wg.Add(1) go func() { var bytesReceived int64 var percent int tick := time.NewTicker(5 * time.Second) defer tick.Stop() defer r.wg.Done() for { select { case b := <-r.ch: bytesReceived += b percent = int((float32(bytesReceived) / float32(r.TotalBytes)) * 100) case <-tick.C: // TODO: Preet This can return an error as well, should return it r.Lease.Progress(percent) if percent == 100 { return } } } }() }
[ "func", "(", "r", "ReadProgress", ")", "StartProgress", "(", ")", "{", "r", ".", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", ")", "{", "var", "bytesReceived", "int64", "\n", "var", "percent", "int", "\n", "tick", ":=", "time", ".", "NewTicker", "(", "5", "*", "time", ".", "Second", ")", "\n", "defer", "tick", ".", "Stop", "(", ")", "\n", "defer", "r", ".", "wg", ".", "Done", "(", ")", "\n", "for", "{", "select", "{", "case", "b", ":=", "<-", "r", ".", "ch", ":", "bytesReceived", "+=", "b", "\n", "percent", "=", "int", "(", "(", "float32", "(", "bytesReceived", ")", "/", "float32", "(", "r", ".", "TotalBytes", ")", ")", "*", "100", ")", "\n", "case", "<-", "tick", ".", "C", ":", "// TODO: Preet This can return an error as well, should return it", "r", ".", "Lease", ".", "Progress", "(", "percent", ")", "\n", "if", "percent", "==", "100", "{", "return", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "}" ]
// StartProgress starts a goroutine that updates local progress on the lease as // well as pass it down to the underlying lease.
[ "StartProgress", "starts", "a", "goroutine", "that", "updates", "local", "progress", "on", "the", "lease", "as", "well", "as", "pass", "it", "down", "to", "the", "underlying", "lease", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L107-L129
146,117
apcera/libretto
virtualmachine/vsphere/vm.go
NewErrorParsingURL
func NewErrorParsingURL(u string, e error) ErrorParsingURL { return ErrorParsingURL{uri: u, err: e} }
go
func NewErrorParsingURL(u string, e error) ErrorParsingURL { return ErrorParsingURL{uri: u, err: e} }
[ "func", "NewErrorParsingURL", "(", "u", "string", ",", "e", "error", ")", "ErrorParsingURL", "{", "return", "ErrorParsingURL", "{", "uri", ":", "u", ",", "err", ":", "e", "}", "\n", "}" ]
// NewErrorParsingURL returns an ErrorParsingURL error.
[ "NewErrorParsingURL", "returns", "an", "ErrorParsingURL", "error", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L216-L218
146,118
apcera/libretto
virtualmachine/vsphere/vm.go
NewErrorInvalidHost
func NewErrorInvalidHost(h string, d string, n map[string]string) ErrorInvalidHost { return ErrorInvalidHost{host: h, ds: d, nw: n} }
go
func NewErrorInvalidHost(h string, d string, n map[string]string) ErrorInvalidHost { return ErrorInvalidHost{host: h, ds: d, nw: n} }
[ "func", "NewErrorInvalidHost", "(", "h", "string", ",", "d", "string", ",", "n", "map", "[", "string", "]", "string", ")", "ErrorInvalidHost", "{", "return", "ErrorInvalidHost", "{", "host", ":", "h", ",", "ds", ":", "d", ",", "nw", ":", "n", "}", "\n", "}" ]
// NewErrorInvalidHost returns an ErrorInvalidHost error.
[ "NewErrorInvalidHost", "returns", "an", "ErrorInvalidHost", "error", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L221-L223
146,119
apcera/libretto
virtualmachine/vsphere/vm.go
NewErrorObjectNotFound
func NewErrorObjectNotFound(e error, o string) ErrorObjectNotFound { return ErrorObjectNotFound{err: e, obj: o} }
go
func NewErrorObjectNotFound(e error, o string) ErrorObjectNotFound { return ErrorObjectNotFound{err: e, obj: o} }
[ "func", "NewErrorObjectNotFound", "(", "e", "error", ",", "o", "string", ")", "ErrorObjectNotFound", "{", "return", "ErrorObjectNotFound", "{", "err", ":", "e", ",", "obj", ":", "o", "}", "\n", "}" ]
// NewErrorObjectNotFound returns an ErrorObjectNotFound error.
[ "NewErrorObjectNotFound", "returns", "an", "ErrorObjectNotFound", "error", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L231-L233
146,120
apcera/libretto
virtualmachine/vsphere/vm.go
NewErrorPropertyRetrieval
func NewErrorPropertyRetrieval(m types.ManagedObjectReference, p []string, e error) ErrorPropertyRetrieval { return ErrorPropertyRetrieval{err: e, mor: m, ps: p} }
go
func NewErrorPropertyRetrieval(m types.ManagedObjectReference, p []string, e error) ErrorPropertyRetrieval { return ErrorPropertyRetrieval{err: e, mor: m, ps: p} }
[ "func", "NewErrorPropertyRetrieval", "(", "m", "types", ".", "ManagedObjectReference", ",", "p", "[", "]", "string", ",", "e", "error", ")", "ErrorPropertyRetrieval", "{", "return", "ErrorPropertyRetrieval", "{", "err", ":", "e", ",", "mor", ":", "m", ",", "ps", ":", "p", "}", "\n", "}" ]
// NewErrorPropertyRetrieval returns an ErrorPropertyRetrieval error.
[ "NewErrorPropertyRetrieval", "returns", "an", "ErrorPropertyRetrieval", "error", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L236-L238
146,121
apcera/libretto
virtualmachine/vsphere/vm.go
Provision
func (vm *VM) Provision() (err error) { if err := SetupSession(vm); err != nil { return fmt.Errorf("Error setting up vSphere session: %s", err) } // Cancel the sdk context defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() // Get a reference to the datacenter with host and vm folders populated dcMo, err := GetDatacenter(vm) if err != nil { return fmt.Errorf("Failed to retrieve datacenter: %s", err) } // Upload a template to all the datastores if `UseLocalTemplates` is set. // Otherwise pick a random datastore out of the list that was passed in. var datastores = vm.Datastores if !vm.UseLocalTemplates { n := util.Random(1, len(vm.Datastores)) datastores = []string{vm.Datastores[n-1]} } usableDatastores := []string{} for _, d := range datastores { template := createTemplateName(vm.Template, d) // Does the VM template already exist? e, err := Exists(vm, dcMo, template) if err != nil { return fmt.Errorf("failed to check if the template already exists: %s", err) } // If it does exist, return an error if the skip existing flag is not set if e { if !vm.SkipExisting { return fmt.Errorf("template already exists: %s", vm.Template) } } else { // Upload the template if it does not exist. If it exists and SkipExisting is true, // use the existing template if err := uploadTemplate(vm, dcMo, d); err != nil { return err } } // Upload successful or the template was found with the SkipExisting flag set to true usableDatastores = append(usableDatastores, d) } // Does the VM already exist? e, err := Exists(vm, dcMo, vm.Name) if err != nil { return fmt.Errorf("failed to check if the vm already exists: %s", err) } if e { return ErrorVMExists } err = cloneFromTemplate(vm, dcMo, usableDatastores) if err != nil { return fmt.Errorf("error while cloning vm from template: %s", err) } return }
go
func (vm *VM) Provision() (err error) { if err := SetupSession(vm); err != nil { return fmt.Errorf("Error setting up vSphere session: %s", err) } // Cancel the sdk context defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() // Get a reference to the datacenter with host and vm folders populated dcMo, err := GetDatacenter(vm) if err != nil { return fmt.Errorf("Failed to retrieve datacenter: %s", err) } // Upload a template to all the datastores if `UseLocalTemplates` is set. // Otherwise pick a random datastore out of the list that was passed in. var datastores = vm.Datastores if !vm.UseLocalTemplates { n := util.Random(1, len(vm.Datastores)) datastores = []string{vm.Datastores[n-1]} } usableDatastores := []string{} for _, d := range datastores { template := createTemplateName(vm.Template, d) // Does the VM template already exist? e, err := Exists(vm, dcMo, template) if err != nil { return fmt.Errorf("failed to check if the template already exists: %s", err) } // If it does exist, return an error if the skip existing flag is not set if e { if !vm.SkipExisting { return fmt.Errorf("template already exists: %s", vm.Template) } } else { // Upload the template if it does not exist. If it exists and SkipExisting is true, // use the existing template if err := uploadTemplate(vm, dcMo, d); err != nil { return err } } // Upload successful or the template was found with the SkipExisting flag set to true usableDatastores = append(usableDatastores, d) } // Does the VM already exist? e, err := Exists(vm, dcMo, vm.Name) if err != nil { return fmt.Errorf("failed to check if the vm already exists: %s", err) } if e { return ErrorVMExists } err = cloneFromTemplate(vm, dcMo, usableDatastores) if err != nil { return fmt.Errorf("error while cloning vm from template: %s", err) } return }
[ "func", "(", "vm", "*", "VM", ")", "Provision", "(", ")", "(", "err", "error", ")", "{", "if", "err", ":=", "SetupSession", "(", "vm", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Cancel the sdk context", "defer", "func", "(", ")", "{", "vm", ".", "client", ".", "Logout", "(", "vm", ".", "ctx", ")", "\n", "vm", ".", "cancel", "(", ")", "\n", "}", "(", ")", "\n\n", "// Get a reference to the datacenter with host and vm folders populated", "dcMo", ",", "err", ":=", "GetDatacenter", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Upload a template to all the datastores if `UseLocalTemplates` is set.", "// Otherwise pick a random datastore out of the list that was passed in.", "var", "datastores", "=", "vm", ".", "Datastores", "\n", "if", "!", "vm", ".", "UseLocalTemplates", "{", "n", ":=", "util", ".", "Random", "(", "1", ",", "len", "(", "vm", ".", "Datastores", ")", ")", "\n", "datastores", "=", "[", "]", "string", "{", "vm", ".", "Datastores", "[", "n", "-", "1", "]", "}", "\n", "}", "\n\n", "usableDatastores", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "d", ":=", "range", "datastores", "{", "template", ":=", "createTemplateName", "(", "vm", ".", "Template", ",", "d", ")", "\n", "// Does the VM template already exist?", "e", ",", "err", ":=", "Exists", "(", "vm", ",", "dcMo", ",", "template", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// If it does exist, return an error if the skip existing flag is not set", "if", "e", "{", "if", "!", "vm", ".", "SkipExisting", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vm", ".", "Template", ")", "\n", "}", "\n", "}", "else", "{", "// Upload the template if it does not exist. If it exists and SkipExisting is true,", "// use the existing template", "if", "err", ":=", "uploadTemplate", "(", "vm", ",", "dcMo", ",", "d", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "// Upload successful or the template was found with the SkipExisting flag set to true", "usableDatastores", "=", "append", "(", "usableDatastores", ",", "d", ")", "\n", "}", "\n\n", "// Does the VM already exist?", "e", ",", "err", ":=", "Exists", "(", "vm", ",", "dcMo", ",", "vm", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "e", "{", "return", "ErrorVMExists", "\n", "}", "\n\n", "err", "=", "cloneFromTemplate", "(", "vm", ",", "dcMo", ",", "usableDatastores", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Provision provisions this VM.
[ "Provision", "provisions", "this", "VM", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L355-L419
146,122
apcera/libretto
virtualmachine/vsphere/vm.go
GetIPs
func (vm *VM) GetIPs() ([]net.IP, error) { if err := SetupSession(vm); err != nil { return nil, err } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() // Get a reference to the datacenter with host and vm folders populated dcMo, err := GetDatacenter(vm) if err != nil { return nil, err } vmMo, err := findVM(vm, dcMo, vm.Name) if err != nil { return nil, err } // Lazy initialized when there is an IP address later. var ips []net.IP for _, nic := range vmMo.Guest.Net { for _, ip := range nic.IpAddress { netIP := net.ParseIP(ip) if netIP == nil { continue } if ips == nil { ips = make([]net.IP, 0, 1) } ips = append(ips, netIP) } } if ips == nil && vmMo.Guest.IpAddress != "" { ip := net.ParseIP(vmMo.Guest.IpAddress) if ip != nil { ips = append(ips, ip) } } return ips, nil }
go
func (vm *VM) GetIPs() ([]net.IP, error) { if err := SetupSession(vm); err != nil { return nil, err } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() // Get a reference to the datacenter with host and vm folders populated dcMo, err := GetDatacenter(vm) if err != nil { return nil, err } vmMo, err := findVM(vm, dcMo, vm.Name) if err != nil { return nil, err } // Lazy initialized when there is an IP address later. var ips []net.IP for _, nic := range vmMo.Guest.Net { for _, ip := range nic.IpAddress { netIP := net.ParseIP(ip) if netIP == nil { continue } if ips == nil { ips = make([]net.IP, 0, 1) } ips = append(ips, netIP) } } if ips == nil && vmMo.Guest.IpAddress != "" { ip := net.ParseIP(vmMo.Guest.IpAddress) if ip != nil { ips = append(ips, ip) } } return ips, nil }
[ "func", "(", "vm", "*", "VM", ")", "GetIPs", "(", ")", "(", "[", "]", "net", ".", "IP", ",", "error", ")", "{", "if", "err", ":=", "SetupSession", "(", "vm", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "vm", ".", "client", ".", "Logout", "(", "vm", ".", "ctx", ")", "\n", "vm", ".", "cancel", "(", ")", "\n", "}", "(", ")", "\n\n", "// Get a reference to the datacenter with host and vm folders populated", "dcMo", ",", "err", ":=", "GetDatacenter", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vmMo", ",", "err", ":=", "findVM", "(", "vm", ",", "dcMo", ",", "vm", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// Lazy initialized when there is an IP address later.", "var", "ips", "[", "]", "net", ".", "IP", "\n", "for", "_", ",", "nic", ":=", "range", "vmMo", ".", "Guest", ".", "Net", "{", "for", "_", ",", "ip", ":=", "range", "nic", ".", "IpAddress", "{", "netIP", ":=", "net", ".", "ParseIP", "(", "ip", ")", "\n", "if", "netIP", "==", "nil", "{", "continue", "\n", "}", "\n", "if", "ips", "==", "nil", "{", "ips", "=", "make", "(", "[", "]", "net", ".", "IP", ",", "0", ",", "1", ")", "\n", "}", "\n", "ips", "=", "append", "(", "ips", ",", "netIP", ")", "\n", "}", "\n", "}", "\n", "if", "ips", "==", "nil", "&&", "vmMo", ".", "Guest", ".", "IpAddress", "!=", "\"", "\"", "{", "ip", ":=", "net", ".", "ParseIP", "(", "vmMo", ".", "Guest", ".", "IpAddress", ")", "\n", "if", "ip", "!=", "nil", "{", "ips", "=", "append", "(", "ips", ",", "ip", ")", "\n", "}", "\n", "}", "\n", "return", "ips", ",", "nil", "\n", "}" ]
// GetIPs returns the IPs of this VM. Returns all the IPs known to the API for // the different network cards for this VM. Includes IPV4 and IPV6 addresses.
[ "GetIPs", "returns", "the", "IPs", "of", "this", "VM", ".", "Returns", "all", "the", "IPs", "known", "to", "the", "API", "for", "the", "different", "network", "cards", "for", "this", "VM", ".", "Includes", "IPV4", "and", "IPV6", "addresses", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L428-L467
146,123
apcera/libretto
virtualmachine/vsphere/vm.go
Destroy
func (vm *VM) Destroy() (err error) { if err := SetupSession(vm); err != nil { return err } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() state, err := getState(vm) if err != nil { return err } // Can't destroy a suspended VM, power it on and update the state if state == "standby" { err = start(vm) if err != nil { return err } } if state != "notRunning" { // Only possible states are running, shuttingDown, resetting or notRunning timer := time.NewTimer(time.Second * 90) wg := sync.WaitGroup{} wg.Add(1) go func() { defer timer.Stop() defer wg.Done() Outerloop: for { state, e := getState(vm) if e != nil { err = e break } if state == "notRunning" { break } if state == "running" { e = halt(vm) if e != nil { err = e break } } select { case <-timer.C: err = fmt.Errorf("timed out waiting for VM to power off") break Outerloop default: // No action } time.Sleep(time.Second) } }() wg.Wait() if err != nil { return err } } // Get a reference to the datacenter with host and vm folders populated dcMo, err := GetDatacenter(vm) if err != nil { return err } vmMo, err := findVM(vm, dcMo, vm.Name) if err != nil { return err } vmo := object.NewVirtualMachine(vm.client.Client, vmMo.Reference()) destroyTask, err := vmo.Destroy(vm.ctx) if err != nil { return fmt.Errorf("error creating a destroy task on the vm: %s", err) } tInfo, err := destroyTask.WaitForResult(vm.ctx, nil) if err != nil { return fmt.Errorf("error waiting for destroy task: %s", err) } if tInfo.Error != nil { return fmt.Errorf("destroy task returned an error: %s", err) } return nil }
go
func (vm *VM) Destroy() (err error) { if err := SetupSession(vm); err != nil { return err } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() state, err := getState(vm) if err != nil { return err } // Can't destroy a suspended VM, power it on and update the state if state == "standby" { err = start(vm) if err != nil { return err } } if state != "notRunning" { // Only possible states are running, shuttingDown, resetting or notRunning timer := time.NewTimer(time.Second * 90) wg := sync.WaitGroup{} wg.Add(1) go func() { defer timer.Stop() defer wg.Done() Outerloop: for { state, e := getState(vm) if e != nil { err = e break } if state == "notRunning" { break } if state == "running" { e = halt(vm) if e != nil { err = e break } } select { case <-timer.C: err = fmt.Errorf("timed out waiting for VM to power off") break Outerloop default: // No action } time.Sleep(time.Second) } }() wg.Wait() if err != nil { return err } } // Get a reference to the datacenter with host and vm folders populated dcMo, err := GetDatacenter(vm) if err != nil { return err } vmMo, err := findVM(vm, dcMo, vm.Name) if err != nil { return err } vmo := object.NewVirtualMachine(vm.client.Client, vmMo.Reference()) destroyTask, err := vmo.Destroy(vm.ctx) if err != nil { return fmt.Errorf("error creating a destroy task on the vm: %s", err) } tInfo, err := destroyTask.WaitForResult(vm.ctx, nil) if err != nil { return fmt.Errorf("error waiting for destroy task: %s", err) } if tInfo.Error != nil { return fmt.Errorf("destroy task returned an error: %s", err) } return nil }
[ "func", "(", "vm", "*", "VM", ")", "Destroy", "(", ")", "(", "err", "error", ")", "{", "if", "err", ":=", "SetupSession", "(", "vm", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "vm", ".", "client", ".", "Logout", "(", "vm", ".", "ctx", ")", "\n", "vm", ".", "cancel", "(", ")", "\n", "}", "(", ")", "\n\n", "state", ",", "err", ":=", "getState", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Can't destroy a suspended VM, power it on and update the state", "if", "state", "==", "\"", "\"", "{", "err", "=", "start", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "state", "!=", "\"", "\"", "{", "// Only possible states are running, shuttingDown, resetting or notRunning", "timer", ":=", "time", ".", "NewTimer", "(", "time", ".", "Second", "*", "90", ")", "\n", "wg", ":=", "sync", ".", "WaitGroup", "{", "}", "\n", "wg", ".", "Add", "(", "1", ")", "\n\n", "go", "func", "(", ")", "{", "defer", "timer", ".", "Stop", "(", ")", "\n", "defer", "wg", ".", "Done", "(", ")", "\n", "Outerloop", ":", "for", "{", "state", ",", "e", ":=", "getState", "(", "vm", ")", "\n", "if", "e", "!=", "nil", "{", "err", "=", "e", "\n", "break", "\n", "}", "\n", "if", "state", "==", "\"", "\"", "{", "break", "\n", "}", "\n\n", "if", "state", "==", "\"", "\"", "{", "e", "=", "halt", "(", "vm", ")", "\n", "if", "e", "!=", "nil", "{", "err", "=", "e", "\n", "break", "\n", "}", "\n", "}", "\n\n", "select", "{", "case", "<-", "timer", ".", "C", ":", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "break", "Outerloop", "\n", "default", ":", "// No action", "}", "\n", "time", ".", "Sleep", "(", "time", ".", "Second", ")", "\n", "}", "\n", "}", "(", ")", "\n", "wg", ".", "Wait", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Get a reference to the datacenter with host and vm folders populated", "dcMo", ",", "err", ":=", "GetDatacenter", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "vmMo", ",", "err", ":=", "findVM", "(", "vm", ",", "dcMo", ",", "vm", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "vmo", ":=", "object", ".", "NewVirtualMachine", "(", "vm", ".", "client", ".", "Client", ",", "vmMo", ".", "Reference", "(", ")", ")", "\n", "destroyTask", ",", "err", ":=", "vmo", ".", "Destroy", "(", "vm", ".", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "tInfo", ",", "err", ":=", "destroyTask", ".", "WaitForResult", "(", "vm", ".", "ctx", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "tInfo", ".", "Error", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Destroy deletes this VM from vSphere.
[ "Destroy", "deletes", "this", "VM", "from", "vSphere", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L470-L558
146,124
apcera/libretto
virtualmachine/vsphere/vm.go
GetState
func (vm *VM) GetState() (state string, err error) { if err := SetupSession(vm); err != nil { return "", lvm.ErrVMInfoFailed } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() state, err = getState(vm) if err != nil { return "", err } if state == "running" { return lvm.VMRunning, nil } else if state == "standby" { return lvm.VMSuspended, nil } else if state == "shuttingDown" || state == "resetting" || state == "notRunning" { return lvm.VMHalted, nil } // VM state "unknown" return "", lvm.ErrVMInfoFailed }
go
func (vm *VM) GetState() (state string, err error) { if err := SetupSession(vm); err != nil { return "", lvm.ErrVMInfoFailed } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() state, err = getState(vm) if err != nil { return "", err } if state == "running" { return lvm.VMRunning, nil } else if state == "standby" { return lvm.VMSuspended, nil } else if state == "shuttingDown" || state == "resetting" || state == "notRunning" { return lvm.VMHalted, nil } // VM state "unknown" return "", lvm.ErrVMInfoFailed }
[ "func", "(", "vm", "*", "VM", ")", "GetState", "(", ")", "(", "state", "string", ",", "err", "error", ")", "{", "if", "err", ":=", "SetupSession", "(", "vm", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "lvm", ".", "ErrVMInfoFailed", "\n", "}", "\n", "defer", "func", "(", ")", "{", "vm", ".", "client", ".", "Logout", "(", "vm", ".", "ctx", ")", "\n", "vm", ".", "cancel", "(", ")", "\n", "}", "(", ")", "\n", "state", ",", "err", "=", "getState", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "state", "==", "\"", "\"", "{", "return", "lvm", ".", "VMRunning", ",", "nil", "\n", "}", "else", "if", "state", "==", "\"", "\"", "{", "return", "lvm", ".", "VMSuspended", ",", "nil", "\n", "}", "else", "if", "state", "==", "\"", "\"", "||", "state", "==", "\"", "\"", "||", "state", "==", "\"", "\"", "{", "return", "lvm", ".", "VMHalted", ",", "nil", "\n", "}", "\n", "// VM state \"unknown\"", "return", "\"", "\"", ",", "lvm", ".", "ErrVMInfoFailed", "\n", "}" ]
// GetState returns the power state of this VM.
[ "GetState", "returns", "the", "power", "state", "of", "this", "VM", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L561-L583
146,125
apcera/libretto
virtualmachine/vsphere/vm.go
Suspend
func (vm *VM) Suspend() (err error) { if err := SetupSession(vm); err != nil { return err } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() // Get a reference to the datacenter with host and vm folders populated dcMo, err := GetDatacenter(vm) if err != nil { return err } vmMo, err := findVM(vm, dcMo, vm.Name) if err != nil { return err } vmo := object.NewVirtualMachine(vm.client.Client, vmMo.Reference()) suspendTask, err := vmo.Suspend(vm.ctx) if err != nil { return fmt.Errorf("error creating a suspend task on the vm: %s", err) } tInfo, err := suspendTask.WaitForResult(vm.ctx, nil) if err != nil { return fmt.Errorf("error waiting for suspend task: %s", err) } if tInfo.Error != nil { return fmt.Errorf("suspend task returned an error: %s", err) } return nil }
go
func (vm *VM) Suspend() (err error) { if err := SetupSession(vm); err != nil { return err } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() // Get a reference to the datacenter with host and vm folders populated dcMo, err := GetDatacenter(vm) if err != nil { return err } vmMo, err := findVM(vm, dcMo, vm.Name) if err != nil { return err } vmo := object.NewVirtualMachine(vm.client.Client, vmMo.Reference()) suspendTask, err := vmo.Suspend(vm.ctx) if err != nil { return fmt.Errorf("error creating a suspend task on the vm: %s", err) } tInfo, err := suspendTask.WaitForResult(vm.ctx, nil) if err != nil { return fmt.Errorf("error waiting for suspend task: %s", err) } if tInfo.Error != nil { return fmt.Errorf("suspend task returned an error: %s", err) } return nil }
[ "func", "(", "vm", "*", "VM", ")", "Suspend", "(", ")", "(", "err", "error", ")", "{", "if", "err", ":=", "SetupSession", "(", "vm", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "func", "(", ")", "{", "vm", ".", "client", ".", "Logout", "(", "vm", ".", "ctx", ")", "\n", "vm", ".", "cancel", "(", ")", "\n", "}", "(", ")", "\n\n", "// Get a reference to the datacenter with host and vm folders populated", "dcMo", ",", "err", ":=", "GetDatacenter", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "vmMo", ",", "err", ":=", "findVM", "(", "vm", ",", "dcMo", ",", "vm", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "vmo", ":=", "object", ".", "NewVirtualMachine", "(", "vm", ".", "client", ".", "Client", ",", "vmMo", ".", "Reference", "(", ")", ")", "\n", "suspendTask", ",", "err", ":=", "vmo", ".", "Suspend", "(", "vm", ".", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "tInfo", ",", "err", ":=", "suspendTask", ".", "WaitForResult", "(", "vm", ".", "ctx", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "tInfo", ".", "Error", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Suspend suspends this VM.
[ "Suspend", "suspends", "this", "VM", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L586-L618
146,126
apcera/libretto
virtualmachine/vsphere/vm.go
Halt
func (vm *VM) Halt() (err error) { if err := SetupSession(vm); err != nil { return err } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() return halt(vm) }
go
func (vm *VM) Halt() (err error) { if err := SetupSession(vm); err != nil { return err } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() return halt(vm) }
[ "func", "(", "vm", "*", "VM", ")", "Halt", "(", ")", "(", "err", "error", ")", "{", "if", "err", ":=", "SetupSession", "(", "vm", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "vm", ".", "client", ".", "Logout", "(", "vm", ".", "ctx", ")", "\n", "vm", ".", "cancel", "(", ")", "\n", "}", "(", ")", "\n\n", "return", "halt", "(", "vm", ")", "\n", "}" ]
// Halt halts this VM.
[ "Halt", "halts", "this", "VM", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L621-L631
146,127
apcera/libretto
virtualmachine/vsphere/vm.go
Start
func (vm *VM) Start() (err error) { if err := SetupSession(vm); err != nil { return err } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() return start(vm) }
go
func (vm *VM) Start() (err error) { if err := SetupSession(vm); err != nil { return err } defer func() { vm.client.Logout(vm.ctx) vm.cancel() }() return start(vm) }
[ "func", "(", "vm", "*", "VM", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "if", "err", ":=", "SetupSession", "(", "vm", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "vm", ".", "client", ".", "Logout", "(", "vm", ".", "ctx", ")", "\n", "vm", ".", "cancel", "(", ")", "\n", "}", "(", ")", "\n\n", "return", "start", "(", "vm", ")", "\n", "}" ]
// Start powers on this VM.
[ "Start", "powers", "on", "this", "VM", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/vm.go#L634-L644
146,128
apcera/libretto
virtualmachine/mockprovider/vm.go
GetSSH
func (vm *VM) GetSSH(options libssh.Options) (libssh.Client, error) { if vm.MockGetSSH != nil { return vm.MockGetSSH(options) } return nil, lvm.ErrNotImplemented }
go
func (vm *VM) GetSSH(options libssh.Options) (libssh.Client, error) { if vm.MockGetSSH != nil { return vm.MockGetSSH(options) } return nil, lvm.ErrNotImplemented }
[ "func", "(", "vm", "*", "VM", ")", "GetSSH", "(", "options", "libssh", ".", "Options", ")", "(", "libssh", ".", "Client", ",", "error", ")", "{", "if", "vm", ".", "MockGetSSH", "!=", "nil", "{", "return", "vm", ".", "MockGetSSH", "(", "options", ")", "\n", "}", "\n", "return", "nil", ",", "lvm", ".", "ErrNotImplemented", "\n", "}" ]
// GetSSH returns an ssh client for the the vm.
[ "GetSSH", "returns", "an", "ssh", "client", "for", "the", "the", "vm", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/mockprovider/vm.go#L37-L42
146,129
apcera/libretto
virtualmachine/mockprovider/vm.go
Resume
func (vm *VM) Resume() error { if vm.MockResume != nil { return vm.MockResume() } return lvm.ErrNotImplemented }
go
func (vm *VM) Resume() error { if vm.MockResume != nil { return vm.MockResume() } return lvm.ErrNotImplemented }
[ "func", "(", "vm", "*", "VM", ")", "Resume", "(", ")", "error", "{", "if", "vm", ".", "MockResume", "!=", "nil", "{", "return", "vm", ".", "MockResume", "(", ")", "\n", "}", "\n", "return", "lvm", ".", "ErrNotImplemented", "\n", "}" ]
// Resume suspends the active state of the VM.
[ "Resume", "suspends", "the", "active", "state", "of", "the", "VM", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/mockprovider/vm.go#L69-L74
146,130
apcera/libretto
virtualmachine/mockprovider/vm.go
GetIPs
func (vm *VM) GetIPs() ([]net.IP, error) { if vm.MockGetIPs != nil { return vm.MockGetIPs() } return []net.IP{}, nil }
go
func (vm *VM) GetIPs() ([]net.IP, error) { if vm.MockGetIPs != nil { return vm.MockGetIPs() } return []net.IP{}, nil }
[ "func", "(", "vm", "*", "VM", ")", "GetIPs", "(", ")", "(", "[", "]", "net", ".", "IP", ",", "error", ")", "{", "if", "vm", ".", "MockGetIPs", "!=", "nil", "{", "return", "vm", ".", "MockGetIPs", "(", ")", "\n", "}", "\n", "return", "[", "]", "net", ".", "IP", "{", "}", ",", "nil", "\n", "}" ]
// GetIPs returns a list of ip addresses associated with the vm through VMware tools
[ "GetIPs", "returns", "a", "list", "of", "ip", "addresses", "associated", "with", "the", "vm", "through", "VMware", "tools" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/mockprovider/vm.go#L85-L90
146,131
apcera/libretto
virtualmachine/mockprovider/vm.go
Provision
func (vm *VM) Provision() error { if vm.MockProvision != nil { return vm.MockProvision() } return lvm.ErrNotImplemented }
go
func (vm *VM) Provision() error { if vm.MockProvision != nil { return vm.MockProvision() } return lvm.ErrNotImplemented }
[ "func", "(", "vm", "*", "VM", ")", "Provision", "(", ")", "error", "{", "if", "vm", ".", "MockProvision", "!=", "nil", "{", "return", "vm", ".", "MockProvision", "(", ")", "\n", "}", "\n", "return", "lvm", ".", "ErrNotImplemented", "\n", "}" ]
// Provision clones this VM and powers it on, while waiting for it to get an IP address.
[ "Provision", "clones", "this", "VM", "and", "powers", "it", "on", "while", "waiting", "for", "it", "to", "get", "an", "IP", "address", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/mockprovider/vm.go#L101-L106
146,132
apcera/libretto
ssh/ssh.go
Connect
func (client *SSHClient) Connect() error { var ( auth cssh.AuthMethod err error ) if err = client.Validate(); err != nil { return err } if client.Creds.SSHPrivateKey != "" { auth, err = getAuth(client.Creds, KeyAuth) if err != nil { return err } } else { auth, err = getAuth(client.Creds, PasswordAuth) if err != nil { return err } } config := &cssh.ClientConfig{ User: client.Creds.SSHUser, Auth: []cssh.AuthMethod{ auth, }, HostKeyCallback: cssh.InsecureIgnoreHostKey(), } port := sshPort if client.Port != 0 { port = client.Port } c, err := dial("tcp", fmt.Sprintf("%s:%d", client.IP, port), config) if err != nil { return err } client.cryptoClient = c client.close = make(chan bool, 1) if client.Options.KeepAlive > 0 { go client.keepAlive() } return nil }
go
func (client *SSHClient) Connect() error { var ( auth cssh.AuthMethod err error ) if err = client.Validate(); err != nil { return err } if client.Creds.SSHPrivateKey != "" { auth, err = getAuth(client.Creds, KeyAuth) if err != nil { return err } } else { auth, err = getAuth(client.Creds, PasswordAuth) if err != nil { return err } } config := &cssh.ClientConfig{ User: client.Creds.SSHUser, Auth: []cssh.AuthMethod{ auth, }, HostKeyCallback: cssh.InsecureIgnoreHostKey(), } port := sshPort if client.Port != 0 { port = client.Port } c, err := dial("tcp", fmt.Sprintf("%s:%d", client.IP, port), config) if err != nil { return err } client.cryptoClient = c client.close = make(chan bool, 1) if client.Options.KeepAlive > 0 { go client.keepAlive() } return nil }
[ "func", "(", "client", "*", "SSHClient", ")", "Connect", "(", ")", "error", "{", "var", "(", "auth", "cssh", ".", "AuthMethod", "\n", "err", "error", "\n", ")", "\n\n", "if", "err", "=", "client", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "client", ".", "Creds", ".", "SSHPrivateKey", "!=", "\"", "\"", "{", "auth", ",", "err", "=", "getAuth", "(", "client", ".", "Creds", ",", "KeyAuth", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "else", "{", "auth", ",", "err", "=", "getAuth", "(", "client", ".", "Creds", ",", "PasswordAuth", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "config", ":=", "&", "cssh", ".", "ClientConfig", "{", "User", ":", "client", ".", "Creds", ".", "SSHUser", ",", "Auth", ":", "[", "]", "cssh", ".", "AuthMethod", "{", "auth", ",", "}", ",", "HostKeyCallback", ":", "cssh", ".", "InsecureIgnoreHostKey", "(", ")", ",", "}", "\n\n", "port", ":=", "sshPort", "\n", "if", "client", ".", "Port", "!=", "0", "{", "port", "=", "client", ".", "Port", "\n", "}", "\n\n", "c", ",", "err", ":=", "dial", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "client", ".", "IP", ",", "port", ")", ",", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "client", ".", "cryptoClient", "=", "c", "\n\n", "client", ".", "close", "=", "make", "(", "chan", "bool", ",", "1", ")", "\n\n", "if", "client", ".", "Options", ".", "KeepAlive", ">", "0", "{", "go", "client", ".", "keepAlive", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Connect connects to a machine using SSH.
[ "Connect", "connects", "to", "a", "machine", "using", "SSH", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/ssh.go#L98-L146
146,133
apcera/libretto
ssh/ssh.go
Run
func (client *SSHClient) Run(command string, stdout io.Writer, stderr io.Writer) error { session, err := client.cryptoClient.NewSession() if err != nil { return err } defer session.Close() session.Stdout = stdout session.Stderr = stderr if client.Options.Pty { modes := cssh.TerminalModes{ cssh.ECHO: 0, cssh.TTY_OP_ISPEED: 14400, cssh.TTY_OP_OSPEED: 14400, } // Request pseudo terminal if err := session.RequestPty(os.Getenv("TERM"), 80, 40, modes); err != nil { return err } } return session.Run(command) }
go
func (client *SSHClient) Run(command string, stdout io.Writer, stderr io.Writer) error { session, err := client.cryptoClient.NewSession() if err != nil { return err } defer session.Close() session.Stdout = stdout session.Stderr = stderr if client.Options.Pty { modes := cssh.TerminalModes{ cssh.ECHO: 0, cssh.TTY_OP_ISPEED: 14400, cssh.TTY_OP_OSPEED: 14400, } // Request pseudo terminal if err := session.RequestPty(os.Getenv("TERM"), 80, 40, modes); err != nil { return err } } return session.Run(command) }
[ "func", "(", "client", "*", "SSHClient", ")", "Run", "(", "command", "string", ",", "stdout", "io", ".", "Writer", ",", "stderr", "io", ".", "Writer", ")", "error", "{", "session", ",", "err", ":=", "client", ".", "cryptoClient", ".", "NewSession", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "session", ".", "Close", "(", ")", "\n\n", "session", ".", "Stdout", "=", "stdout", "\n", "session", ".", "Stderr", "=", "stderr", "\n\n", "if", "client", ".", "Options", ".", "Pty", "{", "modes", ":=", "cssh", ".", "TerminalModes", "{", "cssh", ".", "ECHO", ":", "0", ",", "cssh", ".", "TTY_OP_ISPEED", ":", "14400", ",", "cssh", ".", "TTY_OP_OSPEED", ":", "14400", ",", "}", "\n", "// Request pseudo terminal", "if", "err", ":=", "session", ".", "RequestPty", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ",", "80", ",", "40", ",", "modes", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "session", ".", "Run", "(", "command", ")", "\n", "}" ]
// Run runs a command via SSH.
[ "Run", "runs", "a", "command", "via", "SSH", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/ssh.go#L265-L289
146,134
apcera/libretto
ssh/ssh.go
Validate
func (client *SSHClient) Validate() error { if client.Creds.SSHUser == "" { return ErrInvalidUsername } if client.Creds.SSHPrivateKey == "" && client.Creds.SSHPassword == "" { return ErrInvalidAuth } return nil }
go
func (client *SSHClient) Validate() error { if client.Creds.SSHUser == "" { return ErrInvalidUsername } if client.Creds.SSHPrivateKey == "" && client.Creds.SSHPassword == "" { return ErrInvalidAuth } return nil }
[ "func", "(", "client", "*", "SSHClient", ")", "Validate", "(", ")", "error", "{", "if", "client", ".", "Creds", ".", "SSHUser", "==", "\"", "\"", "{", "return", "ErrInvalidUsername", "\n", "}", "\n\n", "if", "client", ".", "Creds", ".", "SSHPrivateKey", "==", "\"", "\"", "&&", "client", ".", "Creds", ".", "SSHPassword", "==", "\"", "\"", "{", "return", "ErrInvalidAuth", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate verifies that SSH connection credentials were properly configured.
[ "Validate", "verifies", "that", "SSH", "connection", "credentials", "were", "properly", "configured", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/ssh.go#L350-L360
146,135
apcera/libretto
ssh/ssh.go
WaitForSSH
func (client *SSHClient) WaitForSSH(maxWait time.Duration) error { start := time.Now() for { if err := client.Connect(); err == nil { defer client.Disconnect() return nil } timePassed := time.Since(start) if timePassed >= maxWait { break } time.Sleep(5 * time.Second) } return ErrTimeout }
go
func (client *SSHClient) WaitForSSH(maxWait time.Duration) error { start := time.Now() for { if err := client.Connect(); err == nil { defer client.Disconnect() return nil } timePassed := time.Since(start) if timePassed >= maxWait { break } time.Sleep(5 * time.Second) } return ErrTimeout }
[ "func", "(", "client", "*", "SSHClient", ")", "WaitForSSH", "(", "maxWait", "time", ".", "Duration", ")", "error", "{", "start", ":=", "time", ".", "Now", "(", ")", "\n\n", "for", "{", "if", "err", ":=", "client", ".", "Connect", "(", ")", ";", "err", "==", "nil", "{", "defer", "client", ".", "Disconnect", "(", ")", "\n", "return", "nil", "\n", "}", "\n\n", "timePassed", ":=", "time", ".", "Since", "(", "start", ")", "\n", "if", "timePassed", ">=", "maxWait", "{", "break", "\n", "}", "\n\n", "time", ".", "Sleep", "(", "5", "*", "time", ".", "Second", ")", "\n", "}", "\n\n", "return", "ErrTimeout", "\n", "}" ]
// WaitForSSH will try to connect to an SSH server. If it fails, then it'll // sleep for 5 seconds.
[ "WaitForSSH", "will", "try", "to", "connect", "to", "an", "SSH", "server", ".", "If", "it", "fails", "then", "it", "ll", "sleep", "for", "5", "seconds", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/ssh.go#L364-L382
146,136
apcera/libretto
ssh/ssh.go
SetSSHPrivateKey
func (client *SSHClient) SetSSHPrivateKey(s string) { client.Creds.mu.Lock() client.Creds.SSHPrivateKey = s client.Creds.mu.Unlock() }
go
func (client *SSHClient) SetSSHPrivateKey(s string) { client.Creds.mu.Lock() client.Creds.SSHPrivateKey = s client.Creds.mu.Unlock() }
[ "func", "(", "client", "*", "SSHClient", ")", "SetSSHPrivateKey", "(", "s", "string", ")", "{", "client", ".", "Creds", ".", "mu", ".", "Lock", "(", ")", "\n", "client", ".", "Creds", ".", "SSHPrivateKey", "=", "s", "\n", "client", ".", "Creds", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// SetSSHPrivateKey sets the private key on the clients credentials.
[ "SetSSHPrivateKey", "sets", "the", "private", "key", "on", "the", "clients", "credentials", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/ssh.go#L385-L389
146,137
apcera/libretto
ssh/ssh.go
GetSSHPrivateKey
func (client *SSHClient) GetSSHPrivateKey() string { client.Creds.mu.Lock() defer client.Creds.mu.Unlock() return client.Creds.SSHPrivateKey }
go
func (client *SSHClient) GetSSHPrivateKey() string { client.Creds.mu.Lock() defer client.Creds.mu.Unlock() return client.Creds.SSHPrivateKey }
[ "func", "(", "client", "*", "SSHClient", ")", "GetSSHPrivateKey", "(", ")", "string", "{", "client", ".", "Creds", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "client", ".", "Creds", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "client", ".", "Creds", ".", "SSHPrivateKey", "\n", "}" ]
// GetSSHPrivateKey gets the private key on the clients credentials.
[ "GetSSHPrivateKey", "gets", "the", "private", "key", "on", "the", "clients", "credentials", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/ssh.go#L392-L396
146,138
apcera/libretto
ssh/ssh.go
SetSSHPassword
func (client *SSHClient) SetSSHPassword(s string) { client.Creds.mu.Lock() client.Creds.SSHPassword = s client.Creds.mu.Unlock() }
go
func (client *SSHClient) SetSSHPassword(s string) { client.Creds.mu.Lock() client.Creds.SSHPassword = s client.Creds.mu.Unlock() }
[ "func", "(", "client", "*", "SSHClient", ")", "SetSSHPassword", "(", "s", "string", ")", "{", "client", ".", "Creds", ".", "mu", ".", "Lock", "(", ")", "\n", "client", ".", "Creds", ".", "SSHPassword", "=", "s", "\n", "client", ".", "Creds", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// SetSSHPassword sets the SSH password on the clients credentials.
[ "SetSSHPassword", "sets", "the", "SSH", "password", "on", "the", "clients", "credentials", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/ssh.go#L399-L403
146,139
apcera/libretto
ssh/ssh.go
GetSSHPassword
func (client *SSHClient) GetSSHPassword() string { client.Creds.mu.Lock() defer client.Creds.mu.Unlock() return client.Creds.SSHPassword }
go
func (client *SSHClient) GetSSHPassword() string { client.Creds.mu.Lock() defer client.Creds.mu.Unlock() return client.Creds.SSHPassword }
[ "func", "(", "client", "*", "SSHClient", ")", "GetSSHPassword", "(", ")", "string", "{", "client", ".", "Creds", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "client", ".", "Creds", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "client", ".", "Creds", ".", "SSHPassword", "\n", "}" ]
// GetSSHPassword gets the SSH password on the clients credentials.
[ "GetSSHPassword", "gets", "the", "SSH", "password", "on", "the", "clients", "credentials", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/ssh.go#L406-L410
146,140
apcera/libretto
virtualmachine/azure/management/util.go
getClient
func (vm *VM) getClient() (management.Client, error) { mu.Lock() defer mu.Unlock() if client != nil { return client, nil } var err error client, err = management.ClientFromPublishSettingsFile(vm.PublishSettings, "") if err != nil { return nil, err } return client, nil }
go
func (vm *VM) getClient() (management.Client, error) { mu.Lock() defer mu.Unlock() if client != nil { return client, nil } var err error client, err = management.ClientFromPublishSettingsFile(vm.PublishSettings, "") if err != nil { return nil, err } return client, nil }
[ "func", "(", "vm", "*", "VM", ")", "getClient", "(", ")", "(", "management", ".", "Client", ",", "error", ")", "{", "mu", ".", "Lock", "(", ")", "\n", "defer", "mu", ".", "Unlock", "(", ")", "\n", "if", "client", "!=", "nil", "{", "return", "client", ",", "nil", "\n", "}", "\n\n", "var", "err", "error", "\n", "client", ",", "err", "=", "management", ".", "ClientFromPublishSettingsFile", "(", "vm", ".", "PublishSettings", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "client", ",", "nil", "\n", "}" ]
// getClient instantiates an Azure client if necessary and returns a copy of the // client. It returns an error if there is a problem reading or unmarshaling the // .publishSettings file.
[ "getClient", "instantiates", "an", "Azure", "client", "if", "necessary", "and", "returns", "a", "copy", "of", "the", "client", ".", "It", "returns", "an", "error", "if", "there", "is", "a", "problem", "reading", "or", "unmarshaling", "the", ".", "publishSettings", "file", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/management/util.go#L27-L41
146,141
apcera/libretto
virtualmachine/azure/management/util.go
getVMClient
func (vm *VM) getVMClient() (virtualmachine.VirtualMachineClient, error) { c, err := vm.getClient() if err != nil { return virtualmachine.VirtualMachineClient{}, err } return virtualmachine.NewClient(c), nil }
go
func (vm *VM) getVMClient() (virtualmachine.VirtualMachineClient, error) { c, err := vm.getClient() if err != nil { return virtualmachine.VirtualMachineClient{}, err } return virtualmachine.NewClient(c), nil }
[ "func", "(", "vm", "*", "VM", ")", "getVMClient", "(", ")", "(", "virtualmachine", ".", "VirtualMachineClient", ",", "error", ")", "{", "c", ",", "err", ":=", "vm", ".", "getClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "virtualmachine", ".", "VirtualMachineClient", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "virtualmachine", ".", "NewClient", "(", "c", ")", ",", "nil", "\n", "}" ]
// getVMClient returns a new Azure virtual machine client.
[ "getVMClient", "returns", "a", "new", "Azure", "virtual", "machine", "client", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/management/util.go#L44-L51
146,142
apcera/libretto
virtualmachine/azure/management/util.go
getServiceClient
func (vm *VM) getServiceClient() (hostedservice.HostedServiceClient, error) { c, err := vm.getClient() if err != nil { return hostedservice.HostedServiceClient{}, err } return hostedservice.NewClient(c), nil }
go
func (vm *VM) getServiceClient() (hostedservice.HostedServiceClient, error) { c, err := vm.getClient() if err != nil { return hostedservice.HostedServiceClient{}, err } return hostedservice.NewClient(c), nil }
[ "func", "(", "vm", "*", "VM", ")", "getServiceClient", "(", ")", "(", "hostedservice", ".", "HostedServiceClient", ",", "error", ")", "{", "c", ",", "err", ":=", "vm", ".", "getClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "hostedservice", ".", "HostedServiceClient", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "hostedservice", ".", "NewClient", "(", "c", ")", ",", "nil", "\n", "}" ]
// getServiceClient returns a new Azure hosted service client.
[ "getServiceClient", "returns", "a", "new", "Azure", "hosted", "service", "client", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/management/util.go#L54-L61
146,143
apcera/libretto
virtualmachine/azure/management/util.go
getVirtualNetworkClient
func (vm *VM) getVirtualNetworkClient() (virtualnetwork.VirtualNetworkClient, error) { c, err := vm.getClient() if err != nil { return virtualnetwork.VirtualNetworkClient{}, err } return virtualnetwork.NewClient(c), nil }
go
func (vm *VM) getVirtualNetworkClient() (virtualnetwork.VirtualNetworkClient, error) { c, err := vm.getClient() if err != nil { return virtualnetwork.VirtualNetworkClient{}, err } return virtualnetwork.NewClient(c), nil }
[ "func", "(", "vm", "*", "VM", ")", "getVirtualNetworkClient", "(", ")", "(", "virtualnetwork", ".", "VirtualNetworkClient", ",", "error", ")", "{", "c", ",", "err", ":=", "vm", ".", "getClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "virtualnetwork", ".", "VirtualNetworkClient", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "virtualnetwork", ".", "NewClient", "(", "c", ")", ",", "nil", "\n", "}" ]
// getVirtualNetworkClient returns a new virtual network client.
[ "getVirtualNetworkClient", "returns", "a", "new", "virtual", "network", "client", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/management/util.go#L64-L71
146,144
apcera/libretto
virtualmachine/azure/management/util.go
createHostedService
func (vm *VM) createHostedService() error { sc, err := vm.getServiceClient() if err != nil { return fmt.Errorf(errGetClient, err) } // create hosted service if err := sc.CreateHostedService(hostedservice.CreateHostedServiceParameters{ ServiceName: vm.ServiceName, Location: vm.Location, Label: base64.StdEncoding.EncodeToString([]byte(vm.Label))}); err != nil { return err } if vm.Cert.Data != nil { err = vm.addAddCertificate() if err != nil { return err } } return nil }
go
func (vm *VM) createHostedService() error { sc, err := vm.getServiceClient() if err != nil { return fmt.Errorf(errGetClient, err) } // create hosted service if err := sc.CreateHostedService(hostedservice.CreateHostedServiceParameters{ ServiceName: vm.ServiceName, Location: vm.Location, Label: base64.StdEncoding.EncodeToString([]byte(vm.Label))}); err != nil { return err } if vm.Cert.Data != nil { err = vm.addAddCertificate() if err != nil { return err } } return nil }
[ "func", "(", "vm", "*", "VM", ")", "createHostedService", "(", ")", "error", "{", "sc", ",", "err", ":=", "vm", ".", "getServiceClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "errGetClient", ",", "err", ")", "\n", "}", "\n\n", "// create hosted service", "if", "err", ":=", "sc", ".", "CreateHostedService", "(", "hostedservice", ".", "CreateHostedServiceParameters", "{", "ServiceName", ":", "vm", ".", "ServiceName", ",", "Location", ":", "vm", ".", "Location", ",", "Label", ":", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "[", "]", "byte", "(", "vm", ".", "Label", ")", ")", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "vm", ".", "Cert", ".", "Data", "!=", "nil", "{", "err", "=", "vm", ".", "addAddCertificate", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// createHostedService creates a hosted service on Azure.
[ "createHostedService", "creates", "a", "hosted", "service", "on", "Azure", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/management/util.go#L74-L97
146,145
apcera/libretto
virtualmachine/azure/management/util.go
deleteHostedService
func (vm *VM) deleteHostedService() error { sc, err := vm.getServiceClient() if err != nil { return fmt.Errorf(errGetClient, err) } // Delete hosted service _, err = sc.DeleteHostedService(vm.ServiceName, true) return err }
go
func (vm *VM) deleteHostedService() error { sc, err := vm.getServiceClient() if err != nil { return fmt.Errorf(errGetClient, err) } // Delete hosted service _, err = sc.DeleteHostedService(vm.ServiceName, true) return err }
[ "func", "(", "vm", "*", "VM", ")", "deleteHostedService", "(", ")", "error", "{", "sc", ",", "err", ":=", "vm", ".", "getServiceClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "errGetClient", ",", "err", ")", "\n", "}", "\n\n", "// Delete hosted service", "_", ",", "err", "=", "sc", ".", "DeleteHostedService", "(", "vm", ".", "ServiceName", ",", "true", ")", "\n", "return", "err", "\n", "}" ]
// deleteHostedService deletes a hosted service on Azure.
[ "deleteHostedService", "deletes", "a", "hosted", "service", "on", "Azure", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/management/util.go#L100-L109
146,146
apcera/libretto
virtualmachine/azure/management/util.go
listHostedServices
func (vm *VM) listHostedServices() ([]hostedservice.HostedService, error) { sc, err := vm.getServiceClient() if err != nil { return nil, fmt.Errorf(errGetClient, err) } resp, err := sc.ListHostedServices() if err != nil { return nil, err } return resp.HostedServices, nil }
go
func (vm *VM) listHostedServices() ([]hostedservice.HostedService, error) { sc, err := vm.getServiceClient() if err != nil { return nil, fmt.Errorf(errGetClient, err) } resp, err := sc.ListHostedServices() if err != nil { return nil, err } return resp.HostedServices, nil }
[ "func", "(", "vm", "*", "VM", ")", "listHostedServices", "(", ")", "(", "[", "]", "hostedservice", ".", "HostedService", ",", "error", ")", "{", "sc", ",", "err", ":=", "vm", ".", "getServiceClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "errGetClient", ",", "err", ")", "\n", "}", "\n\n", "resp", ",", "err", ":=", "sc", ".", "ListHostedServices", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "resp", ".", "HostedServices", ",", "nil", "\n", "}" ]
// listHostedServices lists all the hosted services under the current account.
[ "listHostedServices", "lists", "all", "the", "hosted", "services", "under", "the", "current", "account", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/management/util.go#L112-L124
146,147
apcera/libretto
virtualmachine/azure/management/util.go
addAddCertificate
func (vm *VM) addAddCertificate() error { sc, err := vm.getServiceClient() if err != nil { return fmt.Errorf(errGetClient, err) } _, err = sc.AddCertificate(vm.Name, vm.Cert.Data, hostedservice.CertificateFormat(vm.Cert.Format), vm.SSHCreds.SSHPassword) return err }
go
func (vm *VM) addAddCertificate() error { sc, err := vm.getServiceClient() if err != nil { return fmt.Errorf(errGetClient, err) } _, err = sc.AddCertificate(vm.Name, vm.Cert.Data, hostedservice.CertificateFormat(vm.Cert.Format), vm.SSHCreds.SSHPassword) return err }
[ "func", "(", "vm", "*", "VM", ")", "addAddCertificate", "(", ")", "error", "{", "sc", ",", "err", ":=", "vm", ".", "getServiceClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "errGetClient", ",", "err", ")", "\n", "}", "\n\n", "_", ",", "err", "=", "sc", ".", "AddCertificate", "(", "vm", ".", "Name", ",", "vm", ".", "Cert", ".", "Data", ",", "hostedservice", ".", "CertificateFormat", "(", "vm", ".", "Cert", ".", "Format", ")", ",", "vm", ".", "SSHCreds", ".", "SSHPassword", ")", "\n", "return", "err", "\n", "}" ]
// addAddCertificate adds certs to a hosted service.
[ "addAddCertificate", "adds", "certs", "to", "a", "hosted", "service", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/management/util.go#L127-L135
146,148
apcera/libretto
virtualmachine/azure/management/util.go
serviceExist
func (vm *VM) serviceExist(services []hostedservice.HostedService) bool { for _, srv := range services { if srv.ServiceName == vm.ServiceName { return true } } return false }
go
func (vm *VM) serviceExist(services []hostedservice.HostedService) bool { for _, srv := range services { if srv.ServiceName == vm.ServiceName { return true } } return false }
[ "func", "(", "vm", "*", "VM", ")", "serviceExist", "(", "services", "[", "]", "hostedservice", ".", "HostedService", ")", "bool", "{", "for", "_", ",", "srv", ":=", "range", "services", "{", "if", "srv", ".", "ServiceName", "==", "vm", ".", "ServiceName", "{", "return", "true", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// serviceExist checks if the desired service name already exists.
[ "serviceExist", "checks", "if", "the", "desired", "service", "name", "already", "exists", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/management/util.go#L138-L146
146,149
apcera/libretto
virtualmachine/azure/management/util.go
getFirstSubnet
func (vm *VM) getFirstSubnet() (string, error) { vc, err := vm.getVirtualNetworkClient() if err != nil { return "", fmt.Errorf(errGetClient, err) } nc, err := vc.GetVirtualNetworkConfiguration() if err != nil { return "", fmt.Errorf("Error to get VirtualNetwork Configuration : %s", err) } for _, vns := range nc.Configuration.VirtualNetworkSites { if vns.Name == vm.DeployOptions.VirtualNetworkName { if len(vns.Subnets) == 0 { return "", fmt.Errorf("No subnet in the virtual network") } return vns.Subnets[0].Name, nil } } return "", fmt.Errorf("VirtualNetwork %s is not found", vm.DeployOptions.VirtualNetworkName) }
go
func (vm *VM) getFirstSubnet() (string, error) { vc, err := vm.getVirtualNetworkClient() if err != nil { return "", fmt.Errorf(errGetClient, err) } nc, err := vc.GetVirtualNetworkConfiguration() if err != nil { return "", fmt.Errorf("Error to get VirtualNetwork Configuration : %s", err) } for _, vns := range nc.Configuration.VirtualNetworkSites { if vns.Name == vm.DeployOptions.VirtualNetworkName { if len(vns.Subnets) == 0 { return "", fmt.Errorf("No subnet in the virtual network") } return vns.Subnets[0].Name, nil } } return "", fmt.Errorf("VirtualNetwork %s is not found", vm.DeployOptions.VirtualNetworkName) }
[ "func", "(", "vm", "*", "VM", ")", "getFirstSubnet", "(", ")", "(", "string", ",", "error", ")", "{", "vc", ",", "err", ":=", "vm", ".", "getVirtualNetworkClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "errGetClient", ",", "err", ")", "\n", "}", "\n\n", "nc", ",", "err", ":=", "vc", ".", "GetVirtualNetworkConfiguration", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "vns", ":=", "range", "nc", ".", "Configuration", ".", "VirtualNetworkSites", "{", "if", "vns", ".", "Name", "==", "vm", ".", "DeployOptions", ".", "VirtualNetworkName", "{", "if", "len", "(", "vns", ".", "Subnets", ")", "==", "0", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "vns", ".", "Subnets", "[", "0", "]", ".", "Name", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vm", ".", "DeployOptions", ".", "VirtualNetworkName", ")", "\n", "}" ]
// getFirstSubnet gets the name of the first subnet within the VM's virtual // network.
[ "getFirstSubnet", "gets", "the", "name", "of", "the", "first", "subnet", "within", "the", "VM", "s", "virtual", "network", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/management/util.go#L158-L180
146,150
apcera/libretto
virtualmachine/digitalocean/util.go
BuildRequest
func BuildRequest(token, method, url string, body io.Reader) (*http.Request, error) { req, err := http.NewRequest(method, url, body) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer "+token) return req, nil }
go
func BuildRequest(token, method, url string, body io.Reader) (*http.Request, error) { req, err := http.NewRequest(method, url, body) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer "+token) return req, nil }
[ "func", "BuildRequest", "(", "token", ",", "method", ",", "url", "string", ",", "body", "io", ".", "Reader", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "method", ",", "url", ",", "body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", "+", "token", ")", "\n\n", "return", "req", ",", "nil", "\n", "}" ]
// BuildRequest builds an http request for this provider.
[ "BuildRequest", "builds", "an", "http", "request", "for", "this", "provider", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/digitalocean/util.go#L14-L23
146,151
apcera/libretto
virtualmachine/digitalocean/util.go
GetDroplets
func GetDroplets(token string) (*DropletsResponse, error) { client := &http.Client{} req, err := BuildRequest(token, "GET", apiBaseURL+apiDropletURL, nil) if err != nil { return nil, err } rsp, err := client.Do(req) if err != nil { return nil, err } defer rsp.Body.Close() b, err := ioutil.ReadAll(rsp.Body) if err != nil { return nil, err } if rsp.Status[0] != StatusOk { return nil, fmt.Errorf("Error: %s: %s", rsp.Status, string(b)) } r := &DropletsResponse{} err = json.Unmarshal(b, r) if err != nil { return nil, err } return r, nil }
go
func GetDroplets(token string) (*DropletsResponse, error) { client := &http.Client{} req, err := BuildRequest(token, "GET", apiBaseURL+apiDropletURL, nil) if err != nil { return nil, err } rsp, err := client.Do(req) if err != nil { return nil, err } defer rsp.Body.Close() b, err := ioutil.ReadAll(rsp.Body) if err != nil { return nil, err } if rsp.Status[0] != StatusOk { return nil, fmt.Errorf("Error: %s: %s", rsp.Status, string(b)) } r := &DropletsResponse{} err = json.Unmarshal(b, r) if err != nil { return nil, err } return r, nil }
[ "func", "GetDroplets", "(", "token", "string", ")", "(", "*", "DropletsResponse", ",", "error", ")", "{", "client", ":=", "&", "http", ".", "Client", "{", "}", "\n", "req", ",", "err", ":=", "BuildRequest", "(", "token", ",", "\"", "\"", ",", "apiBaseURL", "+", "apiDropletURL", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "rsp", ",", "err", ":=", "client", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "rsp", ".", "Body", ".", "Close", "(", ")", "\n", "b", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "rsp", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "rsp", ".", "Status", "[", "0", "]", "!=", "StatusOk", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "rsp", ".", "Status", ",", "string", "(", "b", ")", ")", "\n", "}", "\n\n", "r", ":=", "&", "DropletsResponse", "{", "}", "\n", "err", "=", "json", ".", "Unmarshal", "(", "b", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "r", ",", "nil", "\n", "}" ]
// GetDroplets returns and array of droplets
[ "GetDroplets", "returns", "and", "array", "of", "droplets" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/digitalocean/util.go#L61-L86
146,152
apcera/libretto
virtualmachine/digitalocean/util.go
PrintDroplet
func PrintDroplet(droplet *Droplet) { fmt.Println("ID:", droplet.ID) fmt.Println("Name:", droplet.Name) fmt.Println("Status:", droplet.Status) fmt.Println("Locked:", fmt.Sprintf("%t", droplet.Locked)) fmt.Println("CreatedAt:", droplet.CreatedAt.Format("2006-01-02 15:04:05")) fmt.Println("SizeSlug:", droplet.Size.Slug) fmt.Println("Region:", droplet.Region.Name) fmt.Println("Image:", droplet.Image.Name) for i, ip := range droplet.Networks.V4 { fmt.Println(fmt.Sprintf("IP: %d", i+1), ip.IPAddress, ip.Type) } for i, ip := range droplet.Networks.V6 { fmt.Println(fmt.Sprintf("IP: %d", i+1), ip.IPAddress, ip.Type) } }
go
func PrintDroplet(droplet *Droplet) { fmt.Println("ID:", droplet.ID) fmt.Println("Name:", droplet.Name) fmt.Println("Status:", droplet.Status) fmt.Println("Locked:", fmt.Sprintf("%t", droplet.Locked)) fmt.Println("CreatedAt:", droplet.CreatedAt.Format("2006-01-02 15:04:05")) fmt.Println("SizeSlug:", droplet.Size.Slug) fmt.Println("Region:", droplet.Region.Name) fmt.Println("Image:", droplet.Image.Name) for i, ip := range droplet.Networks.V4 { fmt.Println(fmt.Sprintf("IP: %d", i+1), ip.IPAddress, ip.Type) } for i, ip := range droplet.Networks.V6 { fmt.Println(fmt.Sprintf("IP: %d", i+1), ip.IPAddress, ip.Type) } }
[ "func", "PrintDroplet", "(", "droplet", "*", "Droplet", ")", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "droplet", ".", "ID", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "droplet", ".", "Name", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "droplet", ".", "Status", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "droplet", ".", "Locked", ")", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "droplet", ".", "CreatedAt", ".", "Format", "(", "\"", "\"", ")", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "droplet", ".", "Size", ".", "Slug", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "droplet", ".", "Region", ".", "Name", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "droplet", ".", "Image", ".", "Name", ")", "\n", "for", "i", ",", "ip", ":=", "range", "droplet", ".", "Networks", ".", "V4", "{", "fmt", ".", "Println", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", "+", "1", ")", ",", "ip", ".", "IPAddress", ",", "ip", ".", "Type", ")", "\n", "}", "\n", "for", "i", ",", "ip", ":=", "range", "droplet", ".", "Networks", ".", "V6", "{", "fmt", ".", "Println", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", "+", "1", ")", ",", "ip", ".", "IPAddress", ",", "ip", ".", "Type", ")", "\n", "}", "\n", "}" ]
// PrintDroplet prints the basic droplet values
[ "PrintDroplet", "prints", "the", "basic", "droplet", "values" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/digitalocean/util.go#L89-L104
146,153
apcera/libretto
virtualmachine/aws/vm.go
SetTag
func (vm *VM) SetTag(key, value string) error { svc, err := getService(vm.Region) if err != nil { return fmt.Errorf("failed to get AWS service: %v", err) } if vm.InstanceID == "" { return ErrNoInstanceID } volIDs, err := getInstanceVolumeIDs(svc, vm.InstanceID) if err != nil { return fmt.Errorf("Failed to get instance's volumes IDs: %s", err) } ids := make([]*string, 0, len(volIDs)+1) ids = append(ids, aws.String(vm.InstanceID)) for _, v := range volIDs { ids = append(ids, aws.String(v)) } _, err = svc.CreateTags(&ec2.CreateTagsInput{ Resources: ids, Tags: []*ec2.Tag{ {Key: aws.String(key), Value: aws.String(value)}, }, }) if err != nil { return fmt.Errorf("Failed to create tag on VM: %v", err) } return nil }
go
func (vm *VM) SetTag(key, value string) error { svc, err := getService(vm.Region) if err != nil { return fmt.Errorf("failed to get AWS service: %v", err) } if vm.InstanceID == "" { return ErrNoInstanceID } volIDs, err := getInstanceVolumeIDs(svc, vm.InstanceID) if err != nil { return fmt.Errorf("Failed to get instance's volumes IDs: %s", err) } ids := make([]*string, 0, len(volIDs)+1) ids = append(ids, aws.String(vm.InstanceID)) for _, v := range volIDs { ids = append(ids, aws.String(v)) } _, err = svc.CreateTags(&ec2.CreateTagsInput{ Resources: ids, Tags: []*ec2.Tag{ {Key: aws.String(key), Value: aws.String(value)}, }, }) if err != nil { return fmt.Errorf("Failed to create tag on VM: %v", err) } return nil }
[ "func", "(", "vm", "*", "VM", ")", "SetTag", "(", "key", ",", "value", "string", ")", "error", "{", "svc", ",", "err", ":=", "getService", "(", "vm", ".", "Region", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "vm", ".", "InstanceID", "==", "\"", "\"", "{", "return", "ErrNoInstanceID", "\n", "}", "\n\n", "volIDs", ",", "err", ":=", "getInstanceVolumeIDs", "(", "svc", ",", "vm", ".", "InstanceID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "ids", ":=", "make", "(", "[", "]", "*", "string", ",", "0", ",", "len", "(", "volIDs", ")", "+", "1", ")", "\n", "ids", "=", "append", "(", "ids", ",", "aws", ".", "String", "(", "vm", ".", "InstanceID", ")", ")", "\n", "for", "_", ",", "v", ":=", "range", "volIDs", "{", "ids", "=", "append", "(", "ids", ",", "aws", ".", "String", "(", "v", ")", ")", "\n", "}", "\n\n", "_", ",", "err", "=", "svc", ".", "CreateTags", "(", "&", "ec2", ".", "CreateTagsInput", "{", "Resources", ":", "ids", ",", "Tags", ":", "[", "]", "*", "ec2", ".", "Tag", "{", "{", "Key", ":", "aws", ".", "String", "(", "key", ")", ",", "Value", ":", "aws", ".", "String", "(", "value", ")", "}", ",", "}", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// SetTag adds a tag to the VM and its attached volumes.
[ "SetTag", "adds", "a", "tag", "to", "the", "VM", "and", "its", "attached", "volumes", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/vm.go#L109-L142
146,154
apcera/libretto
virtualmachine/aws/vm.go
SetTags
func (vm *VM) SetTags(tags map[string]string) error { for k, v := range tags { if err := vm.SetTag(k, v); err != nil { return err } } return nil }
go
func (vm *VM) SetTags(tags map[string]string) error { for k, v := range tags { if err := vm.SetTag(k, v); err != nil { return err } } return nil }
[ "func", "(", "vm", "*", "VM", ")", "SetTags", "(", "tags", "map", "[", "string", "]", "string", ")", "error", "{", "for", "k", ",", "v", ":=", "range", "tags", "{", "if", "err", ":=", "vm", ".", "SetTag", "(", "k", ",", "v", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SetTags takes in a map of tags to set to the provisioned instance. This is // essentially a shorter way than calling SetTag many times.
[ "SetTags", "takes", "in", "a", "map", "of", "tags", "to", "set", "to", "the", "provisioned", "instance", ".", "This", "is", "essentially", "a", "shorter", "way", "than", "calling", "SetTag", "many", "times", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/vm.go#L146-L153
146,155
apcera/libretto
virtualmachine/aws/vm.go
Provision
func (vm *VM) Provision() error { wait() // Avoid the AWS rate limit. svc, err := getService(vm.Region) if err != nil { return fmt.Errorf("failed to get AWS service: %v", err) } resp, err := svc.RunInstances(instanceInfo(vm)) if err != nil { return fmt.Errorf("Failed to create instance: %v", err) } if hasInstanceID(resp.Instances[0]) { vm.InstanceID = *resp.Instances[0].InstanceId } else { return ErrNoInstanceID } if err := waitUntilReady(svc, vm.InstanceID); err != nil { return err } if vm.DeleteNonRootVolumeOnDestroy { return setNonRootDeleteOnDestroy(svc, vm.InstanceID, true) } if vm.Name != "" { if err := vm.SetTag("Name", vm.GetName()); err != nil { return err } } return nil }
go
func (vm *VM) Provision() error { wait() // Avoid the AWS rate limit. svc, err := getService(vm.Region) if err != nil { return fmt.Errorf("failed to get AWS service: %v", err) } resp, err := svc.RunInstances(instanceInfo(vm)) if err != nil { return fmt.Errorf("Failed to create instance: %v", err) } if hasInstanceID(resp.Instances[0]) { vm.InstanceID = *resp.Instances[0].InstanceId } else { return ErrNoInstanceID } if err := waitUntilReady(svc, vm.InstanceID); err != nil { return err } if vm.DeleteNonRootVolumeOnDestroy { return setNonRootDeleteOnDestroy(svc, vm.InstanceID, true) } if vm.Name != "" { if err := vm.SetTag("Name", vm.GetName()); err != nil { return err } } return nil }
[ "func", "(", "vm", "*", "VM", ")", "Provision", "(", ")", "error", "{", "wait", "(", ")", "// Avoid the AWS rate limit.", "\n\n", "svc", ",", "err", ":=", "getService", "(", "vm", ".", "Region", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "resp", ",", "err", ":=", "svc", ".", "RunInstances", "(", "instanceInfo", "(", "vm", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "hasInstanceID", "(", "resp", ".", "Instances", "[", "0", "]", ")", "{", "vm", ".", "InstanceID", "=", "*", "resp", ".", "Instances", "[", "0", "]", ".", "InstanceId", "\n", "}", "else", "{", "return", "ErrNoInstanceID", "\n", "}", "\n\n", "if", "err", ":=", "waitUntilReady", "(", "svc", ",", "vm", ".", "InstanceID", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "vm", ".", "DeleteNonRootVolumeOnDestroy", "{", "return", "setNonRootDeleteOnDestroy", "(", "svc", ",", "vm", ".", "InstanceID", ",", "true", ")", "\n", "}", "\n\n", "if", "vm", ".", "Name", "!=", "\"", "\"", "{", "if", "err", ":=", "vm", ".", "SetTag", "(", "\"", "\"", ",", "vm", ".", "GetName", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Provision creates a virtual machine on AWS. It returns an error if // there was a problem during creation, if there was a problem adding a tag, or // if the VM takes too long to enter "running" state.
[ "Provision", "creates", "a", "virtual", "machine", "on", "AWS", ".", "It", "returns", "an", "error", "if", "there", "was", "a", "problem", "during", "creation", "if", "there", "was", "a", "problem", "adding", "a", "tag", "or", "if", "the", "VM", "takes", "too", "long", "to", "enter", "running", "state", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/vm.go#L158-L192
146,156
apcera/libretto
virtualmachine/aws/vm.go
wait
func wait() { const maxWait = 1 * time.Minute now := time.Now().UTC() mu.Lock() wait := getWaitTime(now, maxWait) mu.Unlock() time.Sleep(wait) interval := 500 * time.Millisecond if wait == maxWait { interval = maxWait } mu.Lock() defer mu.Unlock() if now.Before(nextProvision) { nextProvision = nextProvision.Add(interval) return } now = time.Now().UTC() nextProvision = now.Add(interval) }
go
func wait() { const maxWait = 1 * time.Minute now := time.Now().UTC() mu.Lock() wait := getWaitTime(now, maxWait) mu.Unlock() time.Sleep(wait) interval := 500 * time.Millisecond if wait == maxWait { interval = maxWait } mu.Lock() defer mu.Unlock() if now.Before(nextProvision) { nextProvision = nextProvision.Add(interval) return } now = time.Now().UTC() nextProvision = now.Add(interval) }
[ "func", "wait", "(", ")", "{", "const", "maxWait", "=", "1", "*", "time", ".", "Minute", "\n\n", "now", ":=", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", "\n", "mu", ".", "Lock", "(", ")", "\n", "wait", ":=", "getWaitTime", "(", "now", ",", "maxWait", ")", "\n", "mu", ".", "Unlock", "(", ")", "\n\n", "time", ".", "Sleep", "(", "wait", ")", "\n\n", "interval", ":=", "500", "*", "time", ".", "Millisecond", "\n", "if", "wait", "==", "maxWait", "{", "interval", "=", "maxWait", "\n", "}", "\n\n", "mu", ".", "Lock", "(", ")", "\n", "defer", "mu", ".", "Unlock", "(", ")", "\n", "if", "now", ".", "Before", "(", "nextProvision", ")", "{", "nextProvision", "=", "nextProvision", ".", "Add", "(", "interval", ")", "\n", "return", "\n", "}", "\n", "now", "=", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", "\n", "nextProvision", "=", "now", ".", "Add", "(", "interval", ")", "\n", "}" ]
// wait implements a rate limiter that prevents more than one call every // 0.5s. The maximum time that the caller can be delayed is 1m.
[ "wait", "implements", "a", "rate", "limiter", "that", "prevents", "more", "than", "one", "call", "every", "0", ".", "5s", ".", "The", "maximum", "time", "that", "the", "caller", "can", "be", "delayed", "is", "1m", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/vm.go#L196-L219
146,157
apcera/libretto
virtualmachine/aws/vm.go
Destroy
func (vm *VM) Destroy() error { svc, err := getService(vm.Region) if err != nil { return fmt.Errorf("failed to get AWS service: %v", err) } if vm.InstanceID == "" { // Probably need to call Provision first. return ErrNoInstanceID } _, err = svc.TerminateInstances(&ec2.TerminateInstancesInput{ InstanceIds: []*string{ aws.String(vm.InstanceID), }, }) if err != nil { return err } if !vm.DeleteKeysOnDestroy { return nil } vm.ResetKeyPair() return nil }
go
func (vm *VM) Destroy() error { svc, err := getService(vm.Region) if err != nil { return fmt.Errorf("failed to get AWS service: %v", err) } if vm.InstanceID == "" { // Probably need to call Provision first. return ErrNoInstanceID } _, err = svc.TerminateInstances(&ec2.TerminateInstancesInput{ InstanceIds: []*string{ aws.String(vm.InstanceID), }, }) if err != nil { return err } if !vm.DeleteKeysOnDestroy { return nil } vm.ResetKeyPair() return nil }
[ "func", "(", "vm", "*", "VM", ")", "Destroy", "(", ")", "error", "{", "svc", ",", "err", ":=", "getService", "(", "vm", ".", "Region", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "vm", ".", "InstanceID", "==", "\"", "\"", "{", "// Probably need to call Provision first.", "return", "ErrNoInstanceID", "\n", "}", "\n", "_", ",", "err", "=", "svc", ".", "TerminateInstances", "(", "&", "ec2", ".", "TerminateInstancesInput", "{", "InstanceIds", ":", "[", "]", "*", "string", "{", "aws", ".", "String", "(", "vm", ".", "InstanceID", ")", ",", "}", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "!", "vm", ".", "DeleteKeysOnDestroy", "{", "return", "nil", "\n", "}", "\n\n", "vm", ".", "ResetKeyPair", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Destroy terminates the VM on AWS. It returns an error if AWS credentials are // missing or if there is no instance ID.
[ "Destroy", "terminates", "the", "VM", "on", "AWS", ".", "It", "returns", "an", "error", "if", "AWS", "credentials", "are", "missing", "or", "if", "there", "is", "no", "instance", "ID", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/vm.go#L281-L306
146,158
apcera/libretto
virtualmachine/aws/vm.go
GetState
func (vm *VM) GetState() (string, error) { svc, err := getService(vm.Region) if err != nil { return "", fmt.Errorf("failed to get AWS service: %v", err) } if vm.InstanceID == "" { // Probably need to call Provision first. return "", ErrNoInstanceID } stat, err := svc.DescribeInstances(&ec2.DescribeInstancesInput{ InstanceIds: []*string{ aws.String(vm.InstanceID), }, }) if err != nil { return "", fmt.Errorf("Failed to describe instance: %s", err) } if n := len(stat.Reservations); n < 1 { return "", ErrNoInstance } if n := len(stat.Reservations[0].Instances); n < 1 { return "", ErrNoInstance } return *stat.Reservations[0].Instances[0].State.Name, nil }
go
func (vm *VM) GetState() (string, error) { svc, err := getService(vm.Region) if err != nil { return "", fmt.Errorf("failed to get AWS service: %v", err) } if vm.InstanceID == "" { // Probably need to call Provision first. return "", ErrNoInstanceID } stat, err := svc.DescribeInstances(&ec2.DescribeInstancesInput{ InstanceIds: []*string{ aws.String(vm.InstanceID), }, }) if err != nil { return "", fmt.Errorf("Failed to describe instance: %s", err) } if n := len(stat.Reservations); n < 1 { return "", ErrNoInstance } if n := len(stat.Reservations[0].Instances); n < 1 { return "", ErrNoInstance } return *stat.Reservations[0].Instances[0].State.Name, nil }
[ "func", "(", "vm", "*", "VM", ")", "GetState", "(", ")", "(", "string", ",", "error", ")", "{", "svc", ",", "err", ":=", "getService", "(", "vm", ".", "Region", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "vm", ".", "InstanceID", "==", "\"", "\"", "{", "// Probably need to call Provision first.", "return", "\"", "\"", ",", "ErrNoInstanceID", "\n", "}", "\n\n", "stat", ",", "err", ":=", "svc", ".", "DescribeInstances", "(", "&", "ec2", ".", "DescribeInstancesInput", "{", "InstanceIds", ":", "[", "]", "*", "string", "{", "aws", ".", "String", "(", "vm", ".", "InstanceID", ")", ",", "}", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "n", ":=", "len", "(", "stat", ".", "Reservations", ")", ";", "n", "<", "1", "{", "return", "\"", "\"", ",", "ErrNoInstance", "\n", "}", "\n", "if", "n", ":=", "len", "(", "stat", ".", "Reservations", "[", "0", "]", ".", "Instances", ")", ";", "n", "<", "1", "{", "return", "\"", "\"", ",", "ErrNoInstance", "\n", "}", "\n\n", "return", "*", "stat", ".", "Reservations", "[", "0", "]", ".", "Instances", "[", "0", "]", ".", "State", ".", "Name", ",", "nil", "\n", "}" ]
// GetState returns the state of the VM, such as "running". An error is // returned if the instance ID is missing, if there was a problem querying AWS, // or if there are no instances.
[ "GetState", "returns", "the", "state", "of", "the", "VM", "such", "as", "running", ".", "An", "error", "is", "returned", "if", "the", "instance", "ID", "is", "missing", "if", "there", "was", "a", "problem", "querying", "AWS", "or", "if", "there", "are", "no", "instances", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/vm.go#L331-L359
146,159
apcera/libretto
virtualmachine/aws/vm.go
Halt
func (vm *VM) Halt() error { svc, err := getService(vm.Region) if err != nil { return fmt.Errorf("failed to get AWS service: %v", err) } if vm.InstanceID == "" { // Probably need to call Provision first. return ErrNoInstanceID } _, err = svc.StopInstances(&ec2.StopInstancesInput{ InstanceIds: []*string{ aws.String(vm.InstanceID), }, DryRun: aws.Bool(false), Force: aws.Bool(true), }) if err != nil { return fmt.Errorf("Failed to stop instance: %v", err) } return nil }
go
func (vm *VM) Halt() error { svc, err := getService(vm.Region) if err != nil { return fmt.Errorf("failed to get AWS service: %v", err) } if vm.InstanceID == "" { // Probably need to call Provision first. return ErrNoInstanceID } _, err = svc.StopInstances(&ec2.StopInstancesInput{ InstanceIds: []*string{ aws.String(vm.InstanceID), }, DryRun: aws.Bool(false), Force: aws.Bool(true), }) if err != nil { return fmt.Errorf("Failed to stop instance: %v", err) } return nil }
[ "func", "(", "vm", "*", "VM", ")", "Halt", "(", ")", "error", "{", "svc", ",", "err", ":=", "getService", "(", "vm", ".", "Region", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "vm", ".", "InstanceID", "==", "\"", "\"", "{", "// Probably need to call Provision first.", "return", "ErrNoInstanceID", "\n", "}", "\n\n", "_", ",", "err", "=", "svc", ".", "StopInstances", "(", "&", "ec2", ".", "StopInstancesInput", "{", "InstanceIds", ":", "[", "]", "*", "string", "{", "aws", ".", "String", "(", "vm", ".", "InstanceID", ")", ",", "}", ",", "DryRun", ":", "aws", ".", "Bool", "(", "false", ")", ",", "Force", ":", "aws", ".", "Bool", "(", "true", ")", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Halt shuts down the VM on AWS.
[ "Halt", "shuts", "down", "the", "VM", "on", "AWS", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/vm.go#L362-L385
146,160
apcera/libretto
virtualmachine/aws/vm.go
SetKeyPair
func (vm *VM) SetKeyPair(privateKey string, name string) { vm.SSHCreds.SSHPrivateKey = privateKey vm.KeyPair = name }
go
func (vm *VM) SetKeyPair(privateKey string, name string) { vm.SSHCreds.SSHPrivateKey = privateKey vm.KeyPair = name }
[ "func", "(", "vm", "*", "VM", ")", "SetKeyPair", "(", "privateKey", "string", ",", "name", "string", ")", "{", "vm", ".", "SSHCreds", ".", "SSHPrivateKey", "=", "privateKey", "\n", "vm", ".", "KeyPair", "=", "name", "\n", "}" ]
// SetKeyPair sets the given private key and AWS key name for this vm
[ "SetKeyPair", "sets", "the", "given", "private", "key", "and", "AWS", "key", "name", "for", "this", "vm" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/vm.go#L423-L426
146,161
apcera/libretto
virtualmachine/openstack/vm.go
Destroy
func (vm *VM) Destroy() error { if vm.InstanceID == "" { // Probably need to call Provision first. return ErrNoInstanceID } client, err := getComputeClient(vm) if err != nil { return fmt.Errorf("compute client is not set for the VM, %s", err) } // Delete the floating IP first before destroying the VM var errors []error if vm.FloatingIP != nil { err = floatingips.DisassociateInstance(client, vm.InstanceID, floatingips.DisassociateOpts{FloatingIP: vm.FloatingIP.IP}).ExtractErr() if err != nil { errors = append(errors, fmt.Errorf("unable to disassociate floating ip from instance: %s", err)) } else { err = floatingips.Delete(client, vm.FloatingIP.ID).ExtractErr() if err != nil { errors = append(errors, fmt.Errorf("unable to delete floating ip: %s", err)) } } } // De-attach and delete the volume, if there is an attached one if vm.Volume.ID != "" { err = deattachAndDeleteVolume(vm) if err != nil { errors = append(errors, err) } } // Delete the instance err = deleteVM(client, vm.InstanceID) if err != nil { errors = append(errors, err) } // Return all the errors var returnedErr error if len(errors) > 0 { for i, err := range errors { if i == 0 { returnedErr = err continue } returnedErr = fmt.Errorf("%s, %s", returnedErr, err) } } vm.computeClient = nil return returnedErr }
go
func (vm *VM) Destroy() error { if vm.InstanceID == "" { // Probably need to call Provision first. return ErrNoInstanceID } client, err := getComputeClient(vm) if err != nil { return fmt.Errorf("compute client is not set for the VM, %s", err) } // Delete the floating IP first before destroying the VM var errors []error if vm.FloatingIP != nil { err = floatingips.DisassociateInstance(client, vm.InstanceID, floatingips.DisassociateOpts{FloatingIP: vm.FloatingIP.IP}).ExtractErr() if err != nil { errors = append(errors, fmt.Errorf("unable to disassociate floating ip from instance: %s", err)) } else { err = floatingips.Delete(client, vm.FloatingIP.ID).ExtractErr() if err != nil { errors = append(errors, fmt.Errorf("unable to delete floating ip: %s", err)) } } } // De-attach and delete the volume, if there is an attached one if vm.Volume.ID != "" { err = deattachAndDeleteVolume(vm) if err != nil { errors = append(errors, err) } } // Delete the instance err = deleteVM(client, vm.InstanceID) if err != nil { errors = append(errors, err) } // Return all the errors var returnedErr error if len(errors) > 0 { for i, err := range errors { if i == 0 { returnedErr = err continue } returnedErr = fmt.Errorf("%s, %s", returnedErr, err) } } vm.computeClient = nil return returnedErr }
[ "func", "(", "vm", "*", "VM", ")", "Destroy", "(", ")", "error", "{", "if", "vm", ".", "InstanceID", "==", "\"", "\"", "{", "// Probably need to call Provision first.", "return", "ErrNoInstanceID", "\n", "}", "\n\n", "client", ",", "err", ":=", "getComputeClient", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Delete the floating IP first before destroying the VM", "var", "errors", "[", "]", "error", "\n", "if", "vm", ".", "FloatingIP", "!=", "nil", "{", "err", "=", "floatingips", ".", "DisassociateInstance", "(", "client", ",", "vm", ".", "InstanceID", ",", "floatingips", ".", "DisassociateOpts", "{", "FloatingIP", ":", "vm", ".", "FloatingIP", ".", "IP", "}", ")", ".", "ExtractErr", "(", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", ")", "\n", "}", "else", "{", "err", "=", "floatingips", ".", "Delete", "(", "client", ",", "vm", ".", "FloatingIP", ".", "ID", ")", ".", "ExtractErr", "(", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// De-attach and delete the volume, if there is an attached one", "if", "vm", ".", "Volume", ".", "ID", "!=", "\"", "\"", "{", "err", "=", "deattachAndDeleteVolume", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "// Delete the instance", "err", "=", "deleteVM", "(", "client", ",", "vm", ".", "InstanceID", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n\n", "// Return all the errors", "var", "returnedErr", "error", "\n", "if", "len", "(", "errors", ")", ">", "0", "{", "for", "i", ",", "err", ":=", "range", "errors", "{", "if", "i", "==", "0", "{", "returnedErr", "=", "err", "\n", "continue", "\n", "}", "\n\n", "returnedErr", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "returnedErr", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "vm", ".", "computeClient", "=", "nil", "\n", "return", "returnedErr", "\n", "}" ]
// Destroy terminates the VM on Openstack. It returns an error if there is no instance ID.
[ "Destroy", "terminates", "the", "VM", "on", "Openstack", ".", "It", "returns", "an", "error", "if", "there", "is", "no", "instance", "ID", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/vm.go#L425-L480
146,162
apcera/libretto
virtualmachine/openstack/vm.go
GetState
func (vm *VM) GetState() (string, error) { server, err := getServer(vm) if err != nil { return "", err } if server == nil { // VM state "unknown" return "", lvm.ErrVMInfoFailed } if server.Status == StateActive { return lvm.VMRunning, nil } else if server.Status == StateShutOff { return lvm.VMHalted, nil } else if server.Status == StateError { return lvm.VMError, nil } return lvm.VMUnknown, nil }
go
func (vm *VM) GetState() (string, error) { server, err := getServer(vm) if err != nil { return "", err } if server == nil { // VM state "unknown" return "", lvm.ErrVMInfoFailed } if server.Status == StateActive { return lvm.VMRunning, nil } else if server.Status == StateShutOff { return lvm.VMHalted, nil } else if server.Status == StateError { return lvm.VMError, nil } return lvm.VMUnknown, nil }
[ "func", "(", "vm", "*", "VM", ")", "GetState", "(", ")", "(", "string", ",", "error", ")", "{", "server", ",", "err", ":=", "getServer", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "server", "==", "nil", "{", "// VM state \"unknown\"", "return", "\"", "\"", ",", "lvm", ".", "ErrVMInfoFailed", "\n", "}", "\n\n", "if", "server", ".", "Status", "==", "StateActive", "{", "return", "lvm", ".", "VMRunning", ",", "nil", "\n", "}", "else", "if", "server", ".", "Status", "==", "StateShutOff", "{", "return", "lvm", ".", "VMHalted", ",", "nil", "\n", "}", "else", "if", "server", ".", "Status", "==", "StateError", "{", "return", "lvm", ".", "VMError", ",", "nil", "\n", "}", "\n", "return", "lvm", ".", "VMUnknown", ",", "nil", "\n", "}" ]
// GetState returns the state of the VM, such as "ACTIVE". An error is returned // if the instance ID is missing, if there was a problem querying Openstack, or if // there are no instances.
[ "GetState", "returns", "the", "state", "of", "the", "VM", "such", "as", "ACTIVE", ".", "An", "error", "is", "returned", "if", "the", "instance", "ID", "is", "missing", "if", "there", "was", "a", "problem", "querying", "Openstack", "or", "if", "there", "are", "no", "instances", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/vm.go#L497-L516
146,163
apcera/libretto
virtualmachine/openstack/vm.go
Halt
func (vm *VM) Halt() error { if vm.InstanceID == "" { // Probably need to call Provision first. return ErrNoInstanceID } client, err := getComputeClient(vm) if err != nil { return fmt.Errorf("compute client is not set for the VM, %s", err) } // Take a look at the initial state of the VM. Make sure it is in ACTIVE state state, err := vm.GetState() if err != nil { return err } if state != lvm.VMRunning { return fmt.Errorf("the VM is not active, so cannot be halted") } // Stop the VM (instance) err = ss.Stop(client, vm.InstanceID).ExtractErr() if err != nil { return fmt.Errorf("failed to stop the instance: %s", err) } // Wait until VM halts return waitUntil(vm, lvm.VMHalted) }
go
func (vm *VM) Halt() error { if vm.InstanceID == "" { // Probably need to call Provision first. return ErrNoInstanceID } client, err := getComputeClient(vm) if err != nil { return fmt.Errorf("compute client is not set for the VM, %s", err) } // Take a look at the initial state of the VM. Make sure it is in ACTIVE state state, err := vm.GetState() if err != nil { return err } if state != lvm.VMRunning { return fmt.Errorf("the VM is not active, so cannot be halted") } // Stop the VM (instance) err = ss.Stop(client, vm.InstanceID).ExtractErr() if err != nil { return fmt.Errorf("failed to stop the instance: %s", err) } // Wait until VM halts return waitUntil(vm, lvm.VMHalted) }
[ "func", "(", "vm", "*", "VM", ")", "Halt", "(", ")", "error", "{", "if", "vm", ".", "InstanceID", "==", "\"", "\"", "{", "// Probably need to call Provision first.", "return", "ErrNoInstanceID", "\n", "}", "\n\n", "client", ",", "err", ":=", "getComputeClient", "(", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Take a look at the initial state of the VM. Make sure it is in ACTIVE state", "state", ",", "err", ":=", "vm", ".", "GetState", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "state", "!=", "lvm", ".", "VMRunning", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Stop the VM (instance)", "err", "=", "ss", ".", "Stop", "(", "client", ",", "vm", ".", "InstanceID", ")", ".", "ExtractErr", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Wait until VM halts", "return", "waitUntil", "(", "vm", ",", "lvm", ".", "VMHalted", ")", "\n", "}" ]
// Halt shuts down the insance on Openstack.
[ "Halt", "shuts", "down", "the", "insance", "on", "Openstack", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/vm.go#L519-L548
146,164
apcera/libretto
virtualmachine/gcp/util.go
getInstance
func (svc *googleService) getInstance() (*googlecloud.Instance, error) { return svc.service.Instances.Get(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do() }
go
func (svc *googleService) getInstance() (*googlecloud.Instance, error) { return svc.service.Instances.Get(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do() }
[ "func", "(", "svc", "*", "googleService", ")", "getInstance", "(", ")", "(", "*", "googlecloud", ".", "Instance", ",", "error", ")", "{", "return", "svc", ".", "service", ".", "Instances", ".", "Get", "(", "svc", ".", "vm", ".", "Project", ",", "svc", ".", "vm", ".", "Zone", ",", "svc", ".", "vm", ".", "Name", ")", ".", "Do", "(", ")", "\n", "}" ]
// get instance from current VM definition.
[ "get", "instance", "from", "current", "VM", "definition", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L76-L78
146,165
apcera/libretto
virtualmachine/gcp/util.go
waitForOperation
func waitForOperation(timeout int, funcOperation func() (*googlecloud.Operation, error)) error { var op *googlecloud.Operation var err error for i := 0; i < timeout; i++ { op, err = funcOperation() if err != nil { return err } if op.Status == "DONE" { if op.Error != nil { return fmt.Errorf("operation error: %v", *op.Error.Errors[0]) } return nil } time.Sleep(1 * time.Second) } return fmt.Errorf("operation timeout, operations status: %v", op.Status) }
go
func waitForOperation(timeout int, funcOperation func() (*googlecloud.Operation, error)) error { var op *googlecloud.Operation var err error for i := 0; i < timeout; i++ { op, err = funcOperation() if err != nil { return err } if op.Status == "DONE" { if op.Error != nil { return fmt.Errorf("operation error: %v", *op.Error.Errors[0]) } return nil } time.Sleep(1 * time.Second) } return fmt.Errorf("operation timeout, operations status: %v", op.Status) }
[ "func", "waitForOperation", "(", "timeout", "int", ",", "funcOperation", "func", "(", ")", "(", "*", "googlecloud", ".", "Operation", ",", "error", ")", ")", "error", "{", "var", "op", "*", "googlecloud", ".", "Operation", "\n", "var", "err", "error", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "timeout", ";", "i", "++", "{", "op", ",", "err", "=", "funcOperation", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "op", ".", "Status", "==", "\"", "\"", "{", "if", "op", ".", "Error", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "*", "op", ".", "Error", ".", "Errors", "[", "0", "]", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "time", ".", "Sleep", "(", "1", "*", "time", ".", "Second", ")", "\n", "}", "\n\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "op", ".", "Status", ")", "\n", "}" ]
// waitForOperation pulls to wait for the operation to finish.
[ "waitForOperation", "pulls", "to", "wait", "for", "the", "operation", "to", "finish", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L81-L101
146,166
apcera/libretto
virtualmachine/gcp/util.go
waitForOperationReady
func (svc *googleService) waitForOperationReady(operation string) error { return waitForOperation(OperationTimeout, func() (*googlecloud.Operation, error) { return svc.service.ZoneOperations.Get(svc.vm.Project, svc.vm.Zone, operation).Do() }) }
go
func (svc *googleService) waitForOperationReady(operation string) error { return waitForOperation(OperationTimeout, func() (*googlecloud.Operation, error) { return svc.service.ZoneOperations.Get(svc.vm.Project, svc.vm.Zone, operation).Do() }) }
[ "func", "(", "svc", "*", "googleService", ")", "waitForOperationReady", "(", "operation", "string", ")", "error", "{", "return", "waitForOperation", "(", "OperationTimeout", ",", "func", "(", ")", "(", "*", "googlecloud", ".", "Operation", ",", "error", ")", "{", "return", "svc", ".", "service", ".", "ZoneOperations", ".", "Get", "(", "svc", ".", "vm", ".", "Project", ",", "svc", ".", "vm", ".", "Zone", ",", "operation", ")", ".", "Do", "(", ")", "\n", "}", ")", "\n", "}" ]
// waitForOperationReady waits for the regional operation to finish.
[ "waitForOperationReady", "waits", "for", "the", "regional", "operation", "to", "finish", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L104-L108
146,167
apcera/libretto
virtualmachine/gcp/util.go
createDisks
func (svc *googleService) createDisks() (disks []*googlecloud.AttachedDisk, err error) { if len(svc.vm.Disks) == 0 { return nil, errors.New("no disks were found") } image, err := svc.getImage() if err != nil { return nil, err } for i, disk := range svc.vm.Disks { if i == 0 { // First one is booted device, it will created in VM provision stage disks = append(disks, &googlecloud.AttachedDisk{ Type: "PERSISTENT", Mode: "READ_WRITE", Kind: "compute#attachedDisk", Boot: true, AutoDelete: disk.AutoDelete, InitializeParams: &googlecloud.AttachedDiskInitializeParams{ SourceImage: image.SelfLink, DiskSizeGb: int64(disk.DiskSizeGb), DiskType: fmt.Sprintf("zones/%s/diskTypes/%s", svc.vm.Zone, disk.DiskType), }, }) continue } // Reuse the existing disk, create non-booted devices if it does not exist searchDisk, _ := svc.getDisk(disk.Name) if searchDisk == nil { d := &googlecloud.Disk{ Name: disk.Name, SizeGb: int64(disk.DiskSizeGb), Type: fmt.Sprintf("zones/%s/diskTypes/%s", svc.vm.Zone, disk.DiskType), } op, err := svc.service.Disks.Insert(svc.vm.Project, svc.vm.Zone, d).Do() if err != nil { return disks, fmt.Errorf("error while creating disk %s: %v", disk.Name, err) } err = svc.waitForOperationReady(op.Name) if err != nil { return disks, fmt.Errorf("error while waiting for the disk %s ready, error: %v", disk.Name, err) } } disks = append(disks, &googlecloud.AttachedDisk{ DeviceName: disk.Name, Type: "PERSISTENT", Mode: "READ_WRITE", Boot: false, AutoDelete: disk.AutoDelete, Source: fmt.Sprintf("projects/%s/zones/%s/disks/%s", svc.vm.Project, svc.vm.Zone, disk.Name), }) } return disks, nil }
go
func (svc *googleService) createDisks() (disks []*googlecloud.AttachedDisk, err error) { if len(svc.vm.Disks) == 0 { return nil, errors.New("no disks were found") } image, err := svc.getImage() if err != nil { return nil, err } for i, disk := range svc.vm.Disks { if i == 0 { // First one is booted device, it will created in VM provision stage disks = append(disks, &googlecloud.AttachedDisk{ Type: "PERSISTENT", Mode: "READ_WRITE", Kind: "compute#attachedDisk", Boot: true, AutoDelete: disk.AutoDelete, InitializeParams: &googlecloud.AttachedDiskInitializeParams{ SourceImage: image.SelfLink, DiskSizeGb: int64(disk.DiskSizeGb), DiskType: fmt.Sprintf("zones/%s/diskTypes/%s", svc.vm.Zone, disk.DiskType), }, }) continue } // Reuse the existing disk, create non-booted devices if it does not exist searchDisk, _ := svc.getDisk(disk.Name) if searchDisk == nil { d := &googlecloud.Disk{ Name: disk.Name, SizeGb: int64(disk.DiskSizeGb), Type: fmt.Sprintf("zones/%s/diskTypes/%s", svc.vm.Zone, disk.DiskType), } op, err := svc.service.Disks.Insert(svc.vm.Project, svc.vm.Zone, d).Do() if err != nil { return disks, fmt.Errorf("error while creating disk %s: %v", disk.Name, err) } err = svc.waitForOperationReady(op.Name) if err != nil { return disks, fmt.Errorf("error while waiting for the disk %s ready, error: %v", disk.Name, err) } } disks = append(disks, &googlecloud.AttachedDisk{ DeviceName: disk.Name, Type: "PERSISTENT", Mode: "READ_WRITE", Boot: false, AutoDelete: disk.AutoDelete, Source: fmt.Sprintf("projects/%s/zones/%s/disks/%s", svc.vm.Project, svc.vm.Zone, disk.Name), }) } return disks, nil }
[ "func", "(", "svc", "*", "googleService", ")", "createDisks", "(", ")", "(", "disks", "[", "]", "*", "googlecloud", ".", "AttachedDisk", ",", "err", "error", ")", "{", "if", "len", "(", "svc", ".", "vm", ".", "Disks", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "image", ",", "err", ":=", "svc", ".", "getImage", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "i", ",", "disk", ":=", "range", "svc", ".", "vm", ".", "Disks", "{", "if", "i", "==", "0", "{", "// First one is booted device, it will created in VM provision stage", "disks", "=", "append", "(", "disks", ",", "&", "googlecloud", ".", "AttachedDisk", "{", "Type", ":", "\"", "\"", ",", "Mode", ":", "\"", "\"", ",", "Kind", ":", "\"", "\"", ",", "Boot", ":", "true", ",", "AutoDelete", ":", "disk", ".", "AutoDelete", ",", "InitializeParams", ":", "&", "googlecloud", ".", "AttachedDiskInitializeParams", "{", "SourceImage", ":", "image", ".", "SelfLink", ",", "DiskSizeGb", ":", "int64", "(", "disk", ".", "DiskSizeGb", ")", ",", "DiskType", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "svc", ".", "vm", ".", "Zone", ",", "disk", ".", "DiskType", ")", ",", "}", ",", "}", ")", "\n", "continue", "\n", "}", "\n\n", "// Reuse the existing disk, create non-booted devices if it does not exist", "searchDisk", ",", "_", ":=", "svc", ".", "getDisk", "(", "disk", ".", "Name", ")", "\n", "if", "searchDisk", "==", "nil", "{", "d", ":=", "&", "googlecloud", ".", "Disk", "{", "Name", ":", "disk", ".", "Name", ",", "SizeGb", ":", "int64", "(", "disk", ".", "DiskSizeGb", ")", ",", "Type", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "svc", ".", "vm", ".", "Zone", ",", "disk", ".", "DiskType", ")", ",", "}", "\n\n", "op", ",", "err", ":=", "svc", ".", "service", ".", "Disks", ".", "Insert", "(", "svc", ".", "vm", ".", "Project", ",", "svc", ".", "vm", ".", "Zone", ",", "d", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "disks", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "disk", ".", "Name", ",", "err", ")", "\n", "}", "\n\n", "err", "=", "svc", ".", "waitForOperationReady", "(", "op", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "disks", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "disk", ".", "Name", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "disks", "=", "append", "(", "disks", ",", "&", "googlecloud", ".", "AttachedDisk", "{", "DeviceName", ":", "disk", ".", "Name", ",", "Type", ":", "\"", "\"", ",", "Mode", ":", "\"", "\"", ",", "Boot", ":", "false", ",", "AutoDelete", ":", "disk", ".", "AutoDelete", ",", "Source", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "svc", ".", "vm", ".", "Project", ",", "svc", ".", "vm", ".", "Zone", ",", "disk", ".", "Name", ")", ",", "}", ")", "\n", "}", "\n\n", "return", "disks", ",", "nil", "\n", "}" ]
// createDisks creates non-booted disk.
[ "createDisks", "creates", "non", "-", "booted", "disk", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L124-L183
146,168
apcera/libretto
virtualmachine/gcp/util.go
getDisk
func (svc *googleService) getDisk(name string) (*googlecloud.Disk, error) { return svc.service.Disks.Get(svc.vm.Project, svc.vm.Zone, name).Do() }
go
func (svc *googleService) getDisk(name string) (*googlecloud.Disk, error) { return svc.service.Disks.Get(svc.vm.Project, svc.vm.Zone, name).Do() }
[ "func", "(", "svc", "*", "googleService", ")", "getDisk", "(", "name", "string", ")", "(", "*", "googlecloud", ".", "Disk", ",", "error", ")", "{", "return", "svc", ".", "service", ".", "Disks", ".", "Get", "(", "svc", ".", "vm", ".", "Project", ",", "svc", ".", "vm", ".", "Zone", ",", "name", ")", ".", "Do", "(", ")", "\n", "}" ]
// getDisk retrieves the Disk object.
[ "getDisk", "retrieves", "the", "Disk", "object", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L186-L188
146,169
apcera/libretto
virtualmachine/gcp/util.go
deleteDisk
func (svc *googleService) deleteDisk(name string) error { op, err := svc.service.Disks.Delete(svc.vm.Project, svc.vm.Zone, name).Do() if err != nil { return err } return svc.waitForOperationReady(op.Name) }
go
func (svc *googleService) deleteDisk(name string) error { op, err := svc.service.Disks.Delete(svc.vm.Project, svc.vm.Zone, name).Do() if err != nil { return err } return svc.waitForOperationReady(op.Name) }
[ "func", "(", "svc", "*", "googleService", ")", "deleteDisk", "(", "name", "string", ")", "error", "{", "op", ",", "err", ":=", "svc", ".", "service", ".", "Disks", ".", "Delete", "(", "svc", ".", "vm", ".", "Project", ",", "svc", ".", "vm", ".", "Zone", ",", "name", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "svc", ".", "waitForOperationReady", "(", "op", ".", "Name", ")", "\n", "}" ]
// deleteDisk deletes the persistent disk.
[ "deleteDisk", "deletes", "the", "persistent", "disk", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L191-L198
146,170
apcera/libretto
virtualmachine/gcp/util.go
deleteDisks
func (svc *googleService) deleteDisks() (errs []error) { for _, disk := range svc.vm.Disks { err := svc.deleteDisk(disk.Name) if err != nil { errs = append(errs, err) } } return errs }
go
func (svc *googleService) deleteDisks() (errs []error) { for _, disk := range svc.vm.Disks { err := svc.deleteDisk(disk.Name) if err != nil { errs = append(errs, err) } } return errs }
[ "func", "(", "svc", "*", "googleService", ")", "deleteDisks", "(", ")", "(", "errs", "[", "]", "error", ")", "{", "for", "_", ",", "disk", ":=", "range", "svc", ".", "vm", ".", "Disks", "{", "err", ":=", "svc", ".", "deleteDisk", "(", "disk", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "errs", "=", "append", "(", "errs", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "errs", "\n", "}" ]
// deleteDisks deletes all the persistent disk.
[ "deleteDisks", "deletes", "all", "the", "persistent", "disk", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L201-L209
146,171
apcera/libretto
virtualmachine/gcp/util.go
getIPs
func (svc *googleService) getIPs() ([]net.IP, error) { instance, err := svc.service.Instances.Get(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do() if err != nil { return nil, err } ips := make([]net.IP, 2) nic := instance.NetworkInterfaces[0] publicIP := nic.AccessConfigs[0].NatIP if publicIP == "" { return nil, errors.New("error while retrieving public IP") } privateIP := nic.NetworkIP if privateIP == "" { return nil, errors.New("error while retrieving private IP") } ips[PublicIP] = net.ParseIP(publicIP) ips[PrivateIP] = net.ParseIP(privateIP) return ips, nil }
go
func (svc *googleService) getIPs() ([]net.IP, error) { instance, err := svc.service.Instances.Get(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do() if err != nil { return nil, err } ips := make([]net.IP, 2) nic := instance.NetworkInterfaces[0] publicIP := nic.AccessConfigs[0].NatIP if publicIP == "" { return nil, errors.New("error while retrieving public IP") } privateIP := nic.NetworkIP if privateIP == "" { return nil, errors.New("error while retrieving private IP") } ips[PublicIP] = net.ParseIP(publicIP) ips[PrivateIP] = net.ParseIP(privateIP) return ips, nil }
[ "func", "(", "svc", "*", "googleService", ")", "getIPs", "(", ")", "(", "[", "]", "net", ".", "IP", ",", "error", ")", "{", "instance", ",", "err", ":=", "svc", ".", "service", ".", "Instances", ".", "Get", "(", "svc", ".", "vm", ".", "Project", ",", "svc", ".", "vm", ".", "Zone", ",", "svc", ".", "vm", ".", "Name", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "ips", ":=", "make", "(", "[", "]", "net", ".", "IP", ",", "2", ")", "\n", "nic", ":=", "instance", ".", "NetworkInterfaces", "[", "0", "]", "\n\n", "publicIP", ":=", "nic", ".", "AccessConfigs", "[", "0", "]", ".", "NatIP", "\n", "if", "publicIP", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "privateIP", ":=", "nic", ".", "NetworkIP", "\n", "if", "privateIP", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "ips", "[", "PublicIP", "]", "=", "net", ".", "ParseIP", "(", "publicIP", ")", "\n", "ips", "[", "PrivateIP", "]", "=", "net", ".", "ParseIP", "(", "privateIP", ")", "\n\n", "return", "ips", ",", "nil", "\n", "}" ]
// getIPs returns the IP addresses of the GCE instance.
[ "getIPs", "returns", "the", "IP", "addresses", "of", "the", "GCE", "instance", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L212-L235
146,172
apcera/libretto
virtualmachine/gcp/util.go
start
func (svc *googleService) start() error { instance, err := svc.getInstance() if err != nil { if !strings.Contains(err.Error(), "no instance found") { return err } } if instance == nil { return errors.New("no instance found") } op, err := svc.service.Instances.Start(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do() if err != nil { return err } return svc.waitForOperationReady(op.Name) }
go
func (svc *googleService) start() error { instance, err := svc.getInstance() if err != nil { if !strings.Contains(err.Error(), "no instance found") { return err } } if instance == nil { return errors.New("no instance found") } op, err := svc.service.Instances.Start(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do() if err != nil { return err } return svc.waitForOperationReady(op.Name) }
[ "func", "(", "svc", "*", "googleService", ")", "start", "(", ")", "error", "{", "instance", ",", "err", ":=", "svc", ".", "getInstance", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "instance", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "op", ",", "err", ":=", "svc", ".", "service", ".", "Instances", ".", "Start", "(", "svc", ".", "vm", ".", "Project", ",", "svc", ".", "vm", ".", "Zone", ",", "svc", ".", "vm", ".", "Name", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "svc", ".", "waitForOperationReady", "(", "op", ".", "Name", ")", "\n", "}" ]
// start starts a stopped GCE instance.
[ "start", "starts", "a", "stopped", "GCE", "instance", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L335-L353
146,173
apcera/libretto
virtualmachine/gcp/util.go
stop
func (svc *googleService) stop() error { _, err := svc.getInstance() if err != nil { if !strings.Contains(err.Error(), "no instance found") { return err } return fmt.Errorf("no instance found, %v", err) } op, err := svc.service.Instances.Stop(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do() if err != nil { return err } return svc.waitForOperationReady(op.Name) }
go
func (svc *googleService) stop() error { _, err := svc.getInstance() if err != nil { if !strings.Contains(err.Error(), "no instance found") { return err } return fmt.Errorf("no instance found, %v", err) } op, err := svc.service.Instances.Stop(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do() if err != nil { return err } return svc.waitForOperationReady(op.Name) }
[ "func", "(", "svc", "*", "googleService", ")", "stop", "(", ")", "error", "{", "_", ",", "err", ":=", "svc", ".", "getInstance", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", "{", "return", "err", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "op", ",", "err", ":=", "svc", ".", "service", ".", "Instances", ".", "Stop", "(", "svc", ".", "vm", ".", "Project", ",", "svc", ".", "vm", ".", "Zone", ",", "svc", ".", "vm", ".", "Name", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "svc", ".", "waitForOperationReady", "(", "op", ".", "Name", ")", "\n", "}" ]
// stop halts a GCE instance.
[ "stop", "halts", "a", "GCE", "instance", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L356-L371
146,174
apcera/libretto
virtualmachine/gcp/util.go
delete
func (svc *googleService) delete() error { op, err := svc.service.Instances.Delete(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do() if err != nil { return err } return svc.waitForOperationReady(op.Name) }
go
func (svc *googleService) delete() error { op, err := svc.service.Instances.Delete(svc.vm.Project, svc.vm.Zone, svc.vm.Name).Do() if err != nil { return err } return svc.waitForOperationReady(op.Name) }
[ "func", "(", "svc", "*", "googleService", ")", "delete", "(", ")", "error", "{", "op", ",", "err", ":=", "svc", ".", "service", ".", "Instances", ".", "Delete", "(", "svc", ".", "vm", ".", "Project", ",", "svc", ".", "vm", ".", "Zone", ",", "svc", ".", "vm", ".", "Name", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "svc", ".", "waitForOperationReady", "(", "op", ".", "Name", ")", "\n", "}" ]
// deletes the GCE instance.
[ "deletes", "the", "GCE", "instance", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/util.go#L374-L381
146,175
apcera/libretto
virtualmachine/vmrun/vm.go
Run
func (f vmrunRunner) Run(args ...string) (string, string, error) { var vmrunPath string // If vmrun is not found in the system path, fall back to the // hard coded path (VMRunPath). path, err := exec.LookPath("vmrun") if err == nil { vmrunPath = path } else { vmrunPath = VMRunPath } if vmrunPath == "" { return "", "", ErrVmrunNotFound } cmd := exec.Command(vmrunPath, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr var stdout bytes.Buffer var stderr bytes.Buffer cmd.Stdout, cmd.Stderr = &stdout, &stderr err = cmd.Start() timer := time.AfterFunc(vmrunTimeout, func() { cmd.Process.Kill() err = ErrVmrunTimeout }) e := cmd.Wait() timer.Stop() if err != nil || e != nil { err = lvm.WrapErrors(err, e) } return stdout.String(), stderr.String(), err }
go
func (f vmrunRunner) Run(args ...string) (string, string, error) { var vmrunPath string // If vmrun is not found in the system path, fall back to the // hard coded path (VMRunPath). path, err := exec.LookPath("vmrun") if err == nil { vmrunPath = path } else { vmrunPath = VMRunPath } if vmrunPath == "" { return "", "", ErrVmrunNotFound } cmd := exec.Command(vmrunPath, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr var stdout bytes.Buffer var stderr bytes.Buffer cmd.Stdout, cmd.Stderr = &stdout, &stderr err = cmd.Start() timer := time.AfterFunc(vmrunTimeout, func() { cmd.Process.Kill() err = ErrVmrunTimeout }) e := cmd.Wait() timer.Stop() if err != nil || e != nil { err = lvm.WrapErrors(err, e) } return stdout.String(), stderr.String(), err }
[ "func", "(", "f", "vmrunRunner", ")", "Run", "(", "args", "...", "string", ")", "(", "string", ",", "string", ",", "error", ")", "{", "var", "vmrunPath", "string", "\n\n", "// If vmrun is not found in the system path, fall back to the", "// hard coded path (VMRunPath).", "path", ",", "err", ":=", "exec", ".", "LookPath", "(", "\"", "\"", ")", "\n", "if", "err", "==", "nil", "{", "vmrunPath", "=", "path", "\n", "}", "else", "{", "vmrunPath", "=", "VMRunPath", "\n", "}", "\n\n", "if", "vmrunPath", "==", "\"", "\"", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "ErrVmrunNotFound", "\n", "}", "\n\n", "cmd", ":=", "exec", ".", "Command", "(", "vmrunPath", ",", "args", "...", ")", "\n", "cmd", ".", "Stdout", "=", "os", ".", "Stdout", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n\n", "var", "stdout", "bytes", ".", "Buffer", "\n", "var", "stderr", "bytes", ".", "Buffer", "\n\n", "cmd", ".", "Stdout", ",", "cmd", ".", "Stderr", "=", "&", "stdout", ",", "&", "stderr", "\n\n", "err", "=", "cmd", ".", "Start", "(", ")", "\n", "timer", ":=", "time", ".", "AfterFunc", "(", "vmrunTimeout", ",", "func", "(", ")", "{", "cmd", ".", "Process", ".", "Kill", "(", ")", "\n", "err", "=", "ErrVmrunTimeout", "\n", "}", ")", "\n", "e", ":=", "cmd", ".", "Wait", "(", ")", "\n", "timer", ".", "Stop", "(", ")", "\n\n", "if", "err", "!=", "nil", "||", "e", "!=", "nil", "{", "err", "=", "lvm", ".", "WrapErrors", "(", "err", ",", "e", ")", "\n", "}", "\n", "return", "stdout", ".", "String", "(", ")", ",", "stderr", ".", "String", "(", ")", ",", "err", "\n", "}" ]
// Run runs a vmrun command.
[ "Run", "runs", "a", "vmrun", "command", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vmrun/vm.go#L80-L117
146,176
apcera/libretto
virtualmachine/exoscale/vm.go
GetName
func (vm *VM) GetName() string { if err := vm.updateInfo(); err != nil { return "" } return vm.Name }
go
func (vm *VM) GetName() string { if err := vm.updateInfo(); err != nil { return "" } return vm.Name }
[ "func", "(", "vm", "*", "VM", ")", "GetName", "(", ")", "string", "{", "if", "err", ":=", "vm", ".", "updateInfo", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "vm", ".", "Name", "\n", "}" ]
// GetName returns the name of the virtual machine // If an error occurs, an empty string is returned
[ "GetName", "returns", "the", "name", "of", "the", "virtual", "machine", "If", "an", "error", "occurs", "an", "empty", "string", "is", "returned" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/vm.go#L95-L102
146,177
apcera/libretto
virtualmachine/exoscale/vm.go
GetIPs
func (vm *VM) GetIPs() ([]net.IP, error) { if err := vm.updateInfo(); err != nil { return nil, err } return vm.ips, nil }
go
func (vm *VM) GetIPs() ([]net.IP, error) { if err := vm.updateInfo(); err != nil { return nil, err } return vm.ips, nil }
[ "func", "(", "vm", "*", "VM", ")", "GetIPs", "(", ")", "(", "[", "]", "net", ".", "IP", ",", "error", ")", "{", "if", "err", ":=", "vm", ".", "updateInfo", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "vm", ".", "ips", ",", "nil", "\n", "}" ]
// GetIPs returns the list of ip addresses associated with the VM
[ "GetIPs", "returns", "the", "list", "of", "ip", "addresses", "associated", "with", "the", "VM" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/vm.go#L160-L167
146,178
apcera/libretto
virtualmachine/exoscale/vm.go
Destroy
func (vm *VM) Destroy() error { if vm.ID == "" { return fmt.Errorf("Need an ID to destroy the virtual machine") } params := url.Values{} params.Set("id", vm.ID) client := vm.getExoClient() resp, err := client.Request("destroyVirtualMachine", params) if err != nil { return fmt.Errorf("Destroying virtual machine %q: %s", vm.ID, err) } destroy := &egoscale.DestroyVirtualMachineResponse{} if err := json.Unmarshal(resp, destroy); err != nil { return fmt.Errorf("Destroying virtual machine %q: %s", vm.ID, err) } vm.JobID = destroy.JobID return nil }
go
func (vm *VM) Destroy() error { if vm.ID == "" { return fmt.Errorf("Need an ID to destroy the virtual machine") } params := url.Values{} params.Set("id", vm.ID) client := vm.getExoClient() resp, err := client.Request("destroyVirtualMachine", params) if err != nil { return fmt.Errorf("Destroying virtual machine %q: %s", vm.ID, err) } destroy := &egoscale.DestroyVirtualMachineResponse{} if err := json.Unmarshal(resp, destroy); err != nil { return fmt.Errorf("Destroying virtual machine %q: %s", vm.ID, err) } vm.JobID = destroy.JobID return nil }
[ "func", "(", "vm", "*", "VM", ")", "Destroy", "(", ")", "error", "{", "if", "vm", ".", "ID", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "params", ":=", "url", ".", "Values", "{", "}", "\n", "params", ".", "Set", "(", "\"", "\"", ",", "vm", ".", "ID", ")", "\n\n", "client", ":=", "vm", ".", "getExoClient", "(", ")", "\n", "resp", ",", "err", ":=", "client", ".", "Request", "(", "\"", "\"", ",", "params", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vm", ".", "ID", ",", "err", ")", "\n", "}", "\n\n", "destroy", ":=", "&", "egoscale", ".", "DestroyVirtualMachineResponse", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "resp", ",", "destroy", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vm", ".", "ID", ",", "err", ")", "\n", "}", "\n\n", "vm", ".", "JobID", "=", "destroy", ".", "JobID", "\n\n", "return", "nil", "\n", "}" ]
// Destroy removes virtual machine and all storage associated
[ "Destroy", "removes", "virtual", "machine", "and", "all", "storage", "associated" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/vm.go#L170-L193
146,179
apcera/libretto
virtualmachine/exoscale/vm.go
GetState
func (vm *VM) GetState() (string, error) { if vm.ID == "" { return "", fmt.Errorf("Need an ID to get virtual machine state") } if err := vm.updateInfo(); err != nil { return "", err } return vm.state, nil }
go
func (vm *VM) GetState() (string, error) { if vm.ID == "" { return "", fmt.Errorf("Need an ID to get virtual machine state") } if err := vm.updateInfo(); err != nil { return "", err } return vm.state, nil }
[ "func", "(", "vm", "*", "VM", ")", "GetState", "(", ")", "(", "string", ",", "error", ")", "{", "if", "vm", ".", "ID", "==", "\"", "\"", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", ":=", "vm", ".", "updateInfo", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "vm", ".", "state", ",", "nil", "\n", "}" ]
// GetState returns virtual machine state
[ "GetState", "returns", "virtual", "machine", "state" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/vm.go#L196-L207
146,180
apcera/libretto
virtualmachine/exoscale/vm.go
Halt
func (vm *VM) Halt() error { if vm.ID == "" { return fmt.Errorf("Need an ID to stop the virtual machine") } params := url.Values{} params.Set("id", vm.ID) client := vm.getExoClient() resp, err := client.Request("stopVirtualMachine", params) if err != nil { return fmt.Errorf("Stopping virtual machine %q: %s", vm.ID, err) } stop := &egoscale.StopVirtualMachineResponse{} if err := json.Unmarshal(resp, stop); err != nil { return fmt.Errorf("Stopping virtual machine %q: %s", vm.ID, err) } vm.JobID = stop.JobID return nil }
go
func (vm *VM) Halt() error { if vm.ID == "" { return fmt.Errorf("Need an ID to stop the virtual machine") } params := url.Values{} params.Set("id", vm.ID) client := vm.getExoClient() resp, err := client.Request("stopVirtualMachine", params) if err != nil { return fmt.Errorf("Stopping virtual machine %q: %s", vm.ID, err) } stop := &egoscale.StopVirtualMachineResponse{} if err := json.Unmarshal(resp, stop); err != nil { return fmt.Errorf("Stopping virtual machine %q: %s", vm.ID, err) } vm.JobID = stop.JobID return nil }
[ "func", "(", "vm", "*", "VM", ")", "Halt", "(", ")", "error", "{", "if", "vm", ".", "ID", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "params", ":=", "url", ".", "Values", "{", "}", "\n", "params", ".", "Set", "(", "\"", "\"", ",", "vm", ".", "ID", ")", "\n\n", "client", ":=", "vm", ".", "getExoClient", "(", ")", "\n", "resp", ",", "err", ":=", "client", ".", "Request", "(", "\"", "\"", ",", "params", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vm", ".", "ID", ",", "err", ")", "\n", "}", "\n\n", "stop", ":=", "&", "egoscale", ".", "StopVirtualMachineResponse", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "resp", ",", "stop", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vm", ".", "ID", ",", "err", ")", "\n", "}", "\n\n", "vm", ".", "JobID", "=", "stop", ".", "JobID", "\n\n", "return", "nil", "\n\n", "}" ]
// Halt stop a virtual machine
[ "Halt", "stop", "a", "virtual", "machine" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/vm.go#L220-L244
146,181
apcera/libretto
virtualmachine/exoscale/vm.go
Start
func (vm *VM) Start() error { if vm.ID == "" { return fmt.Errorf("Need an ID to start the virtual machine") } params := url.Values{} params.Set("id", vm.ID) client := vm.getExoClient() resp, err := client.Request("startVirtualMachine", params) if err != nil { return fmt.Errorf("Starting virtual machine %q: %s", vm.ID, err) } start := &egoscale.StartVirtualMachineResponse{} if err := json.Unmarshal(resp, start); err != nil { return fmt.Errorf("Starting virtual machine %q: %s", vm.ID, err) } vm.JobID = start.JobID return nil }
go
func (vm *VM) Start() error { if vm.ID == "" { return fmt.Errorf("Need an ID to start the virtual machine") } params := url.Values{} params.Set("id", vm.ID) client := vm.getExoClient() resp, err := client.Request("startVirtualMachine", params) if err != nil { return fmt.Errorf("Starting virtual machine %q: %s", vm.ID, err) } start := &egoscale.StartVirtualMachineResponse{} if err := json.Unmarshal(resp, start); err != nil { return fmt.Errorf("Starting virtual machine %q: %s", vm.ID, err) } vm.JobID = start.JobID return nil }
[ "func", "(", "vm", "*", "VM", ")", "Start", "(", ")", "error", "{", "if", "vm", ".", "ID", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "params", ":=", "url", ".", "Values", "{", "}", "\n", "params", ".", "Set", "(", "\"", "\"", ",", "vm", ".", "ID", ")", "\n\n", "client", ":=", "vm", ".", "getExoClient", "(", ")", "\n", "resp", ",", "err", ":=", "client", ".", "Request", "(", "\"", "\"", ",", "params", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vm", ".", "ID", ",", "err", ")", "\n", "}", "\n\n", "start", ":=", "&", "egoscale", ".", "StartVirtualMachineResponse", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "resp", ",", "start", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vm", ".", "ID", ",", "err", ")", "\n", "}", "\n\n", "vm", ".", "JobID", "=", "start", ".", "JobID", "\n\n", "return", "nil", "\n", "}" ]
// Start starts virtual machine
[ "Start", "starts", "virtual", "machine" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/vm.go#L247-L270
146,182
apcera/libretto
virtualmachine/exoscale/vm.go
GetSSH
func (vm *VM) GetSSH(options ssh.Options) (ssh.Client, error) { ips, err := util.GetVMIPs(vm, options) if err != nil { return nil, err } client := &ssh.SSHClient{ Creds: &vm.SSHCreds, IP: ips[0], // public IP Options: options, Port: 22, } if err := client.WaitForSSH(SSHTimeout); err != nil { return nil, err } return client, nil }
go
func (vm *VM) GetSSH(options ssh.Options) (ssh.Client, error) { ips, err := util.GetVMIPs(vm, options) if err != nil { return nil, err } client := &ssh.SSHClient{ Creds: &vm.SSHCreds, IP: ips[0], // public IP Options: options, Port: 22, } if err := client.WaitForSSH(SSHTimeout); err != nil { return nil, err } return client, nil }
[ "func", "(", "vm", "*", "VM", ")", "GetSSH", "(", "options", "ssh", ".", "Options", ")", "(", "ssh", ".", "Client", ",", "error", ")", "{", "ips", ",", "err", ":=", "util", ".", "GetVMIPs", "(", "vm", ",", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "client", ":=", "&", "ssh", ".", "SSHClient", "{", "Creds", ":", "&", "vm", ".", "SSHCreds", ",", "IP", ":", "ips", "[", "0", "]", ",", "// public IP", "Options", ":", "options", ",", "Port", ":", "22", ",", "}", "\n", "if", "err", ":=", "client", ".", "WaitForSSH", "(", "SSHTimeout", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "client", ",", "nil", "\n\n", "}" ]
// GetSSH returns SSH keys to access the virtual machine
[ "GetSSH", "returns", "SSH", "keys", "to", "access", "the", "virtual", "machine" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/vm.go#L273-L292
146,183
apcera/libretto
ssh/mock_ssh.go
Connect
func (c *MockSSHClient) Connect() error { if c.MockConnect != nil { return c.MockConnect() } return ErrNotImplemented }
go
func (c *MockSSHClient) Connect() error { if c.MockConnect != nil { return c.MockConnect() } return ErrNotImplemented }
[ "func", "(", "c", "*", "MockSSHClient", ")", "Connect", "(", ")", "error", "{", "if", "c", ".", "MockConnect", "!=", "nil", "{", "return", "c", ".", "MockConnect", "(", ")", "\n", "}", "\n", "return", "ErrNotImplemented", "\n", "}" ]
// Connect calls the mocked connect.
[ "Connect", "calls", "the", "mocked", "connect", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/mock_ssh.go#L27-L32
146,184
apcera/libretto
ssh/mock_ssh.go
Download
func (c *MockSSHClient) Download(src io.WriteCloser, dst string) error { if c.MockDownload != nil { return c.MockDownload(src, dst) } return ErrNotImplemented }
go
func (c *MockSSHClient) Download(src io.WriteCloser, dst string) error { if c.MockDownload != nil { return c.MockDownload(src, dst) } return ErrNotImplemented }
[ "func", "(", "c", "*", "MockSSHClient", ")", "Download", "(", "src", "io", ".", "WriteCloser", ",", "dst", "string", ")", "error", "{", "if", "c", ".", "MockDownload", "!=", "nil", "{", "return", "c", ".", "MockDownload", "(", "src", ",", "dst", ")", "\n", "}", "\n", "return", "ErrNotImplemented", "\n", "}" ]
// Download calls the mocked download.
[ "Download", "calls", "the", "mocked", "download", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/mock_ssh.go#L42-L47
146,185
apcera/libretto
ssh/mock_ssh.go
Run
func (c *MockSSHClient) Run(command string, stdout io.Writer, stderr io.Writer) error { if c.MockRun != nil { return c.MockRun(command, stdout, stderr) } return ErrNotImplemented }
go
func (c *MockSSHClient) Run(command string, stdout io.Writer, stderr io.Writer) error { if c.MockRun != nil { return c.MockRun(command, stdout, stderr) } return ErrNotImplemented }
[ "func", "(", "c", "*", "MockSSHClient", ")", "Run", "(", "command", "string", ",", "stdout", "io", ".", "Writer", ",", "stderr", "io", ".", "Writer", ")", "error", "{", "if", "c", ".", "MockRun", "!=", "nil", "{", "return", "c", ".", "MockRun", "(", "command", ",", "stdout", ",", "stderr", ")", "\n", "}", "\n", "return", "ErrNotImplemented", "\n", "}" ]
// Run calls the mocked run
[ "Run", "calls", "the", "mocked", "run" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/mock_ssh.go#L50-L55
146,186
apcera/libretto
ssh/mock_ssh.go
Upload
func (c *MockSSHClient) Upload(src io.Reader, dst string, size int, mode uint32) error { if c.MockUpload != nil { return c.MockUpload(src, dst, size, mode) } return ErrNotImplemented }
go
func (c *MockSSHClient) Upload(src io.Reader, dst string, size int, mode uint32) error { if c.MockUpload != nil { return c.MockUpload(src, dst, size, mode) } return ErrNotImplemented }
[ "func", "(", "c", "*", "MockSSHClient", ")", "Upload", "(", "src", "io", ".", "Reader", ",", "dst", "string", ",", "size", "int", ",", "mode", "uint32", ")", "error", "{", "if", "c", ".", "MockUpload", "!=", "nil", "{", "return", "c", ".", "MockUpload", "(", "src", ",", "dst", ",", "size", ",", "mode", ")", "\n", "}", "\n", "return", "ErrNotImplemented", "\n", "}" ]
// Upload calls the mocked upload
[ "Upload", "calls", "the", "mocked", "upload" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/mock_ssh.go#L58-L63
146,187
apcera/libretto
ssh/mock_ssh.go
Validate
func (c *MockSSHClient) Validate() error { if c.MockValidate != nil { return c.MockValidate() } return ErrNotImplemented }
go
func (c *MockSSHClient) Validate() error { if c.MockValidate != nil { return c.MockValidate() } return ErrNotImplemented }
[ "func", "(", "c", "*", "MockSSHClient", ")", "Validate", "(", ")", "error", "{", "if", "c", ".", "MockValidate", "!=", "nil", "{", "return", "c", ".", "MockValidate", "(", ")", "\n", "}", "\n", "return", "ErrNotImplemented", "\n", "}" ]
// Validate calls the mocked validate.
[ "Validate", "calls", "the", "mocked", "validate", "." ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/mock_ssh.go#L66-L71
146,188
apcera/libretto
ssh/mock_ssh.go
WaitForSSH
func (c *MockSSHClient) WaitForSSH(maxWait time.Duration) error { if c.MockWaitForSSH != nil { return c.MockWaitForSSH(maxWait) } return ErrNotImplemented }
go
func (c *MockSSHClient) WaitForSSH(maxWait time.Duration) error { if c.MockWaitForSSH != nil { return c.MockWaitForSSH(maxWait) } return ErrNotImplemented }
[ "func", "(", "c", "*", "MockSSHClient", ")", "WaitForSSH", "(", "maxWait", "time", ".", "Duration", ")", "error", "{", "if", "c", ".", "MockWaitForSSH", "!=", "nil", "{", "return", "c", ".", "MockWaitForSSH", "(", "maxWait", ")", "\n", "}", "\n", "return", "ErrNotImplemented", "\n", "}" ]
// WaitForSSH calls the mocked WaitForSSH
[ "WaitForSSH", "calls", "the", "mocked", "WaitForSSH" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/mock_ssh.go#L74-L79
146,189
apcera/libretto
ssh/mock_ssh.go
SetSSHPrivateKey
func (c *MockSSHClient) SetSSHPrivateKey(s string) { if c.MockSetSSHPrivateKey != nil { c.MockSetSSHPrivateKey(s) } }
go
func (c *MockSSHClient) SetSSHPrivateKey(s string) { if c.MockSetSSHPrivateKey != nil { c.MockSetSSHPrivateKey(s) } }
[ "func", "(", "c", "*", "MockSSHClient", ")", "SetSSHPrivateKey", "(", "s", "string", ")", "{", "if", "c", ".", "MockSetSSHPrivateKey", "!=", "nil", "{", "c", ".", "MockSetSSHPrivateKey", "(", "s", ")", "\n", "}", "\n", "}" ]
// SetSSHPrivateKey calls the mocked SetSSHPrivateKey
[ "SetSSHPrivateKey", "calls", "the", "mocked", "SetSSHPrivateKey" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/mock_ssh.go#L82-L86
146,190
apcera/libretto
ssh/mock_ssh.go
SetSSHPassword
func (c *MockSSHClient) SetSSHPassword(s string) { if c.MockSetSSHPassword != nil { c.MockSetSSHPassword(s) } }
go
func (c *MockSSHClient) SetSSHPassword(s string) { if c.MockSetSSHPassword != nil { c.MockSetSSHPassword(s) } }
[ "func", "(", "c", "*", "MockSSHClient", ")", "SetSSHPassword", "(", "s", "string", ")", "{", "if", "c", ".", "MockSetSSHPassword", "!=", "nil", "{", "c", ".", "MockSetSSHPassword", "(", "s", ")", "\n", "}", "\n", "}" ]
// SetSSHPassword calls the mocked SetSSHPassword
[ "SetSSHPassword", "calls", "the", "mocked", "SetSSHPassword" ]
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/ssh/mock_ssh.go#L97-L101
146,191
kubernetes-incubator/reference-docs
gen-apidocs/generators/api/definition.go
InitializeFields
func (s *Definitions) InitializeFields(d *Definition) { for fieldName, property := range d.schema.Properties { des := strings.Replace(property.Description, "\n", " ", -1) f := &Field{ Name: fieldName, Type: GetTypeName(property), Description: EscapeAsterisks(des), } if len(property.Extensions) > 0 { if ps, ok := property.Extensions.GetString(patchStrategyKey); ok { f.PatchStrategy = ps } if pmk, ok := property.Extensions.GetString(patchMergeKeyKey); ok { f.PatchMergeKey = pmk } } if fd, ok := s.GetForSchema(property); ok { f.Definition = fd } d.Fields = append(d.Fields, f) } }
go
func (s *Definitions) InitializeFields(d *Definition) { for fieldName, property := range d.schema.Properties { des := strings.Replace(property.Description, "\n", " ", -1) f := &Field{ Name: fieldName, Type: GetTypeName(property), Description: EscapeAsterisks(des), } if len(property.Extensions) > 0 { if ps, ok := property.Extensions.GetString(patchStrategyKey); ok { f.PatchStrategy = ps } if pmk, ok := property.Extensions.GetString(patchMergeKeyKey); ok { f.PatchMergeKey = pmk } } if fd, ok := s.GetForSchema(property); ok { f.Definition = fd } d.Fields = append(d.Fields, f) } }
[ "func", "(", "s", "*", "Definitions", ")", "InitializeFields", "(", "d", "*", "Definition", ")", "{", "for", "fieldName", ",", "property", ":=", "range", "d", ".", "schema", ".", "Properties", "{", "des", ":=", "strings", ".", "Replace", "(", "property", ".", "Description", ",", "\"", "\\n", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "f", ":=", "&", "Field", "{", "Name", ":", "fieldName", ",", "Type", ":", "GetTypeName", "(", "property", ")", ",", "Description", ":", "EscapeAsterisks", "(", "des", ")", ",", "}", "\n", "if", "len", "(", "property", ".", "Extensions", ")", ">", "0", "{", "if", "ps", ",", "ok", ":=", "property", ".", "Extensions", ".", "GetString", "(", "patchStrategyKey", ")", ";", "ok", "{", "f", ".", "PatchStrategy", "=", "ps", "\n", "}", "\n", "if", "pmk", ",", "ok", ":=", "property", ".", "Extensions", ".", "GetString", "(", "patchMergeKeyKey", ")", ";", "ok", "{", "f", ".", "PatchMergeKey", "=", "pmk", "\n", "}", "\n", "}", "\n\n", "if", "fd", ",", "ok", ":=", "s", ".", "GetForSchema", "(", "property", ")", ";", "ok", "{", "f", ".", "Definition", "=", "fd", "\n", "}", "\n", "d", ".", "Fields", "=", "append", "(", "d", ".", "Fields", ",", "f", ")", "\n", "}", "\n", "}" ]
// Initializes the fields for a definition
[ "Initializes", "the", "fields", "for", "a", "definition" ]
9642bd3f4de59e831d66fecfeb3b465681ba5711
https://github.com/kubernetes-incubator/reference-docs/blob/9642bd3f4de59e831d66fecfeb3b465681ba5711/gen-apidocs/generators/api/definition.go#L163-L185
146,192
kubernetes-incubator/reference-docs
gen-apidocs/generators/api/util.go
GetDefinitionVersionKind
func GetDefinitionVersionKind(s spec.Schema) (string, string, string) { // Get the reference for complex types if IsDefinition(s) { s := fmt.Sprintf("%s", s.SchemaProps.Ref.GetPointer()) s = strings.Replace(s, "/definitions/", "", -1) name := strings.Split(s, ".") var group, version, kind string if name[len(name)-3] == "api" { // e.g. "io.k8s.apimachinery.pkg.api.resource.Quantity" group = "core" version = name[len(name)-2] kind = name[len(name)-1] } else if name[len(name)-4] == "api" { // e.g. "io.k8s.api.core.v1.Pod" group = name[len(name)-3] version = name[len(name)-2] kind = name[len(name)-1] } else if name[len(name)-4] == "apis" { // e.g. "io.k8s.apimachinery.pkg.apis.meta.v1.Status" group = name[len(name)-3] version = name[len(name)-2] kind = name[len(name)-1] } else if name[len(name)-3] == "util" || name[len(name)-3] == "pkg" { // e.g. io.k8s.apimachinery.pkg.util.intstr.IntOrString // e.g. io.k8s.apimachinery.pkg.runtime.RawExtension return "", "", "" } else { panic(errors.New(fmt.Sprintf("Could not locate group for %s", name))) } return group, version, kind } // Recurse if type is array if IsArray(s) { return GetDefinitionVersionKind(*s.Items.Schema) } return "", "", "" }
go
func GetDefinitionVersionKind(s spec.Schema) (string, string, string) { // Get the reference for complex types if IsDefinition(s) { s := fmt.Sprintf("%s", s.SchemaProps.Ref.GetPointer()) s = strings.Replace(s, "/definitions/", "", -1) name := strings.Split(s, ".") var group, version, kind string if name[len(name)-3] == "api" { // e.g. "io.k8s.apimachinery.pkg.api.resource.Quantity" group = "core" version = name[len(name)-2] kind = name[len(name)-1] } else if name[len(name)-4] == "api" { // e.g. "io.k8s.api.core.v1.Pod" group = name[len(name)-3] version = name[len(name)-2] kind = name[len(name)-1] } else if name[len(name)-4] == "apis" { // e.g. "io.k8s.apimachinery.pkg.apis.meta.v1.Status" group = name[len(name)-3] version = name[len(name)-2] kind = name[len(name)-1] } else if name[len(name)-3] == "util" || name[len(name)-3] == "pkg" { // e.g. io.k8s.apimachinery.pkg.util.intstr.IntOrString // e.g. io.k8s.apimachinery.pkg.runtime.RawExtension return "", "", "" } else { panic(errors.New(fmt.Sprintf("Could not locate group for %s", name))) } return group, version, kind } // Recurse if type is array if IsArray(s) { return GetDefinitionVersionKind(*s.Items.Schema) } return "", "", "" }
[ "func", "GetDefinitionVersionKind", "(", "s", "spec", ".", "Schema", ")", "(", "string", ",", "string", ",", "string", ")", "{", "// Get the reference for complex types", "if", "IsDefinition", "(", "s", ")", "{", "s", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "SchemaProps", ".", "Ref", ".", "GetPointer", "(", ")", ")", "\n", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "name", ":=", "strings", ".", "Split", "(", "s", ",", "\"", "\"", ")", "\n\n", "var", "group", ",", "version", ",", "kind", "string", "\n", "if", "name", "[", "len", "(", "name", ")", "-", "3", "]", "==", "\"", "\"", "{", "// e.g. \"io.k8s.apimachinery.pkg.api.resource.Quantity\"", "group", "=", "\"", "\"", "\n", "version", "=", "name", "[", "len", "(", "name", ")", "-", "2", "]", "\n", "kind", "=", "name", "[", "len", "(", "name", ")", "-", "1", "]", "\n", "}", "else", "if", "name", "[", "len", "(", "name", ")", "-", "4", "]", "==", "\"", "\"", "{", "// e.g. \"io.k8s.api.core.v1.Pod\"", "group", "=", "name", "[", "len", "(", "name", ")", "-", "3", "]", "\n", "version", "=", "name", "[", "len", "(", "name", ")", "-", "2", "]", "\n", "kind", "=", "name", "[", "len", "(", "name", ")", "-", "1", "]", "\n", "}", "else", "if", "name", "[", "len", "(", "name", ")", "-", "4", "]", "==", "\"", "\"", "{", "// e.g. \"io.k8s.apimachinery.pkg.apis.meta.v1.Status\"", "group", "=", "name", "[", "len", "(", "name", ")", "-", "3", "]", "\n", "version", "=", "name", "[", "len", "(", "name", ")", "-", "2", "]", "\n", "kind", "=", "name", "[", "len", "(", "name", ")", "-", "1", "]", "\n", "}", "else", "if", "name", "[", "len", "(", "name", ")", "-", "3", "]", "==", "\"", "\"", "||", "name", "[", "len", "(", "name", ")", "-", "3", "]", "==", "\"", "\"", "{", "// e.g. io.k8s.apimachinery.pkg.util.intstr.IntOrString", "// e.g. io.k8s.apimachinery.pkg.runtime.RawExtension", "return", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "\n", "}", "else", "{", "panic", "(", "errors", ".", "New", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ")", ")", ")", "\n", "}", "\n", "return", "group", ",", "version", ",", "kind", "\n", "}", "\n", "// Recurse if type is array", "if", "IsArray", "(", "s", ")", "{", "return", "GetDefinitionVersionKind", "(", "*", "s", ".", "Items", ".", "Schema", ")", "\n", "}", "\n", "return", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "\n", "}" ]
// GetDefinitionVersionKind returns the api version and kind for the spec. This is the primary key of a Definition.
[ "GetDefinitionVersionKind", "returns", "the", "api", "version", "and", "kind", "for", "the", "spec", ".", "This", "is", "the", "primary", "key", "of", "a", "Definition", "." ]
9642bd3f4de59e831d66fecfeb3b465681ba5711
https://github.com/kubernetes-incubator/reference-docs/blob/9642bd3f4de59e831d66fecfeb3b465681ba5711/gen-apidocs/generators/api/util.go#L39-L76
146,193
kubernetes-incubator/reference-docs
gen-apidocs/generators/api/util.go
GetTypeName
func GetTypeName(s spec.Schema) string { // Get the reference for complex types if IsDefinition(s) { _, _, name := GetDefinitionVersionKind(s) return name } // Recurse if type is array if IsArray(s) { return fmt.Sprintf("%s array", GetTypeName(*s.Items.Schema)) } // Get the value for primitive types if len(s.Type) > 0 { return fmt.Sprintf("%s", s.Type[0]) } panic(fmt.Errorf("No type found for object %v", s)) }
go
func GetTypeName(s spec.Schema) string { // Get the reference for complex types if IsDefinition(s) { _, _, name := GetDefinitionVersionKind(s) return name } // Recurse if type is array if IsArray(s) { return fmt.Sprintf("%s array", GetTypeName(*s.Items.Schema)) } // Get the value for primitive types if len(s.Type) > 0 { return fmt.Sprintf("%s", s.Type[0]) } panic(fmt.Errorf("No type found for object %v", s)) }
[ "func", "GetTypeName", "(", "s", "spec", ".", "Schema", ")", "string", "{", "// Get the reference for complex types", "if", "IsDefinition", "(", "s", ")", "{", "_", ",", "_", ",", "name", ":=", "GetDefinitionVersionKind", "(", "s", ")", "\n", "return", "name", "\n", "}", "\n", "// Recurse if type is array", "if", "IsArray", "(", "s", ")", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "GetTypeName", "(", "*", "s", ".", "Items", ".", "Schema", ")", ")", "\n", "}", "\n", "// Get the value for primitive types", "if", "len", "(", "s", ".", "Type", ")", ">", "0", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "Type", "[", "0", "]", ")", "\n", "}", "\n", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ")", ")", "\n", "}" ]
// GetTypeName returns the display name of a Schema. This is the api kind for definitions and the type for // primitive types. Arrays of objects have "array" appended.
[ "GetTypeName", "returns", "the", "display", "name", "of", "a", "Schema", ".", "This", "is", "the", "api", "kind", "for", "definitions", "and", "the", "type", "for", "primitive", "types", ".", "Arrays", "of", "objects", "have", "array", "appended", "." ]
9642bd3f4de59e831d66fecfeb3b465681ba5711
https://github.com/kubernetes-incubator/reference-docs/blob/9642bd3f4de59e831d66fecfeb3b465681ba5711/gen-apidocs/generators/api/util.go#L80-L95
146,194
kubernetes-incubator/reference-docs
gen-apidocs/generators/api/util.go
IsArray
func IsArray(s spec.Schema) bool { return len(s.Type) > 0 && s.Type[0] == "array" }
go
func IsArray(s spec.Schema) bool { return len(s.Type) > 0 && s.Type[0] == "array" }
[ "func", "IsArray", "(", "s", "spec", ".", "Schema", ")", "bool", "{", "return", "len", "(", "s", ".", "Type", ")", ">", "0", "&&", "s", ".", "Type", "[", "0", "]", "==", "\"", "\"", "\n", "}" ]
// IsArray returns true if the type is an array type.
[ "IsArray", "returns", "true", "if", "the", "type", "is", "an", "array", "type", "." ]
9642bd3f4de59e831d66fecfeb3b465681ba5711
https://github.com/kubernetes-incubator/reference-docs/blob/9642bd3f4de59e831d66fecfeb3b465681ba5711/gen-apidocs/generators/api/util.go#L98-L100
146,195
kubernetes-incubator/reference-docs
gen-apidocs/generators/api/util.go
IsDefinition
func IsDefinition(s spec.Schema) bool { return len(s.SchemaProps.Ref.GetPointer().String()) > 0 }
go
func IsDefinition(s spec.Schema) bool { return len(s.SchemaProps.Ref.GetPointer().String()) > 0 }
[ "func", "IsDefinition", "(", "s", "spec", ".", "Schema", ")", "bool", "{", "return", "len", "(", "s", ".", "SchemaProps", ".", "Ref", ".", "GetPointer", "(", ")", ".", "String", "(", ")", ")", ">", "0", "\n", "}" ]
// IsDefinition returns true if Schema is a complex type that should have a Definition.
[ "IsDefinition", "returns", "true", "if", "Schema", "is", "a", "complex", "type", "that", "should", "have", "a", "Definition", "." ]
9642bd3f4de59e831d66fecfeb3b465681ba5711
https://github.com/kubernetes-incubator/reference-docs/blob/9642bd3f4de59e831d66fecfeb3b465681ba5711/gen-apidocs/generators/api/util.go#L103-L105
146,196
kubernetes-incubator/reference-docs
gen-apidocs/generators/api/config.go
initOperations
func (c *Config) initOperations(specs []*loads.Document) { ops := Operations{} c.GroupMap = map[string]string{} VisitOperations(specs, func(op Operation) { ops[op.ID] = &op // Build a map of the group names to the group name appearing in operation ids // This is necessary because the group will appear without the domain // in the resource, but with the domain in the operationID, and we // will be unable to match the operationID to the resource because they // don't agree on the name of the group. // TODO: Fix this by getting the group-version-kind in the resource if *MungeGroups { if v, ok := op.op.Extensions[typeKey]; ok { gvk := v.(map[string]interface{}) group, ok := gvk["group"].(string) if !ok { log.Fatalf("group not type string %v", v) } groupId := "" for _, s := range strings.Split(group, ".") { groupId = groupId + strings.Title(s) } c.GroupMap[strings.Title(strings.Split(group, ".")[0])] = groupId } } }) c.Operations = ops c.mapOperationsToDefinitions() c.initOperationsFromTags(specs) VisitOperations(specs, func(target Operation) { if op, ok := c.Operations[target.ID]; !ok || op.Definition == nil { op.VerifyBlackListed() } }) c.initOperationParameters() // Clear the operations. We still have to calculate the operations because that is how we determine // the API Group for each definition. if !*BuildOps { c.Operations = Operations{} c.OperationCategories = []OperationCategory{} for _, d := range c.Definitions.All { d.OperationCategories = []*OperationCategory{} } } }
go
func (c *Config) initOperations(specs []*loads.Document) { ops := Operations{} c.GroupMap = map[string]string{} VisitOperations(specs, func(op Operation) { ops[op.ID] = &op // Build a map of the group names to the group name appearing in operation ids // This is necessary because the group will appear without the domain // in the resource, but with the domain in the operationID, and we // will be unable to match the operationID to the resource because they // don't agree on the name of the group. // TODO: Fix this by getting the group-version-kind in the resource if *MungeGroups { if v, ok := op.op.Extensions[typeKey]; ok { gvk := v.(map[string]interface{}) group, ok := gvk["group"].(string) if !ok { log.Fatalf("group not type string %v", v) } groupId := "" for _, s := range strings.Split(group, ".") { groupId = groupId + strings.Title(s) } c.GroupMap[strings.Title(strings.Split(group, ".")[0])] = groupId } } }) c.Operations = ops c.mapOperationsToDefinitions() c.initOperationsFromTags(specs) VisitOperations(specs, func(target Operation) { if op, ok := c.Operations[target.ID]; !ok || op.Definition == nil { op.VerifyBlackListed() } }) c.initOperationParameters() // Clear the operations. We still have to calculate the operations because that is how we determine // the API Group for each definition. if !*BuildOps { c.Operations = Operations{} c.OperationCategories = []OperationCategory{} for _, d := range c.Definitions.All { d.OperationCategories = []*OperationCategory{} } } }
[ "func", "(", "c", "*", "Config", ")", "initOperations", "(", "specs", "[", "]", "*", "loads", ".", "Document", ")", "{", "ops", ":=", "Operations", "{", "}", "\n\n", "c", ".", "GroupMap", "=", "map", "[", "string", "]", "string", "{", "}", "\n", "VisitOperations", "(", "specs", ",", "func", "(", "op", "Operation", ")", "{", "ops", "[", "op", ".", "ID", "]", "=", "&", "op", "\n\n", "// Build a map of the group names to the group name appearing in operation ids", "// This is necessary because the group will appear without the domain", "// in the resource, but with the domain in the operationID, and we", "// will be unable to match the operationID to the resource because they", "// don't agree on the name of the group.", "// TODO: Fix this by getting the group-version-kind in the resource", "if", "*", "MungeGroups", "{", "if", "v", ",", "ok", ":=", "op", ".", "op", ".", "Extensions", "[", "typeKey", "]", ";", "ok", "{", "gvk", ":=", "v", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "group", ",", "ok", ":=", "gvk", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "v", ")", "\n", "}", "\n", "groupId", ":=", "\"", "\"", "\n", "for", "_", ",", "s", ":=", "range", "strings", ".", "Split", "(", "group", ",", "\"", "\"", ")", "{", "groupId", "=", "groupId", "+", "strings", ".", "Title", "(", "s", ")", "\n", "}", "\n", "c", ".", "GroupMap", "[", "strings", ".", "Title", "(", "strings", ".", "Split", "(", "group", ",", "\"", "\"", ")", "[", "0", "]", ")", "]", "=", "groupId", "\n", "}", "\n", "}", "\n", "}", ")", "\n\n", "c", ".", "Operations", "=", "ops", "\n", "c", ".", "mapOperationsToDefinitions", "(", ")", "\n", "c", ".", "initOperationsFromTags", "(", "specs", ")", "\n\n", "VisitOperations", "(", "specs", ",", "func", "(", "target", "Operation", ")", "{", "if", "op", ",", "ok", ":=", "c", ".", "Operations", "[", "target", ".", "ID", "]", ";", "!", "ok", "||", "op", ".", "Definition", "==", "nil", "{", "op", ".", "VerifyBlackListed", "(", ")", "\n", "}", "\n", "}", ")", "\n", "c", ".", "initOperationParameters", "(", ")", "\n\n", "// Clear the operations. We still have to calculate the operations because that is how we determine", "// the API Group for each definition.", "if", "!", "*", "BuildOps", "{", "c", ".", "Operations", "=", "Operations", "{", "}", "\n", "c", ".", "OperationCategories", "=", "[", "]", "OperationCategory", "{", "}", "\n", "for", "_", ",", "d", ":=", "range", "c", ".", "Definitions", ".", "All", "{", "d", ".", "OperationCategories", "=", "[", "]", "*", "OperationCategory", "{", "}", "\n", "}", "\n", "}", "\n", "}" ]
// initOperations returns all Operations found in the Documents
[ "initOperations", "returns", "all", "Operations", "found", "in", "the", "Documents" ]
9642bd3f4de59e831d66fecfeb3b465681ba5711
https://github.com/kubernetes-incubator/reference-docs/blob/9642bd3f4de59e831d66fecfeb3b465681ba5711/gen-apidocs/generators/api/config.go#L195-L244
146,197
kubernetes-incubator/reference-docs
gen-apidocs/generators/api/config.go
CleanUp
func (c *Config) CleanUp() { for _, d := range c.Definitions.All { sort.Sort(d.AppearsIn) sort.Sort(d.Fields) dedup := SortDefinitionsByName{} var last *Definition for _, i := range d.AppearsIn { if last != nil && i.Name == last.Name && i.Group.String() == last.Group.String() && i.Version.String() == last.Version.String() { continue } last = i dedup = append(dedup, i) } d.AppearsIn = dedup } }
go
func (c *Config) CleanUp() { for _, d := range c.Definitions.All { sort.Sort(d.AppearsIn) sort.Sort(d.Fields) dedup := SortDefinitionsByName{} var last *Definition for _, i := range d.AppearsIn { if last != nil && i.Name == last.Name && i.Group.String() == last.Group.String() && i.Version.String() == last.Version.String() { continue } last = i dedup = append(dedup, i) } d.AppearsIn = dedup } }
[ "func", "(", "c", "*", "Config", ")", "CleanUp", "(", ")", "{", "for", "_", ",", "d", ":=", "range", "c", ".", "Definitions", ".", "All", "{", "sort", ".", "Sort", "(", "d", ".", "AppearsIn", ")", "\n", "sort", ".", "Sort", "(", "d", ".", "Fields", ")", "\n", "dedup", ":=", "SortDefinitionsByName", "{", "}", "\n", "var", "last", "*", "Definition", "\n", "for", "_", ",", "i", ":=", "range", "d", ".", "AppearsIn", "{", "if", "last", "!=", "nil", "&&", "i", ".", "Name", "==", "last", ".", "Name", "&&", "i", ".", "Group", ".", "String", "(", ")", "==", "last", ".", "Group", ".", "String", "(", ")", "&&", "i", ".", "Version", ".", "String", "(", ")", "==", "last", ".", "Version", ".", "String", "(", ")", "{", "continue", "\n", "}", "\n", "last", "=", "i", "\n", "dedup", "=", "append", "(", "dedup", ",", "i", ")", "\n", "}", "\n", "d", ".", "AppearsIn", "=", "dedup", "\n", "}", "\n", "}" ]
// CleanUp sorts and dedups fields
[ "CleanUp", "sorts", "and", "dedups", "fields" ]
9642bd3f4de59e831d66fecfeb3b465681ba5711
https://github.com/kubernetes-incubator/reference-docs/blob/9642bd3f4de59e831d66fecfeb3b465681ba5711/gen-apidocs/generators/api/config.go#L247-L265
146,198
kubernetes-incubator/reference-docs
gen-apidocs/generators/api/config.go
LoadConfigFromYAML
func LoadConfigFromYAML() *Config { f := filepath.Join(*ConfigDir, "config.yaml") config := &Config{} contents, err := ioutil.ReadFile(f) if err != nil { if !*UseTags { fmt.Printf("Failed to read yaml file %s: %v", f, err) os.Exit(2) } } else { err = yaml.Unmarshal(contents, config) if err != nil { fmt.Println(err) os.Exit(1) } } writeCategory := OperationCategory{ Name: "Write Operations", OperationTypes: []OperationType{ { Name: "Create", Match: "create${group}${version}(Namespaced)?${resource}", }, { Name: "Create Eviction", Match: "create${group}${version}(Namespaced)?${resource}Eviction", }, { Name: "Patch", Match: "patch${group}${version}(Namespaced)?${resource}", }, { Name: "Replace", Match: "replace${group}${version}(Namespaced)?${resource}", }, { Name: "Delete", Match: "delete${group}${version}(Namespaced)?${resource}", }, { Name: "Delete Collection", Match: "delete${group}${version}Collection(Namespaced)?${resource}", }, }, } readCategory := OperationCategory{ Name: "Read Operations", OperationTypes: []OperationType{ { Name: "Read", Match: "read${group}${version}(Namespaced)?${resource}", }, { Name: "List", Match: "list${group}${version}(Namespaced)?${resource}", }, { Name: "List All Namespaces", Match: "list${group}${version}(Namespaced)?${resource}ForAllNamespaces", }, { Name: "Watch", Match: "watch${group}${version}(Namespaced)?${resource}", }, { Name: "Watch List", Match: "watch${group}${version}(Namespaced)?${resource}List", }, { Name: "Watch List All Namespaces", Match: "watch${group}${version}(Namespaced)?${resource}ListForAllNamespaces", }, }, } statusCategory := OperationCategory{ Name: "Status Operations", OperationTypes: []OperationType{ { Name: "Patch Status", Match: "patch${group}${version}(Namespaced)?${resource}Status", }, { Name: "Read Status", Match: "read${group}${version}(Namespaced)?${resource}Status", }, { Name: "Replace Status", Match: "replace${group}${version}(Namespaced)?${resource}Status", }, }, } config.OperationCategories = append([]OperationCategory{writeCategory, readCategory, statusCategory}, config.OperationCategories...) return config }
go
func LoadConfigFromYAML() *Config { f := filepath.Join(*ConfigDir, "config.yaml") config := &Config{} contents, err := ioutil.ReadFile(f) if err != nil { if !*UseTags { fmt.Printf("Failed to read yaml file %s: %v", f, err) os.Exit(2) } } else { err = yaml.Unmarshal(contents, config) if err != nil { fmt.Println(err) os.Exit(1) } } writeCategory := OperationCategory{ Name: "Write Operations", OperationTypes: []OperationType{ { Name: "Create", Match: "create${group}${version}(Namespaced)?${resource}", }, { Name: "Create Eviction", Match: "create${group}${version}(Namespaced)?${resource}Eviction", }, { Name: "Patch", Match: "patch${group}${version}(Namespaced)?${resource}", }, { Name: "Replace", Match: "replace${group}${version}(Namespaced)?${resource}", }, { Name: "Delete", Match: "delete${group}${version}(Namespaced)?${resource}", }, { Name: "Delete Collection", Match: "delete${group}${version}Collection(Namespaced)?${resource}", }, }, } readCategory := OperationCategory{ Name: "Read Operations", OperationTypes: []OperationType{ { Name: "Read", Match: "read${group}${version}(Namespaced)?${resource}", }, { Name: "List", Match: "list${group}${version}(Namespaced)?${resource}", }, { Name: "List All Namespaces", Match: "list${group}${version}(Namespaced)?${resource}ForAllNamespaces", }, { Name: "Watch", Match: "watch${group}${version}(Namespaced)?${resource}", }, { Name: "Watch List", Match: "watch${group}${version}(Namespaced)?${resource}List", }, { Name: "Watch List All Namespaces", Match: "watch${group}${version}(Namespaced)?${resource}ListForAllNamespaces", }, }, } statusCategory := OperationCategory{ Name: "Status Operations", OperationTypes: []OperationType{ { Name: "Patch Status", Match: "patch${group}${version}(Namespaced)?${resource}Status", }, { Name: "Read Status", Match: "read${group}${version}(Namespaced)?${resource}Status", }, { Name: "Replace Status", Match: "replace${group}${version}(Namespaced)?${resource}Status", }, }, } config.OperationCategories = append([]OperationCategory{writeCategory, readCategory, statusCategory}, config.OperationCategories...) return config }
[ "func", "LoadConfigFromYAML", "(", ")", "*", "Config", "{", "f", ":=", "filepath", ".", "Join", "(", "*", "ConfigDir", ",", "\"", "\"", ")", "\n\n", "config", ":=", "&", "Config", "{", "}", "\n", "contents", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "f", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "*", "UseTags", "{", "fmt", ".", "Printf", "(", "\"", "\"", ",", "f", ",", "err", ")", "\n", "os", ".", "Exit", "(", "2", ")", "\n", "}", "\n", "}", "else", "{", "err", "=", "yaml", ".", "Unmarshal", "(", "contents", ",", "config", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "err", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "}", "\n\n", "writeCategory", ":=", "OperationCategory", "{", "Name", ":", "\"", "\"", ",", "OperationTypes", ":", "[", "]", "OperationType", "{", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n\n", "readCategory", ":=", "OperationCategory", "{", "Name", ":", "\"", "\"", ",", "OperationTypes", ":", "[", "]", "OperationType", "{", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n\n", "statusCategory", ":=", "OperationCategory", "{", "Name", ":", "\"", "\"", ",", "OperationTypes", ":", "[", "]", "OperationType", "{", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Match", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", "\n\n", "config", ".", "OperationCategories", "=", "append", "(", "[", "]", "OperationCategory", "{", "writeCategory", ",", "readCategory", ",", "statusCategory", "}", ",", "config", ".", "OperationCategories", "...", ")", "\n\n", "return", "config", "\n", "}" ]
// LoadConfigFromYAML reads the config yaml file into a struct
[ "LoadConfigFromYAML", "reads", "the", "config", "yaml", "file", "into", "a", "struct" ]
9642bd3f4de59e831d66fecfeb3b465681ba5711
https://github.com/kubernetes-incubator/reference-docs/blob/9642bd3f4de59e831d66fecfeb3b465681ba5711/gen-apidocs/generators/api/config.go#L268-L367
146,199
kubernetes-incubator/reference-docs
gen-apidocs/generators/api/config.go
mapOperationsToDefinitions
func (c *Config) mapOperationsToDefinitions() { for _, d := range c.Definitions.All { if d.IsInlined { continue } for i := range c.OperationCategories { oc := c.OperationCategories[i] for j := range oc.OperationTypes { ot := oc.OperationTypes[j] operationId := c.getOperationId(ot.Match, d.GetOperationGroupName(), d.Version, d.Name) c.setOperation(operationId, "Namespaced", &ot, &oc, d) c.setOperation(operationId, "", &ot, &oc, d) } if len(oc.Operations) > 0 { d.OperationCategories = append(d.OperationCategories, &oc) } } } }
go
func (c *Config) mapOperationsToDefinitions() { for _, d := range c.Definitions.All { if d.IsInlined { continue } for i := range c.OperationCategories { oc := c.OperationCategories[i] for j := range oc.OperationTypes { ot := oc.OperationTypes[j] operationId := c.getOperationId(ot.Match, d.GetOperationGroupName(), d.Version, d.Name) c.setOperation(operationId, "Namespaced", &ot, &oc, d) c.setOperation(operationId, "", &ot, &oc, d) } if len(oc.Operations) > 0 { d.OperationCategories = append(d.OperationCategories, &oc) } } } }
[ "func", "(", "c", "*", "Config", ")", "mapOperationsToDefinitions", "(", ")", "{", "for", "_", ",", "d", ":=", "range", "c", ".", "Definitions", ".", "All", "{", "if", "d", ".", "IsInlined", "{", "continue", "\n", "}", "\n\n", "for", "i", ":=", "range", "c", ".", "OperationCategories", "{", "oc", ":=", "c", ".", "OperationCategories", "[", "i", "]", "\n", "for", "j", ":=", "range", "oc", ".", "OperationTypes", "{", "ot", ":=", "oc", ".", "OperationTypes", "[", "j", "]", "\n", "operationId", ":=", "c", ".", "getOperationId", "(", "ot", ".", "Match", ",", "d", ".", "GetOperationGroupName", "(", ")", ",", "d", ".", "Version", ",", "d", ".", "Name", ")", "\n", "c", ".", "setOperation", "(", "operationId", ",", "\"", "\"", ",", "&", "ot", ",", "&", "oc", ",", "d", ")", "\n", "c", ".", "setOperation", "(", "operationId", ",", "\"", "\"", ",", "&", "ot", ",", "&", "oc", ",", "d", ")", "\n", "}", "\n\n", "if", "len", "(", "oc", ".", "Operations", ")", ">", "0", "{", "d", ".", "OperationCategories", "=", "append", "(", "d", ".", "OperationCategories", ",", "&", "oc", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// mapOperationsToDefinitions adds operations to the definitions they operate
[ "mapOperationsToDefinitions", "adds", "operations", "to", "the", "definitions", "they", "operate" ]
9642bd3f4de59e831d66fecfeb3b465681ba5711
https://github.com/kubernetes-incubator/reference-docs/blob/9642bd3f4de59e831d66fecfeb3b465681ba5711/gen-apidocs/generators/api/config.go#L471-L491