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
597cadcc
Commit
597cadcc
authored
14 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
Add migrate command
parent
367c4e22
No related branches found
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cccli/command/__init__.py
+1
-0
1 addition, 0 deletions
cccli/command/__init__.py
cccli/command/migrate.py
+83
-0
83 additions, 0 deletions
cccli/command/migrate.py
with
84 additions
and
0 deletions
cccli/command/__init__.py
+
1
−
0
View file @
597cadcc
...
...
@@ -20,6 +20,7 @@ from cccli.command.expert import Command_expert
from
cccli.command.jobs
import
Command_jobs
from
cccli.command.kill
import
Command_kill
from
cccli.command.list
import
Command_list
from
cccli.command.migrate
import
Command_migrate
from
cccli.command.server
import
Command_server
from
cccli.command.shutdown
import
Command_shutdown
from
cccli.command.tagdisplay
import
Command_tagdisplay
This diff is collapsed.
Click to expand it.
cccli/command/migrate.py
0 → 100644
+
83
−
0
View file @
597cadcc
#!/usr/bin/env python
#coding=utf8
'''
CloudControl jobs command
'''
from
cccli.exception
import
*
from
sjrpc.core.exceptions
import
*
from
cccli.printer
import
Printer
,
color
from
cccli.command.command
import
TqlCommand
class
Command_migrate
(
TqlCommand
):
'''
Migrate vm
'''
def
__init__
(
self
,
cli
,
argv0
):
TqlCommand
.
__init__
(
self
,
cli
,
argv0
)
self
.
set_usage
(
"
%prog [options] [source tql] [dest tql]
"
)
self
.
remove_option
(
"
--direct
"
)
self
.
remove_option
(
"
--raw
"
)
self
.
remove_option
(
"
--print-tql
"
)
self
.
add_option
(
"
-l
"
,
"
--list
"
,
action
=
"
store_true
"
,
dest
=
"
list
"
,
default
=
False
,
help
=
"
List migration types and algo
"
)
self
.
add_option
(
"
-t
"
,
"
--type
"
,
action
=
"
store
"
,
dest
=
"
type
"
,
default
=
""
,
help
=
"
Selection migration type
"
)
self
.
add_option
(
"
-a
"
,
"
--algo
"
,
action
=
"
store
"
,
dest
=
"
algo
"
,
default
=
""
,
help
=
"
Select migration algorithm
"
)
def
__call__
(
self
,
argv
):
# Parse argline
self
.
parse_args
(
argv
)
# Retrieve election types
self
.
etypes
=
self
.
get_electiontypes
()
# Check args and do listings
if
self
.
options
.
list
:
self
.
list
()
return
elif
self
.
options
.
type
not
in
self
.
etypes
:
raise
cmdBadArgument
(
"
No such type: %s
"
%
self
.
options
.
type
)
elif
self
.
options
.
algo
not
in
self
.
etypes
[
self
.
options
.
type
]:
raise
cmdBadArgument
(
"
No such algo: %s for type: %s
"
%
(
self
.
options
.
algo
,
self
.
options
.
type
))
elif
len
(
self
.
args
)
!=
2
:
raise
cmdBadArgument
()
stql
=
self
.
args
[
0
]
dtql
=
self
.
args
[
1
]
# election(query_vm, query_dest, mtype='cold', algo='fair', **kwargs)
scrutin
=
self
.
rpccall
(
"
election
"
,
stql
,
dtql
,
mtype
=
self
.
options
.
type
,
algo
=
self
.
options
.
algo
,
_direct
=
True
,
_status
=
False
)
# check election result
if
len
(
scrutin
)
==
0
:
raise
cmdError
(
"
No migration plan found
"
)
# print election
for
(
i
,
o
)
in
enumerate
(
scrutin
):
if
self
.
options
.
index
:
self
.
printer
.
out
(
"
[%d]
"
%
i
,
nl
=
""
)
self
.
printer
.
out
(
"
%s%s %s-> %s%s%s (%s)
"
%
(
self
.
tdc
(
"
id
"
),
o
[
"
sid
"
],
color
[
"
reset
"
],
self
.
tdc
(
"
id
"
),
o
[
"
did
"
],
color
[
"
reset
"
],
o
[
"
type
"
]))
# ask confirmation
if
self
.
printer
.
ask
(
"
Do you confirm election? (Yes baby)
"
)
!=
"
Yes baby
"
:
raise
cmdWarning
(
"
User resign
"
)
# run migration
self
.
rpccall
(
"
migrate
"
,
scrutin
,
_direct
=
True
)
def
get_electiontypes
(
self
):
'''
Return a list of migration type
'''
try
:
return
self
.
cli
.
rpc
.
call
(
"
electiontypes
"
)
except
RpcError
as
e
:
raise
cmdError
(
e
)
def
list
(
self
):
'''
Print a list of migration type
'''
self
.
printer
.
out
(
"
Migration types: Election Algo
"
)
for
t
in
self
.
etypes
.
keys
():
self
.
printer
.
out
(
"
%s: %s
"
%
(
t
,
"
,
"
.
join
(
self
.
etypes
[
t
])))
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