本文整理汇总了Golang中github.com/lxc/lxd.Client.ContainerInfo方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.ContainerInfo方法的具体用法?Golang Client.ContainerInfo怎么用?Golang Client.ContainerInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lxc/lxd.Client
的用法示例。
在下文中一共展示了Client.ContainerInfo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: doNetworkDetach
func (c *networkCmd) doNetworkDetach(client *lxd.Client, name string, args []string) error {
if len(args) < 1 || len(args) > 2 {
return errArgs
}
containerName := args[0]
devName := ""
if len(args) > 1 {
devName = args[1]
}
container, err := client.ContainerInfo(containerName)
if err != nil {
return err
}
if devName == "" {
for n, d := range container.Devices {
if d["type"] == "nic" && d["parent"] == name {
if devName != "" {
return fmt.Errorf(i18n.G("More than one device matches, specify the device name."))
}
devName = n
}
}
}
if devName == "" {
return fmt.Errorf(i18n.G("No device found for this network"))
}
device, ok := container.Devices[devName]
if !ok {
return fmt.Errorf(i18n.G("The specified device doesn't exist"))
}
if device["type"] != "nic" || device["parent"] != name {
return fmt.Errorf(i18n.G("The specified device doesn't match the network"))
}
resp, err := client.ContainerDeviceDelete(containerName, devName)
if err != nil {
return err
}
return client.WaitForSuccess(resp.Operation)
}
示例3: checkNetwork
func (c *initCmd) checkNetwork(d *lxd.Client, name string) {
ct, err := d.ContainerInfo(name)
if err != nil {
return
}
for _, d := range ct.ExpandedDevices {
if d["type"] == "nic" {
return
}
}
fmt.Fprintf(os.Stderr, "\n"+i18n.G("The container you are starting doesn’t have any network attached to it.")+"\n")
fmt.Fprintf(os.Stderr, " "+i18n.G("To create a new network, use: lxc network create")+"\n")
fmt.Fprintf(os.Stderr, " "+i18n.G("To assign a network to a container, use: lxc network assign")+"\n\n")
}
示例4: doProfileAdd
func (c *profileCmd) doProfileAdd(client *lxd.Client, d string, p string) error {
ct, err := client.ContainerInfo(d)
if err != nil {
return err
}
ct.Profiles = append(ct.Profiles, p)
err = client.UpdateContainerConfig(d, ct.Brief())
if err != nil {
return err
}
fmt.Printf(i18n.G("Profile %s added to %s")+"\n", p, d)
return err
}
示例5: doContainerConfigEdit
func (c *configCmd) doContainerConfigEdit(client *lxd.Client, cont string) error {
// If stdin isn't a terminal, read text from it
if !termios.IsTerminal(int(syscall.Stdin)) {
contents, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
newdata := shared.BriefContainerInfo{}
err = yaml.Unmarshal(contents, &newdata)
if err != nil {
return err
}
return client.UpdateContainerConfig(cont, newdata)
}
// Extract the current value
config, err := client.ContainerInfo(cont)
if err != nil {
return err
}
brief := config.Brief()
data, err := yaml.Marshal(&brief)
if err != nil {
return err
}
// Spawn the editor
content, err := shared.TextEditor("", []byte(c.configEditHelp()+"\n\n"+string(data)))
if err != nil {
return err
}
for {
// Parse the text received from the editor
newdata := shared.BriefContainerInfo{}
err = yaml.Unmarshal(content, &newdata)
if err == nil {
err = client.UpdateContainerConfig(cont, newdata)
}
// Respawn the editor
if err != nil {
fmt.Fprintf(os.Stderr, i18n.G("Config parsing error: %s")+"\n", err)
fmt.Println(i18n.G("Press enter to start the editor again"))
_, err := os.Stdin.Read(make([]byte, 1))
if err != nil {
return err
}
content, err = shared.TextEditor("", content)
if err != nil {
return err
}
continue
}
break
}
return nil
}
示例6: containerInfo
func (c *infoCmd) containerInfo(d *lxd.Client, name string, showLog bool) error {
ct, err := d.ContainerInfo(name)
if err != nil {
return err
}
cs, err := d.ContainerState(name)
if err != nil {
return err
}
const layout = "2006/01/02 15:04 UTC"
fmt.Printf(i18n.G("Name: %s")+"\n", ct.Name)
fmt.Printf(i18n.G("Architecture: %s")+"\n", ct.Architecture)
if ct.CreationDate.UTC().Unix() != 0 {
fmt.Printf(i18n.G("Created: %s")+"\n", ct.CreationDate.UTC().Format(layout))
}
fmt.Printf(i18n.G("Status: %s")+"\n", ct.Status)
if ct.Ephemeral {
fmt.Printf(i18n.G("Type: ephemeral") + "\n")
} else {
fmt.Printf(i18n.G("Type: persistent") + "\n")
}
fmt.Printf(i18n.G("Profiles: %s")+"\n", strings.Join(ct.Profiles, ", "))
if cs.Pid != 0 {
fmt.Printf(i18n.G("Pid: %d")+"\n", cs.Pid)
fmt.Printf(i18n.G("Processes: %d")+"\n", cs.Processes)
ipInfo := ""
for netName, net := range cs.Network {
vethStr := ""
if net.HostName != "" {
vethStr = fmt.Sprintf("\t%s", net.HostName)
}
for _, addr := range net.Addresses {
ipInfo += fmt.Sprintf(" %s:\t%s\t%s%s\n", netName, addr.Family, addr.Address, vethStr)
}
}
if ipInfo != "" {
fmt.Printf(i18n.G("Ips:") + "\n")
fmt.Printf(ipInfo)
}
}
// List snapshots
first_snapshot := true
snaps, err := d.ListSnapshots(name)
if err != nil {
return nil
}
for _, snap := range snaps {
if first_snapshot {
fmt.Println(i18n.G("Snapshots:"))
}
fmt.Printf(" %s", snap.Name)
if snap.CreationDate.UTC().Unix() != 0 {
fmt.Printf(" ("+i18n.G("taken at %s")+")", snap.CreationDate.UTC().Format(layout))
}
if snap.Stateful {
fmt.Printf(" (" + i18n.G("stateful") + ")")
} else {
fmt.Printf(" (" + i18n.G("stateless") + ")")
}
fmt.Printf("\n")
first_snapshot = false
}
if showLog {
log, err := d.GetLog(name, "lxc.log")
if err != nil {
return err
}
stuff, err := ioutil.ReadAll(log)
if err != nil {
return err
}
fmt.Printf("\n"+i18n.G("Log:")+"\n\n%s\n", string(stuff))
}
return nil
}
示例7: containerInfo
func (c *infoCmd) containerInfo(d *lxd.Client, name string, showLog bool) error {
ct, err := d.ContainerInfo(name)
if err != nil {
return err
}
cs, err := d.ContainerState(name)
if err != nil {
return err
}
const layout = "2006/01/02 15:04 UTC"
fmt.Printf(i18n.G("Name: %s")+"\n", ct.Name)
if d.Remote != nil && d.Remote.Addr != "" {
fmt.Printf(i18n.G("Remote: %s")+"\n", d.Remote.Addr)
}
fmt.Printf(i18n.G("Architecture: %s")+"\n", ct.Architecture)
if ct.CreationDate.UTC().Unix() != 0 {
fmt.Printf(i18n.G("Created: %s")+"\n", ct.CreationDate.UTC().Format(layout))
}
fmt.Printf(i18n.G("Status: %s")+"\n", ct.Status)
if ct.Ephemeral {
fmt.Printf(i18n.G("Type: ephemeral") + "\n")
} else {
fmt.Printf(i18n.G("Type: persistent") + "\n")
}
fmt.Printf(i18n.G("Profiles: %s")+"\n", strings.Join(ct.Profiles, ", "))
if cs.Pid != 0 {
fmt.Printf(i18n.G("Pid: %d")+"\n", cs.Pid)
// IP addresses
ipInfo := ""
if cs.Network != nil {
for netName, net := range cs.Network {
vethStr := ""
if net.HostName != "" {
vethStr = fmt.Sprintf("\t%s", net.HostName)
}
for _, addr := range net.Addresses {
ipInfo += fmt.Sprintf(" %s:\t%s\t%s%s\n", netName, addr.Family, addr.Address, vethStr)
}
}
}
if ipInfo != "" {
fmt.Println(i18n.G("Ips:"))
fmt.Printf(ipInfo)
}
fmt.Println(i18n.G("Resources:"))
// Processes
fmt.Printf(" "+i18n.G("Processes: %d")+"\n", cs.Processes)
// Disk usage
diskInfo := ""
if cs.Disk != nil {
for entry, disk := range cs.Disk {
if disk.Usage != 0 {
diskInfo += fmt.Sprintf(" %s: %s\n", entry, shared.GetByteSizeString(disk.Usage))
}
}
}
if diskInfo != "" {
fmt.Println(i18n.G(" Disk usage:"))
fmt.Printf(diskInfo)
}
// CPU usage
cpuInfo := ""
if cs.CPU.Usage != 0 {
cpuInfo += fmt.Sprintf(" %s: %v\n", i18n.G("CPU usage (in seconds)"), cs.CPU.Usage/1000000000)
}
if cpuInfo != "" {
fmt.Println(i18n.G(" CPU usage:"))
fmt.Printf(cpuInfo)
}
// Memory usage
memoryInfo := ""
if cs.Memory.Usage != 0 {
memoryInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Memory (current)"), shared.GetByteSizeString(cs.Memory.Usage))
}
if cs.Memory.UsagePeak != 0 {
memoryInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Memory (peak)"), shared.GetByteSizeString(cs.Memory.UsagePeak))
}
if cs.Memory.SwapUsage != 0 {
memoryInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Swap (current)"), shared.GetByteSizeString(cs.Memory.SwapUsage))
}
if cs.Memory.SwapUsagePeak != 0 {
memoryInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Swap (peak)"), shared.GetByteSizeString(cs.Memory.SwapUsagePeak))
}
//.........这里部分代码省略.........
示例8: cmdCreate
//.........这里部分代码省略.........
}
} else {
if router.Tier >= 1 && router.Tier <= 3 {
interfaces += fmt.Sprintf(" post-up sleep 10 ; ip -6 route add dev %s %s via %s || true\n", p.Interface, r.Subnet.String(), p.Remote)
}
}
}
}
}
}
if router.Tier >= 1 && router.Tier <= 3 {
bgpd += " address-family ipv6\n"
if router.Peers != nil {
for _, p := range router.Peers {
if p.ASN != 0 {
bgpd += fmt.Sprintf(" neighbor %s activate\n", p.Remote)
}
}
}
bgpd += ` redistribute connected
redistribute kernel
exit-address-family
`
config["user.internet.config.interfaces"] = interfaces
config["user.internet.config.bgpd"] = bgpd
}
// Config-only containers
if router.Tier > 3 {
ct, err := c.ContainerInfo(router.Name)
if err != nil {
logf("Failed to configure container '%s': %s", router.Name, err)
return
}
for k, _ := range ct.Config {
if strings.HasPrefix(k, "user.internet.") {
delete(ct.Config, k)
}
}
for k, v := range config {
ct.Config[k] = v
}
err = c.UpdateContainerConfig(router.Name, ct.Writable())
if err != nil {
logf("Failed to configure container '%s': %s", router.Name, err)
return
}
return
}
// Create the container
resp, err := c.Init(router.Name, "local", "internet-router", &[]string{"internet-base"}, config, nil, false)
if err != nil {
logf("Failed to create container '%s': %s", router.Name, err)
return
}
err = c.WaitForSuccess(resp.Operation)