Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
873eb1dd
Commit
873eb1dd
authored
Feb 08, 2013
by
Christos Stavrakakis
Browse files
Fix pep8 issues
parent
46b01f6f
Changes
2
Hide whitespace changes
Inline
Side-by-side
snf-cyclades-app/synnefo/logic/management/commands/reconcile-servers.py
View file @
873eb1dd
...
...
@@ -84,8 +84,8 @@ class Command(BaseCommand):
dest
=
'fix_build_errors'
,
default
=
False
,
help
=
'Fix (remove) instances with build errors'
),
make_option
(
'--fix-unsynced-nics'
,
action
=
'store_true'
,
dest
=
'fix_unsynced_nics'
,
default
=
False
,
help
=
'Fix unsynced nics between DB and Ganeti'
),
dest
=
'fix_unsynced_nics'
,
default
=
False
,
help
=
'Fix unsynced nics between DB and Ganeti'
),
make_option
(
'--fix-all'
,
action
=
'store_true'
,
dest
=
'fix_all'
,
default
=
False
,
help
=
'Enable all --fix-* arguments'
),
make_option
(
'--backend-id'
,
default
=
None
,
dest
=
'backend-id'
,
...
...
@@ -160,8 +160,9 @@ class Command(BaseCommand):
if
options
[
'detect_build_errors'
]:
build_errors
=
reconciliation
.
instances_with_build_errors
(
D
,
G
)
if
len
(
build_errors
)
>
0
:
print
>>
sys
.
stderr
,
"The os for the following server IDs was "
\
"not build successfully:"
msg
=
"The os for the following server IDs was not build"
\
" successfully:"
print
>>
sys
.
stderr
,
msg
print
" "
+
"
\n
"
.
join
(
[
"%d"
%
x
for
x
in
build_errors
])
elif
verbosity
==
2
:
...
...
@@ -172,13 +173,15 @@ class Command(BaseCommand):
if
not
nics
:
print
''
.
ljust
(
18
)
+
'None'
for
index
,
info
in
nics
.
items
():
print
''
.
ljust
(
18
)
+
'nic/'
+
str
(
index
)
+
': MAC: %s, IP: %s, Network: %s'
%
\
(
info
[
'mac'
],
info
[
'ipv4'
],
info
[
'network'
])
print
''
.
ljust
(
18
)
+
'nic/'
+
str
(
index
)
+
\
': MAC: %s, IP: %s, Network: %s'
%
\
(
info
[
'mac'
],
info
[
'ipv4'
],
info
[
'network'
])
unsynced_nics
=
reconciliation
.
unsynced_nics
(
DBNics
,
GNics
)
if
len
(
unsynced_nics
)
>
0
:
print
>>
sys
.
stderr
,
"The NICs of servers with the following IDs "
\
"are unsynced:"
msg
=
"The NICs of the servers with the following IDs are"
\
" unsynced:"
print
>>
sys
.
stderr
,
msg
for
id
,
nics
in
unsynced_nics
.
items
():
print
''
.
ljust
(
2
)
+
'%6d:'
%
id
print
''
.
ljust
(
8
)
+
'%8s:'
%
'DB'
...
...
@@ -233,19 +236,20 @@ class Command(BaseCommand):
print
>>
sys
.
stderr
,
" ...done"
if
options
[
'fix_build_errors'
]
and
len
(
build_errors
)
>
0
:
print
>>
sys
.
stderr
,
"Setting the state of %d build-errors VMs:"
%
\
len
(
build_errors
)
print
>>
sys
.
stderr
,
"Setting the state of %d build-errors VMs:"
%
\
len
(
build_errors
)
for
id
in
build_errors
:
vm
=
VirtualMachine
.
objects
.
get
(
pk
=
id
)
event_time
=
datetime
.
datetime
.
now
()
backend_mod
.
process_op_status
(
vm
=
vm
,
etime
=
event_time
,
jobid
=-
0
,
backend_mod
.
process_op_status
(
vm
=
vm
,
etime
=
event_time
,
jobid
=-
0
,
opcode
=
"OP_INSTANCE_CREATE"
,
status
=
'error'
,
logmsg
=
'Reconciliation: simulated Ganeti event'
)
print
>>
sys
.
stderr
,
" ...done"
if
options
[
'fix_unsynced_nics'
]
and
len
(
unsynced_nics
)
>
0
:
print
>>
sys
.
stderr
,
"Setting the nics of %d out-of-sync VMs:"
%
\
len
(
unsynced_nics
)
len
(
unsynced_nics
)
for
id
,
nics
in
unsynced_nics
.
items
():
vm
=
VirtualMachine
.
objects
.
get
(
pk
=
id
)
nics
=
nics
[
1
]
# Ganeti nics
...
...
snf-cyclades-gtools/synnefo/ganeti/hook.py
View file @
873eb1dd
...
...
@@ -78,7 +78,7 @@ def ganeti_net_status(logger, environ):
if
env
.
startswith
(
"GANETI_INSTANCE_NIC"
):
s
=
env
.
replace
(
"GANETI_INSTANCE_NIC"
,
""
).
split
(
'_'
,
1
)
if
len
(
s
)
==
2
and
s
[
0
].
isdigit
()
and
\
s
[
1
]
in
(
'MAC'
,
'IP'
,
'BRIDGE'
,
'NETWORK'
):
s
[
1
]
in
(
'MAC'
,
'IP'
,
'BRIDGE'
,
'NETWORK'
):
index
=
int
(
s
[
0
])
key
=
key_to_attr
[
s
[
1
]]
...
...
@@ -119,12 +119,14 @@ def ganeti_net_status(logger, environ):
ganeti_nic_count
=
int
(
environ
[
'GANETI_INSTANCE_NIC_COUNT'
])
if
len
(
indexes
)
!=
ganeti_nic_count
:
logger
.
error
(
"I have %d NICs, Ganeti says number of NICs is %d"
,
len
(
indexes
),
ganeti_nic_count
)
len
(
indexes
),
ganeti_nic_count
)
raise
Exception
(
"Inconsistent number of NICs in Ganeti environment"
)
if
indexes
!=
range
(
0
,
len
(
indexes
)):
logger
.
error
(
"Ganeti NIC indexes are not consecutive starting at zero."
);
logger
.
error
(
"NIC indexes are: %s. Environment is: %s"
,
indexes
,
environ
)
msg
=
"Ganeti NIC indexes are not consecutive starting at zero."
logger
.
error
(
msg
)
msg
=
"NIC indexes are: %s. Environment is: %s"
%
(
indexes
,
environ
)
logger
.
error
(
msg
)
raise
Exception
(
"Unexpected inconsistency in the Ganeti environment"
)
# Construct the notification
...
...
@@ -193,7 +195,9 @@ class PostStartHook(GanetiHook):
def
run
(
self
):
if
self
.
on_master
():
notifs
=
[]
notifs
.
append
((
"net"
,
ganeti_net_status
(
self
.
logger
,
self
.
environ
)))
notifs
.
append
((
"net"
,
ganeti_net_status
(
self
.
logger
,
self
.
environ
))
)
self
.
publish_msgs
(
notifs
)
...
...
@@ -214,15 +218,17 @@ def main():
op
=
os
.
environ
[
'GANETI_HOOKS_PATH'
]
phase
=
os
.
environ
[
'GANETI_HOOKS_PHASE'
]
except
KeyError
:
raise
Exception
(
"Environment missing one of: "
\
"GANETI_INSTANCE_NAME, GANETI_HOOKS_PATH, GANETI_HOOKS_PHASE"
)
raise
Exception
(
"Environment missing one of: "
"GANETI_INSTANCE_NAME, GANETI_HOOKS_PATH,"
" GANETI_HOOKS_PHASE"
)
prefix
=
instance
.
split
(
'-'
)[
0
]
# FIXME: The hooks should only run for Synnefo instances.
# Uncomment the following lines for a shared Ganeti deployment.
# Currently, the following code is commented out because multiple
# backend prefixes are used in the same Ganeti installation during development.
# backend prefixes are used in the same Ganeti installation during
# development.
#if not instance.startswith(settings.BACKEND_PREFIX_ID):
# logger.warning("Ignoring non-Synnefo instance %s", instance)
# return 0
...
...
@@ -238,7 +244,8 @@ def main():
try
:
hook
=
hooks
[(
op
,
phase
)](
logger
,
os
.
environ
,
instance
,
prefix
)
except
KeyError
:
raise
Exception
(
"No hook found for operation = '%s', phase = '%s'"
%
(
op
,
phase
))
raise
Exception
(
"No hook found for operation = '%s', phase = '%s'"
%
(
op
,
phase
))
return
hook
.
run
()
if
__name__
==
"__main__"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment