本文整理汇总了Golang中github.com/lxc/lxd.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doProfileDelete
func (c *profileCmd) doProfileDelete(client *lxd.Client, p string) error {
err := client.ProfileDelete(p)
if err == nil {
fmt.Printf(i18n.G("Profile %s deleted")+"\n", p)
}
return err
}
示例2: doProfileCreate
func doProfileCreate(client *lxd.Client, p string) error {
err := client.ProfileCreate(p)
if err == nil {
fmt.Printf(gettext.Gettext("Profile %s created\n"), p)
}
return err
}
示例3: dereferenceAlias
func (c *imageCmd) dereferenceAlias(d *lxd.Client, inName string) string {
result := d.GetAlias(inName)
if result == "" {
return inName
}
return result
}
示例4: doProfileSet
func doProfileSet(client *lxd.Client, p string, args []string) error {
// we shifted @args so so it should read "<key> [<value>]"
if len(args) < 1 {
return errArgs
}
key := args[0]
var value string
if len(args) < 2 {
value = ""
} else {
value = args[1]
}
if !terminal.IsTerminal(syscall.Stdin) && value == "-" {
buf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("Can't read from stdin: %s", err)
}
value = string(buf[:])
}
err := client.SetProfileConfigItem(p, key, value)
return err
}
示例5: doProfileDelete
func doProfileDelete(client *lxd.Client, p string) error {
err := client.ProfileDelete(p)
if err == nil {
fmt.Printf(gettext.Gettext("Profile %s deleted")+"\n", p)
}
return err
}
示例6: doProfileCreate
func doProfileCreate(client *lxd.Client, p string) error {
err := client.ProfileCreate(p)
if err == nil {
fmt.Printf(i18n.G("Profile %s created")+"\n", p)
}
return err
}
示例7: doNetworkAttachProfile
func (c *networkCmd) doNetworkAttachProfile(client *lxd.Client, name string, args []string) error {
if len(args) < 1 || len(args) > 2 {
return errArgs
}
profile := args[0]
devName := name
if len(args) > 1 {
devName = args[1]
}
network, err := client.NetworkGet(name)
if err != nil {
return err
}
nicType := "macvlan"
if network.Type == "bridge" {
nicType = "bridged"
}
props := []string{fmt.Sprintf("nictype=%s", nicType), fmt.Sprintf("parent=%s", name)}
_, err = client.ProfileDeviceAdd(profile, devName, "nic", props)
return err
}
示例8: doProfileRemove
func (c *profileCmd) doProfileRemove(client *lxd.Client, d string, p string) error {
ct, err := client.ContainerInfo(d)
if err != nil {
return err
}
if !shared.StringInSlice(p, ct.Profiles) {
return fmt.Errorf("Profile %s isn't currently applied to %s", p, d)
}
profiles := []string{}
for _, profile := range ct.Profiles {
if profile == p {
continue
}
profiles = append(profiles, profile)
}
ct.Profiles = profiles
err = client.UpdateContainerConfig(d, ct.Brief())
if err != nil {
return err
}
fmt.Printf(i18n.G("Profile %s removed from %s")+"\n", p, d)
return err
}
示例9: getContainerState
func getContainerState(client *lxd.Client, name string) *shared.ContainerState {
ct, err := client.ContainerState(name)
if err != nil {
return nil
}
return ct
}
示例10: doNetworkSet
func (c *networkCmd) doNetworkSet(client *lxd.Client, name string, args []string) error {
// we shifted @args so so it should read "<key> [<value>]"
if len(args) < 1 {
return errArgs
}
network, err := client.NetworkGet(name)
if err != nil {
return err
}
key := args[0]
var value string
if len(args) < 2 {
value = ""
} else {
value = args[1]
}
if !termios.IsTerminal(int(syscall.Stdin)) && value == "-" {
buf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("Can't read from stdin: %s", err)
}
value = string(buf[:])
}
network.Config[key] = value
return client.NetworkPut(name, network)
}
示例11: doNetworkDelete
func (c *networkCmd) doNetworkDelete(client *lxd.Client, name string) error {
err := client.NetworkDelete(name)
if err == nil {
fmt.Printf(i18n.G("Network %s deleted")+"\n", name)
}
return err
}
示例12: doDelete
func doDelete(d *lxd.Client, name string) error {
resp, err := d.Delete(name)
if err != nil {
return err
}
return d.WaitForSuccess(resp.Operation)
}
示例13: resourceLxdContainerRefresh
func resourceLxdContainerRefresh(client *lxd.Client, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
ct, err := client.ContainerState(name)
if err != nil {
return ct, "Error", err
}
return ct, ct.Status, nil
}
}
示例14: doNetworkShow
func (c *networkCmd) doNetworkShow(client *lxd.Client, name string) error {
network, err := client.NetworkGet(name)
if err != nil {
return err
}
data, err := yaml.Marshal(&network)
fmt.Printf("%s", data)
return nil
}
示例15: doProfileShow
func doProfileShow(client *lxd.Client, p string) error {
profile, err := client.ProfileConfig(p)
if err != nil {
return err
}
data, err := yaml.Marshal(&profile)
fmt.Printf("%s", data)
return nil
}