Skip to content

Commit aebaf74

Browse files
author
Andre Keedy
authored
Merge pull request #378 from keedya/master
Add support for dell switch discoveryand add basic configuration
2 parents ff84e7c + a490dd6 commit aebaf74

9 files changed

Lines changed: 434 additions & 5 deletions

data/profiles/dell-bmp.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/sh
2+
3+
# Copyright 2018, DELL EMC, Inc.
4+
5+
TASKS_URI="http://<%=server%>:<%=port%>/api/2.0/tasks/<%=identifier%>"
6+
echo $TASKS_URI
7+
LOGFILE="/tmp/rackhd.log"
8+
9+
# tasks will be downloaded to:
10+
# /tmp/mytask.json
11+
getTask(){
12+
curl -X GET -s -w '%{http_code}' $TASKS_URI -o /tmp/mytask.json
13+
}
14+
15+
# Once the task is excecuted and updated
16+
# post task will post it to TASKS_URI
17+
postTask(){
18+
# Below is an example of expected data
19+
# DATA='{"identifier":"5aeb28b34e9d8e96b83877b1","tasks":[{"stdout":"{\"version\":\"1.2.3.4\"}","source":"version","format":"json","catalog":true}]}'
20+
read DATA</tmp/mytask.json
21+
echo "$DATA" >> $LOGFILE
22+
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d @/tmp/mytask.json $TASKS_URI
23+
}
24+
25+
# Args:
26+
# $1 key
27+
# return : key value
28+
getValue(){
29+
grep -o "\"${1}\":*\"[^\"]*\"" /tmp/mytask.json | grep -o '"[^"]*"$' | tr -d '"'
30+
}
31+
32+
# If the loaded task contains a Download URI; Download & execute
33+
# key we are looking for is: downloadUrl
34+
executeUrl(){
35+
DOWNLOAD_URL=$( getValue downloadUrl);
36+
echo " downloaded URL $DOWNLOAD_URL" >> $LOGFILE
37+
if [ ! -z $DOWNLOAD_URL ]; then
38+
if [[ $DOWNLOAD_URL = *".exp"* ]]; then
39+
echo "Run expect script"
40+
RESP='"'$( curl -o - $DOWNLOAD_URL | expect 2>&1 )'"'
41+
# Assuming that the .exp is a configuration script,
42+
# the network is disconnected until we exit the configuration bmp mode
43+
# We need to exit bmp and then update RackHD task to finish the workflow
44+
(n=0; until [ $n -ge 5 ]; do postTask && break; n=$[$n+1]; sleep 15; done;) &
45+
echo "exit taskrunner"
46+
exit 0
47+
else
48+
RESP='"'$( curl -s -o - $DOWNLOAD_URL | sh 2>&1 )'"'
49+
fi
50+
fi
51+
if [ $? -ne 0 ]; then
52+
echo Error: $RESP
53+
# Add error to the pulled task
54+
sed -e '$s/}/,"error":'"${RESP}"'}/' /tmp/mytask.json | tee /tmp/mytask.json
55+
fi
56+
}
57+
58+
# main
59+
while :
60+
do
61+
echo "Pull tasks from RackHD"
62+
RESP=$( getTask)
63+
echo "get task return $?" >> $LOGFILE
64+
# If there is any tasks; proceed
65+
# othewise, wait 30 seconds and try again
66+
if [ $?=0 ] && [ $RESP -eq 200 ]
67+
then
68+
#check for exit task
69+
EXIT=$( grep -o '"exit"' /tmp/mytask.json || echo "failed" )
70+
executeUrl
71+
postTask
72+
# if the tasks contains "exit" command; exit this loop
73+
if [ $EXIT == '"exit"' ]
74+
then
75+
echo " Don't Exit; We need the task runner to stay up for the next task"
76+
# skip exit for now
77+
#return 0
78+
fi;
79+
sleep 10;
80+
else
81+
sleep 120;
82+
fi;
83+
done;
84+
#TODO upload task result
85+
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/usr/bin/expect
2+
#/DELL-FORCE10
3+
# Copyright 2018, Dell EMC, Inc.
4+
5+
############FUNCTIONS############
6+
#access the switch CLI via Dell 'f10do' shell command and execute FTOS command
7+
proc execFtosCommand {cmd_str} {
8+
set str [exec f10do "$cmd_str"]
9+
print_output $str
10+
}
11+
########Logging Functions########
12+
#print to terminal and to log file
13+
proc print_output {str {fd ""}} {
14+
puts $str
15+
if {$fd != ""} {
16+
puts $fd $str
17+
}
18+
}
19+
#starts logging status
20+
proc startLogging {} {
21+
global status_file
22+
global fp
23+
set status_file "/tmp/rackhd.log"
24+
#open status file
25+
set fp [open $status_file w]
26+
}
27+
#stop logging status
28+
proc stopLogging {} {
29+
global fp
30+
print_output "========================================\n" $fp
31+
close $fp
32+
}
33+
#####Prereq Check Functions######
34+
#resets watchdog timer
35+
proc resetTimer {} {
36+
print_output [exec rstimer 30]
37+
print_output "\nReset Timer Complete!\n"
38+
}
39+
########Config Functions#########
40+
#write changes to startup-config
41+
proc doWrite {} {
42+
execFtosCommand "write"
43+
#wait 2 seconds
44+
after 2000
45+
}
46+
#configures management interface with IP address
47+
proc setManagement {} {
48+
global fp
49+
print_output "Configuring ManagementEthernet <%=mgmtPort%> ...\n" $fp
50+
execFtosCommand "configure terminal"
51+
execFtosCommand "interface managementEthernet <%=mgmtPort%>"
52+
execFtosCommand "ip address <%=ipAddr%>"
53+
execFtosCommand "no shut"
54+
execFtosCommand "end"
55+
}
56+
#enable ssh
57+
proc enableSsh {} {
58+
global fp
59+
print_output "Configuring ssh ...\n" $fp
60+
execFtosCommand "configure terminal"
61+
execFtosCommand "ip ssh server enable"
62+
execFtosCommand "end"
63+
}
64+
#create an account
65+
proc createAccount {} {
66+
global fp
67+
print_output "Create an new account ...\n" $fp
68+
execFtosCommand "configure terminal"
69+
execFtosCommand "username <%=username%> password <%=userPassword%>"
70+
execFtosCommand "end"
71+
}
72+
#set admin password
73+
proc updateAdminPassword {} {
74+
global fp
75+
print_output "update admin password ...\n" $fp
76+
execFtosCommand "configure terminal"
77+
execFtosCommand "enable password level 15 0 <%=adminPassword%>"
78+
execFtosCommand "end"
79+
}
80+
81+
#################################
82+
#translate CR and LF correctly
83+
fconfigure stdout -translation crlf
84+
fconfigure stderr -translation crlf
85+
#flag variables to confirm if initial check and configuration pass/succeed
86+
set checkFail 0
87+
set configFail 0
88+
#name to set the switch to
89+
set hostname <%=hostname%>"
90+
print_output "!!!Executing Config Script!!!\n"
91+
#set Unix watchdog timer to 30 minutes
92+
if [catch resetTimer] {
93+
print_output "Error encountered during watchdog timer reset!\n"
94+
set checkFail 1
95+
exit 2
96+
}
97+
#start logging
98+
if [catch startLogging] {
99+
print_output "Error encountered during start of logging!\n"
100+
} else {
101+
print_output "Status logging for bmp successfully started!\n" $fp
102+
}
103+
print_output "========================================\n" $fp
104+
print_output " Status: $hostname\n" $fp
105+
print_output "========================================\n" $fp
106+
#set the management IP address
107+
if [catch setManagement] {
108+
print_output "Error configuring management!\n" $fp
109+
set configFail 1
110+
}
111+
#Enable SSH
112+
if [catch enableSsh] {
113+
print_output "Error enabling ssh"
114+
set configFail 1
115+
}
116+
#create a new account
117+
if [catch createAccount] {
118+
print_output "Error creating a new account"
119+
set configFail 1
120+
}
121+
#updating admin password
122+
if [catch updateAdminPassword] {
123+
print_output "Error updaing admin password"
124+
set configFail 1
125+
}
126+
#write the configuration to startup-config
127+
if [catch doWrite] {
128+
print_output "Error saving configuration!\n" $fp
129+
set configFail 1
130+
}
131+
132+
#NOTIFY IF CONFIGURATION FAILED OR PASSED
133+
if {$configFail} {
134+
print_output "\n!!!!!Errors were encountered during configuration - check log file!!!!!\n" $fp
135+
} else {
136+
print_output "\n!!!!!Configuration Successfully Applied!!!!!\n" $fp
137+
}
138+
139+
#stop logging to status file
140+
if [catch stopLogging] {
141+
print_output "Error upon stopping logging!\n" $fp
142+
exit 2
143+
}
144+
#IF CONFIGURATION FAILED, EXIT ON ERROR, OR, IF PASSED, EXIT ON SUCCESS
145+
if {$configFail} {
146+
exit 2
147+
} else {
148+
exit 0
149+
}
150+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
# Copyright 2018, DELL EMC, Inc.
4+
OPEN_CURLY='{'
5+
CLOSE_CURLY='}'
6+
LOGFILE="/tmp/rackhd.log"
7+
8+
OS_VERSION=$( f10do "show system" | grep 'Dell EMC Networking OS Version' | awk -F: '{print $NF}' | tr -d '[:space:]')
9+
STACK_MAC=$( f10do "show system" | grep 'Stack MAC' | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
10+
MODUL_TYPE=$( f10do "show system" | grep 'Module Type' | awk -F: '{print $NF}' | tr -d '[:space:]')
11+
12+
# build the stdout data in json format
13+
STDOUT='"'$OPEN_CURLY'
14+
\\\\\\"osVersion\\\\\\":\\\\\\"'$OS_VERSION'\\\\\\",
15+
\\\\\\"stackMack\\\\\\":\\\\\\"'$STACK_MAC'\\\\\\",
16+
\\\\\\"moduleType\\\\\\":\\\\\\"'$MODUL_TYPE'\\\\\\"
17+
'$CLOSE_CURLY'"'
18+
19+
#remove white space from stdout
20+
STDOUT=$( echo $STDOUT | tr -d ' ')
21+
echo $STDOUT >> $LOGFILE
22+
# Finally, Add stdout to the pulled task
23+
sed -e '$s/}/,"stdout":'${STDOUT}'}/' /tmp/mytask.json | tee /tmp/mytask.json
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/sh
2+
3+
# Copyright 2018, DELL EMC, Inc.
4+
OPEN_CURLY='{'
5+
CLOSE_CURLY='}'
6+
7+
# using onie-sysinfo
8+
# onie-sysinfo [-hsevimrpcfdatP]
9+
# Dump ONIE system information.
10+
11+
# COMMAND LINE OPTIONS
12+
13+
# The default is to dump the ONIE platform (-p).
14+
# -h
15+
# Help. Print this message.
16+
# -s
17+
# Serial Number
18+
# -P
19+
# Part Number
20+
# -e
21+
# Management Ethernet MAC address
22+
# -v
23+
# ONIE version string
24+
# -i
25+
# ONIE vendor ID. Print the ONIE vendor's IANA enterprise number.
26+
# -m
27+
# ONIE machine string
28+
# -r
29+
# ONIE machine revision string
30+
# -p
31+
# ONIE platform string. This is the default.
32+
# -c
33+
# ONIE CPU architecture
34+
# -f
35+
# ONIE configuration version
36+
# -d
37+
# ONIE build date
38+
# -t
39+
# ONIE partition type
40+
# -a
41+
# Dump all information.
42+
# Commands to run
43+
# Collecting version and serial nb
44+
VERSION=$( onie-sysinfo -v )
45+
SERIAL_NB=$( onie-sysinfo -s)
46+
47+
48+
# build the stdout data in json format
49+
STDOUT='"'$OPEN_CURLY'
50+
\\\\"version\\\\":\\\\"'$VERSION'\\\\",
51+
\\\\"serialNb\\\\":\\\\"'$SERIAL_NB'\\\\"
52+
'$CLOSE_CURLY'"'
53+
54+
#remove white space from stdout
55+
STDOUT=$( echo $STDOUT | tr -d ' ')
56+
57+
# Finally, Add stdout to the pulled task
58+
sed -i '$s/}/,"stdout":'${STDOUT}'}/' /tmp/mytask.json
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2018, Dell EMC, Inc.
2+
3+
"use strict";
4+
5+
module.exports = {
6+
"friendlyName": "Dell Switch Onie Discovery",
7+
"injectableName": "Graph.Switch.Discovery.Dell.Onie",
8+
"tasks": [
9+
{
10+
"label": "catalog-switch",
11+
"taskDefinition": {
12+
"friendlyName": "Catalog Dell Switch",
13+
"injectableName": "Task.Inline.Catalog.Switch.Dell",
14+
"implementsTask": "Task.Base.Linux.Commands",
15+
"options": {
16+
"commands": [
17+
{
18+
"downloadUrl": "{{ api.templates }}/dell-switch-onie-catalog.sh?nodeId={{ task.nodeId }}",
19+
"catalog": { "format": "json", "source": "onieSysinfo" }
20+
}
21+
]
22+
},
23+
"properties": {}
24+
}
25+
}
26+
]
27+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2018, Dell EMC, Inc.
2+
3+
"use strict";
4+
5+
module.exports = {
6+
"friendlyName": "Dell Switch configuration",
7+
"injectableName": "Graph.Switch.Dell.Configuration",
8+
"tasks": [
9+
{
10+
"label": "config-switch",
11+
"taskDefinition": {
12+
"friendlyName": "Dell Switch configuration",
13+
"injectableName": "Task.Inline.Switch.Dell.Configuration",
14+
"implementsTask": "Task.Base.Linux.Commands",
15+
"options": {
16+
"mgmtPort": "1/1",
17+
"username": "rackhd",
18+
"userPassword": "RackHDRocks1!",
19+
"adminPassword": "RackHDRocks1!",
20+
"hostname": "rackhd",
21+
"ipAddr": "dhcp",
22+
"commands": [
23+
{
24+
"downloadUrl": "{{ api.templates }}/dell-switch-basic-config.exp?nodeId={{ task.nodeId }}",
25+
}
26+
]
27+
},
28+
"properties": {}
29+
}
30+
}
31+
]
32+
};

0 commit comments

Comments
 (0)