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
460c8634
Commit
460c8634
authored
14 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
new start/stop/pause/resume commands
remove global --force-yes options
parent
0ff976c3
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bin/cc-cli
+0
-2
0 additions, 2 deletions
bin/cc-cli
cccli/cli.py
+0
-1
0 additions, 1 deletion
cccli/cli.py
cccli/command.py
+69
-39
69 additions, 39 deletions
cccli/command.py
cccli/printer.py
+2
-5
2 additions, 5 deletions
cccli/printer.py
with
71 additions
and
47 deletions
bin/cc-cli
+
0
−
2
View file @
460c8634
...
...
@@ -90,8 +90,6 @@ try:
help
=
"
History file
"
)
oparser
.
add_option
(
"
--history-size
"
,
action
=
"
store
"
,
dest
=
"
hsize
"
,
help
=
"
History max entry count
"
)
oparser
.
add_option
(
"
--force-yes
"
,
action
=
"
store_true
"
,
dest
=
"
forceyes
"
,
help
=
"
Answer Yes to all questions (Dangerous)
"
)
(
options
,
args
)
=
oparser
.
parse_args
()
# options handling
...
...
This diff is collapsed.
Click to expand it.
cccli/cli.py
+
0
−
1
View file @
460c8634
...
...
@@ -37,7 +37,6 @@ class Cli(object):
self
.
interactive
=
sys
.
stderr
.
isatty
()
and
sys
.
stdin
.
isatty
()
# start printer and load history
self
.
printer
=
Printer
(
self
.
interactive
,
self
.
settings
.
get
(
"
forceyes
"
,
False
),
historyfile
=
self
.
settings
.
get
(
"
history
"
,
""
),
historysize
=
self
.
settings
.
get
(
"
hsize
"
,
None
))
# load alias
...
...
This diff is collapsed.
Click to expand it.
cccli/command.py
+
69
−
39
View file @
460c8634
...
...
@@ -192,7 +192,7 @@ class Command(object):
self
.
_list_table
(
objs
)
else
:
self
.
_list
(
objs
)
cmd_list
.
usage
=
"
list [tql
]
"
cmd_list
.
usage
=
"
list [
-t] [--help]
tql
"
def
_list
(
self
,
objs
):
for
o
in
objs
:
...
...
@@ -221,60 +221,90 @@ class Command(object):
self
.
printer
.
out
(
str
(
obj
.
get
(
t
,
""
)).
ljust
(
v
)
,
nl
=
"
"
)
self
.
printer
.
out
()
def
_vm_action
(
self
,
argv
):
# arg stuff
if
len
(
argv
)
==
1
:
raise
cmdBadArgument
()
tql
=
str
.
join
(
""
,
argv
[
1
:])
# print tql list result
try
:
objs
=
self
.
cli
.
rpc
.
call
(
"
list
"
,
tql
)
except
RpcError
as
e
:
raise
cmdError
(
"
RPCError: %s
"
%
str
(
e
))
if
len
(
objs
)
==
0
:
raise
cmdWarning
(
"
No selected object
"
)
self
.
printer
.
out
(
"
You request give the following result:
"
)
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
)))
if
self
.
printer
.
ask
(
"
Are you sure to %s%s%s these %s id? (yes/NO)
"
%
(
color
[
"
lred
"
],
argv
[
0
],
color
[
"
reset
"
],
len
(
objs
)),
"
yes
"
)
!=
"
yes
"
:
raise
cmdWarning
(
"
Aborted
"
)
if
len
(
objs
)
>
5
:
if
self
.
printer
.
ask
(
"
You request is on more than 5 objets. Are you really sure to %s its? (Sir, yes Sir!)
"
%
argv
[
0
],
"
Sir, yes Sir!
"
)
!=
"
Sir, yes Sir!
"
:
raise
cmdWarning
(
"
Aborted
"
)
def
_vm_action
(
self
,
argv
,
filters
=
None
):
'''
All command about vm are the same
'''
try
:
self
.
cli
.
rpc
.
call
(
argv
[
0
],
tql
)
except
RpcError
as
e
:
raise
cmdError
(
"
RPCError: %s
"
%
str
(
e
))
oparser
=
OptionParser
(
prog
=
argv
[
0
])
oparser
.
add_option
(
"
--raw
"
,
action
=
"
store_true
"
,
dest
=
"
raw
"
,
help
=
"
Don
'
t append filter on request
"
)
oparser
.
add_option
(
"
--direct
"
,
action
=
"
store_true
"
,
dest
=
"
direct
"
,
help
=
"
Directly send tql to server (don
'
t list before)
"
)
oparser
.
add_option
(
"
--force
"
,
action
=
"
store_true
"
,
dest
=
"
force
"
,
help
=
"
Don
'
t ask confirmation (Dangerous)
"
)
(
options
,
args
)
=
oparser
.
parse_args
(
argv
[
1
:])
except
SystemExit
:
return
if
len
(
args
)
==
0
:
raise
cmdBadArgument
()
tql
=
str
.
join
(
""
,
args
)
# append securty options by command name
if
filters
is
not
None
and
not
options
.
raw
:
tql
+=
filters
if
options
.
direct
:
try
:
objs
=
self
.
cli
.
rpc
.
call
(
argv
[
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:
"
%
argv
[
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
options
.
force
:
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
))
def
cmd_start
(
self
,
argv
):
'''
Start objects
'''
self
.
_vm_action
(
argv
)
cmd_start
.
usage
=
"
start [tql
]
"
self
.
_vm_action
(
argv
,
"
&role=vm&status=stopped
"
)
cmd_start
.
usage
=
"
start [
--raw] [--direct] [--force] [--help]
tql
"
def
cmd_stop
(
self
,
argv
):
'''
Stop objects
'''
self
.
_vm_action
(
argv
)
cmd_stop
.
usage
=
"
stop [tql
]
"
self
.
_vm_action
(
argv
,
"
&role=vm&status=running
"
)
cmd_stop
.
usage
=
"
stop [
--raw] [--direct] [--force] [--help]
tql
"
def
cmd_pause
(
self
,
argv
):
'''
Pause objects
'''
self
.
_vm_action
(
argv
)
cmd_pause
.
usage
=
"
pause [tql
]
"
self
.
_vm_action
(
argv
,
"
&role=vm&status=running
"
)
cmd_pause
.
usage
=
"
pause [
--raw] [--direct] [--force] [--help]
tql
"
def
cmd_resume
(
self
,
argv
):
'''
Resume objects
'''
self
.
_vm_action
(
argv
)
cmd_resume
.
usage
=
"
resume [tql
]
"
self
.
_vm_action
(
argv
,
"
&role=vm&status=stalled
"
)
cmd_resume
.
usage
=
"
resume [
--raw] [--direct] [--force] [--help]
tql
"
def
cmd_destroy
(
self
,
argv
):
'''
Force objects to stop
'''
self
.
_vm_action
(
argv
)
cmd_destroy
.
usage
=
"
destroy [tql
]
"
self
.
_vm_action
(
argv
,
"
&role=vm&status!=stopped
"
)
cmd_destroy
.
usage
=
"
destroy [
--raw] [--direct] [--force] [--help]
tql
"
def
cmd_clear
(
self
,
argv
):
'''
Clear tty
'''
...
...
This diff is collapsed.
Click to expand it.
cccli/printer.py
+
2
−
5
View file @
460c8634
...
...
@@ -46,12 +46,11 @@ color = {
class
Printer
(
object
):
'''
Print relative class
'''
def
__init__
(
self
,
interactive
=
False
,
forceyes
=
False
,
historyfile
=
None
,
historysize
=
None
):
def
__init__
(
self
,
interactive
=
False
,
historyfile
=
None
,
historysize
=
None
):
self
.
readline
=
None
self
.
history
=
History
()
self
.
historyfile
=
historyfile
self
.
historysize
=
historysize
self
.
forceyes
=
forceyes
if
interactive
:
self
.
setinteractive
()
...
...
@@ -120,10 +119,8 @@ class Printer(object):
raise
cliError
(
"
Unable to ask a password in non-interactive mode
"
)
return
getpass
.
getpass
(
prompt
)
def
ask
(
self
,
prompt
,
goodans
=
None
):
def
ask
(
self
,
prompt
):
'''
Used to ask a question. Default answer not saved to history
'''
if
self
.
forceyes
and
goodans
is
not
None
:
return
goodans
if
self
.
readline
is
None
:
raise
cliError
(
"
Unable to ask question in non-interactive mode
"
)
return
self
.
getline
(
prompt
,
history
=
False
)
...
...
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