Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cc-cli
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
cc-cli
Commits
9d7d4878
Commit
9d7d4878
authored
14 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
implement start/stop/pause/resume/destroy
parent
6cb6ee00
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cccli/cli.py
+22
-15
22 additions, 15 deletions
cccli/cli.py
cccli/command.py
+41
-20
41 additions, 20 deletions
cccli/command.py
debian/control
+1
-1
1 addition, 1 deletion
debian/control
with
64 additions
and
36 deletions
cccli/cli.py
+
22
−
15
View file @
9d7d4878
...
@@ -28,7 +28,7 @@ class Cli(object):
...
@@ -28,7 +28,7 @@ class Cli(object):
self
.
prompt
=
"
>
"
self
.
prompt
=
"
>
"
self
.
rpc
=
None
self
.
rpc
=
None
self
.
alias
=
Alias
()
self
.
alias
=
Alias
()
self
.
history
=
History
()
self
.
history
=
History
(
self
)
def
start
(
self
,
line
=
""
):
def
start
(
self
,
line
=
""
):
'''
Start a CLI
'''
'''
Start a CLI
'''
...
@@ -38,7 +38,7 @@ class Cli(object):
...
@@ -38,7 +38,7 @@ class Cli(object):
# start readline and load history
# start readline and load history
if
self
.
isinteractive
:
if
self
.
isinteractive
:
import
readline
import
readline
self
.
history
.
readline
=
readline
self
.
readline
=
readline
self
.
history
.
load
(
self
.
settings
.
get
(
"
history
"
,
""
))
self
.
history
.
load
(
self
.
settings
.
get
(
"
history
"
,
""
))
self
.
history
.
maxsize
(
self
.
settings
.
get
(
"
hsize
"
,
None
))
self
.
history
.
maxsize
(
self
.
settings
.
get
(
"
hsize
"
,
None
))
# load alias
# load alias
...
@@ -159,49 +159,56 @@ class Alias(dict):
...
@@ -159,49 +159,56 @@ class Alias(dict):
fparser
.
set
(
"
alias
"
,
n
,
v
)
fparser
.
set
(
"
alias
"
,
n
,
v
)
fparser
.
write
(
open
(
filename
,
"
w
"
))
fparser
.
write
(
open
(
filename
,
"
w
"
))
class
History
(
object
):
class
History
(
object
):
'''
History class
'''
'''
History class
'''
def
__init__
(
self
,
readline
=
None
):
def
__init__
(
self
,
cli
):
self
.
readline
=
readline
self
.
cli
=
cli
def
__nonzero__
(
self
):
def
__nonzero__
(
self
):
return
not
self
.
readline
is
None
return
not
self
.
cli
.
readline
is
None
def
__getattribute__
(
self
,
name
):
def
__getattribute__
(
self
,
name
):
r
=
object
.
__getattribute__
(
self
,
"
readline
"
)
r
=
object
.
__getattribute__
(
self
,
"
cli
"
)
if
name
==
"
readline
"
:
if
name
==
"
cli
"
:
return
r
return
r
if
r
is
None
:
if
r
.
readline
is
None
:
return
lambda
*
a
,
**
k
:
None
return
lambda
*
a
,
**
k
:
None
return
object
.
__getattribute__
(
self
,
name
)
return
object
.
__getattribute__
(
self
,
name
)
def
__iter__
(
self
):
def
__iter__
(
self
):
for
i
in
range
(
1
,
len
(
self
)):
for
i
in
range
(
1
,
len
(
self
)):
yield
self
.
readline
.
get_history_item
(
i
)
yield
self
.
cli
.
readline
.
get_history_item
(
i
)
def
__len__
(
self
):
def
__len__
(
self
):
return
self
.
readline
.
get_current_history_length
()
return
self
.
cli
.
readline
.
get_current_history_length
()
def
load
(
self
,
path
):
def
load
(
self
,
path
):
'''
Load history from a file
'''
'''
Load history from a file
'''
try
:
try
:
self
.
readline
.
read_history_file
(
path
)
self
.
cli
.
readline
.
read_history_file
(
path
)
except
IOError
:
except
IOError
:
pass
pass
def
save
(
self
,
path
):
def
save
(
self
,
path
):
'''
Save history into path
'''
'''
Save history into path
'''
try
:
try
:
self
.
readline
.
write_history_file
(
path
)
self
.
cli
.
readline
.
write_history_file
(
path
)
except
IOError
:
except
IOError
:
pass
pass
def
maxsize
(
self
,
size
=
None
):
def
maxsize
(
self
,
size
=
None
):
'''
Set or return max history size
'''
'''
Set or return max history size
'''
if
size
is
not
None
:
if
size
is
not
None
:
self
.
readline
.
set_history_length
(
size
)
self
.
cli
.
readline
.
set_history_length
(
size
)
return
self
.
readline
.
get_history_length
()
return
self
.
cli
.
readline
.
get_history_length
()
def
removelast
(
self
):
'''
Remove last history line
'''
self
.
cli
.
readline
.
remove_history_item
(
self
.
cli
.
readline
.
get_current_history_length
())
def
clear
(
self
):
'''
Clear history
'''
self
.
cli
.
readline
.
clear_history
()
class
CliHandler
(
RpcHandler
):
class
CliHandler
(
RpcHandler
):
...
...
This diff is collapsed.
Click to expand it.
cccli/command.py
+
41
−
20
View file @
9d7d4878
...
@@ -169,30 +169,51 @@ class Command(object):
...
@@ -169,30 +169,51 @@ class Command(object):
#for key, val in item.items():
#for key, val in item.items():
# printer.out("%s: %s "%(key, val))
# printer.out("%s: %s "%(key, val))
cmd_list
.
usage
=
"
list [tql]
"
cmd_list
.
usage
=
"
list [tql]
"
cmd_list
.
desc
=
"
Print information about tags
"
def
cmd_stop
(
self
,
argv
):
def
_startstopsdestroypauseresume
(
self
,
argv
):
'''
Stop an object
'''
# arg stuff
if
len
(
argv
)
==
0
:
if
len
(
argv
)
==
1
:
raise
BadArgument
()
raise
BadArgument
()
tql
=
str
.
join
(
""
,
argv
[
1
:])
tql
=
str
.
join
(
"
"
,
argv
[
1
:])
# print tql list result
items
=
self
.
cli
.
rpc
.
list
(
tql
)
items
=
self
.
cli
.
rpc
.
list
(
tql
)
if
len
(
items
)
==
0
:
printer
.
out
(
"
No selected object
"
)
return
printer
.
out
(
"
Your request give the following result:
"
)
for
item
in
items
:
for
item
in
items
:
pprint
.
pprint
(
item
)
printer
.
out
(
"
%s
"
%
item
[
"
id
"
])
if
raw_input
(
"
Are you sure? (yes/no)
"
)
==
"
yes
"
:
printer
.
out
(
"
Count: %s
"
%
len
(
items
))
items
=
self
.
cli
.
rpc
.
stop
(
tql
)
if
raw_input
(
"
Are you sure to %s? (yes/NO)
"
%
argv
[
0
])
!=
"
yes
"
:
cmd_stop
.
usage
=
"
stop [tql]
"
raise
Exception
(
"
Aborted
"
)
cmd_stop
.
desc
=
"
Stop objects
"
if
len
(
items
)
>
5
:
if
raw_input
(
"
You request is on more than 5 objets. Are you really sure to %s its? (Yes, I am)
"
%
argv
[
0
])
!=
"
Yes, I am
"
:
raise
Exception
(
"
Aborted
"
)
self
.
cli
.
rpc
[
argv
[
0
]](
tql
)
def
cmd_start
(
self
,
argv
):
def
cmd_start
(
self
,
argv
):
'''
Start an object
'''
'''
Start objects
'''
if
len
(
argv
)
==
0
:
self
.
_startstopsdestroypauseresume
(
argv
)
raise
BadArgument
()
tql
=
str
.
join
(
""
,
argv
[
1
:])
items
=
self
.
cli
.
rpc
.
list
(
tql
)
for
item
in
items
:
pprint
.
pprint
(
item
)
if
raw_input
(
"
Are you sure? (yes/no)
"
)
==
"
yes
"
:
items
=
self
.
cli
.
rpc
.
start
(
tql
)
cmd_start
.
usage
=
"
start [tql]
"
cmd_start
.
usage
=
"
start [tql]
"
cmd_start
.
desc
=
"
Start objects
"
def
cmd_stop
(
self
,
argv
):
'''
Stop objects
'''
self
.
_startstopsdestroypauseresume
(
argv
)
cmd_stop
.
usage
=
"
stop [tql]
"
def
cmd_pause
(
self
,
argv
):
'''
Pause objects
'''
self
.
_startstopsdestroypauseresume
(
argv
)
cmd_pause
.
usage
=
"
pause [tql]
"
def
cmd_resume
(
self
,
argv
):
'''
Resume objects
'''
self
.
_startstopsdestroypauseresume
(
argv
)
cmd_resume
.
usage
=
"
resume [tql]
"
def
cmd_destroy
(
self
,
argv
):
'''
Force objects to stop
'''
self
.
_startstopsdestroypauseresume
(
argv
)
cmd_destroy
.
usage
=
"
destroy [tql]
"
This diff is collapsed.
Click to expand it.
debian/control
+
1
−
1
View file @
9d7d4878
...
@@ -9,7 +9,7 @@ Standards-Version: 3.8.0
...
@@ -9,7 +9,7 @@ Standards-Version: 3.8.0
Package: cc-cli
Package: cc-cli
Architecture: all
Architecture: all
Depends: ${misc:Depends}, ${python:Depends}, python (<< 3), python-sjrpc (>=
6
)
Depends: ${misc:Depends}, ${python:Depends}, python (<< 3), python-sjrpc (>=
7
)
XB-Python-Version: ${python:Versions}
XB-Python-Version: ${python:Versions}
Description: CloudControl CLI
Description: CloudControl CLI
This package provides the Command Line Interface to CloudControl.
This package provides the Command Line Interface to CloudControl.
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