Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
synnefo
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
itminedu
synnefo
Commits
873eb1dd
Commit
873eb1dd
authored
12 years ago
by
Christos Stavrakakis
Browse files
Options
Downloads
Patches
Plain Diff
Fix pep8 issues
parent
46b01f6f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
snf-cyclades-app/synnefo/logic/management/commands/reconcile-servers.py
+16
-12
16 additions, 12 deletions
...pp/synnefo/logic/management/commands/reconcile-servers.py
snf-cyclades-gtools/synnefo/ganeti/hook.py
+16
-9
16 additions, 9 deletions
snf-cyclades-gtools/synnefo/ganeti/hook.py
with
32 additions
and
21 deletions
snf-cyclades-app/synnefo/logic/management/commands/reconcile-servers.py
+
16
−
12
View file @
873eb1dd
...
@@ -84,8 +84,8 @@ class Command(BaseCommand):
...
@@ -84,8 +84,8 @@ class Command(BaseCommand):
dest
=
'
fix_build_errors
'
,
default
=
False
,
dest
=
'
fix_build_errors
'
,
default
=
False
,
help
=
'
Fix (remove) instances with build errors
'
),
help
=
'
Fix (remove) instances with build errors
'
),
make_option
(
'
--fix-unsynced-nics
'
,
action
=
'
store_true
'
,
make_option
(
'
--fix-unsynced-nics
'
,
action
=
'
store_true
'
,
dest
=
'
fix_unsynced_nics
'
,
default
=
False
,
dest
=
'
fix_unsynced_nics
'
,
default
=
False
,
help
=
'
Fix unsynced nics between DB and Ganeti
'
),
help
=
'
Fix unsynced nics between DB and Ganeti
'
),
make_option
(
'
--fix-all
'
,
action
=
'
store_true
'
,
dest
=
'
fix_all
'
,
make_option
(
'
--fix-all
'
,
action
=
'
store_true
'
,
dest
=
'
fix_all
'
,
default
=
False
,
help
=
'
Enable all --fix-* arguments
'
),
default
=
False
,
help
=
'
Enable all --fix-* arguments
'
),
make_option
(
'
--backend-id
'
,
default
=
None
,
dest
=
'
backend-id
'
,
make_option
(
'
--backend-id
'
,
default
=
None
,
dest
=
'
backend-id
'
,
...
@@ -160,8 +160,9 @@ class Command(BaseCommand):
...
@@ -160,8 +160,9 @@ class Command(BaseCommand):
if
options
[
'
detect_build_errors
'
]:
if
options
[
'
detect_build_errors
'
]:
build_errors
=
reconciliation
.
instances_with_build_errors
(
D
,
G
)
build_errors
=
reconciliation
.
instances_with_build_errors
(
D
,
G
)
if
len
(
build_errors
)
>
0
:
if
len
(
build_errors
)
>
0
:
print
>>
sys
.
stderr
,
"
The os for the following server IDs was
"
\
msg
=
"
The os for the following server IDs was not build
"
\
"
not build successfully:
"
"
successfully:
"
print
>>
sys
.
stderr
,
msg
print
"
"
+
"
\n
"
.
join
(
print
"
"
+
"
\n
"
.
join
(
[
"
%d
"
%
x
for
x
in
build_errors
])
[
"
%d
"
%
x
for
x
in
build_errors
])
elif
verbosity
==
2
:
elif
verbosity
==
2
:
...
@@ -172,13 +173,15 @@ class Command(BaseCommand):
...
@@ -172,13 +173,15 @@ class Command(BaseCommand):
if
not
nics
:
if
not
nics
:
print
''
.
ljust
(
18
)
+
'
None
'
print
''
.
ljust
(
18
)
+
'
None
'
for
index
,
info
in
nics
.
items
():
for
index
,
info
in
nics
.
items
():
print
''
.
ljust
(
18
)
+
'
nic/
'
+
str
(
index
)
+
'
: MAC: %s, IP: %s, Network: %s
'
%
\
print
''
.
ljust
(
18
)
+
'
nic/
'
+
str
(
index
)
+
\
(
info
[
'
mac
'
],
info
[
'
ipv4
'
],
info
[
'
network
'
])
'
: MAC: %s, IP: %s, Network: %s
'
%
\
(
info
[
'
mac
'
],
info
[
'
ipv4
'
],
info
[
'
network
'
])
unsynced_nics
=
reconciliation
.
unsynced_nics
(
DBNics
,
GNics
)
unsynced_nics
=
reconciliation
.
unsynced_nics
(
DBNics
,
GNics
)
if
len
(
unsynced_nics
)
>
0
:
if
len
(
unsynced_nics
)
>
0
:
print
>>
sys
.
stderr
,
"
The NICs of servers with the following IDs
"
\
msg
=
"
The NICs of the servers with the following IDs are
"
\
"
are unsynced:
"
"
unsynced:
"
print
>>
sys
.
stderr
,
msg
for
id
,
nics
in
unsynced_nics
.
items
():
for
id
,
nics
in
unsynced_nics
.
items
():
print
''
.
ljust
(
2
)
+
'
%6d:
'
%
id
print
''
.
ljust
(
2
)
+
'
%6d:
'
%
id
print
''
.
ljust
(
8
)
+
'
%8s:
'
%
'
DB
'
print
''
.
ljust
(
8
)
+
'
%8s:
'
%
'
DB
'
...
@@ -233,19 +236,20 @@ class Command(BaseCommand):
...
@@ -233,19 +236,20 @@ class Command(BaseCommand):
print
>>
sys
.
stderr
,
"
...done
"
print
>>
sys
.
stderr
,
"
...done
"
if
options
[
'
fix_build_errors
'
]
and
len
(
build_errors
)
>
0
:
if
options
[
'
fix_build_errors
'
]
and
len
(
build_errors
)
>
0
:
print
>>
sys
.
stderr
,
"
Setting the state of %d build-errors VMs:
"
%
\
print
>>
sys
.
stderr
,
"
Setting the state of %d build-errors VMs:
"
%
\
len
(
build_errors
)
len
(
build_errors
)
for
id
in
build_errors
:
for
id
in
build_errors
:
vm
=
VirtualMachine
.
objects
.
get
(
pk
=
id
)
vm
=
VirtualMachine
.
objects
.
get
(
pk
=
id
)
event_time
=
datetime
.
datetime
.
now
()
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
'
,
opcode
=
"
OP_INSTANCE_CREATE
"
,
status
=
'
error
'
,
logmsg
=
'
Reconciliation: simulated Ganeti event
'
)
logmsg
=
'
Reconciliation: simulated Ganeti event
'
)
print
>>
sys
.
stderr
,
"
...done
"
print
>>
sys
.
stderr
,
"
...done
"
if
options
[
'
fix_unsynced_nics
'
]
and
len
(
unsynced_nics
)
>
0
:
if
options
[
'
fix_unsynced_nics
'
]
and
len
(
unsynced_nics
)
>
0
:
print
>>
sys
.
stderr
,
"
Setting the nics of %d out-of-sync VMs:
"
%
\
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
():
for
id
,
nics
in
unsynced_nics
.
items
():
vm
=
VirtualMachine
.
objects
.
get
(
pk
=
id
)
vm
=
VirtualMachine
.
objects
.
get
(
pk
=
id
)
nics
=
nics
[
1
]
# Ganeti nics
nics
=
nics
[
1
]
# Ganeti nics
...
...
This diff is collapsed.
Click to expand it.
snf-cyclades-gtools/synnefo/ganeti/hook.py
+
16
−
9
View file @
873eb1dd
...
@@ -78,7 +78,7 @@ def ganeti_net_status(logger, environ):
...
@@ -78,7 +78,7 @@ def ganeti_net_status(logger, environ):
if
env
.
startswith
(
"
GANETI_INSTANCE_NIC
"
):
if
env
.
startswith
(
"
GANETI_INSTANCE_NIC
"
):
s
=
env
.
replace
(
"
GANETI_INSTANCE_NIC
"
,
""
).
split
(
'
_
'
,
1
)
s
=
env
.
replace
(
"
GANETI_INSTANCE_NIC
"
,
""
).
split
(
'
_
'
,
1
)
if
len
(
s
)
==
2
and
s
[
0
].
isdigit
()
and
\
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
])
index
=
int
(
s
[
0
])
key
=
key_to_attr
[
s
[
1
]]
key
=
key_to_attr
[
s
[
1
]]
...
@@ -119,12 +119,14 @@ def ganeti_net_status(logger, environ):
...
@@ -119,12 +119,14 @@ def ganeti_net_status(logger, environ):
ganeti_nic_count
=
int
(
environ
[
'
GANETI_INSTANCE_NIC_COUNT
'
])
ganeti_nic_count
=
int
(
environ
[
'
GANETI_INSTANCE_NIC_COUNT
'
])
if
len
(
indexes
)
!=
ganeti_nic_count
:
if
len
(
indexes
)
!=
ganeti_nic_count
:
logger
.
error
(
"
I have %d NICs, Ganeti says number of NICs is %d
"
,
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
"
)
raise
Exception
(
"
Inconsistent number of NICs in Ganeti environment
"
)
if
indexes
!=
range
(
0
,
len
(
indexes
)):
if
indexes
!=
range
(
0
,
len
(
indexes
)):
logger
.
error
(
"
Ganeti NIC indexes are not consecutive starting at zero.
"
);
msg
=
"
Ganeti NIC indexes are not consecutive starting at zero.
"
logger
.
error
(
"
NIC indexes are: %s. Environment is: %s
"
,
indexes
,
environ
)
logger
.
error
(
msg
)
msg
=
"
NIC indexes are: %s. Environment is: %s
"
%
(
indexes
,
environ
)
logger
.
error
(
msg
)
raise
Exception
(
"
Unexpected inconsistency in the Ganeti environment
"
)
raise
Exception
(
"
Unexpected inconsistency in the Ganeti environment
"
)
# Construct the notification
# Construct the notification
...
@@ -193,7 +195,9 @@ class PostStartHook(GanetiHook):
...
@@ -193,7 +195,9 @@ class PostStartHook(GanetiHook):
def
run
(
self
):
def
run
(
self
):
if
self
.
on_master
():
if
self
.
on_master
():
notifs
=
[]
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
)
self
.
publish_msgs
(
notifs
)
...
@@ -214,15 +218,17 @@ def main():
...
@@ -214,15 +218,17 @@ def main():
op
=
os
.
environ
[
'
GANETI_HOOKS_PATH
'
]
op
=
os
.
environ
[
'
GANETI_HOOKS_PATH
'
]
phase
=
os
.
environ
[
'
GANETI_HOOKS_PHASE
'
]
phase
=
os
.
environ
[
'
GANETI_HOOKS_PHASE
'
]
except
KeyError
:
except
KeyError
:
raise
Exception
(
"
Environment missing one of:
"
\
raise
Exception
(
"
Environment missing one of:
"
"
GANETI_INSTANCE_NAME, GANETI_HOOKS_PATH, GANETI_HOOKS_PHASE
"
)
"
GANETI_INSTANCE_NAME, GANETI_HOOKS_PATH,
"
"
GANETI_HOOKS_PHASE
"
)
prefix
=
instance
.
split
(
'
-
'
)[
0
]
prefix
=
instance
.
split
(
'
-
'
)[
0
]
# FIXME: The hooks should only run for Synnefo instances.
# FIXME: The hooks should only run for Synnefo instances.
# Uncomment the following lines for a shared Ganeti deployment.
# Uncomment the following lines for a shared Ganeti deployment.
# Currently, the following code is commented out because multiple
# 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):
#if not instance.startswith(settings.BACKEND_PREFIX_ID):
# logger.warning("Ignoring non-Synnefo instance %s", instance)
# logger.warning("Ignoring non-Synnefo instance %s", instance)
# return 0
# return 0
...
@@ -238,7 +244,8 @@ def main():
...
@@ -238,7 +244,8 @@ def main():
try
:
try
:
hook
=
hooks
[(
op
,
phase
)](
logger
,
os
.
environ
,
instance
,
prefix
)
hook
=
hooks
[(
op
,
phase
)](
logger
,
os
.
environ
,
instance
,
prefix
)
except
KeyError
:
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
()
return
hook
.
run
()
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
...
...
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