2 Contains html text in variables to make and html response
6 from http
import HTTPStatus
8 __author__
= "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
14 <link href="/osm/static/style.css" rel="stylesheet">
15 <title>Welcome to OSM</title>
18 <div id="osm_topmenu">
20 <a href="https://osm.etsi.org"> <img src="/osm/static/OSM-logo.png" height="42" width="100" style="vertical-align:middle"> </a>
22 <a href="/osm/vnfpkgm/v1/vnf_packages">VNFDs </a>
23 <a href="/osm/nsd/v1/ns_descriptors">NSDs </a>
24 <a href="/osm/nslcm/v1/ns_instances">NSs </a>
25 <a href="/osm/user/v1">USERs </a>
26 <a href="/osm/project/v1">PROJECTs </a>
27 <a href="/osm/token/v1">TOKENs </a>
28 <a href="/osm/token/v1?METHOD=DELETE">logout </a>
42 html_body_error
= "<h2> Error <pre>{}</pre> </h2>"
47 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
49 <head><META http-equiv="Content-Type" content="text/html; charset=UTF-8">
50 <link href="/osm/static/style.css" rel="stylesheet">
51 <title>OSM Login</title>
56 <a href="https://osm.etsi.org"> <h1><img src="/osm/static/OSM-logo.png" style="vertical-align:middle"></h1> </a>
59 <div id="osm_error_message">
62 <div class="gerritBody" id="osm_body">
63 <h1>Sign in to OSM</h1>
64 <form action="/osm/token/v1" id="login_form" method="POST">
65 <table style="border: 0;">
66 <tr><th>Username</th><td><input id="f_user" name="username" size="25" tabindex="1" type="text"></td></tr>
67 <tr><th>Password</th><td><input id="f_pass" name="password" size="25" tabindex="2" type="password"></td></tr>
68 <tr><td><input tabindex="3" type="submit" value="Sign In"></td></tr>
71 <div style="clear: both; margin-top: 15px; padding-top: 2px; margin-bottom: 15px;">
77 <script src="/osm/static/login.js"> </script>
82 html_upload_body
= """
83 <form action="/osm{}" method="post" enctype="multipart/form-data">
84 <h3> <table style="border: 0;"> <tr>
85 <td> Upload {} descriptor (tar.gz) file: <input type="file" name="descriptor_file"/> </td>
86 <td> <input type="submit" value="Upload"/> </td>
92 def format(data
, request
, response
, session
):
94 Format a nice html response, depending on the data
96 :param request: cherrypy request
97 :param response: cherrypy response
98 :return: string with teh html response
100 response
.headers
["Content-Type"] = 'text/html'
101 if response
.status
== HTTPStatus
.UNAUTHORIZED
.value
:
102 if response
.headers
.get("WWW-Authenticate") and request
.config
.get("auth.allow_basic_authentication"):
103 response
.headers
["WWW-Authenticate"] = "Basic" + response
.headers
["WWW-Authenticate"][6:]
106 return html_auth2
.format(error
=data
)
107 body
= html_body
.format(item
=request
.path_info
)
108 if response
.status
and response
.status
> 202:
109 body
+= html_body_error
.format(yaml
.safe_dump(data
, explicit_start
=True, indent
=4, default_flow_style
=False))
110 elif isinstance(data
, (list, tuple)):
111 if request
.path_info
== "/vnfpkgm/v1/vnf_packages":
112 body
+= html_upload_body
.format("VNFD", request
.path_info
)
113 elif request
.path_info
== "/nsd/v1/ns_descriptors":
114 body
+= html_upload_body
.format("NSD", request
.path_info
)
116 data_id
= k
.pop("_id", None)
117 body
+= '<p> <a href="/osm/{url}/{id}">{id}</a>: {t} </p>'.format(url
=request
.path_info
, id=data_id
, t
=k
)
118 elif isinstance(data
, dict):
119 if "Location" in response
.headers
:
120 body
+= '<a href="{}"> show </a>'.format(response
.headers
["Location"])
122 body
+= '<a href="/osm/{}?METHOD=DELETE"> <img src="/osm/static/delete.png" height="25" width="25"> </a>'.format(request
.path_info
)
123 body
+= "<pre>" + yaml
.safe_dump(data
, explicit_start
=True, indent
=4, default_flow_style
=False) + "</pre>"
128 if session
.get("username"):
129 user_text
+= "user: {}".format(session
.get("username"))
130 if session
.get("project_id"):
131 user_text
+= ", project: {}".format(session
.get("project_id"))
132 return html_start
.format(user_text
) + body
+ html_end
133 #yaml.safe_dump(data, explicit_start=True, indent=4, default_flow_style=False)
135 # encoding='utf-8', allow_unicode=True)