Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sjrpc
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
sjrpc
Commits
fe742047
Commit
fe742047
authored
14 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
Command start,stop,pause,resume,destroy use now TqlCommand
parent
b6c36592
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cccli/command/vm.py
+64
-68
64 additions, 68 deletions
cccli/command/vm.py
with
64 additions
and
68 deletions
cccli/command/vm.py
+
64
−
68
View file @
fe742047
...
...
@@ -8,101 +8,97 @@ from sjrpc.core.exceptions import *
from
cccli.printer
import
Printer
,
color
from
cccli.command.command
import
TqlCommand
class
Vm
Command
(
TqlCommand
):
'''
Command for vm style
'''
class
Command
_start
(
TqlCommand
):
'''
Start a stopped vm
'''
def
__init__
(
self
,
cli
,
argv0
):
TqlCommand
.
__init__
(
self
,
cli
,
argv0
)
self
.
set_usage
(
"
%prog [options] <tql>
"
)
self
.
add_option
(
"
--tg
"
,
action
=
"
store_true
"
,
dest
=
"
noask
"
,
help
=
"
Don
'
t ask confirmation (Dangerous)
"
)
self
.
tql_filter
+=
"
&r=vm&status=stopped
"
def
_
vm_action
(
self
,
argv
,
filters
=
None
):
# parse
args
def
_
_call__
(
self
,
argv
):
#
arg
parse
self
.
parse_args
(
argv
)
if
len
(
self
.
args
)
=
=
0
:
if
len
(
self
.
args
)
!
=
1
:
raise
cmdBadArgument
()
tql
=
str
.
join
(
""
,
self
.
args
)
# append securty options by command name
if
filters
is
not
None
and
not
self
.
options
.
raw
:
tql
+=
filters
if
self
.
options
.
direct
:
try
:
objs
=
self
.
cli
.
rpc
.
call
(
self
.
args
[
0
],
tql
)
except
RpcError
as
e
:
raise
cmdError
(
"
RPCError: %s
"
%
str
(
e
))
else
:
# get objects id
try
:
objs
=
self
.
cli
.
rpc
.
call
(
"
list
"
,
tql
)
except
RpcError
as
e
:
raise
cmdError
(
"
RPCError: %s
"
%
str
(
e
))
# no result, goodbye
if
len
(
objs
)
==
0
:
raise
cmdWarning
(
"
tql:
'
%s
'
: No result.
"
%
tql
)
self
.
printer
.
out
(
"
You will %s:
"
%
self
.
args
[
0
])
for
obj
in
objs
:
self
.
printer
.
out
(
"
%sid:%s%s%s
"
%
(
color
[
"
green
"
],
color
[
"
yellow
"
],
obj
[
"
id
"
],
color
[
"
reset
"
]))
self
.
printer
.
out
(
"
%sCount: %s%s
"
%
(
color
[
"
green
"
],
color
[
"
reset
"
],
len
(
objs
)))
# be sure boby want do that
if
not
self
.
options
.
noask
:
self
.
printer
.
out
(
"
%sProceed?%s
"
%
(
color
[
"
lred
"
],
color
[
"
reset
"
]))
if
self
.
printer
.
ask
(
"
Answer (yes/NO):
"
)
!=
"
yes
"
:
raise
cmdWarning
(
"
Aborted
"
)
if
len
(
objs
)
>
5
:
self
.
printer
.
out
(
"
%sYou request is on more than 5 objets!%s
"
%
(
color
[
"
yellow
"
],
color
[
"
reset
"
]))
self
.
printer
.
out
(
"
%sAre you really sure?%s
"
%
(
color
[
"
lred
"
],
color
[
"
reset
"
]))
if
self
.
printer
.
ask
(
"
Answer (Sir, yes Sir!):
"
)
!=
"
Sir, yes Sir!
"
:
raise
cmdWarning
(
"
Bad Answer. Aborted
"
)
# execute action for each object
for
obj
in
objs
:
self
.
printer
.
out
(
"
%s%s%s %s%s%s
"
%
(
color
[
"
lblue
"
],
argv
[
0
],
color
[
"
reset
"
],
color
[
"
yellow
"
],
obj
[
"
id
"
],
color
[
"
reset
"
]))
try
:
self
.
cli
.
rpc
.
call
(
argv
[
0
],
"
id:%s
"
%
obj
[
"
id
"
])
except
RpcError
as
e
:
self
.
printer
.
error
(
"
RPCError: %s
"
%
str
(
e
))
class
Command_start
(
VmCommand
):
'''
Start a stopped vm
'''
def
__call__
(
self
,
argv
):
self
.
_vm_action
(
argv
,
"
&r=vm&status=stopped
"
)
# rpc call
self
.
rpccall
(
"
start
"
,
self
.
args
[
0
])
class
Command_stop
(
Vm
Command
):
class
Command_stop
(
Tql
Command
):
'''
Stop a running vm
'''
def
__init__
(
self
,
cli
,
argv0
):
TqlCommand
.
__init__
(
self
,
cli
,
argv0
)
self
.
tql_filter
+=
"
&r=vm&status=running
"
def
__call__
(
self
,
argv
):
self
.
_vm_action
(
argv
,
"
&r=vm&status=running
"
)
# arg parse
self
.
parse_args
(
argv
)
if
len
(
self
.
args
)
!=
1
:
raise
cmdBadArgument
()
# rpc call
self
.
rpccall
(
"
stop
"
,
self
.
args
[
0
])
class
Command_destroy
(
Vm
Command
):
class
Command_destroy
(
Tql
Command
):
'''
Force a vm to stop
'''
def
__init__
(
self
,
cli
,
argv0
):
TqlCommand
.
__init__
(
self
,
cli
,
argv0
)
self
.
tql_filter
+=
"
&r=vm&status!=stopped
"
def
__call__
(
self
,
argv
):
self
.
_vm_action
(
argv
,
"
&r=vm&status!=stopped
"
)
# arg parse
self
.
parse_args
(
argv
)
if
len
(
self
.
args
)
!=
1
:
raise
cmdBadArgument
()
# rpc call
self
.
rpccall
(
"
destroy
"
,
self
.
args
[
0
])
class
Command_restart
(
Vm
Command
):
class
Command_restart
(
Tql
Command
):
'''
Restart a vm
'''
def
__init__
(
self
,
cli
,
argv0
):
TqlCommand
.
__init__
(
self
,
cli
,
argv0
)
self
.
tql_filter
+=
"
&r=vm&status=running
"
def
__call__
(
self
,
argv
):
self
.
_vm_action
(
argv
,
"
&r=vm
"
)
# arg parse
self
.
parse_args
(
argv
)
if
len
(
self
.
args
)
!=
1
:
raise
cmdBadArgument
()
# rpc call
self
.
rpccall
(
"
restart
"
,
self
.
args
[
0
])
class
Command_pause
(
Vm
Command
):
class
Command_pause
(
Tql
Command
):
'''
Pause a running vm
'''
def
__init__
(
self
,
cli
,
argv0
):
TqlCommand
.
__init__
(
self
,
cli
,
argv0
)
self
.
tql_filter
+=
"
&r=vm&status=stopped
"
def
__call__
(
self
,
argv
):
self
.
_vm_action
(
argv
,
"
&r=vm&status=running
"
)
# arg parse
self
.
parse_args
(
argv
)
if
len
(
self
.
args
)
!=
1
:
raise
cmdBadArgument
()
# rpc call
self
.
rpccall
(
"
pause
"
,
self
.
args
[
0
])
class
Command_resume
(
Vm
Command
):
class
Command_resume
(
Tql
Command
):
'''
Resume a paused vm
'''
def
__init__
(
self
,
cli
,
argv0
):
TqlCommand
.
__init__
(
self
,
cli
,
argv0
)
self
.
tql_filter
+=
"
&r=vm&status=paused
"
def
__call__
(
self
,
argv
):
self
.
_vm_action
(
argv
,
"
&r=vm&status=paused
"
)
# arg parse
self
.
parse_args
(
argv
)
if
len
(
self
.
args
)
!=
1
:
raise
cmdBadArgument
()
# rpc call
self
.
rpccall
(
"
resume
"
,
self
.
args
[
0
])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment