本文整理汇总了Golang中github.com/lxc/lxd.Client.GetLog方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.GetLog方法的具体用法?Golang Client.GetLog怎么用?Golang Client.GetLog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lxc/lxd.Client
的用法示例。
在下文中一共展示了Client.GetLog方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: containerInfo
func containerInfo(d *lxd.Client, name string, showLog bool) error {
ct, err := d.ContainerStatus(name)
if err != nil {
return err
}
fmt.Printf(gettext.Gettext("Name: %s")+"\n", ct.Name)
fmt.Printf(gettext.Gettext("Status: %s")+"\n", ct.Status.Status)
if ct.Status.Init != 0 {
fmt.Printf(gettext.Gettext("Init: %d")+"\n", ct.Status.Init)
fmt.Printf(gettext.Gettext("Processcount: %d")+"\n", ct.Status.Processcount)
fmt.Printf(gettext.Gettext("Ips:") + "\n")
foundone := false
for _, ip := range ct.Status.Ips {
vethStr := ""
if ip.HostVeth != "" {
vethStr = fmt.Sprintf("\t%s", ip.HostVeth)
}
fmt.Printf(" %s:\t%s\t%s%s\n", ip.Interface, ip.Protocol, ip.Address, vethStr)
foundone = true
}
if !foundone {
fmt.Println(gettext.Gettext("(none)"))
}
}
// List snapshots
first_snapshot := true
snaps, err := d.ListSnapshots(name)
if err != nil {
return nil
}
for _, snap := range snaps {
if first_snapshot {
fmt.Println(gettext.Gettext("Snapshots:"))
}
fmt.Printf(" %s\n", snap)
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"+gettext.Gettext("Log:")+"\n\n%s\n", string(stuff))
}
return nil
}
示例2: 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
}
示例3: containerInfo
func containerInfo(d *lxd.Client, name string, showLog bool) error {
ct, err := d.ContainerStatus(name)
if err != nil {
return err
}
const layout = "2006/01/02 15:04 UTC"
fmt.Printf(i18n.G("Name: %s")+"\n", ct.Name)
if ct.CreationDate != 0 {
fmt.Printf(i18n.G("Created: %s")+"\n", time.Unix(ct.CreationDate, 0).UTC().Format(layout))
}
fmt.Printf(i18n.G("Status: %s")+"\n", ct.Status.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 ct.Status.Init != 0 {
fmt.Printf(i18n.G("Init: %d")+"\n", ct.Status.Init)
fmt.Printf(i18n.G("Processcount: %d")+"\n", ct.Status.Processcount)
fmt.Printf(i18n.G("Ips:") + "\n")
foundone := false
for _, ip := range ct.Status.Ips {
vethStr := ""
if ip.HostVeth != "" {
vethStr = fmt.Sprintf("\t%s", ip.HostVeth)
}
fmt.Printf(" %s:\t%s\t%s%s\n", ip.Interface, ip.Protocol, ip.Address, vethStr)
foundone = true
}
if !foundone {
fmt.Println(i18n.G("(none)"))
}
}
// 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 != 0 {
fmt.Printf(" ("+i18n.G("taken at %s")+")", time.Unix(snap.CreationDate, 0).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
}
示例4: containerInfo
//.........这里部分代码省略.........
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))
}
if memoryInfo != "" {
fmt.Println(i18n.G(" Memory usage:"))
fmt.Printf(memoryInfo)
}
// Network usage
networkInfo := ""
if cs.Network != nil {
for netName, net := range cs.Network {
networkInfo += fmt.Sprintf(" %s:\n", netName)
networkInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Bytes received"), shared.GetByteSizeString(net.Counters.BytesReceived))
networkInfo += fmt.Sprintf(" %s: %s\n", i18n.G("Bytes sent"), shared.GetByteSizeString(net.Counters.BytesSent))
networkInfo += fmt.Sprintf(" %s: %d\n", i18n.G("Packets received"), net.Counters.PacketsReceived)
networkInfo += fmt.Sprintf(" %s: %d\n", i18n.G("Packets sent"), net.Counters.PacketsSent)
}
}
if networkInfo != "" {
fmt.Println(i18n.G(" Network usage:"))
fmt.Printf(networkInfo)
}
}
// 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:"))
}
fields := strings.Split(snap.Name, shared.SnapshotDelimiter)
fmt.Printf(" %s", fields[len(fields)-1])
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
}