Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5e8e9dca
authored
Oct 24, 2016
by
Sulyok Gabor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bugfixes and reworking deployment[WIP]
parent
1f4825c9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
35 deletions
+118
-35
circle/setty/controller.py
+37
-27
circle/setty/migrations/0026_WordPressMemberChange.py
+63
-0
circle/setty/models.py
+0
-0
circle/setty/saltstackhelper.py
+11
-6
circle/setty/static/setty/setty.js
+7
-2
No files found.
circle/setty/controller.py
View file @
5e8e9dca
...
...
@@ -6,6 +6,7 @@ from django.db import transaction
from
saltstackhelper
import
*
import
os
from
vm.models
import
Instance
import
logging
class
SettyController
:
salthelper
=
SaltStackHelper
()
...
...
@@ -113,7 +114,6 @@ class SettyController:
else
:
raise
PermissionDenied
# TODO: something more meaningful
@staticmethod
def
getMachineAvailableList
(
serviceId
,
usedHostnames
,
current_user
):
saltMinions
=
SettyController
.
salthelper
.
getAllMinionsUngrouped
()
...
...
@@ -121,21 +121,23 @@ class SettyController:
savedHostNames
=
[]
for
machine
in
savedMachines
:
savedHostNames
.
append
(
machine
.
hostname
)
savedHostNames
.
append
(
machine
.
hostname
)
userInstances
=
Instance
.
objects
.
filter
(
owner
=
current_user
)
userInstances
=
Instance
.
objects
.
filter
(
owner
=
current_user
,
destroyed_at
=
None
)
userMachines
=
[]
for
instance
in
userInstances
:
if
instance
.
vm_name
:
userMachines
.
append
(
instance
.
vm_name
)
usedHostnamesByUser
=
set
(
savedHostNames
+
usedHostnames
)
usedHostnamesByUser
=
set
(
savedHostNames
+
usedHostnames
)
if
not
usedHostnamesByUser
:
return
{
'machinedata'
:
userMachines
}
#{'machinedata': [machineName for machineName in userMachines if machineName in saltMinions] }
return
{
'machinedata'
:
[
machineName
for
machineName
in
userMachines
if
machineName
in
saltMinions
]
}
availableInstance
Names
=
list
(
set
(
userMachines
)
-
usedHostnamesByUser
)
return
{
'machinedata'
:
availableInstanceNames
}
#[ machineName for machineName in availableInstanceNam
es if machineName in saltMinions ]}
availableInstance
s
=
list
(
set
(
userMachines
)
-
usedHostnamesByUser
)
return
{
'machinedata'
:
[
machineName
for
machineName
in
availableInstanc
es
if
machineName
in
saltMinions
]}
@staticmethod
def
addMachine
(
hostname
):
...
...
@@ -180,49 +182,57 @@ class SettyController:
if
errorMessages
:
return
{
'status'
:
'error'
,
'errors'
:
errorMessages
}
'errors'
:
errorMessages
}
elementConnections
=
ElementConnection
.
objects
.
filter
(
Q
(
target__in
=
machines
)
|
Q
(
source__in
=
machines
))
firstLevelServiceNodes
=
[]
# 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
)
else
:
raise
PermissionDenied
firstLevelServiceNodes
.
append
(
serviceNode
)
# phase two: let the nodes create configurations recursively
configuratedNodes
=
list
()
for
serviceNode
in
firstLevelServiceNodes
:
generatedNodes
=
serviceNode
.
generateConfigurationRecursively
()
if
isinstance
(
generatedNodes
,
list
):
configuratedNodes
=
configuratedNodes
+
generatedNodes
else
:
configuratedNodes
.
append
(
generatedNodes
)
for
serviceNode
in
serviveNodeList
:
node
=
serviceNode
.
cast
()
node
.
generateSaltCommands
()
configuratedNodes
.
append
(
node
)
# phase three: sort the nodes by deployment priority(lower the prio,
# later in the deployement)
configuratedNodes
.
sort
(
reverse
=
True
)
return
{
'status'
:
'success'
}
# deploy the nodes
# dbgCheck = []
# for node in configuratedNodes:
# SettyController.salthelper.deploy(
# node.machine.hostname, node.generatedConfig)
# return {'status': 'deployed'}
# commandDict = []
# 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
:
deployErrorMessages
=
SettyController
.
salthelper
.
executeCommand
(
node
.
generatedCommands
)
if
errorMessages
:
errorMessages
.
append
(
deployErrorMessages
)
# phase five: cleanup generated commands
for
serviceNode
in
firstLevelServiceNodes
:
serviceNode
.
generatedCommands
=
None
# cleanup the temporary data
''' for node in configuratedNodes:
node.deployCleanUp()'''
if
errorMessages
:
return
{
'status'
:
'error'
,
'errors'
:
errorMessages
}
return
{
'status'
:
'success'
}
circle/setty/migrations/0026_WordPressMemberChange.py
0 → 100644
View file @
5e8e9dca
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'setty'
,
'0025_AddDatabases'
),
]
operations
=
[
migrations
.
RemoveField
(
model_name
=
'wordpressnode'
,
name
=
'databaseListeningPort'
,
),
migrations
.
AddField
(
model_name
=
'wordpressnode'
,
name
=
'databaseName'
,
field
=
models
.
TextField
(
default
=
b
''
),
),
migrations
.
AlterField
(
model_name
=
'wordpressnode'
,
name
=
'adminEmail'
,
field
=
models
.
TextField
(
default
=
b
''
),
),
migrations
.
AlterField
(
model_name
=
'wordpressnode'
,
name
=
'adminPassword'
,
field
=
models
.
TextField
(
default
=
b
''
),
),
migrations
.
AlterField
(
model_name
=
'wordpressnode'
,
name
=
'adminUsername'
,
field
=
models
.
TextField
(
default
=
b
''
),
),
migrations
.
AlterField
(
model_name
=
'wordpressnode'
,
name
=
'databaseHost'
,
field
=
models
.
TextField
(
default
=
b
''
),
),
migrations
.
AlterField
(
model_name
=
'wordpressnode'
,
name
=
'databasePass'
,
field
=
models
.
TextField
(
default
=
b
''
),
),
migrations
.
AlterField
(
model_name
=
'wordpressnode'
,
name
=
'databaseUser'
,
field
=
models
.
TextField
(
default
=
b
''
),
),
migrations
.
AlterField
(
model_name
=
'wordpressnode'
,
name
=
'siteTitle'
,
field
=
models
.
TextField
(
default
=
b
''
),
),
migrations
.
AlterField
(
model_name
=
'wordpressnode'
,
name
=
'siteUrl'
,
field
=
models
.
TextField
(
default
=
b
''
),
),
]
circle/setty/models.py
View file @
5e8e9dca
This diff is collapsed.
Click to expand it.
circle/setty/saltstackhelper.py
View file @
5e8e9dca
...
...
@@ -3,8 +3,16 @@ import salt.config
import
salt.runner
import
salt.client
class
SaltCommand
:
def
__init__
(
self
):
self
.
hostname
=
""
self
.
command
=
""
self
.
parameters
=
""
# For debugging purposes only
def
__str__
(
self
):
return
"Command: "
+
self
.
hostname
+
" - "
+
self
.
command
+
" - "
+
str
(
self
.
parameters
)
SALTSTACK_STATE_FOLDER
=
"/srv/salt"
class
SaltStackHelper
:
def
__init__
(
self
):
self
.
master_opts
=
salt
.
config
.
client_config
(
'/etc/salt/master'
)
...
...
@@ -38,9 +46,7 @@ class SaltStackHelper:
def
checkMinionExists
(
self
,
hostname
):
query_res
=
self
.
salt_localclient
.
cmd
(
hostname
,
'network.get_hostname'
);
print
query_res
return
query_res
!=
{}
def
deploy
(
self
,
hostname
,
configFilePath
):
print
configFilePath
self
.
salt_localclient
.
cmd
(
hostname
,
'state.apply'
,
[
configFilePath
.
split
(
'.'
)[
0
]]
)
\ No newline at end of file
def
executeCommand
(
self
,
saltCommand
):
return
self
.
salt_localclient
.
cmd
(
saltCommand
.
hostname
,
"state.sls"
,[
saltCommand
.
command
],
kwarg
=
{
"pillar"
:
saltCommand
.
parameters
}
)
circle/setty/static/setty/setty.js
View file @
5e8e9dca
...
...
@@ -501,7 +501,7 @@ jsPlumb.ready(function() {
$
.
post
(
""
,
{
event
:
"addServiceNode"
,
data
:
JSON
.
stringify
({
"elementTemplateId"
:
$
(
this
).
attr
(
"id"
)
})
"elementTemplateId"
:
$
(
elementTemplate
).
attr
(
"id"
)
})
},
function
(
result
)
{
addElement
(
$
(
elementTemplate
).
attr
(
"id"
),
(
++
elementIndex
)
+
"_"
+
$
(
elementTemplate
).
attr
(
"id"
),
...
...
@@ -791,10 +791,15 @@ jsPlumb.ready(function() {
/* Registering events concerning persistence. */
$
(
'body'
).
on
(
'click'
,
'#deployService'
,
function
()
{
if
(
$
(
"#serviceStatus"
).
text
()
==
"Unsaved"
)
{
alert
(
"Only saved services can be deployed"
);
return
;
}
$
.
post
(
""
,
{
event
:
"deploy"
,
},
function
(
result
)
{
if
(
result
.
error
)
if
(
result
.
status
)
alert
(
result
.
errors
);
else
alert
(
"Deploying...."
);
...
...
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