Diff
Not logged in

Differences From Artifact [14e25b598f]:

To Artifact [a01d53b13c]:


10
11
12
13
14
15
16
17

18
19
20
21
22
23



24








25
26
27
28
29
30
31
32
def find_vm(name):
    search_path=[os.environ['HOME']+"/VWs",
        config.get("directories","SharedVMs"),
        config.get("directories","AutostartVMs")]
    for dirname in search_path:
        if not os.access(dirname,os.X_OK):
            continue
        if name in os.listdir(dirname):

            return dirname+"/"+name
    raise ValueError("Machine "+name+" not found.")


def connect_vm(vm_dir):
    sock=socket.socket(socket.AF_UNIX)



    sock.connect(vm_dir+"/monitor")








    greeting=sock.recv(1024)
    return sock

def send_command(sock,command):
    fcntl.flock(sock,fcntl.LOCK_EX)
    try:
        sock.send(command+"\n")
        answer=""







|
>






>
>
>
|
>
>
>
>
>
>
>
>
|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def find_vm(name):
    search_path=[os.environ['HOME']+"/VWs",
        config.get("directories","SharedVMs"),
        config.get("directories","AutostartVMs")]
    for dirname in search_path:
        if not os.access(dirname,os.X_OK):
            continue
        if ( name in os.listdir(dirname) and
             os.access(dirname+"/"+name+"/start",os.X_OK)):
            return dirname+"/"+name
    raise ValueError("Machine "+name+" not found.")


def connect_vm(vm_dir):
    sock=socket.socket(socket.AF_UNIX)
    if not os.access(vm_dir+"/monitor",os.W_OK):
        return None
    try:
        sock.connect(vm_dir+"/monitor")
    except IOError as e:
        if e.errno == errno.ECONNREFUSED:
            # virtal machine is not running
            return None
        else:
            raise e
    r,w,x=select.select([sock],[],[],0.001)
    if sock in r:
        greeting=sock.recv(1024)
    return sock

def send_command(sock,command):
    fcntl.flock(sock,fcntl.LOCK_EX)
    try:
        sock.send(command+"\n")
        answer=""
146
147
148
149
150
151
152


153
154
155
















156
157
158
159
160
161
162
163
    count = 0
    search_path=[os.environ['HOME']+"/VWs",
        config.get("directories","SharedVMs"),
        config.get("directories","AutostartVMs")]
    for dirname in search_path:
        if not os.access(dirname+"/.",os.X_OK):
            continue


        for vmname in os.listdir(dirname):
            if os.access(dirname+"/"+vmname+"/start",os.X_OK):
                count += 1
















                print vmname
    if not count:
        sys.exit(1)
def cmd_version(options):
    print VERSION
#
# Utility functions for arg parsing
#







>
>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|







158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
    count = 0
    search_path=[os.environ['HOME']+"/VWs",
        config.get("directories","SharedVMs"),
        config.get("directories","AutostartVMs")]
    for dirname in search_path:
        if not os.access(dirname+"/.",os.X_OK):
            continue
        maxlen=0
        vms=[]
        for vmname in os.listdir(dirname):
            if os.access(dirname+"/"+vmname+"/start",os.X_OK):
                count += 1
                f=[vmname]
                if maxlen < len(vmname):
                    maxlen = len(vmname)
                if options.state:
                    sock = connect_vm(dirname+"/"+vmname)
                    if sock is None:
                        state = "stopped"
                    else:
                        sock.close()
                        state = "running"
                    f.append(state)
                vms.append(f)
        for f in sorted(vms):
            if len(f)==2:
                print "%*s %s" % (-maxlen,f[0],f[1])
            else:
                print f[0]
    if not count:
        sys.exit(1)
def cmd_version(options):
    print VERSION
#
# Utility functions for arg parsing
#
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
p=new_command(cmds,'spiceuri',help='Output spice URI of machine')
parsed_args=args.parse_args(sys.argv[1:])

parsed_args.stopped = False
stopped_vm_commands = ['start','snapshot','revert','commit','snapshots']
if hasattr(parsed_args,'machine'):
    parsed_args.dir=find_vm(parsed_args.machine)
    try:
        parsed_args.sock=connect_vm(parsed_args.dir)
    except IOError as e:
        if e.errno == errno.ECONNREFUSED:
            # virtal machine is not running
            if not parsed_args.command in stopped_vm_commands:
                print >>sys.stderr, "Virtual machine %s is not running."%parsed_args.machine
                sys.exit(1)
            else:
                parsed_args.stopped = True
        else:
            raise e
funcname="cmd_"+parsed_args.command

if hasattr(parsed_args,"subcommand"):
    funcname+="_"+parsed_args.subcommand
try:
   func=globals()[funcname]
except KeyError:
    print >>sys.stderr,"Operation %s is not implemented"%funcname
    sys.exit(3)
func(parsed_args)







<
|
<
|
<
|
|
|
|
|
|
<










258
259
260
261
262
263
264

265

266

267
268
269
270
271
272

273
274
275
276
277
278
279
280
281
282
p=new_command(cmds,'spiceuri',help='Output spice URI of machine')
parsed_args=args.parse_args(sys.argv[1:])

parsed_args.stopped = False
stopped_vm_commands = ['start','snapshot','revert','commit','snapshots']
if hasattr(parsed_args,'machine'):
    parsed_args.dir=find_vm(parsed_args.machine)

    parsed_args.sock=connect_vm(parsed_args.dir)

    if parsed_args.sock  is None:

        if not parsed_args.command in stopped_vm_commands:
            print >>sys.stderr, "Virtual machine %s is not running."%parsed_args.machine
            sys.exit(1)
        else:
            parsed_args.stopped = True


funcname="cmd_"+parsed_args.command

if hasattr(parsed_args,"subcommand"):
    funcname+="_"+parsed_args.subcommand
try:
   func=globals()[funcname]
except KeyError:
    print >>sys.stderr,"Operation %s is not implemented"%funcname
    sys.exit(3)
func(parsed_args)