Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Delta Between Two Patch Sets: container/kvm/libvirt.go

Issue 77970043: Container Manager Interface
Left Patch Set: Container Manager Interface Created 11 years ago
Right Patch Set: Container Manager Interface Created 11 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « container/kvm/kvm_test.go ('k') | container/kvm/mock/mock-kvm.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package kvm 4 package kvm
5 5
6 // This file contains wrappers around the following executables: 6 // This file contains wrappers around the following executables:
7 // uvt-simplestreams-libvirt 7 // uvt-simplestreams-libvirt
8 // uvt-kvm 8 // uvt-kvm
9 // virsh 9 // virsh
10 // Those executables are found in the following packages: 10 // Those executables are found in the following packages:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 // AutostartMachine indicates that the virtual machines should automatically 117 // AutostartMachine indicates that the virtual machines should automatically
118 // restart when the host restarts. 118 // restart when the host restarts.
119 func AutostartMachine(hostname string) error { 119 func AutostartMachine(hostname string) error {
120 _, err := run("virsh", "autostart", hostname) 120 _, err := run("virsh", "autostart", hostname)
121 return err 121 return err
122 } 122 }
123 123
124 // ListMachines returns a map of machine name to state, where state is one of: 124 // ListMachines returns a map of machine name to state, where state is one of:
125 // running, idle, paused, shutdown, shut off, crashed, dying, pmsuspended. 125 // running, idle, paused, shutdown, shut off, crashed, dying, pmsuspended.
126 func ListMachines() (map[string]string, error) { 126 func ListMachines() (map[string]KvmState, error) {
127 output, err := run("virsh", "-q", "list", "--all") 127 output, err := run("virsh", "-q", "list", "--all")
128 if err != nil { 128 if err != nil {
129 return nil, err 129 return nil, err
130 } 130 }
131 // Split the output into lines. 131 // Split the output into lines.
132 // Regex matching is the easiest way to match the lines. 132 // Regex matching is the easiest way to match the lines.
133 // id hostname status 133 // id hostname status
134 // separated by whitespace, with whitespace at the start too. 134 // separated by whitespace, with whitespace at the start too.
135 » result := make(map[string]string) 135 » result := make(map[string]KvmState)
136 for _, s := range machineListPattern.FindAllStringSubmatchIndex(output, -1) { 136 for _, s := range machineListPattern.FindAllStringSubmatchIndex(output, -1) {
137 hostnameAndStatus := machineListPattern.ExpandString(nil, "$host name $status", output, s) 137 hostnameAndStatus := machineListPattern.ExpandString(nil, "$host name $status", output, s)
138 parts := strings.SplitN(string(hostnameAndStatus), " ", 2) 138 parts := strings.SplitN(string(hostnameAndStatus), " ", 2)
139 » » result[parts[0]] = parts[1] 139 » » result[parts[0]] = KvmState(parts[1])
140 } 140 }
141 return result, nil 141 return result, nil
142 } 142 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b