-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
88 lines (78 loc) · 2.48 KB
/
utils.py
File metadata and controls
88 lines (78 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Utility functions for the Akamai Property and Hostname Manager
"""
import dns.resolver
def resolve_hostname(hostname):
"""
Resolve hostname to IP addresses using DNS
Args:
hostname: Hostname to resolve
Returns:
List of IP addresses
"""
try:
# Create a new resolver
resolver = dns.resolver.Resolver()
# Get A records
answers = resolver.resolve(hostname, 'A')
return [str(rdata) for rdata in answers]
except Exception as e:
return [f"Resolution failed: {str(e)}"]
def get_staging_hostname(prod_hostname):
"""
Convert production hostname to staging hostname
Args:
prod_hostname: Production edgekey hostname
Returns:
Staging hostname
"""
if '.edgekey.net' in prod_hostname:
return prod_hostname.replace('.edgekey.net', '.edgekey-staging.net')
return prod_hostname
def generate_html_table(headers, data):
"""
Generate HTML table from headers and data
Args:
headers: List of table headers
data: List of rows or dictionaries containing the table data
Returns:
HTML table as string
"""
html_table = "<table><tr>"
# Add headers
for header in headers:
html_table += f"<th>{header}</th>"
html_table += "</tr>"
# Add rows
for row in data:
html_table += "<tr>"
# Handle both list and dictionary data formats
if isinstance(row, dict):
for header in headers:
html_table += f"<td>{row.get(header, '')}</td>"
else:
for cell in row:
html_table += f"<td>{cell}</td>"
html_table += "</tr>"
html_table += "</table>"
return html_table
def generate_markdown_table(headers, data):
"""
Generate Markdown table from headers and data
Args:
headers: List of table headers
data: List of rows or dictionaries containing the table data
Returns:
Markdown table as string
"""
md_table = "| " + " | ".join(headers) + " |\n"
md_table += "| " + " | ".join(["---"] * len(headers)) + " |\n"
for row in data:
# Handle both list and dictionary data formats
if isinstance(row, dict):
values = [str(row.get(header, '')) for header in headers]
md_row = "| " + " | ".join(values) + " |"
else:
md_row = "| " + " | ".join([str(cell) for cell in row]) + " |"
md_table += md_row + "\n"
return md_table