Read now works, and terraform directory contains example code

This commit is contained in:
Joachim Friberg committed 2026-08-25 18:58:03 +02:00
1 parent ef498e4a72
commit a6f1019175
43 files changed
+4341 -38

No files matched your search

@@ -0,0 +1,160 @@
// Package client is a Go port of the reference Python implementation's
// switch_client.py (see ~/code/experiments/hpe/switch_client.py).
package client
import (
"fmt"
"io"
"net/http"
"net/http/cookiejar"
"net/url"
"regexp"
"strings"
)
type Client struct {
BaseURL string
httpClient *http.Client
password string
}
func NewClient(host string, https bool, password string) (*Client, error) {
scheme := "http"
if https {
scheme = "https"
}
jar, err := cookiejar.New(nil)
if err != nil {
return nil, fmt.Errorf("creating cookie jar: %w", err)
}
return &Client{
BaseURL: fmt.Sprintf("%s://%s", scheme, host),
httpClient: &http.Client{Jar: jar},
password: password,
}, nil
}
func (c *Client) resolveURL(path string) string {
if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") {
return path
}
if strings.HasPrefix(path, "/") {
return c.BaseURL + path
}
return c.BaseURL + "/" + path
}
// Login POSTs to /hp_login.html and establishes the session cookie.
//
// A bare POST occasionally comes back without setting SID (the switch seems
// to want a session cookie already present, even an empty one, before it
// will issue a real one) -- a GET first makes login reliable.
//
// Unlike the Python version, there's no on-disk session cache here: this
// provider process lives for the whole plan/apply run, so Configure() logs
// in once and every resource/data source reuses the same *Client.
func (c *Client) Login() error {
if _, err := c.httpClient.Get(c.resolveURL("/")); err != nil {
return fmt.Errorf("priming session: %w", err)
}
form := url.Values{
"pwd": {c.password},
"login": {"Login"},
"err_flag": {""},
"err_msg": {""},
}
resp, err := c.httpClient.PostForm(c.resolveURL("/hp_login.html"), form)
if err != nil {
return fmt.Errorf("login request: %w", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("reading login response: %w", err)
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("login request returned status %d", resp.StatusCode)
}
if strings.Contains(strings.ToLower(string(body)), "<title>login</title>") {
snippet := string(body)
if len(snippet) > 500 {
snippet = snippet[:500]
}
return fmt.Errorf("login failed, response still looks like the login page: %q", snippet)
}
return nil
}
// Fetch GETs BaseURL+path (path may be relative or absolute) and returns the body.
func (c *Client) Fetch(path string) (string, error) {
resp, err := c.httpClient.Get(c.resolveURL(path))
if err != nil {
return "", fmt.Errorf("fetching %s: %w", path, err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("reading response for %s: %w", path, err)
}
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("fetching %s returned status %d", path, resp.StatusCode)
}
return string(body), nil
}
var errFlagRejectedRe = regexp.MustCompile(`(?i)name="err_flag"[^>]*value="1"`)
var errMsgRe = regexp.MustCompile(`(?i)name="err_msg"[^>]*value="([^"]*)"`)
// SubmitForm POSTs fields to path, merged with the firmware's standard
// bookkeeping fields (submit_flag, submit_target, err_flag, err_msg,
// clazz_information), and returns the response body.
//
// Returns an error if the response's err_flag comes back "1" -- the
// firmware's own validation-failure signal. NOTE: most value validation in
// this firmware happens client-side in JS, not on the server -- an invalid
// enum value, for example, is just silently ignored (state left unchanged)
// rather than reported via err_flag. So this check catches *some* rejected
// writes, but a caller that needs certainty should read the value back
// afterwards and compare, rather than trusting the absence of an error.
func (c *Client) SubmitForm(path string, fields map[string]string) (string, error) {
target := strings.TrimPrefix(path, "/")
form := url.Values{
// 8 == xui_operation_submit (per the firmware's own _xe_jsvars.js);
// 1 is xui_operation_reload and silently applies nothing.
"submit_flag": {"8"},
"submit_target": {target},
"err_flag": {"0"},
"err_msg": {""},
"clazz_information": {target},
}
for k, v := range fields {
form.Set(k, v)
}
resp, err := c.httpClient.PostForm(c.resolveURL(path), form)
if err != nil {
return "", fmt.Errorf("submitting form to %s: %w", path, err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("reading response for %s: %w", path, err)
}
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("submitting form to %s returned status %d", path, resp.StatusCode)
}
bodyStr := string(body)
if errFlagRejectedRe.MatchString(bodyStr) {
msg := "unknown error"
if m := errMsgRe.FindStringSubmatch(bodyStr); m != nil {
msg = m[1]
}
return "", fmt.Errorf("switch rejected write to %q: %s", path, msg)
}
return bodyStr, nil
}
@@ -0,0 +1,67 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- (C) Copyright Broadcom Corporation 2000-2020 : This file is auto-generated by XE - DON'T EDIT -->
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE>
HP ProCurve Forwarding Database Search
</TITLE>
<link href="/50021801/css/style1.css" rel="stylesheet" type="text/css" id="fastpath">
<script type="text/javascript" src="/50021801/scripts/xui_common.js"></script>
<script type="text/javascript" src="/50021801/scripts/globalStyleJS.js"></script>
<script type="text/javascript" src="/50021801/scripts/globalStyleJS.js"></script>
<script type="text/javascript" >
xuiIncludeCommonJSFiles("/50021801/scripts/");
xuiIncludeJSFile("/50021801/scripts/_xe_FDBSearch.js");
</script>
</HEAD>
<BODY onload="formLoad();" CLASS=page>
<FORM method=post ACTION="/FDBSearch.html">
<DIV ID="topdiv">
<script type="text/javascript" >
</script>
<script type="text/javascript" >
</script>
<DIV id=scalar DIV_XID = 1><TABLE ID=1><CAPTION>MAC Table</CAPTION>
<TR id=1_3 class=def>
<TD class=defleft id=1_3_1>Maximum Entries Supported</TD>
<TD class=defright id=1_3_1><INPUT xid=1_3_1 TYPE=hidden NAME=v_1_3_1 VALUE="8192"></TD>
</TR>
<TR id=1_2 class=def>
<TD class=defleft id=1_2_1>Current Entries</TD>
<TD class=defright id=1_2_1><INPUT xid=1_2_1 TYPE=hidden NAME=v_1_2_1 VALUE="2"></TD>
</TR>
</TABLE></DIV><br>
<DIV id=summary NORENDER DIV_XID = 1_1><TABLE ID=1_1><CAPTION></CAPTION>
<TH id=1_1_1 style="display:none">MAC Address</TH>
<TH id=1_1_5>MAC Address</TH>
<TH id=1_1_4>VLAN</TH>
<TH id=1_1_2>Source Port</TH>
<TH id=1_1_3>MAC Type</TH>
<tr><td CLASS="tabledata0" style="display: none;">00:01:4C:EA:41:63:04:1B</td><td CLASS="tabledata0">4C:EA:41:63:04:1B</td><td CLASS="tabledata0">1</td><td CLASS="tabledata0">5</td><td CLASS="tabledata0">Learned</td></tr>
<tr><td CLASS="tabledata1" style="display: none;">00:01:B4:99:BA:DA:3A:20</td><td CLASS="tabledata1">B4:99:BA:DA:3A:20</td><td CLASS="tabledata1">1</td><td CLASS="tabledata1">CPU</td><td CLASS="tabledata1">Management</td></tr>
</TABLE></DIV><br>
<script type="text/javascript" >
</script>
<!-- redirection elements -->
<INPUT TYPE="hidden" NAME="submit_flag" XC=hidden VALUE="0">
<INPUT TYPE="hidden" NAME="submit_target" XC=hidden VALUE="FDBSearch.html">
<INPUT TYPE="hidden" NAME="err_flag" XC=hidden SIZE="16" MAXLENGTH="15" VALUE="0">
<INPUT TYPE="hidden" NAME="err_msg" XC=hidden SIZE="80" MAXLENGTH="79" VALUE="">
<INPUT TYPE="hidden" NAME="clazz_information" XC=hidden VALUE="FDBSearch.html">
<center>
<DIV ID="buttons" style="visibility:visible;">
<TABLE><TR align=center>
</TR></TABLE>
</DIV>
</center>
</DIV>
</FORM>
</BODY>
</HTML>
@@ -0,0 +1,434 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- (C) Copyright Broadcom Corporation 2000-2020 : This file is auto-generated by XE - DON'T EDIT -->
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE>
HP ProCurve Port Summary
</TITLE>
<link href="/50021801/css/style1.css" rel="stylesheet" type="text/css" id="fastpath">
<script type="text/javascript" src="/50021801/scripts/xui_common.js"></script>
<script type="text/javascript" src="/50021801/scripts/globalStyleJS.js"></script>
<script type="text/javascript" src="/50021801/scripts/globalStyleJS.js"></script>
<script type="text/javascript" >
xuiIncludeCommonJSFiles("/50021801/scripts/");
xuiIncludeJSFile("/50021801/scripts/_xe_PortSummary.js");
</script>
</HEAD>
<BODY onload="formLoad();" CLASS=page>
<FORM method=post ACTION="/PortSummary.html">
<DIV ID="topdiv">
<script type="text/javascript" >
</script>
<script type="text/javascript" >
</script>
<DIV id=summary DIV_XID = 1_1><TABLE ID=1_1><CAPTION>Port Summary</CAPTION>
<TH id=1_1_21 style="display:none">UnitIndex</TH>
<TH id=1_1_22>Interface</TH>
<TH id=1_1_1 style="display:none">Interface</TH>
<TH id=1_1_2>Physical Type</TH>
<TH id=1_1_3>Port Status</TH>
<TH id=1_1_4>AutoNeg Status</TH>
<TH id=1_1_5>Link Speed</TH>
<TH id=1_1_6>MTU</TH>
<TR p="1.0.240" id=1_1>
<TD style="display:none" class="def" p="1.0.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.0.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.0.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.0.24.v_1_1_22 VALUE="1"></TD>
<TD style="display:none" class="def" p="1.0.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.0.24.v_1_1_1 VALUE="1"></TD>
<TD class="def" p="1.0.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.0.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.0.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.0.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.0.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.0.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.0.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.0.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.0.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.0.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.1.240" id=1_1>
<TD style="display:none" class="def" p="1.1.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.1.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.1.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.1.24.v_1_1_22 VALUE="2"></TD>
<TD style="display:none" class="def" p="1.1.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.1.24.v_1_1_1 VALUE="2"></TD>
<TD class="def" p="1.1.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.1.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.1.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.1.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.1.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.1.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.1.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.1.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.1.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.1.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.2.240" id=1_1>
<TD style="display:none" class="def" p="1.2.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.2.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.2.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.2.24.v_1_1_22 VALUE="3"></TD>
<TD style="display:none" class="def" p="1.2.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.2.24.v_1_1_1 VALUE="3"></TD>
<TD class="def" p="1.2.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.2.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.2.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.2.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.2.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.2.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.2.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.2.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.2.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.2.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.3.240" id=1_1>
<TD style="display:none" class="def" p="1.3.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.3.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.3.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.3.24.v_1_1_22 VALUE="4"></TD>
<TD style="display:none" class="def" p="1.3.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.3.24.v_1_1_1 VALUE="4"></TD>
<TD class="def" p="1.3.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.3.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.3.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.3.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.3.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.3.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.3.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.3.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.3.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.3.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.4.240" id=1_1>
<TD style="display:none" class="def" p="1.4.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.4.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.4.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.4.24.v_1_1_22 VALUE="5"></TD>
<TD style="display:none" class="def" p="1.4.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.4.24.v_1_1_1 VALUE="5"></TD>
<TD class="def" p="1.4.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.4.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.4.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.4.24.v_1_1_3 VALUE="Link Up"></TD>
<TD class="def" p="1.4.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.4.24.v_1_1_4 VALUE="Disable"></TD>
<TD class="def" p="1.4.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.4.24.v_1_1_5 VALUE="100MbpsFullDuplex"></TD>
<TD class="def" p="1.4.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.4.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.5.240" id=1_1>
<TD style="display:none" class="def" p="1.5.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.5.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.5.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.5.24.v_1_1_22 VALUE="6"></TD>
<TD style="display:none" class="def" p="1.5.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.5.24.v_1_1_1 VALUE="6"></TD>
<TD class="def" p="1.5.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.5.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.5.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.5.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.5.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.5.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.5.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.5.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.5.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.5.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.6.240" id=1_1>
<TD style="display:none" class="def" p="1.6.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.6.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.6.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.6.24.v_1_1_22 VALUE="7"></TD>
<TD style="display:none" class="def" p="1.6.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.6.24.v_1_1_1 VALUE="7"></TD>
<TD class="def" p="1.6.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.6.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.6.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.6.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.6.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.6.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.6.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.6.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.6.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.6.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.7.240" id=1_1>
<TD style="display:none" class="def" p="1.7.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.7.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.7.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.7.24.v_1_1_22 VALUE="8"></TD>
<TD style="display:none" class="def" p="1.7.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.7.24.v_1_1_1 VALUE="8"></TD>
<TD class="def" p="1.7.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.7.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.7.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.7.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.7.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.7.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.7.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.7.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.7.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.7.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.8.240" id=1_1>
<TD style="display:none" class="def" p="1.8.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.8.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.8.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.8.24.v_1_1_22 VALUE="9"></TD>
<TD style="display:none" class="def" p="1.8.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.8.24.v_1_1_1 VALUE="9"></TD>
<TD class="def" p="1.8.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.8.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.8.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.8.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.8.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.8.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.8.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.8.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.8.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.8.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.9.240" id=1_1>
<TD style="display:none" class="def" p="1.9.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.9.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.9.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.9.24.v_1_1_22 VALUE="10"></TD>
<TD style="display:none" class="def" p="1.9.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.9.24.v_1_1_1 VALUE="10"></TD>
<TD class="def" p="1.9.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.9.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.9.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.9.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.9.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.9.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.9.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.9.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.9.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.9.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.10.240" id=1_1>
<TD style="display:none" class="def" p="1.10.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.10.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.10.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.10.24.v_1_1_22 VALUE="11"></TD>
<TD style="display:none" class="def" p="1.10.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.10.24.v_1_1_1 VALUE="11"></TD>
<TD class="def" p="1.10.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.10.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.10.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.10.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.10.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.10.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.10.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.10.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.10.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.10.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.11.240" id=1_1>
<TD style="display:none" class="def" p="1.11.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.11.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.11.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.11.24.v_1_1_22 VALUE="12"></TD>
<TD style="display:none" class="def" p="1.11.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.11.24.v_1_1_1 VALUE="12"></TD>
<TD class="def" p="1.11.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.11.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.11.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.11.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.11.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.11.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.11.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.11.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.11.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.11.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.12.240" id=1_1>
<TD style="display:none" class="def" p="1.12.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.12.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.12.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.12.24.v_1_1_22 VALUE="13"></TD>
<TD style="display:none" class="def" p="1.12.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.12.24.v_1_1_1 VALUE="13"></TD>
<TD class="def" p="1.12.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.12.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.12.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.12.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.12.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.12.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.12.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.12.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.12.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.12.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.13.240" id=1_1>
<TD style="display:none" class="def" p="1.13.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.13.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.13.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.13.24.v_1_1_22 VALUE="14"></TD>
<TD style="display:none" class="def" p="1.13.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.13.24.v_1_1_1 VALUE="14"></TD>
<TD class="def" p="1.13.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.13.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.13.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.13.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.13.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.13.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.13.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.13.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.13.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.13.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.14.240" id=1_1>
<TD style="display:none" class="def" p="1.14.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.14.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.14.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.14.24.v_1_1_22 VALUE="15"></TD>
<TD style="display:none" class="def" p="1.14.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.14.24.v_1_1_1 VALUE="15"></TD>
<TD class="def" p="1.14.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.14.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.14.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.14.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.14.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.14.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.14.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.14.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.14.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.14.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.15.240" id=1_1>
<TD style="display:none" class="def" p="1.15.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.15.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.15.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.15.24.v_1_1_22 VALUE="16"></TD>
<TD style="display:none" class="def" p="1.15.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.15.24.v_1_1_1 VALUE="16"></TD>
<TD class="def" p="1.15.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.15.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.15.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.15.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.15.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.15.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.15.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.15.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.15.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.15.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.16.240" id=1_1>
<TD style="display:none" class="def" p="1.16.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.16.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.16.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.16.24.v_1_1_22 VALUE="17"></TD>
<TD style="display:none" class="def" p="1.16.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.16.24.v_1_1_1 VALUE="17"></TD>
<TD class="def" p="1.16.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.16.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.16.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.16.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.16.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.16.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.16.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.16.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.16.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.16.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.17.240" id=1_1>
<TD style="display:none" class="def" p="1.17.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.17.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.17.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.17.24.v_1_1_22 VALUE="18"></TD>
<TD style="display:none" class="def" p="1.17.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.17.24.v_1_1_1 VALUE="18"></TD>
<TD class="def" p="1.17.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.17.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.17.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.17.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.17.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.17.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.17.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.17.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.17.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.17.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.18.240" id=1_1>
<TD style="display:none" class="def" p="1.18.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.18.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.18.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.18.24.v_1_1_22 VALUE="19"></TD>
<TD style="display:none" class="def" p="1.18.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.18.24.v_1_1_1 VALUE="19"></TD>
<TD class="def" p="1.18.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.18.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.18.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.18.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.18.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.18.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.18.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.18.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.18.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.18.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.19.240" id=1_1>
<TD style="display:none" class="def" p="1.19.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.19.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.19.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.19.24.v_1_1_22 VALUE="20"></TD>
<TD style="display:none" class="def" p="1.19.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.19.24.v_1_1_1 VALUE="20"></TD>
<TD class="def" p="1.19.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.19.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.19.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.19.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.19.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.19.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.19.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.19.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.19.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.19.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.20.240" id=1_1>
<TD style="display:none" class="def" p="1.20.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.20.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.20.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.20.24.v_1_1_22 VALUE="21"></TD>
<TD style="display:none" class="def" p="1.20.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.20.24.v_1_1_1 VALUE="21"></TD>
<TD class="def" p="1.20.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.20.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.20.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.20.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.20.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.20.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.20.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.20.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.20.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.20.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.21.240" id=1_1>
<TD style="display:none" class="def" p="1.21.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.21.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.21.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.21.24.v_1_1_22 VALUE="22"></TD>
<TD style="display:none" class="def" p="1.21.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.21.24.v_1_1_1 VALUE="22"></TD>
<TD class="def" p="1.21.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.21.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.21.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.21.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.21.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.21.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.21.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.21.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.21.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.21.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.22.240" id=1_1>
<TD style="display:none" class="def" p="1.22.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.22.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.22.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.22.24.v_1_1_22 VALUE="23"></TD>
<TD style="display:none" class="def" p="1.22.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.22.24.v_1_1_1 VALUE="23"></TD>
<TD class="def" p="1.22.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.22.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.22.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.22.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.22.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.22.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.22.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.22.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.22.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.22.24.v_1_1_6 VALUE="1518"></TD>
</TR>
<TR p="1.23.240" id=1_1>
<TD style="display:none" class="def" p="1.23.240" id=1_1_21 ><INPUT xid=1_1_21 TYPE=hidden NAME=1.23.24.v_1_1_21 VALUE="1"></TD>
<TD class="def" p="1.23.240" id=1_1_22><INPUT xid=1_1_22 TYPE=hidden NAME=1.23.24.v_1_1_22 VALUE="24"></TD>
<TD style="display:none" class="def" p="1.23.240" id=1_1_1 ><INPUT xid=1_1_1 TYPE=hidden NAME=1.23.24.v_1_1_1 VALUE="24"></TD>
<TD class="def" p="1.23.240" id=1_1_2><INPUT xid=1_1_2 TYPE=hidden NAME=1.23.24.v_1_1_2 VALUE="RJ45"></TD>
<TD class="def" p="1.23.240" id=1_1_3><INPUT xid=1_1_3 TYPE=hidden NAME=1.23.24.v_1_1_3 VALUE="Link Down"></TD>
<TD class="def" p="1.23.240" id=1_1_4><INPUT xid=1_1_4 TYPE=hidden NAME=1.23.24.v_1_1_4 VALUE="Enable"></TD>
<TD class="def" p="1.23.240" id=1_1_5><INPUT xid=1_1_5 TYPE=hidden NAME=1.23.24.v_1_1_5 VALUE=" "></TD>
<TD class="def" p="1.23.240" id=1_1_6><INPUT xid=1_1_6 TYPE=hidden NAME=1.23.24.v_1_1_6 VALUE="1518"></TD>
</TR>
</TABLE></DIV><br>
<DIV id=summary NORENDER DIV_XID = 2_3><TABLE ID=2_3><CAPTION>Port Statistics</CAPTION>
<TH id=2_3_1>Interface</TH>
<TH id=2_3_6 style="display:none">ifIndex</TH>
<TH id=2_3_13 style="display:none">ifIndex</TH>
<TH id=2_3_2>Received Packets <BR>w/o Error</TH>
<TH id=2_3_3>Received Packets <BR>with Error</TH>
<TH id=2_3_7>Broadcast<BR>Received Packets</TH>
<TH id=2_3_8>Transmitted Packets <BR>w/o Errors</TH>
<TH id=2_3_9>Transmitted Packets <BR>with Errors</TH>
<TH id=2_3_10>Collisions</TH>
<TH id=2_3_11>Transmitted <BR>Pause Frames</TH>
<TH id=2_3_12>Received <BR>Pause Frames</TH>
<tr><td CLASS="tabledata0">1</td><td CLASS="tabledata0" style="display: none;">1</td><td CLASS="tabledata0" style="display: none;">1</td><td CLASS="tabledata0">11338</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">79</td><td CLASS="tabledata0">11918</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">2</td><td CLASS="tabledata1" style="display: none;">2</td><td CLASS="tabledata1" style="display: none;">2</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">3</td><td CLASS="tabledata0" style="display: none;">3</td><td CLASS="tabledata0" style="display: none;">3</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">4</td><td CLASS="tabledata1" style="display: none;">4</td><td CLASS="tabledata1" style="display: none;">4</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">5</td><td CLASS="tabledata0" style="display: none;">5</td><td CLASS="tabledata0" style="display: none;">5</td><td CLASS="tabledata0">4832</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">27</td><td CLASS="tabledata0">5390</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">6</td><td CLASS="tabledata1" style="display: none;">6</td><td CLASS="tabledata1" style="display: none;">6</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">7</td><td CLASS="tabledata0" style="display: none;">7</td><td CLASS="tabledata0" style="display: none;">7</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">8</td><td CLASS="tabledata1" style="display: none;">8</td><td CLASS="tabledata1" style="display: none;">8</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">9</td><td CLASS="tabledata0" style="display: none;">9</td><td CLASS="tabledata0" style="display: none;">9</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">10</td><td CLASS="tabledata1" style="display: none;">10</td><td CLASS="tabledata1" style="display: none;">10</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">11</td><td CLASS="tabledata0" style="display: none;">11</td><td CLASS="tabledata0" style="display: none;">11</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">12</td><td CLASS="tabledata1" style="display: none;">12</td><td CLASS="tabledata1" style="display: none;">12</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">13</td><td CLASS="tabledata0" style="display: none;">13</td><td CLASS="tabledata0" style="display: none;">13</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">14</td><td CLASS="tabledata1" style="display: none;">14</td><td CLASS="tabledata1" style="display: none;">14</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">15</td><td CLASS="tabledata0" style="display: none;">15</td><td CLASS="tabledata0" style="display: none;">15</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">16</td><td CLASS="tabledata1" style="display: none;">16</td><td CLASS="tabledata1" style="display: none;">16</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">17</td><td CLASS="tabledata0" style="display: none;">17</td><td CLASS="tabledata0" style="display: none;">17</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">18</td><td CLASS="tabledata1" style="display: none;">18</td><td CLASS="tabledata1" style="display: none;">18</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">19</td><td CLASS="tabledata0" style="display: none;">19</td><td CLASS="tabledata0" style="display: none;">19</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">20</td><td CLASS="tabledata1" style="display: none;">20</td><td CLASS="tabledata1" style="display: none;">20</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">21</td><td CLASS="tabledata0" style="display: none;">21</td><td CLASS="tabledata0" style="display: none;">21</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">22</td><td CLASS="tabledata1" style="display: none;">22</td><td CLASS="tabledata1" style="display: none;">22</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
<tr><td CLASS="tabledata0">23</td><td CLASS="tabledata0" style="display: none;">23</td><td CLASS="tabledata0" style="display: none;">23</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td><td CLASS="tabledata0">0</td></tr>
<tr><td CLASS="tabledata1">24</td><td CLASS="tabledata1" style="display: none;">24</td><td CLASS="tabledata1" style="display: none;">24</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td><td CLASS="tabledata1">0</td></tr>
</TABLE></DIV><br>
<DIV id=summary NORENDER DIV_XID = 4_3><TABLE ID=4_3><CAPTION>Trunk Statistics</CAPTION>
<TH id=4_3_1>Trunk</TH>
<TH id=4_3_6 style="display:none">ifIndex</TH>
<TH id=4_3_11 style="display:none">ifIndex</TH>
<TH id=4_3_2>Received Packets <BR>w/o Error</TH>
<TH id=4_3_3>Received Packets <BR>with Error</TH>
<TH id=4_3_7>Broadcast<BR>Received Packets</TH>
<TH id=4_3_8>Transmitted Packets <BR>w/o Errors</TH>
<TH id=4_3_9>Transmitted Packets <BR>with Errors</TH>
<TH id=4_3_10>Collisions</TH>
</TABLE></DIV><br>
<DIV id=buttons DIV_XID = 3><TABLE ID=3><CAPTION> </CAPTION>
<TD id=3_1_2 style="display:none" ><INPUT xid=3_1_2 TYPE=hidden NAME=v_3_1_2 VALUE="TRUE"></TD>
</TABLE></DIV><br>
<script type="text/javascript" >
allWebEnums.e_v_1_1_21_values = [ "1" ];
allWebEnums.e_v_1_1_21_eactions = [];
allWebEnums.e_v_1_1_21 = xuiInsertEActionStrings("1_1_21" , allWebEnums.e_v_1_1_21_values,allWebEnums.e_v_1_1_21_eactions);
allWebEnums.e_v_1_1_22_values = [ "1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24" ];
allWebEnums.e_v_1_1_22_eactions = [];
allWebEnums.e_v_1_1_22 = xuiInsertEActionStrings("1_1_22" , allWebEnums.e_v_1_1_22_values,allWebEnums.e_v_1_1_22_eactions);
allWebEnums.e_v_1_1_1_values = [ "1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24" ];
allWebEnums.e_v_1_1_1_eactions = [];
allWebEnums.e_v_1_1_1 = xuiInsertEActionStrings("1_1_1" , allWebEnums.e_v_1_1_1_values,allWebEnums.e_v_1_1_1_eactions);
</script>
<!-- redirection elements -->
<INPUT TYPE="hidden" NAME="submit_flag" XC=hidden VALUE="0">
<INPUT TYPE="hidden" NAME="submit_target" XC=hidden VALUE="PortSummary.html">
<INPUT TYPE="hidden" NAME="err_flag" XC=hidden SIZE="16" MAXLENGTH="15" VALUE="0">
<INPUT TYPE="hidden" NAME="err_msg" XC=hidden SIZE="80" MAXLENGTH="79" VALUE="">
<INPUT TYPE="hidden" NAME="clazz_information" XC=hidden VALUE="PortSummary.html">
<center>
<DIV ID="buttons" style="visibility:visible;">
<TABLE><TR align=center>
<TD id=3_1_1><INPUT xid=3_1_1 DISABLED TYPE=hidden NAME=v_3_1_1 VALUE="Clear"></TD>
</TR></TABLE>
</DIV>
</center>
</DIV>
</FORM>
</BODY>
</HTML>
@@ -0,0 +1,118 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- (C) Copyright Broadcom Corporation 2000-2020 : This file is auto-generated by XE - DON'T EDIT -->
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE>
HP ProCurve
</TITLE>
<link href="/50021801/css/style1.css" rel="stylesheet" type="text/css" id="fastpath">
<script type="text/javascript" src="/50021801/scripts/xui_common.js"></script>
<script type="text/javascript" src="/50021801/scripts/globalStyleJS.js"></script>
<script type="text/javascript" src="/50021801/scripts/globalStyleJS.js"></script>
<script type="text/javascript" >
xuiIncludeCommonJSFiles("/50021801/scripts/");
xuiIncludeJSFile("/50021801/scripts/_xe_SysDescription.js");
</script>
</HEAD>
<BODY onload="formLoad();" CLASS=page>
<FORM method=post ACTION="/SysDescription.html">
<DIV ID="topdiv">
<script type="text/javascript" >
xeValData.xv_1_2_1_260 = "Error! Invalid String:Unable to set '$$objName$$' with '$$objValue$$'.";
xeValData.xv_1_2_1_340 = "Error! Invalid String:Unable to set '$$objName$$' with '$$objValue$$'. Enter string with alphanumeric characters, hyphens and commas.";
xeValData.xv_1_3_1_260 = "Error! Invalid String:Unable to set '$$objName$$' with '$$objValue$$'.";
xeValData.xv_1_3_1_340 = "Error! Invalid String:Unable to set '$$objName$$' with '$$objValue$$'. Enter string with alphanumeric characters, hyphens and commas.";
xeValData.xv_1_4_1_260 = "Error! Invalid String:Unable to set '$$objName$$' with '$$objValue$$'.";
xeValData.xv_1_4_1_340 = "Error! Invalid String:Unable to set '$$objName$$' with '$$objValue$$'. Enter string with alphanumeric characters, hyphens and commas.";
</script>
<script type="text/javascript" >
xeData.arghelp_1_11_1 = "( hh:mm:ss )";
</script>
<DIV id=scalar DIV_XID = 1><TABLE ID=1><CAPTION>System Description </CAPTION>
<TR id=1_1 class=def>
<TD class=defleft id=1_1_1>System Description</TD>
<TD class=defright id=1_1_1><INPUT xid=1_1_1 TYPE=hidden NAME=v_1_1_1 VALUE=" HP ProCurve 1810G - 24 GE, P.2.24, eCos-2.0, CFE-2.1"></TD>
</TR>
<TR id=1_2 class=def>
<TD class=defleft id=1_2_1>System Name</TD>
<TD class=defright id=1_2_1><INPUT xid=1_2_1 TYPE=hidden NAME=v_1_2_1 VALUE="Draupnir01"></TD>
</TR>
<TR id=1_3 class=def>
<TD class=defleft id=1_3_1>System Location</TD>
<TD class=defright id=1_3_1><INPUT xid=1_3_1 TYPE=hidden NAME=v_1_3_1 VALUE="Lab"></TD>
</TR>
<TR id=1_4 class=def>
<TD class=defleft id=1_4_1>System Contact</TD>
<TD class=defright id=1_4_1><INPUT xid=1_4_1 TYPE=hidden NAME=v_1_4_1 VALUE=""></TD>
</TR>
<TR id=1_8 class=def>
<TD class=defleft id=1_8_1>Software Version</TD>
<TD class=defright id=1_8_1><INPUT xid=1_8_1 TYPE=hidden NAME=v_1_8_1 VALUE="P.2.24"></TD>
</TR>
<TR id=1_9 class=def>
<TD class=defleft id=1_9_1>System Object ID</TD>
<TD class=defright id=1_9_1><INPUT xid=1_9_1 TYPE=hidden NAME=v_1_9_1 VALUE="1.3.6.1.4.1.11.2.3.7.11.104"></TD>
</TR>
<TR id=1_10 class=def>
<TD class=defleft id=1_10_1>System Up Time</TD>
<TD class=defright id=1_10_1><INPUT xid=1_10_1 TYPE=hidden NAME=v_1_10_1 VALUE="0 days, 3 hours, 56 mins, 19 secs"></TD>
</TR>
<TR id=1_11 class=def>
<TD class=defleft id=1_11_1>Current Time</TD>
<TD class=defright id=1_11_1><INPUT xid=1_11_1 TYPE=hidden NAME=v_1_11_1 VALUE="04:56:19"></TD>
</TR>
<TR id=1_12 class=def>
<TD class=defleft id=1_12_1>Date</TD>
<TD class=defright id=1_12_1><INPUT xid=1_12_1 TYPE=hidden NAME=v_1_12_1 VALUE="01/01/1970"></TD>
</TR>
</TABLE></DIV><br>
<DIV id=buttons DIV_XID = 2><TABLE ID=2><CAPTION> </CAPTION>
</TABLE></DIV><br>
<script type="text/javascript" >
</script>
<!-- redirection elements -->
<INPUT TYPE="hidden" NAME="submit_flag" XC=hidden VALUE="0">
<INPUT TYPE="hidden" NAME="submit_target" XC=hidden VALUE="SysDescription.html">
<INPUT TYPE="hidden" NAME="err_flag" XC=hidden SIZE="16" MAXLENGTH="15" VALUE="0">
<INPUT TYPE="hidden" NAME="err_msg" XC=hidden SIZE="80" MAXLENGTH="79" VALUE="">
<INPUT TYPE="hidden" NAME="clazz_information" XC=hidden VALUE="SysDescription.html">
<center>
<DIV ID="buttons" style="visibility:visible;">
<TABLE><TR align=center>
<TD id=2_1_1><INPUT xid=2_1_1 DISABLED TYPE=hidden NAME=v_2_1_1 VALUE="Apply"></TD>
</TR></TABLE>
</DIV>
</center>
</DIV>
</FORM>
</BODY>
</HTML>
@@ -0,0 +1,137 @@
// Port of ~/code/experiments/hpe/extractors/xe_page.py -- see that file's
// docstring for the two table shapes this parses.
//
// Note on traversal: the switch firmware's HTML puts <TH>/<TR> as direct
// children of <TABLE> with no <TBODY> wrapper. A strict browser-grade HTML5
// parser (which golang.org/x/net/html, underlying goquery, implements) would
// normally insert a synthetic <TBODY> around those rows, which would break a
// "direct children only" traversal the way the Python version does (Python's
// html.parser is lenient and doesn't insert one). We sidestep this by using
// Find() (any descendant) instead of direct-children selectors -- safe here
// because tables in this firmware are never nested inside one another.
package client
import (
"strings"
"github.com/PuerkitoBio/goquery"
)
type Table struct {
Caption string
Kind string // "scalar" | "tabular"
Record map[string]string
FieldNames map[string]string
Rows []map[string]string
ID string
}
func extractCellValue(td *goquery.Selection) string {
if inp := td.Find("input").First(); inp.Length() > 0 {
if v, exists := inp.Attr("value"); exists {
return v
}
return ""
}
return strings.TrimSpace(td.Text())
}
func parseTable(table *goquery.Selection) Table {
id, _ := table.Attr("id")
caption := strings.TrimSpace(table.Find("caption").First().Text())
var headers []string
table.Find("th").Each(func(_ int, th *goquery.Selection) {
headers = append(headers, strings.TrimSpace(th.Text()))
})
if len(headers) > 0 {
var rows []map[string]string
table.Find("tr").Each(func(_ int, tr *goquery.Selection) {
tds := tr.Find("td")
if tds.Length() != len(headers) {
return
}
row := make(map[string]string, len(headers))
tds.Each(func(i int, td *goquery.Selection) {
// Later (visible) column wins on a duplicate header label --
// see the same caveat noted in extractors/xe_page.py.
row[headers[i]] = extractCellValue(td)
})
rows = append(rows, row)
})
return Table{Caption: caption, Kind: "tabular", Rows: rows, ID: id}
}
record := make(map[string]string)
fieldNames := make(map[string]string)
table.Find("tr").Each(func(_ int, tr *goquery.Selection) {
defleft := tr.Find("td.defleft").First()
defright := tr.Find("td.defright").First()
if defleft.Length() == 0 || defright.Length() == 0 {
return
}
label := strings.TrimSpace(defleft.Text())
if label == "" {
return
}
record[label] = extractCellValue(defright)
if inp := defright.Find("input").First(); inp.Length() > 0 {
if name, exists := inp.Attr("name"); exists && name != "" {
fieldNames[label] = name
}
}
})
return Table{
Caption: caption,
Kind: "scalar",
Record: record,
FieldNames: fieldNames,
ID: id,
}
}
// ParseXETables parses every <TABLE> in html, in document order.
func ParseXETables(html string) ([]Table, error) {
doc, err := goquery.NewDocumentFromReader(strings.NewReader(html))
if err != nil {
return nil, err
}
var tables []Table
doc.Find("table").Each(func(_ int, table *goquery.Selection) {
tables = append(tables, parseTable(table))
})
return tables, nil
}
// FetchTables fetches path and returns {caption: table} for every captioned
// table. Tables with no/blank caption are dropped -- use FetchAllTables +
// Table.ID for those (e.g. the MAC Table entries table on FDBSearch.html).
func (c *Client) FetchTables(path string) (map[string]Table, error) {
html, err := c.Fetch(path)
if err != nil {
return nil, err
}
tables, err := ParseXETables(html)
if err != nil {
return nil, err
}
result := make(map[string]Table, len(tables))
for _, t := range tables {
if t.Caption != "" {
result[t.Caption] = t
}
}
return result, nil
}
// FetchAllTables fetches path and returns every table, including
// uncaptioned ones, in document order.
func (c *Client) FetchAllTables(path string) ([]Table, error) {
html, err := c.Fetch(path)
if err != nil {
return nil, err
}
return ParseXETables(html)
}
@@ -0,0 +1,130 @@
package client
import (
"os"
"testing"
)
func loadFixture(t *testing.T, name string) string {
t.Helper()
data, err := os.ReadFile("testdata/" + name)
if err != nil {
t.Fatalf("reading fixture %s: %v", name, err)
}
return string(data)
}
// Expected values below were captured live from the real switch (see
// ~/code/experiments/hpe/page_snapshots/current_state.json) at the time
// these fixtures were saved -- this test is about the parser's correctness,
// not about the switch's current state.
func TestParseXETables_ScalarShape_SysDescription(t *testing.T) {
tables, err := ParseXETables(loadFixture(t, "SysDescription.html"))
if err != nil {
t.Fatalf("ParseXETables: %v", err)
}
var sysDesc *Table
for i := range tables {
if tables[i].Caption == "System Description" {
sysDesc = &tables[i]
}
}
if sysDesc == nil {
t.Fatalf("no table captioned %q found; got captions: %v", "System Description", captions(tables))
}
if sysDesc.Kind != "scalar" {
t.Errorf("Kind = %q, want %q", sysDesc.Kind, "scalar")
}
want := map[string]string{
"System Name": "Draupnir01",
"System Location": "Lab",
"Software Version": "P.2.24",
}
for label, wantValue := range want {
if got := sysDesc.Record[label]; got != wantValue {
t.Errorf("Record[%q] = %q, want %q", label, got, wantValue)
}
}
if fieldName := sysDesc.FieldNames["System Name"]; fieldName != "v_1_2_1" {
t.Errorf("FieldNames[%q] = %q, want %q", "System Name", fieldName, "v_1_2_1")
}
}
func TestParseXETables_TabularShape_PortSummary(t *testing.T) {
tables, err := ParseXETables(loadFixture(t, "PortSummary.html"))
if err != nil {
t.Fatalf("ParseXETables: %v", err)
}
var portSummary *Table
for i := range tables {
if tables[i].Caption == "Port Summary" {
portSummary = &tables[i]
}
}
if portSummary == nil {
t.Fatalf("no table captioned %q found; got captions: %v", "Port Summary", captions(tables))
}
if portSummary.Kind != "tabular" {
t.Errorf("Kind = %q, want %q", portSummary.Kind, "tabular")
}
if len(portSummary.Rows) != 24 {
t.Fatalf("len(Rows) = %d, want 24", len(portSummary.Rows))
}
first := portSummary.Rows[0]
if first["Interface"] != "1" {
t.Errorf(`Rows[0]["Interface"] = %q, want "1"`, first["Interface"])
}
if first["Physical Type"] != "RJ45" {
t.Errorf(`Rows[0]["Physical Type"] = %q, want "RJ45"`, first["Physical Type"])
}
}
func TestFetchAllTables_BlankCaptionTable_FDBSearch(t *testing.T) {
tables, err := ParseXETables(loadFixture(t, "FDBSearch.html"))
if err != nil {
t.Fatalf("ParseXETables: %v", err)
}
var summary, entries *Table
for i := range tables {
if tables[i].Caption == "MAC Table" {
summary = &tables[i]
}
if tables[i].ID == "1_1" {
entries = &tables[i]
}
}
if summary == nil {
t.Fatalf("no table captioned %q found; got captions: %v", "MAC Table", captions(tables))
}
if summary.Record["Current Entries"] != "2" {
t.Errorf(`summary.Record["Current Entries"] = %q, want "2"`, summary.Record["Current Entries"])
}
if entries == nil {
t.Fatalf("no table with id %q found", "1_1")
}
if entries.Kind != "tabular" {
t.Errorf("entries.Kind = %q, want %q", entries.Kind, "tabular")
}
if len(entries.Rows) != 2 {
t.Fatalf("len(entries.Rows) = %d, want 2", len(entries.Rows))
}
if entries.Rows[0]["MAC Address"] != "4C:EA:41:63:04:1B" {
t.Errorf(`entries.Rows[0]["MAC Address"] = %q, want "4C:EA:41:63:04:1B"`, entries.Rows[0]["MAC Address"])
}
}
func captions(tables []Table) []string {
out := make([]string, len(tables))
for i, t := range tables {
out[i] = t.Caption
}
return out
}
@@ -0,0 +1,24 @@
// Shared helpers for turning client.Table pieces (plain Go maps/slices) into
// the typed map/list values the Plugin Framework wants in state.
package provider
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
)
var rowType = types.MapType{ElemType: types.StringType}
func stringMapToTF(ctx context.Context, m map[string]string) (types.Map, diag.Diagnostics) {
return types.MapValueFrom(ctx, types.StringType, m)
}
func rowsToTF(ctx context.Context, rows []map[string]string) (types.List, diag.Diagnostics) {
return types.ListValueFrom(ctx, rowType, rows)
}
func tableOfRecordsToTF(ctx context.Context, tables map[string]map[string]string) (types.Map, diag.Diagnostics) {
return types.MapValueFrom(ctx, types.MapType{ElemType: types.StringType}, tables)
}
@@ -0,0 +1,82 @@
// Port of ~/code/experiments/hpe/extractors/backup_manager.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const backupManagerPath = "/UploadFile.html"
var (
_ datasource.DataSource = &backupManagerDataSource{}
_ datasource.DataSourceWithConfigure = &backupManagerDataSource{}
)
func NewBackupManagerDataSource() datasource.DataSource {
return &backupManagerDataSource{}
}
type backupManagerDataSource struct {
client *client.Client
}
type backupManagerModel struct {
Values types.Map `tfsdk:"values"`
}
func (d *backupManagerDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_backup_manager"
}
func (d *backupManagerDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's Backup/Upload File page's current form fields (method, server address, etc.). This is a config form, not a data table, so values reflect whatever was last configured or left blank.",
Attributes: map[string]schema.Attribute{
"values": schema.MapAttribute{
Computed: true,
ElementType: types.StringType,
},
},
}
}
func (d *backupManagerDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *backupManagerDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(backupManagerPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch Backup page", err.Error())
return
}
table, ok := tables["Backup"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "Backup" not found`)
return
}
valuesValue, diags := stringMapToTF(ctx, table.Record)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := backupManagerModel{Values: valuesValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,82 @@
// Port of ~/code/experiments/hpe/extractors/buffered_log.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const bufferedLogPath = "/BufferedLogs.html"
var (
_ datasource.DataSource = &bufferedLogDataSource{}
_ datasource.DataSourceWithConfigure = &bufferedLogDataSource{}
)
func NewBufferedLogDataSource() datasource.DataSource {
return &bufferedLogDataSource{}
}
type bufferedLogDataSource struct {
client *client.Client
}
type bufferedLogModel struct {
Entries types.List `tfsdk:"entries"`
}
func (d *bufferedLogDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_buffered_log"
}
func (d *bufferedLogDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's Buffered Log page: one entry per log message (Log Index, Severity, Log Time, Component, Description, Message Text).",
Attributes: map[string]schema.Attribute{
"entries": schema.ListAttribute{
Computed: true,
ElementType: types.MapType{ElemType: types.StringType},
},
},
}
}
func (d *bufferedLogDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *bufferedLogDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(bufferedLogPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch Buffered Log page", err.Error())
return
}
table, ok := tables["Log Message"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "Log Message" not found`)
return
}
entriesValue, diags := rowsToTF(ctx, table.Rows)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := bufferedLogModel{Entries: entriesValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,82 @@
// Port of ~/code/experiments/hpe/extractors/clock.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const clockPath = "/Clock_Detail.html"
var (
_ datasource.DataSource = &clockDataSource{}
_ datasource.DataSourceWithConfigure = &clockDataSource{}
)
func NewClockDataSource() datasource.DataSource {
return &clockDataSource{}
}
type clockDataSource struct {
client *client.Client
}
type clockModel struct {
Tables types.Map `tfsdk:"tables"`
}
func (d *clockDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_clock"
}
func (d *clockDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's Clock Detail page: Current Time, Time Zone and Daylight Saving Time, keyed by table caption.",
Attributes: map[string]schema.Attribute{
"tables": schema.MapAttribute{
Computed: true,
ElementType: types.MapType{ElemType: types.StringType},
},
},
}
}
func (d *clockDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *clockDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(clockPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch Clock Detail page", err.Error())
return
}
records := make(map[string]map[string]string, len(tables))
for caption, table := range tables {
records[caption] = table.Record
}
tablesValue, diags := tableOfRecordsToTF(ctx, records)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := clockModel{Tables: tablesValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,82 @@
// Port of ~/code/experiments/hpe/extractors/dual_image_status.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const dualImageStatusPath = "/dual_image_status.html"
var (
_ datasource.DataSource = &dualImageStatusDataSource{}
_ datasource.DataSourceWithConfigure = &dualImageStatusDataSource{}
)
func NewDualImageStatusDataSource() datasource.DataSource {
return &dualImageStatusDataSource{}
}
type dualImageStatusDataSource struct {
client *client.Client
}
type dualImageStatusModel struct {
Units types.List `tfsdk:"units"`
}
func (d *dualImageStatusDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_dual_image_status"
}
func (d *dualImageStatusDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's Dual Image Status page: one entry per unit (Active image, Next-Active image). The page's separate \"Dual Image Descriptions\" table uses a header shape the generic parser doesn't handle and is skipped, matching the Python reference implementation.",
Attributes: map[string]schema.Attribute{
"units": schema.ListAttribute{
Computed: true,
ElementType: types.MapType{ElemType: types.StringType},
},
},
}
}
func (d *dualImageStatusDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *dualImageStatusDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(dualImageStatusPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch Dual Image Status page", err.Error())
return
}
table, ok := tables["Dual Image Status"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "Dual Image Status" not found`)
return
}
unitsValue, diags := rowsToTF(ctx, table.Rows)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := dualImageStatusModel{Units: unitsValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,94 @@
// Port of ~/code/experiments/hpe/extractors/lldp_statistics.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const lldpStatisticsPath = "/LLDPStats.html"
var (
_ datasource.DataSource = &lldpStatisticsDataSource{}
_ datasource.DataSourceWithConfigure = &lldpStatisticsDataSource{}
)
func NewLLDPStatisticsDataSource() datasource.DataSource {
return &lldpStatisticsDataSource{}
}
type lldpStatisticsDataSource struct {
client *client.Client
}
type lldpStatisticsModel struct {
Global types.Map `tfsdk:"global"`
Interfaces types.List `tfsdk:"interfaces"`
}
func (d *lldpStatisticsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_lldp_statistics"
}
func (d *lldpStatisticsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's LLDP Statistics page: global counters plus one entry per interface.",
Attributes: map[string]schema.Attribute{
"global": schema.MapAttribute{
Computed: true,
ElementType: types.StringType,
},
"interfaces": schema.ListAttribute{
Computed: true,
ElementType: types.MapType{ElemType: types.StringType},
},
},
}
}
func (d *lldpStatisticsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *lldpStatisticsDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(lldpStatisticsPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch LLDP Statistics page", err.Error())
return
}
global, ok := tables["LLDP Global Statistics"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "LLDP Global Statistics" not found`)
return
}
interfaces, ok := tables["LLDP Interface Statistics"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "LLDP Interface Statistics" not found`)
return
}
globalValue, diags := stringMapToTF(ctx, global.Record)
resp.Diagnostics.Append(diags...)
interfacesValue, diags := rowsToTF(ctx, interfaces.Rows)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := lldpStatisticsModel{Global: globalValue, Interfaces: interfacesValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,82 @@
// Port of ~/code/experiments/hpe/extractors/log_configuration.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const logConfigurationPath = "/Logging.html"
var (
_ datasource.DataSource = &logConfigurationDataSource{}
_ datasource.DataSourceWithConfigure = &logConfigurationDataSource{}
)
func NewLogConfigurationDataSource() datasource.DataSource {
return &logConfigurationDataSource{}
}
type logConfigurationDataSource struct {
client *client.Client
}
type logConfigurationModel struct {
Values types.Map `tfsdk:"values"`
}
func (d *logConfigurationDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_log_configuration"
}
func (d *logConfigurationDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's Logging Configuration page.",
Attributes: map[string]schema.Attribute{
"values": schema.MapAttribute{
Computed: true,
ElementType: types.StringType,
},
},
}
}
func (d *logConfigurationDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *logConfigurationDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(logConfigurationPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch Logging page", err.Error())
return
}
table, ok := tables["Logging"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "Logging" not found`)
return
}
valuesValue, diags := stringMapToTF(ctx, table.Record)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := logConfigurationModel{Values: valuesValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,82 @@
// Port of ~/code/experiments/hpe/extractors/loop_protection_status.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const loopProtectionStatusPath = "/LoopProtectionStatus.html"
var (
_ datasource.DataSource = &loopProtectionStatusDataSource{}
_ datasource.DataSourceWithConfigure = &loopProtectionStatusDataSource{}
)
func NewLoopProtectionStatusDataSource() datasource.DataSource {
return &loopProtectionStatusDataSource{}
}
type loopProtectionStatusDataSource struct {
client *client.Client
}
type loopProtectionStatusModel struct {
Ports types.List `tfsdk:"ports"`
}
func (d *loopProtectionStatusDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_loop_protection_status"
}
func (d *loopProtectionStatusDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's Loop Protection Status page: one entry per port (Interface, Configured Action Taken, Protection Feature Mode, Tx Mode, counters, Loop Detected).",
Attributes: map[string]schema.Attribute{
"ports": schema.ListAttribute{
Computed: true,
ElementType: types.MapType{ElemType: types.StringType},
},
},
}
}
func (d *loopProtectionStatusDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *loopProtectionStatusDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(loopProtectionStatusPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch Loop Protection Status page", err.Error())
return
}
table, ok := tables["Loop Protection Status"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "Loop Protection Status" not found`)
return
}
portsValue, diags := rowsToTF(ctx, table.Rows)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := loopProtectionStatusModel{Ports: portsValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,103 @@
// Port of ~/code/experiments/hpe/extractors/mac_table.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const macTablePath = "/FDBSearch.html"
var (
_ datasource.DataSource = &macTableDataSource{}
_ datasource.DataSourceWithConfigure = &macTableDataSource{}
)
func NewMACTableDataSource() datasource.DataSource {
return &macTableDataSource{}
}
type macTableDataSource struct {
client *client.Client
}
type macTableModel struct {
Summary types.Map `tfsdk:"summary"`
Entries types.List `tfsdk:"entries"`
}
func (d *macTableDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_mac_table"
}
func (d *macTableDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's MAC Address Table (FDB Search) page: summary counters plus one entry per learned MAC. The per-entry table has a blank <CAPTION>, so it's looked up by table id (\"1_1\") instead of caption.",
Attributes: map[string]schema.Attribute{
"summary": schema.MapAttribute{
Computed: true,
ElementType: types.StringType,
},
"entries": schema.ListAttribute{
Computed: true,
ElementType: types.MapType{ElemType: types.StringType},
},
},
}
}
func (d *macTableDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *macTableDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchAllTables(macTablePath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch MAC Table page", err.Error())
return
}
var summary map[string]string
var entries []map[string]string
for _, t := range tables {
if t.Caption == "MAC Table" {
summary = t.Record
}
if t.ID == "1_1" {
entries = t.Rows
}
}
if summary == nil {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "MAC Table" not found`)
return
}
if entries == nil {
resp.Diagnostics.AddError("Unexpected page layout", `table with id "1_1" not found`)
return
}
summaryValue, diags := stringMapToTF(ctx, summary)
resp.Diagnostics.Append(diags...)
entriesValue, diags := rowsToTF(ctx, entries)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := macTableModel{Summary: summaryValue, Entries: entriesValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,82 @@
// Port of ~/code/experiments/hpe/extractors/network_setup.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const networkSetupPath = "/Network.html"
var (
_ datasource.DataSource = &networkSetupDataSource{}
_ datasource.DataSourceWithConfigure = &networkSetupDataSource{}
)
func NewNetworkSetupDataSource() datasource.DataSource {
return &networkSetupDataSource{}
}
type networkSetupDataSource struct {
client *client.Client
}
type networkSetupModel struct {
Tables types.Map `tfsdk:"tables"`
}
func (d *networkSetupDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_network_setup"
}
func (d *networkSetupDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's Network Setup page: Network Details, Web Parameters, Management Access and SNMP, keyed by table caption.",
Attributes: map[string]schema.Attribute{
"tables": schema.MapAttribute{
Computed: true,
ElementType: types.MapType{ElemType: types.StringType},
},
},
}
}
func (d *networkSetupDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *networkSetupDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(networkSetupPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch Network Setup page", err.Error())
return
}
records := make(map[string]map[string]string, len(tables))
for caption, table := range tables {
records[caption] = table.Record
}
tablesValue, diags := tableOfRecordsToTF(ctx, records)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := networkSetupModel{Tables: tablesValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,82 @@
// Port of ~/code/experiments/hpe/extractors/port_summary.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const portSummaryPath = "/PortSummary.html"
var (
_ datasource.DataSource = &portSummaryDataSource{}
_ datasource.DataSourceWithConfigure = &portSummaryDataSource{}
)
func NewPortSummaryDataSource() datasource.DataSource {
return &portSummaryDataSource{}
}
type portSummaryDataSource struct {
client *client.Client
}
type portSummaryModel struct {
Ports types.List `tfsdk:"ports"`
}
func (d *portSummaryDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_port_summary"
}
func (d *portSummaryDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's Port Summary page: one entry per port (Interface, Physical Type, Port Status, AutoNeg Status, Link Speed, MTU).",
Attributes: map[string]schema.Attribute{
"ports": schema.ListAttribute{
Computed: true,
ElementType: types.MapType{ElemType: types.StringType},
},
},
}
}
func (d *portSummaryDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *portSummaryDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(portSummaryPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch Port Summary page", err.Error())
return
}
table, ok := tables["Port Summary"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "Port Summary" not found`)
return
}
portsValue, diags := rowsToTF(ctx, table.Rows)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := portSummaryModel{Ports: portsValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,82 @@
// Port of ~/code/experiments/hpe/extractors/sntp.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const sntpPath = "/SNTP.html"
var (
_ datasource.DataSource = &sntpDataSource{}
_ datasource.DataSourceWithConfigure = &sntpDataSource{}
)
func NewSNTPDataSource() datasource.DataSource {
return &sntpDataSource{}
}
type sntpDataSource struct {
client *client.Client
}
type sntpModel struct {
Values types.Map `tfsdk:"values"`
}
func (d *sntpDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_sntp"
}
func (d *sntpDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's SNTP Configuration page.",
Attributes: map[string]schema.Attribute{
"values": schema.MapAttribute{
Computed: true,
ElementType: types.StringType,
},
},
}
}
func (d *sntpDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *sntpDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(sntpPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch SNTP page", err.Error())
return
}
table, ok := tables["SNTP Configuration"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "SNTP Configuration" not found`)
return
}
valuesValue, diags := stringMapToTF(ctx, table.Record)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := sntpModel{Values: valuesValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,101 @@
// Port of ~/code/experiments/hpe/extractors/system_description.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const systemDescriptionPath = "/SysDescription.html"
var (
_ datasource.DataSource = &systemDescriptionDataSource{}
_ datasource.DataSourceWithConfigure = &systemDescriptionDataSource{}
)
func NewSystemDescriptionDataSource() datasource.DataSource {
return &systemDescriptionDataSource{}
}
type systemDescriptionDataSource struct {
client *client.Client
}
type systemDescriptionModel struct {
Description types.String `tfsdk:"description"`
Name types.String `tfsdk:"name"`
Location types.String `tfsdk:"location"`
Contact types.String `tfsdk:"contact"`
SoftwareVersion types.String `tfsdk:"software_version"`
ObjectID types.String `tfsdk:"object_id"`
UpTime types.String `tfsdk:"up_time"`
CurrentTime types.String `tfsdk:"current_time"`
Date types.String `tfsdk:"date"`
}
func (d *systemDescriptionDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_system_description"
}
func (d *systemDescriptionDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's System Description page (name, location, contact, uptime, ...).",
Attributes: map[string]schema.Attribute{
"description": schema.StringAttribute{Computed: true},
"name": schema.StringAttribute{Computed: true},
"location": schema.StringAttribute{Computed: true},
"contact": schema.StringAttribute{Computed: true},
"software_version": schema.StringAttribute{Computed: true},
"object_id": schema.StringAttribute{Computed: true},
"up_time": schema.StringAttribute{Computed: true},
"current_time": schema.StringAttribute{Computed: true},
"date": schema.StringAttribute{Computed: true},
},
}
}
func (d *systemDescriptionDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *systemDescriptionDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(systemDescriptionPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch System Description page", err.Error())
return
}
table, ok := tables["System Description"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "System Description" not found`)
return
}
record := table.Record
state := systemDescriptionModel{
Description: types.StringValue(record["System Description"]),
Name: types.StringValue(record["System Name"]),
Location: types.StringValue(record["System Location"]),
Contact: types.StringValue(record["System Contact"]),
SoftwareVersion: types.StringValue(record["Software Version"]),
ObjectID: types.StringValue(record["System Object ID"]),
UpTime: types.StringValue(record["System Up Time"]),
CurrentTime: types.StringValue(record["Current Time"]),
Date: types.StringValue(record["Date"]),
}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,82 @@
// Port of ~/code/experiments/hpe/extractors/trunk_status.py
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
const trunkStatusPath = "/TrunkStatus.html"
var (
_ datasource.DataSource = &trunkStatusDataSource{}
_ datasource.DataSourceWithConfigure = &trunkStatusDataSource{}
)
func NewTrunkStatusDataSource() datasource.DataSource {
return &trunkStatusDataSource{}
}
type trunkStatusDataSource struct {
client *client.Client
}
type trunkStatusModel struct {
Trunks types.List `tfsdk:"trunks"`
}
func (d *trunkStatusDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_trunk_status"
}
func (d *trunkStatusDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Reads the switch's Trunk Status page: one entry per configured trunk. Empty list if no trunks exist.",
Attributes: map[string]schema.Attribute{
"trunks": schema.ListAttribute{
Computed: true,
ElementType: types.MapType{ElemType: types.StringType},
},
},
}
}
func (d *trunkStatusDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
c, ok := req.ProviderData.(*client.Client)
if !ok {
resp.Diagnostics.AddError("Unexpected data source configure type", fmt.Sprintf("expected *client.Client, got %T", req.ProviderData))
return
}
d.client = c
}
func (d *trunkStatusDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
tables, err := d.client.FetchTables(trunkStatusPath)
if err != nil {
resp.Diagnostics.AddError("Unable to fetch Trunk Status page", err.Error())
return
}
table, ok := tables["Trunk Status"]
if !ok {
resp.Diagnostics.AddError("Unexpected page layout", `table captioned "Trunk Status" not found`)
return
}
trunksValue, diags := rowsToTF(ctx, table.Rows)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
state := trunkStatusModel{Trunks: trunksValue}
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
@@ -0,0 +1,128 @@
package provider
import (
"context"
"os"
"strconv"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-hpe1810/internal/provider/client"
)
var _ provider.Provider = &hpe1810Provider{}
type hpe1810Provider struct {
version string
}
// hpe1810ProviderModel mirrors config.py's three settings (SWITCH_HOST,
// SWITCH_HTTPS, SWITCH_PASSWORD) from the Python reference implementation.
type hpe1810ProviderModel struct {
Host types.String `tfsdk:"host"`
HTTPS types.Bool `tfsdk:"https"`
Password types.String `tfsdk:"password"`
}
func New(version string) func() provider.Provider {
return func() provider.Provider {
return &hpe1810Provider{version: version}
}
}
func (p *hpe1810Provider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = "hpe1810"
resp.Version = p.version
}
func (p *hpe1810Provider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Manages an HP ProCurve/OfficeConnect 1810 switch over its built-in web UI.",
Attributes: map[string]schema.Attribute{
"host": schema.StringAttribute{
Optional: true,
Description: "Switch IP or hostname. Falls back to the HPE1810_HOST env var, then \"192.168.2.10\".",
},
"https": schema.BoolAttribute{
Optional: true,
Description: "Use HTTPS instead of HTTP. Falls back to the HPE1810_HTTPS env var, then false.",
},
"password": schema.StringAttribute{
Optional: true,
Sensitive: true,
Description: "Switch login password. Falls back to the HPE1810_PASSWORD env var, then empty.",
},
},
}
}
func (p *hpe1810Provider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
var config hpe1810ProviderModel
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
}
host := os.Getenv("HPE1810_HOST")
if host == "" {
host = "192.168.2.10"
}
if !config.Host.IsNull() {
host = config.Host.ValueString()
}
https := false
if envHTTPS := os.Getenv("HPE1810_HTTPS"); envHTTPS != "" {
https, _ = strconv.ParseBool(envHTTPS)
}
if !config.HTTPS.IsNull() {
https = config.HTTPS.ValueBool()
}
password := os.Getenv("HPE1810_PASSWORD")
if !config.Password.IsNull() {
password = config.Password.ValueString()
}
c, err := client.NewClient(host, https, password)
if err != nil {
resp.Diagnostics.AddError("Unable to create switch client", err.Error())
return
}
if err := c.Login(); err != nil {
resp.Diagnostics.AddError("Unable to log in to switch", err.Error())
return
}
resp.DataSourceData = c
resp.ResourceData = c
}
// DataSources: one entry per extractors/*.py equivalent.
func (p *hpe1810Provider) DataSources(_ context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
NewSystemDescriptionDataSource,
NewNetworkSetupDataSource,
NewPortSummaryDataSource,
NewLLDPStatisticsDataSource,
NewBufferedLogDataSource,
NewMACTableDataSource,
NewTrunkStatusDataSource,
NewLoopProtectionStatusDataSource,
NewDualImageStatusDataSource,
NewClockDataSource,
NewSNTPDataSource,
NewLogConfigurationDataSource,
NewBackupManagerDataSource,
}
}
// Resources will grow one entry per actions/*.py equivalent (locator first)
// as they're ported.
func (p *hpe1810Provider) Resources(_ context.Context) []func() resource.Resource {
return []func() resource.Resource{}
}