mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-03 01:17:41 +03:00
M #-: Add warning to Sched Action (#3177)
This commit is contained in:
parent
8069081c29
commit
4cb89d8032
@ -168,6 +168,8 @@ private:
|
||||
|
||||
std::string _message;
|
||||
|
||||
time_t _warning;
|
||||
|
||||
/**
|
||||
* Rebuilds the object from an xml formatted string
|
||||
* @param xml_str The xml-formatted string
|
||||
|
@ -33,14 +33,15 @@
|
||||
<xs:element name="PARENT_ID" type="xs:integer"/>
|
||||
<xs:element name="TYPE" type="xs:string"/>
|
||||
<xs:element name="ACTION" type="xs:string"/>
|
||||
<xs:element name="ARGS" type="xs:string" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="ARGS" type="xs:string"/>
|
||||
<xs:element name="TIME" type="xs:string"/>
|
||||
<xs:element name="REPEAT" type="xs:integer" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="DAYS" type="xs:string" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="END_TYPE" type="xs:integer" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="END_VALUE" type="xs:integer" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="DONE" type="xs:integer" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="MESSAGE" type="xs:string" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="REPEAT" type="xs:integer"/>
|
||||
<xs:element name="DAYS" type="xs:string"/>
|
||||
<xs:element name="END_TYPE" type="xs:integer"/>
|
||||
<xs:element name="END_VALUE" type="xs:integer"/>
|
||||
<xs:element name="DONE" type="xs:integer"/>
|
||||
<xs:element name="MESSAGE" type="xs:string"/>
|
||||
<xs:element name="WARNING" type="xs:integer"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
||||
|
@ -2556,7 +2556,12 @@ Bash symbols must be escaped on STDIN passing'
|
||||
def self.scheduled_action_table(object)
|
||||
CLIHelper::ShowTable.new(nil, object) do
|
||||
column :ID, '', :adjust => true do |d|
|
||||
d['ID']
|
||||
warn = d['WARNING'].to_i
|
||||
|
||||
prefix = ''
|
||||
prefix = '*' if d['DONE'].to_i <= 0 && warn != 0 && warn < Time.now.to_i
|
||||
|
||||
prefix + d['ID']
|
||||
end
|
||||
|
||||
column :ACTION, '', :adjust => true do |d|
|
||||
|
@ -1486,7 +1486,6 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
acc_t = 0
|
||||
acc_w = 0
|
||||
|
||||
helper.perform_action(args[0], {}, 'Charter added') do |vm|
|
||||
vm.info
|
||||
@ -1499,12 +1498,11 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
rc = helper.schedule_actions([args[0]].flatten,
|
||||
{ :schedule => sched },
|
||||
action.to_s,
|
||||
time[:warning][:time] + acc_w)
|
||||
"+#{time[:warning][:time] + acc_t}")
|
||||
|
||||
exit(-1) if rc < 0
|
||||
|
||||
acc_t += time[:time].to_i
|
||||
acc_w += time[:warning][:time].to_i
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -42,6 +42,8 @@ const (
|
||||
EndType SchedActionKeys = "END_TYPE"
|
||||
EndValue SchedActionKeys = "END_VALUE"
|
||||
Done SchedActionKeys = "DONE"
|
||||
Message SchedActionKeys = "MESSAGE"
|
||||
Warning SchedActionKeys = "WARNING"
|
||||
)
|
||||
|
||||
// AddSchedAction returns a Scheduled Action structure
|
||||
|
@ -65,7 +65,7 @@ ScheduledAction::ScheduledAction(PoolObjectSQL::ObjectType type,
|
||||
, _end_type(END_NONE)
|
||||
, _end_value(-1)
|
||||
, _done(-1)
|
||||
, _message("")
|
||||
, _warning(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -89,6 +89,7 @@ string& ScheduledAction::to_xml(string& xml) const
|
||||
<< "<END_VALUE>" << _end_value << "</END_VALUE>"
|
||||
<< "<DONE>" << _done << "</DONE>"
|
||||
<< "<MESSAGE>" << _message << "</MESSAGE>"
|
||||
<< "<WARNING>" << _warning << "</WARNING>"
|
||||
<< "</SCHED_ACTION>";
|
||||
|
||||
xml = oss.str();
|
||||
@ -147,6 +148,17 @@ int ScheduledAction::parse(const VectorAttribute * va, time_t origin, string& er
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (va->vector_value("WARNING", tmp_str) == 0 && !tmp_str.empty())
|
||||
{
|
||||
_warning = parse_time(tmp_str, origin);
|
||||
}
|
||||
|
||||
if (_warning == -1)
|
||||
{
|
||||
error_str = "Unable to parse the warning value: " + tmp_str;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int tmp_int;
|
||||
|
||||
if (va->vector_value("REPEAT", tmp_int) == 0)
|
||||
@ -443,6 +455,8 @@ time_t ScheduledAction::next_action()
|
||||
|
||||
_time += delta * 24 * 3600;
|
||||
|
||||
_warning = 0; // Reset warning for repeated action
|
||||
|
||||
return _time;
|
||||
}
|
||||
|
||||
@ -464,6 +478,7 @@ int ScheduledAction::rebuild_attributes()
|
||||
rc += xpath(_days, "/SCHED_ACTION/DAYS", "");
|
||||
rc += xpath(_message, "/SCHED_ACTION/MESSAGE", "");
|
||||
rc += xpath(_end_value, "/SCHED_ACTION/END_VALUE", (time_t)-1);
|
||||
rc += xpath(_warning, "/SCHED_ACTION/WARNING", (time_t)0);
|
||||
|
||||
rc += xpath(tmp_str, "/SCHED_ACTION/TYPE", "");
|
||||
_type = str_to_type(tmp_str);
|
||||
|
Loading…
Reference in New Issue
Block a user