Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
97c4dbde
authored
Oct 25, 2016
by
Sulyok Gabor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SaltCommand generation and deployement fixes
parent
5e8e9dca
Pipeline
#260
failed with stage
in 0 seconds
Changes
4
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
42 deletions
+34
-42
circle/setty/controller.py
+26
-37
circle/setty/models.py
+0
-0
circle/setty/saltstackhelper.py
+7
-2
circle/setty/views.py
+1
-3
No files found.
circle/setty/controller.py
View file @
97c4dbde
...
...
@@ -171,12 +171,14 @@ class SettyController:
@staticmethod
def
deploy
(
serviceId
):
service
=
Service
.
objects
.
get
(
id
=
serviceId
)
machines
=
Machine
.
objects
.
filter
(
service
=
service
)
serviveNodeList
=
ServiceNode
.
objects
.
filter
(
service
=
service
)
errorMessages
=
[]
nodesToBeDeployed
=
[]
for
serviceNode
in
serviveNodeList
:
errorMessage
=
serviceNode
.
cast
()
.
checkDependenciesAndAttributes
()
castedServiceNode
=
serviceNode
.
cast
()
nodesToBeDeployed
.
append
(
castedServiceNode
)
errorMessage
=
castedServiceNode
.
checkDependenciesAndAttributes
()
if
errorMessage
:
errorMessages
.
append
(
errorMessage
)
...
...
@@ -184,52 +186,39 @@ class SettyController:
return
{
'status'
:
'error'
,
'errors'
:
errorMessages
}
elementConnections
=
ElementConnection
.
objects
.
filter
(
Q
(
target__in
=
machines
)
|
Q
(
source__in
=
machines
))
# phase one: set the machine ptr in serviceNodes which can be accessed by
# connections from machines
logger
=
logging
.
getLogger
(
'project.interesting.stuff'
)
for
machine
in
machines
:
for
connection
in
elementConnections
:
serviceNode
=
None
if
connection
.
target
.
cast
()
==
machine
:
serviceNode
=
connection
.
source
.
cast
()
serviceNode
.
setMachineForDeploy
(
machine
)
elif
connection
.
source
.
cast
()
==
machine
:
serviceNode
=
connection
.
target
.
cast
()
serviceNode
.
setMachineForDeploy
(
machine
)
# phase two: let the nodes create configurations recursively
configuratedNodes
=
list
()
for
serviceNode
in
serviveNodeList
:
node
=
serviceNode
.
cast
()
node
.
generateSaltCommands
()
configuratedNodes
.
append
(
node
)
# phase one: ask the servicenodes to generate their needed salt commands
for
serviceNode
in
nodesToBeDeployed
:
serviceNode
.
generateSaltCommands
()
# phase t
hree
: sort the nodes by deployment priority(lower the prio,
# phase t
wo
: sort the nodes by deployment priority(lower the prio,
# later in the deployement)
configuratedNodes
.
sort
(
reverse
=
True
)
nodesToBeDeployed
.
sort
(
reverse
=
True
)
# dbgCheck = []
# for node in
configuratedNodes
:
# command
Dict
= []
# for node in
nodesToBeDeployed
:
# command
Array
= []
# for command in node.generatedCommands:
# commandDict.append( command.__dict__ )
# dbgCheck.append({ "nodeName": my_instance.__class__.__name__,
# "commands": commandDict })
# return dbgCheck
# phase four: deploy the nodes
for
node
in
configuratedNodes
:
# commandArray.append( command.toDict() )
#
# dbgCheck.append({ "nodeName": str(node.__class__.__name__),
# "hostingMachineName": str(node.hostingMachine.hostname),
# "commands": commandArray })
#
# return {"status": "error", "errors":dbgCheck}
# phase three: deploy the nodes
for
node
in
nodesToBeDeployed
:
deployErrorMessages
=
SettyController
.
salthelper
.
executeCommand
(
node
.
generatedCommands
)
if
errorMessages
:
errorMessages
.
append
(
deployErrorMessages
)
# phase f
ive
: cleanup generated commands
for
serviceNode
in
firstLevelServiceNodes
:
# phase f
our
: cleanup generated commands
for
serviceNode
in
nodesToBeDeployed
:
serviceNode
.
generatedCommands
=
None
serviceNode
.
hostingMachine
=
None
if
errorMessages
:
return
{
'status'
:
'error'
,
...
...
circle/setty/models.py
View file @
97c4dbde
This diff is collapsed.
Click to expand it.
circle/setty/saltstackhelper.py
View file @
97c4dbde
...
...
@@ -13,6 +13,10 @@ class SaltCommand:
def
__str__
(
self
):
return
"Command: "
+
self
.
hostname
+
" - "
+
self
.
command
+
" - "
+
str
(
self
.
parameters
)
def
toDict
(
self
):
return
{
'hostname'
:
self
.
hostname
,
'command'
:
self
.
command
,
'parameters'
:
self
.
parameters
}
class
SaltStackHelper
:
def
__init__
(
self
):
self
.
master_opts
=
salt
.
config
.
client_config
(
'/etc/salt/master'
)
...
...
@@ -48,5 +52,6 @@ class SaltStackHelper:
query_res
=
self
.
salt_localclient
.
cmd
(
hostname
,
'network.get_hostname'
);
return
query_res
!=
{}
def
executeCommand
(
self
,
saltCommand
):
return
self
.
salt_localclient
.
cmd
(
saltCommand
.
hostname
,
"state.sls"
,[
saltCommand
.
command
],
kwarg
=
{
"pillar"
:
saltCommand
.
parameters
}
)
def
executeCommand
(
self
,
saltCommands
):
for
saltCommand
in
saltCommands
:
self
.
salt_localclient
.
cmd
(
saltCommand
.
hostname
,
"state.sls"
,[
saltCommand
.
command
],
kwarg
=
{
"pillar"
:
saltCommand
.
parameters
}
)
circle/setty/views.py
View file @
97c4dbde
...
...
@@ -103,9 +103,7 @@ class DetailView(LoginRequiredMixin, TemplateView):
result
=
SettyController
.
getInformation
(
templateId
,
hostname
)
print
'------------'
print
result
print
'------------'
return
JsonResponse
(
result
)
...
...
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