Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
zoe
main
Commits
3c7dcda3
Commit
3c7dcda3
authored
Feb 10, 2017
by
Daniele Venzano
Browse files
Expose public IP addresses and ports
parent
e15b341a
Changes
7
Hide whitespace changes
Inline
Side-by-side
zoe_api/web/custom_request_handler.py
View file @
3c7dcda3
...
...
@@ -21,6 +21,7 @@
import
json
import
datetime
import
logging
from
jinja2
import
Environment
,
FileSystemLoader
,
Markup
...
...
@@ -28,9 +29,10 @@ from tornado.escape import squeeze, linkify, url_escape, xhtml_escape
import
tornado.web
import
zoe_lib.version
import
zoe_api.web.utils
log
=
logging
.
getLogger
(
__name__
)
class
JinjaApp
(
object
):
"""A Jinja2-capable Tornado application."""
...
...
@@ -122,6 +124,7 @@ class ZoeRequestHandler(tornado.web.RequestHandler):
try
:
html
=
self
.
_render
(
template
,
**
kwargs
)
except
Exception
:
log
.
exception
(
'Jinja2 template exception'
)
zoe_api
.
web
.
utils
.
error_page
(
self
,
'Jinja2 template exception'
,
500
)
return
self
.
finish
(
html
)
...
...
zoe_api/web/executions.py
View file @
3c7dcda3
...
...
@@ -130,11 +130,20 @@ class ExecutionInspectWeb(ZoeRequestHandler):
e
=
self
.
api_endpoint
.
execution_by_id
(
uid
,
role
,
execution_id
)
services_info
=
[]
endpoints
=
[]
for
service
in
e
.
services
:
services_info
.
append
(
self
.
api_endpoint
.
service_by_id
(
uid
,
role
,
service
.
id
))
port_mappings
=
service
.
ports
for
port
in
service
.
description
[
'ports'
]:
if
'expose'
in
port
and
port
[
'expose'
]:
port_number
=
str
(
port
[
'port_number'
])
+
"/tcp"
if
port_number
in
port_mappings
:
endpoint
=
port
[
'protocol'
]
+
"://"
+
port_mappings
[
port_number
][
0
]
+
":"
+
port_mappings
[
port_number
][
1
]
+
port
[
'path'
]
endpoints
.
append
((
port
[
'name'
],
endpoint
))
template_vars
=
{
"e"
:
e
,
"endpoints"
:
endpoints
,
"services_info"
:
services_info
}
self
.
render
(
'execution_inspect.html'
,
**
template_vars
)
zoe_api/web/templates/execution_inspect.html
View file @
3c7dcda3
...
...
@@ -23,6 +23,17 @@
<p>
Error message:
<code>
{{ e.error_message }}
</code></p>
{% endif %}
<div
id=
"endpoints"
>
{% if endpoints|length > 0 %}
<h3>
Endpoints:
</h3>
{% endif %}
<ul>
{% for e in endpoints %}
<li><a
href=
"{{ e[1] }}"
>
{{ e[0] }}
</a></li>
{% endfor %}
</ul>
</div>
<div
id=
"container_list"
>
{% if services_info|length > 0 %}
<h3>
Services:
</h3>
...
...
@@ -36,11 +47,6 @@
{% if s['error_message'] is not none %}
<li>
Error: {{ s['error_message'] }}
</li>
{% endif %}
{% if s['docker_status'] == 'started' %}
{% for p in s['description']['ports'] %}
<li><a
href=
"{{ p['protocol'] }}://{{ s['ip_address'] }}:{{ p['port_number'] }}{{ p['path'] }}"
>
{{ p['name'] }}
</a></li>
{% endfor %}
{% endif %}
</ul>
{% endfor %}
</ul>
...
...
zoe_api/web/utils.py
View file @
3c7dcda3
...
...
@@ -48,7 +48,7 @@ def catch_exceptions(func):
return
error_page
(
self
,
str
(
e
),
400
)
except
Exception
as
e
:
log
.
exception
(
str
(
e
))
return
{
'message'
:
str
(
e
)
}
,
500
return
error_page
(
self
,
str
(
e
),
500
)
return
func_wrapper
...
...
zoe_lib/config.py
View file @
3c7dcda3
...
...
@@ -88,6 +88,10 @@ def load_configuration(test_conf=None):
argparser
.
add_argument
(
'--scheduler-class'
,
help
=
'Scheduler class to use for scheduling ZApps'
,
default
=
'ZoeSimpleScheduler'
)
argparser
.
add_argument
(
'--docker-tls-cert'
,
help
=
'Docker TLS certificate file'
,
default
=
'cert.pem'
)
argparser
.
add_argument
(
'--docker-tls-key'
,
help
=
'Docker TLS private key file'
,
default
=
'key.pem'
)
argparser
.
add_argument
(
'--docker-tls-ca'
,
help
=
'Docker TLS CA certificate file'
,
default
=
'ca.pem'
)
opts
=
argparser
.
parse_args
()
if
opts
.
debug
:
argparser
.
print_values
()
...
...
zoe_lib/sql_manager.py
View file @
3c7dcda3
...
...
@@ -407,6 +407,15 @@ class Service(Base):
s_info
=
swarm
.
inspect_container
(
self
.
docker_id
)
return
s_info
[
'ip_address'
][
get_conf
().
overlay_network_name
]
@
property
def
ports
(
self
):
"""Getter for the port mappings created by Swarm."""
if
self
.
docker_status
!=
self
.
DOCKER_START_STATUS
:
return
{}
swarm
=
SwarmClient
(
get_conf
())
s_info
=
swarm
.
inspect_container
(
self
.
docker_id
)
return
s_info
[
'ports'
]
@
property
def
user_id
(
self
):
"""Getter for the user_id, that is actually taken form the parent execution."""
...
...
zoe_lib/swarm_client.py
View file @
3c7dcda3
...
...
@@ -126,15 +126,19 @@ class SwarmClient:
def
__init__
(
self
,
opts
:
Namespace
)
->
None
:
self
.
opts
=
opts
url
=
opts
.
swarm
tls
=
False
if
'zk://'
in
url
:
url
=
url
[
len
(
'zk://'
):]
manager
=
zookeeper_swarm
(
url
)
elif
'http://'
or
'https://'
in
url
:
elif
'http://'
in
url
:
manager
=
url
elif
'https://'
in
url
:
tls
=
docker
.
tls
.
TLSConfig
(
client_cert
=
(
opts
.
docker_tls_cert
,
opts
.
docker_tls_key
),
verify
=
opts
.
docker_tls_ca
)
manager
=
url
else
:
raise
ZoeLibException
(
'Unsupported URL scheme for Swarm'
)
log
.
debug
(
'Connecting to Swarm at {}'
.
format
(
manager
))
self
.
cli
=
docker
.
Client
(
base_url
=
manager
,
version
=
"auto"
)
self
.
cli
=
docker
.
Client
(
base_url
=
manager
,
version
=
"auto"
,
tls
=
tls
)
def
info
(
self
)
->
SwarmStats
:
"""Retrieve Swarm statistics. The Docker API returns a mess difficult to parse."""
...
...
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