Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
ebaa5dac
Commit
ebaa5dac
authored
Jun 17, 2020
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make sure we only update changed nodes
parent
8edc8b29
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
71 additions
and
49 deletions
+71
-49
__main__.py
deployer/__main__.py
+15
-15
semaphore_client-1.0.0-py3.6.egg
deployer/dist/semaphore_client-1.0.0-py3.6.egg
+0
-0
ansible_service.py
deployer/service/ansible_service.py
+0
-2
deploy_service.py
deployer/service/deploy_service.py
+28
-11
tosca_helper.py
deployer/service/tosca_helper.py
+3
-2
docker-compose.yml
docker-compose/docker-compose.yml
+9
-9
nginx.conf
docker-compose/nginx.conf
+4
-4
test_default_api.py
sure_tosca-client_python_stubs/test/test_default_api.py
+12
-6
No files found.
deployer/__main__.py
View file @
ebaa5dac
...
...
@@ -90,26 +90,26 @@ def handle_delivery(message):
semaphore_password
=
semaphore_password
,
vms
=
tosca_helper
.
get_vms
())
try
:
for
node_pair
in
nodes_pairs
:
updated_node_pairs
=
deployService
.
deploy
(
node_pair
)
for
updated_node
in
updated_node_pairs
:
if
isinstance
(
updated_node
,
list
):
for
node
in
updated_node
:
tosca_helper
.
set_node
(
node
,
tosca_template_dict
)
else
:
tosca_helper
.
set_node
(
updated_node
,
tosca_template_dict
)
updated_node
=
deployService
.
deploy
(
node_pair
)
if
isinstance
(
updated_node
,
list
):
for
node
in
updated_node
:
tosca_template_dict
=
tosca_helper
.
set_node
(
node
,
tosca_template_dict
)
logger
.
info
(
"tosca_template_dict :"
+
json
.
dumps
(
tosca_template_dict
))
else
:
tosca_template_dict
=
tosca_helper
.
set_node
(
updated_node
,
tosca_template_dict
)
logger
.
info
(
"tosca_template_dict :"
+
json
.
dumps
(
tosca_template_dict
))
response
=
{
'toscaTemplate'
:
tosca_template_dict
}
output_current_milli_time
=
int
(
round
(
time
.
time
()
*
1000
))
response
[
"creationDate"
]
=
output_current_milli_time
logger
.
info
(
"Returning Deployment"
)
logger
.
info
(
"Output message:"
+
json
.
dumps
(
response
))
return
json
.
dumps
(
response
)
except
Exception
as
e
:
track
=
traceback
.
format_exc
()
print
(
track
)
raise
response
=
{
'toscaTemplate'
:
tosca_template_dict
}
output_current_milli_time
=
int
(
round
(
time
.
time
()
*
1000
))
response
[
"creationDate"
]
=
output_current_milli_time
logger
.
info
(
"Returning Deployment"
)
logger
.
info
(
"Output message:"
+
json
.
dumps
(
response
))
return
json
.
dumps
(
response
)
def
threaded_function
(
args
):
while
not
done
:
...
...
deployer/dist/semaphore_client-1.0.0-py3.6.egg
0 → 100644
View file @
ebaa5dac
File added
deployer/service/ansible_service.py
View file @
ebaa5dac
...
...
@@ -130,6 +130,4 @@ class AnsibleService:
logger
.
info
(
'task name: '
+
name
+
', task status: '
+
str
(
task
.
status
))
last_status
=
this_status
sleep
(
3
)
if
'k8s/create_k8s_dashboard.yaml'
==
playbook_name
:
print
(
playbook_name
)
return
task_id
deployer/service/deploy_service.py
View file @
ebaa5dac
...
...
@@ -38,12 +38,12 @@ class DeployService:
env_vars
=
self
.
get_env_vars
(
nodes_pair
)
if
'Standard'
in
interface_types
:
task_outputs
=
ansible_service
.
execute
(
nodes_pair
,
'Standard'
,
self
.
vms
,
env_vars
=
env_vars
)
nodes_pair
=
self
.
set_attributes
(
task_outputs
,
nodes_pair
)
source
=
self
.
set_attributes
(
task_outputs
,
source
)
if
'Kubernetes'
in
interface_types
:
task_outputs
=
ansible_service
.
execute
(
nodes_pair
,
'Kubernetes'
,
self
.
vms
,
env_vars
=
env_vars
)
nodes_pair
=
self
.
set_attributes
(
task_outputs
,
nodes_pair
)
source
=
self
.
set_attributes
(
task_outputs
,
source
)
return
nodes_pair
return
source
def
get_env_vars
(
self
,
nodes_pair
):
target
=
nodes_pair
[
0
]
...
...
@@ -55,15 +55,17 @@ class DeployService:
env_vars
[
'CONTAINER_PORT'
]
=
source
.
node_template
.
properties
[
'ports'
][
0
]
.
split
(
':'
)[
1
]
return
env_vars
def
set_attributes
(
self
,
task_outputs
,
nodes_pair
):
target
=
nodes_pair
[
0
]
source
=
nodes_pair
[
1
]
def
set_attributes
(
self
,
task_outputs
,
source
):
#
target = nodes_pair[0]
#
source = nodes_pair[1]
if
source
.
node_template
.
type
==
'tosca.nodes.QC.docker.Orchestrator.Kubernetes'
:
source
=
self
.
set_kubernetes_attributes
(
source
=
source
,
task_outputs
=
task_outputs
)
lst
=
list
(
nodes_pair
)
lst
[
1
]
=
source
nodes_pair
=
tuple
(
lst
)
return
nodes_pair
if
source
.
node_template
.
type
==
'tosca.nodes.QC.Container.Application.Docker'
:
source
=
self
.
set_docker_attributes
(
source
=
source
,
task_outputs
=
task_outputs
)
# lst = list(nodes_pair)
# lst[1] = source
# nodes_pair = tuple(lst)
return
source
...
...
@@ -130,7 +132,7 @@ class DeployService:
if
'dashboard_url'
not
in
source
.
node_template
.
attributes
:
dashboard_url
=
''
attributes
[
'dashboard_url'
]
=
tokens
attributes
[
'dashboard_url'
]
=
dashboard_url
else
:
dashboard_url
=
attributes
[
'dashboard_url'
]
...
...
@@ -152,3 +154,18 @@ class DeployService:
attributes
[
'dashboard_url'
]
=
dashboard_url
logger
.
info
(
'source.node_template.attributes: '
+
str
(
attributes
))
return
source
def
set_docker_attributes
(
self
,
source
,
task_outputs
):
attributes
=
source
.
node_template
.
attributes
if
'service_url'
not
in
source
.
node_template
.
attributes
:
service_url
=
''
attributes
[
'service_url'
]
=
service_url
for
task_output_key
in
task_outputs
:
task_output
=
task_outputs
[
task_output_key
]
k8s_services
=
self
.
parse_ansible_var
(
'k8s_services'
,
task_output
)
service_port
=
self
.
get_service_port
(
k8s_services
,
source
.
name
,
'nodePort'
)
if
service_port
:
service_url
=
'http://'
+
self
.
master_ip
+
':'
+
str
(
service_port
)
attributes
[
'service_url'
]
=
service_url
logger
.
info
(
'source.node_template.attributes: '
+
str
(
attributes
))
return
source
deployer/service/tosca_helper.py
View file @
ebaa5dac
import
copy
import
os
import
sys
import
urllib.request
from
sure_tosca_client
import
Configuration
,
ApiClient
from
sure_tosca_client
import
Configuration
,
ApiClient
,
NodeTemplate
from
sure_tosca_client.api
import
default_api
...
...
@@ -76,7 +77,7 @@ class ToscaHelper:
node_templates
=
tosca_template_dict
[
'topology_template'
][
'node_templates'
]
for
node_name
in
node_templates
:
if
node_name
==
updated_node
.
name
:
node_templates
[
node_name
]
=
updated_node
.
node_template
node_templates
[
node_name
]
=
updated_node
.
node_template
.
to_dict
()
return
tosca_template_dict
...
...
docker-compose/docker-compose.yml
View file @
ebaa5dac
...
...
@@ -93,15 +93,15 @@ services:
CLOUD_STORM_SECRET
:
456
CREDENTIAL_SECRET
:
123
deployer
:
depends_on
:
-
rabbit
-
sure-tosca
image
:
deployer:3.0.0
environment
:
RABBITMQ_HOST
:
rabbit
SURE_TOSCA_BASE_PATH
:
http://sure-tosca:8081/tosca-sure/1.0.0
SEMAPHORE_BASE_PATH
:
http://semaphore:3000/api
#
deployer:
#
depends_on:
#
- rabbit
#
- sure-tosca
#
image: deployer:3.0.0
#
environment:
#
RABBITMQ_HOST: rabbit
#
SURE_TOSCA_BASE_PATH: http://sure-tosca:8081/tosca-sure/1.0.0
#
SEMAPHORE_BASE_PATH: http://semaphore:3000/api
...
...
docker-compose/nginx.conf
View file @
ebaa5dac
...
...
@@ -9,10 +9,10 @@ events {
http
{
proxy_connect_timeout
1
200
;
proxy_send_timeout
1
200
;
proxy_read_timeout
1
200
;
send_timeout
1
200
;
proxy_connect_timeout
9
200
;
proxy_send_timeout
9
200
;
proxy_read_timeout
9
200
;
send_timeout
9
200
;
tcp_nodelay
on
;
...
...
sure_tosca-client_python_stubs/test/test_default_api.py
View file @
ebaa5dac
...
...
@@ -14,9 +14,10 @@ from __future__ import absolute_import
import
os
import
unittest
from
urllib.error
import
HTTPError
import
urllib3
from
urllib.request
import
urlopen
import
ssl
import
sure_tosca_client
from
sure_tosca_client
import
Configuration
,
ApiClient
from
sure_tosca_client.api.default_api
import
DefaultApi
# noqa: E501
...
...
@@ -28,7 +29,7 @@ class TestDefaultApi(unittest.TestCase):
def
setUp
(
self
):
configuration
=
Configuration
()
configuration
.
host
=
'http://127.0.0.1:8081/tosca-sure/1.0.0'
#Make sure we don't have '/' on the end of url
if
self
.
service_is_up
(
configuration
.
host
):
if
self
.
check_
service_is_up
(
configuration
.
host
):
configuration
.
verify_ssl
=
False
api_client
=
ApiClient
(
configuration
=
configuration
)
self
.
api
=
sure_tosca_client
.
api
.
default_api
.
DefaultApi
(
api_client
=
api_client
)
# noqa: E501
...
...
@@ -190,12 +191,17 @@ class TestDefaultApi(unittest.TestCase):
return
file_id
def
service_is_up
(
self
,
url
):
def
check_
service_is_up
(
self
,
url
):
code
=
None
try
:
http
=
urllib3
.
PoolManager
()
r
=
http
.
request
(
'HEAD'
,
url
)
response
=
urlopen
(
url
,
context
=
ssl
.
_create_unverified_context
())
print
(
response
)
# http = urllib3.PoolManager()
# r = http.request('HEAD', url,context=ctx)
except
Exception
as
e
:
if
isinstance
(
e
,
HTTPError
)
and
e
.
code
==
401
:
return
True
return
False
return
True
...
...
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