Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue-398
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwolfs authored Dec 6, 2023
2 parents 24108aa + 41235bd commit b52d5ce
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Standards/scs-0100-v3-flavor-naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ It goes beyond the above example in checking that the discoverable
features of flavors (vCPUs, RAM, Disk) match what the flavor names claim.
This is used for SCS-compatible compliance testing.

The functionality of the `flavor-name-check.py` script is also
(partially) exposed via the web page <https://flavors.scs.community/>.

## Extensions

Extensions provide a possibility for providers that offer a very differentiated set
Expand Down
76 changes: 76 additions & 0 deletions Tests/iaas/flavor-naming/flavor-form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python3
# Little wrapper to output flavor pretty description
# from a CGI form with flavor
#
# (c) Kurt Garloff <kurt@garloff.de>, 11/2023
# SPDX-License-Identifier: CC-BY-SA-4.0
"""
flavor-form.py
CGI script to get passed flavor from a html form (GET)
and parses it according to SCS flavor naming.
It returns an error (sometimes with a useful error message)
or a human-readable description of the flavor.
"""

# import os
import sys
import re
# import traceback
# TODO: Replace cgi by urllib, cgi is deprecated
import cgi


class TestForm:
"Class for testing via cmd line"
def __init__(self, fnm):
self.value = fnm


def parse_form(form):
"output pretty description from SCS flavor name"
import importlib
fnmd = importlib.import_module("flavor-name-describe")
fnm = ""
try:
fnm = form["flavor"].value
except KeyError:
pass
print('\t<br/>\n\t<FORM ACTION="/cgi-bin/flavor-form.py" METHOD="GET">')
print(f'\t Flavor name: <INPUT TYPE="text" NAME="flavor" SIZE=24 VALUE="{fnm}"/>')
print('\t <INPUT TYPE="submit" VALUE="Submit"/>')
# print(' <INPUT TYPE="reset" VALUE="Clear"/>\n</FORM>')
print('\t</FORM>')
if fnm:
print("\t<br/><b>Flavor</b>")
try:
fnmd.main((fnm,))
except (TypeError, NameError, KeyError) as exc:
print(f"\tERROR<br/>\n\t{exc}")


def parse_generate(form):
"input details to generate SCS flavor name"
print("\tNot implemented yet as webform, use")
print('\t<tt><a href="https://github.com/SovereignCloudStack/standards/blob/main/Tests/iaas/flavor-naming/flavor-name-check.py">flavor-name-check.py</a> -i</tt>')


def main(argv):
"Entry point for cgi flavor parsing"
print("Content-Type: text/html\n")
form = cgi.FieldStorage()
# For testing
if len(argv) > 0:
form = {"flavor": TestForm(argv[0])}
find_parse = re.compile(r'^[ \t]*<!\-\-FLAVOR\-FORM: PARSE\-\->[ \t]*$')
find_generate = re.compile(r'^[ \t]*<!\-\-FLAVOR\-FORM: GENERATE\-\->[ \t]*$')
with open("page/index.html", "r", encoding='utf-8') as infile:
for line in infile:
print(line, end='')
if find_parse.match(line):
parse_form(form)
elif find_generate.match(line):
parse_generate(form)


if __name__ == "__main__":
main(sys.argv[1:])
5 changes: 4 additions & 1 deletion Tests/iaas/flavor-naming/flavor-name-describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def main(argv):
fnmck = importlib.import_module("flavor-name-check")
for nm in argv:
ret = fnmck.parsename(nm)
print(f'{nm}: {prettyname(ret)}')
if ret:
print(f'{nm}: {prettyname(ret)}')
else:
print(f'{nm}: Not an SCS flavor')


if __name__ == "__main__":
Expand Down
31 changes: 31 additions & 0 deletions Tests/iaas/flavor-naming/page/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta property="og:locale" content="en" />
<meta name="description" content="Sovereign Cloud Stack combines the best of cloud computing in one unified standard. One standards are the SCS flavor names and this page is about parsing and generating SCS flavor names." />
<link rel="canonical" href="https://flavors.scs.community/" />
<meta property="og:url" content="https://flavors.scs.community/" />
<meta property="og:site_name" content="Sovereign Cloud Stack Flavors" />
<!-- Favicon -->
<link rel="apple-touch-icon" sizes="180x180" href="/assets/scs-apple-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/assets/scs-favicon-32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/assets/scs-favicon-16.png" />
</head>
<body>
<h1>SCS flavor name parser and generator</h1>
<h2>SCS flavor name parser</h2>
<!--FLAVOR-FORM: PARSE-->
<h2>SCS flavor name generator</h2>
<!--FLAVOR-FORM: GENERATE-->
<h2>References</h2>
<ul>
<li><a href="https://scs.community/">SCS homepage</a></li>
<li><a href="https://docs.scs.community/">SCS docs pages</a></li>
<li><a href="https://docs.scs.community/standards">SCS standards</a></li>
<li><a href="https://docs.scs.community/standards/iaas/scs-0100">SCS flavor naming standard</a></li>
<li><a href="https://github.com/SovereignCloudStack/standards/blob/main/Drafts/flavor-naming-strategy.md">SCS flavor naming rationale</a></li>
<li><a href="https://github.com/SovereignCloudStack/standards/tree/main/Tests/iaas/flavor-naming">SCS flavor naming tools</a></li>
</ul>
</body>
</html>

0 comments on commit b52d5ce

Please sign in to comment.