Adding firmware upgrade automation.

This commit is contained in:
stephb9959
2021-10-04 21:46:24 -07:00
parent 13cae4de6e
commit 8ec72b426a
5 changed files with 165 additions and 5 deletions

View File

@@ -485,7 +485,7 @@ components:
- inherit
firmwareUpgrade:
type: string
example: "auto" or a time string of the format "DOW-HH:MM"
example: auto or a time string of the format DOW-HH:MM
firmwareRCOnly:
type: boolean
@@ -587,6 +587,18 @@ components:
items:
$ref: '#/components/schemas/ExpandedUseEntryMap'
FirmwareOptions:
type: object
properties:
firmwareUpgrade:
type: string
example: auto or a time string of the format DOW-HH:MM
firmwareRCOnly:
type: boolean
from:
type: string
#########################################################################################
##
## These are endpoints that all services in the OPenWiFI stack must provide
@@ -774,7 +786,7 @@ components:
items:
type: string
SystemGetSubSystemNemesResult:
SystemGetSubSystemNamesResult:
type: object
properties:
taglist:
@@ -1389,9 +1401,30 @@ paths:
type: string
format: uuid
required: true
- in: query
name: config
schema:
type: boolean
required: false
- in: query
name: explain
schema:
type: boolean
required: false
- in: query
name: firmwareOptions
schema:
type: boolean
required: false
responses:
200:
$ref: '#/components/schemas/InventoryTag'
description: Succesful retrieve configuratiopn or part of the configuration
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/InventoryTag'
- $ref: '#/components/schemas/FirmwareOptions'
403:
$ref: '#/components/responses/Unauthorized'
404:
@@ -1414,7 +1447,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/InventoryTag'
responses:
200:
$ref: '#/components/schemas/InventoryTag'
@@ -2213,7 +2245,7 @@ paths:
oneOf:
- $ref: '#/components/schemas/SystemGetLogLevelsResult'
- $ref: '#/components/schemas/SystemCommandGetLogLevelNamesResult'
- $ref: '#/components/schemas/SystemGetSubSystemNemesResult'
- $ref: '#/components/schemas/SystemGetSubSystemNamesResult'
403:
$ref: '#/components/responses/Unauthorized'
404:

View File

@@ -41,6 +41,18 @@ namespace OpenWifi{
}
ReturnObject(Answer);
return;
} else if(HasParameter("firmwareOptions", Arg) && Arg=="true") {
Poco::JSON::Object Answer;
std::string firmwareUpgrade;
bool firmwareRCOnly=false;
Storage()->InventoryDB().FindFirmwareOptions(SerialNumber,firmwareUpgrade, firmwareRCOnly);
Answer.set("firmwareUpgrade",firmwareUpgrade);
Answer.set("firmwareRCOnly", firmwareRCOnly);
ReturnObject(Answer);
return;
}
Poco::JSON::Object Answer;

View File

@@ -111,6 +111,110 @@ namespace OpenWifi {
return false;
}
bool InventoryDB::FindFirmwareOptionsForEntity(std::string &EntityUUID, std::string &firmwareUpgrade,
bool &firmwareRCOnly) {
std::string UUID = EntityUUID;
while(!UUID.empty() && UUID!=EntityDB::RootUUID()) {
ProvObjects::Entity E;
if(Storage()->EntityDB().GetRecord("id",UUID,E)) {
if(!E.deviceConfiguration.empty()) {
ProvObjects::DeviceConfiguration C;
if(Storage()->ConfigurationDB().GetRecord("id",E.deviceConfiguration,C)) {
if(C.firmwareUpgrade=="no") {
firmwareUpgrade="no";
return false;
}
if(C.firmwareUpgrade=="yes") {
firmwareUpgrade="yes";
firmwareRCOnly=C.firmwareRCOnly;
return true;
}
}
} else {
UUID = E.parent;
}
} else {
break;
}
}
firmwareUpgrade="no";
firmwareRCOnly= false;
return false;
}
bool InventoryDB::FindFirmwareOptionsForVenue(std::string &VenueUUID, std::string &firmwareUpgrade,
bool &firmwareRCOnly) {
std::string UUID = VenueUUID;
while(!UUID.empty()) {
ProvObjects::Venue V;
if(Storage()->VenueDB().GetRecord("id",UUID,V)) {
if(!V.deviceConfiguration.empty()) {
ProvObjects::DeviceConfiguration C;
if(Storage()->ConfigurationDB().GetRecord("id",V.deviceConfiguration,C)) {
if(C.firmwareUpgrade=="no") {
firmwareUpgrade="no";
return false;
}
if(C.firmwareUpgrade=="yes") {
firmwareUpgrade="yes";
firmwareRCOnly=C.firmwareRCOnly;
return true;
}
}
}
// must be inherit...
if(!V.entity.empty()) {
return FindFirmwareOptionsForEntity(V.entity,firmwareUpgrade,firmwareRCOnly);
} else {
UUID=V.parent;
}
} else {
break;
}
}
firmwareUpgrade="no";
firmwareRCOnly= false;
return false;
}
bool InventoryDB::FindFirmwareOptions(std::string &SerialNumber, std::string &firmwareUpgrade,
bool &firmwareRCOnly) {
ProvObjects::InventoryTag T;
firmwareRCOnly = false;
firmwareUpgrade.clear();
if(GetRecord("serialNumber",SerialNumber,T)) {
// if there is a local configuration, use this
firmwareRCOnly = false;
firmwareUpgrade.clear();
if(!T.deviceConfiguration.empty()) {
ProvObjects::DeviceConfiguration C;
if(Storage()->ConfigurationDB().GetRecord("id",T.deviceConfiguration,C)) {
if(C.firmwareUpgrade=="no") {
firmwareUpgrade="no";
return false;
}
if(C.firmwareUpgrade=="yes") {
firmwareUpgrade="yes";
firmwareRCOnly = C.firmwareRCOnly;
return true;
}
}
}
// look at entity...
if(!T.entity.empty()) {
return FindFirmwareOptionsForEntity(T.entity,firmwareUpgrade,firmwareRCOnly);
}
if(!T.venue.empty()) {
return FindFirmwareOptionsForVenue(T.entity,firmwareUpgrade,firmwareRCOnly);
}
return false;
}
return false;
}
}
template<> void ORM::DB< OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjects::InventoryTag>::Convert(OpenWifi::InventoryDBRecordType &In, OpenWifi::ProvObjects::InventoryTag &Out) {

View File

@@ -40,6 +40,9 @@ namespace OpenWifi {
public:
InventoryDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
bool CreateFromConnection(const std::string & SerialNumber, const std::string & ConnectionInfo, const std::string & DeviceType);
bool FindFirmwareOptions(std::string & SerialNumber, std::string &firmwareUpgrade, bool &firmwareRCOnly);
bool FindFirmwareOptionsForEntity(std::string & EntityUUID, std::string &firmwareUpgrade, bool &firmwareRCOnly);
bool FindFirmwareOptionsForVenue(std::string & VenueUUID, std::string &firmwareUpgrade, bool &firmwareRCOnly);
private:
};
}

View File

@@ -370,6 +370,14 @@ deviceconfig() {
jq < ${result_file}
}
devicefwoptions() {
curl ${FLAGS} "https://${OWPROV}/api/v1/inventory/$1?firmwareOptions=true" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-H "accept: application/json" > ${result_file}
jq < ${result_file}
}
adddeviceconfig() {
payload="{\"deviceConfiguration\" : \"$2\"}";
curl ${FLAGS} -X PUT "https://${OWPROV}/api/v1/inventory/$1" \
@@ -448,6 +456,7 @@ case "$1" in
"tree") login; tree ; logout;;
"importtree") login; importtree $2; logout;;
"deviceconfig") login; deviceconfig "$2"; logout;;
"devicefwoptions") login; devicefwoptions "$2"; logout;;
"addtag") login; addtag "$2"; logout;;
"unassigntag") login; unassigntag $2; logout;;
"addunassignedtag") login; addunassignedtag $2 ; logout;;