summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Verboso <fverboso@unime.it>2019-02-04 15:44:35 +0100
committerFabio Verboso <fverboso@unime.it>2019-02-04 15:44:35 +0100
commit4a7dc9166d7c3fe14cf8975a175b3ae5f1b3c365 (patch)
treef43929703c4cdd40b5162f99c8682e4facbf0aed
parent4eb23145334b512a0807d48337b7518920bef8b2 (diff)
Http to https redirect.
Notes
Notes (review): Code-Review+2: Fabio Verboso <fverboso@unime.it> Workflow+1: Fabio Verboso <fverboso@unime.it> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 04 Feb 2019 15:05:03 +0000 Reviewed-on: https://review.openstack.org/634702 Project: openstack/iotronic Branch: refs/heads/master
-rw-r--r--iotronic/conductor/endpoints.py24
-rw-r--r--iotronic/wamp/proxies/nginx.py55
2 files changed, 78 insertions, 1 deletions
diff --git a/iotronic/conductor/endpoints.py b/iotronic/conductor/endpoints.py
index 396a4cf..b30258d 100644
--- a/iotronic/conductor/endpoints.py
+++ b/iotronic/conductor/endpoints.py
@@ -596,7 +596,13 @@ class ConductorEndpoint(object):
596 except exception: 596 except exception:
597 return exception 597 return exception
598 598
599 cctx = self.wamp_agent_client.prepare(server=board.agent)
600 cctx.call(ctx, 'add_redirect', board_dns=en_webservice.dns,
601 zone=en_webservice.zone, dns=newwbs.name)
602 cctx.call(ctx, 'reload_proxy')
603
599 newwbs.create() 604 newwbs.create()
605
600 return serializer.serialize_entity(ctx, newwbs) 606 return serializer.serialize_entity(ctx, newwbs)
601 607
602 def destroy_webservice(self, ctx, webservice_id): 608 def destroy_webservice(self, ctx, webservice_id):
@@ -632,6 +638,16 @@ class ConductorEndpoint(object):
632 except exception: 638 except exception:
633 return exception 639 return exception
634 640
641 board = objects.Board.get_by_uuid(ctx, wbsrv.board_uuid)
642 if board.agent == None:
643 raise exception.BoardInvalidStatus(uuid=board.uuid,
644 status=board.status)
645
646 cctx = self.wamp_agent_client.prepare(server=board.agent)
647 cctx.call(ctx, 'remove_redirect', board_dns=en_webservice.dns,
648 zone=en_webservice.zone, dns=wbsrv.name)
649 cctx.call(ctx, 'reload_proxy')
650
635 wbsrv.destroy() 651 wbsrv.destroy()
636 designate.delete_record(wbsrv.name + "." + en_webservice.dns, 652 designate.delete_record(wbsrv.name + "." + en_webservice.dns,
637 en_webservice.zone) 653 en_webservice.zone)
@@ -717,7 +733,6 @@ class ConductorEndpoint(object):
717 cctx = self.wamp_agent_client.prepare(server=board.agent) 733 cctx = self.wamp_agent_client.prepare(server=board.agent)
718 cctx.call(ctx, 'enable_webservice', board=dns, 734 cctx.call(ctx, 'enable_webservice', board=dns,
719 https_port=https_port, http_port=http_port, zone=zone) 735 https_port=https_port, http_port=http_port, zone=zone)
720 cctx.call(ctx, 'reload_proxy')
721 736
722 LOG.debug('Configure Web Proxy on Board %s with dns %s (email: %s) ', 737 LOG.debug('Configure Web Proxy on Board %s with dns %s (email: %s) ',
723 board.uuid, dns, email) 738 board.uuid, dns, email)
@@ -731,6 +746,9 @@ class ConductorEndpoint(object):
731 except exception: 746 except exception:
732 return exception 747 return exception
733 748
749 cctx.call(ctx, 'add_redirect', board_dns=dns, zone=zone)
750 cctx.call(ctx, 'reload_proxy')
751
734 return serializer.serialize_entity(ctx, en_webservice) 752 return serializer.serialize_entity(ctx, en_webservice)
735 753
736 def disable_webservice(self, ctx, board_uuid): 754 def disable_webservice(self, ctx, board_uuid):
@@ -784,6 +802,10 @@ class ConductorEndpoint(object):
784 802
785 cctx = self.wamp_agent_client.prepare(server=board.agent) 803 cctx = self.wamp_agent_client.prepare(server=board.agent)
786 cctx.call(ctx, 'disable_webservice', board=webservice.dns) 804 cctx.call(ctx, 'disable_webservice', board=webservice.dns)
805
806 # cctx.call(ctx, 'remove_redirect', board_dns=en_webservice.dns,
807 # zone=en_webservice.zone)
808
787 cctx.call(ctx, 'reload_proxy') 809 cctx.call(ctx, 'reload_proxy')
788 810
789 webservice.destroy() 811 webservice.destroy()
diff --git a/iotronic/wamp/proxies/nginx.py b/iotronic/wamp/proxies/nginx.py
index b8ac651..017b902 100644
--- a/iotronic/wamp/proxies/nginx.py
+++ b/iotronic/wamp/proxies/nginx.py
@@ -71,6 +71,39 @@ def remove(board):
71 ]) 71 ])
72 72
73 73
74def string_redirect(board, zone, dns=None):
75 if not dns:
76 host = "%s.%s" % (board, zone)
77 else:
78 host = "%s.%s.%s" % (dns, board, zone)
79 string = "if ($host = %s) { return 301 https://$host$request_uri; }\n" % (
80 host)
81 return string
82
83
84def insert_entry(line, lines):
85 try:
86 lines.index(line)
87 except Exception:
88 lines.insert(4, line)
89 return lines
90
91
92def remove_entry(line, lines):
93 try:
94 lines.remove(line)
95 except Exception:
96 pass
97 return lines
98
99
100def save_conf(f_conf, lines):
101 f = open(f_conf, "w")
102 lines = "".join(lines)
103 f.write(lines)
104 f.close()
105
106
74class ProxyManager(Proxy): 107class ProxyManager(Proxy):
75 108
76 def __init__(self): 109 def __init__(self):
@@ -91,3 +124,25 @@ class ProxyManager(Proxy):
91 LOG.debug('Disabling WebService on board %s', 124 LOG.debug('Disabling WebService on board %s',
92 board) 125 board)
93 remove(board) 126 remove(board)
127
128 def add_redirect(self, ctx, board_dns, zone, dns=None):
129 line = string_redirect(board_dns, zone, dns)
130 path = CONF.nginx.nginx_path + "/servers/" + board_dns
131 LOG.debug('Adding redirect %s on %s', line, path)
132
133 f = open(str(CONF.nginx.nginx_path + "/servers/" + board_dns), "r")
134 lines = f.readlines()
135 f.close()
136 lines = insert_entry(line, lines)
137 save_conf(path, lines)
138
139 def remove_redirect(self, ctx, board_dns, zone, dns=None):
140 path = CONF.nginx.nginx_path + "/servers/" + board_dns
141 line = string_redirect(board_dns, zone, dns)
142 LOG.debug('Removing redirect %s on %s', line, path)
143
144 f = open(path, "r")
145 lines = f.readlines()
146 f.close()
147 lines = remove_entry(line, lines)
148 save_conf(path, lines)