|
@@ 1430-1578 (lines=149) @@
|
| 1427 |
|
cmd.add_element("copy", scanner_id) |
| 1428 |
|
return self._send_xml_command(cmd) |
| 1429 |
|
|
| 1430 |
|
def create_schedule( |
| 1431 |
|
self, |
| 1432 |
|
name, |
| 1433 |
|
*, |
| 1434 |
|
comment=None, |
| 1435 |
|
first_time_minute=None, |
| 1436 |
|
first_time_hour=None, |
| 1437 |
|
first_time_day_of_month=None, |
| 1438 |
|
first_time_month=None, |
| 1439 |
|
first_time_year=None, |
| 1440 |
|
duration=None, |
| 1441 |
|
duration_unit=None, |
| 1442 |
|
period=None, |
| 1443 |
|
period_unit=None, |
| 1444 |
|
timezone=None |
| 1445 |
|
): |
| 1446 |
|
"""Create a new schedule |
| 1447 |
|
|
| 1448 |
|
Arguments: |
| 1449 |
|
name (str): Name of the schedule |
| 1450 |
|
comment (str, optional): Comment for the schedule |
| 1451 |
|
first_time_minute (int, optional): First time minute the schedule |
| 1452 |
|
will run. Must be an integer >= 0. |
| 1453 |
|
first_time_hour (int, optional): First time hour the schedule |
| 1454 |
|
will run. Must be an integer >= 0. |
| 1455 |
|
first_time_day_of_month (int, optional): First time day of month the |
| 1456 |
|
schedule will run. Must be an integer > 0 <= 31. |
| 1457 |
|
first_time_month (int, optional): First time month the schedule |
| 1458 |
|
will run. Must be an integer >= 1 <= 12. |
| 1459 |
|
first_time_year (int, optional): First time year the schedule |
| 1460 |
|
will run. Must be an integer >= 1970. |
| 1461 |
|
duration (int, optional): How long the Manager will run the |
| 1462 |
|
scheduled task for until it gets paused if not finished yet. |
| 1463 |
|
Must be an integer > 0. |
| 1464 |
|
duration_unit (str, optional): Unit of the duration. One of second, |
| 1465 |
|
minute, hour, day, week, month, year, decade. Required if |
| 1466 |
|
duration is set. |
| 1467 |
|
period (int, optional): How often the Manager will repeat the |
| 1468 |
|
scheduled task. Must be an integer > 0. |
| 1469 |
|
period_unit (str, optional): Unit of the period. One of second, |
| 1470 |
|
minute, hour, day, week, month, year, decade. Required if |
| 1471 |
|
period is set. |
| 1472 |
|
timezone (str, optional): The timezone the schedule will follow |
| 1473 |
|
|
| 1474 |
|
Returns: |
| 1475 |
|
The response. See :py:meth:`send_command` for details. |
| 1476 |
|
""" |
| 1477 |
|
if not name: |
| 1478 |
|
raise RequiredArgument("create_schedule requires a name argument") |
| 1479 |
|
|
| 1480 |
|
cmd = XmlCommand("create_schedule") |
| 1481 |
|
cmd.add_element("name", name) |
| 1482 |
|
|
| 1483 |
|
if comment: |
| 1484 |
|
cmd.add_element("comment", comment) |
| 1485 |
|
|
| 1486 |
|
if ( |
| 1487 |
|
first_time_minute is not None |
| 1488 |
|
or first_time_hour is not None |
| 1489 |
|
or first_time_day_of_month is not None |
| 1490 |
|
or first_time_month is not None |
| 1491 |
|
or first_time_year is not None |
| 1492 |
|
): |
| 1493 |
|
|
| 1494 |
|
if first_time_minute is None: |
| 1495 |
|
raise RequiredArgument( |
| 1496 |
|
"Setting first_time requires first_time_minute argument" |
| 1497 |
|
) |
| 1498 |
|
elif ( |
| 1499 |
|
not isinstance(first_time_minute, numbers.Integral) |
| 1500 |
|
or first_time_minute < 0 |
| 1501 |
|
): |
| 1502 |
|
raise InvalidArgument( |
| 1503 |
|
"first_time_minute argument of create_schedule needs to be " |
| 1504 |
|
"an integer greater or equal 0" |
| 1505 |
|
) |
| 1506 |
|
|
| 1507 |
|
if first_time_hour is None: |
| 1508 |
|
raise RequiredArgument( |
| 1509 |
|
"Setting first_time requires first_time_hour argument" |
| 1510 |
|
) |
| 1511 |
|
elif ( |
| 1512 |
|
not isinstance(first_time_hour, numbers.Integral) |
| 1513 |
|
or first_time_hour < 0 |
| 1514 |
|
): |
| 1515 |
|
raise InvalidArgument( |
| 1516 |
|
"first_time_hour argument of create_schedule needs to be " |
| 1517 |
|
"an integer greater or equal 0" |
| 1518 |
|
) |
| 1519 |
|
|
| 1520 |
|
if first_time_day_of_month is None: |
| 1521 |
|
raise RequiredArgument( |
| 1522 |
|
"Setting first_time requires first_time_day_of_month " |
| 1523 |
|
"argument" |
| 1524 |
|
) |
| 1525 |
|
elif ( |
| 1526 |
|
not isinstance(first_time_day_of_month, numbers.Integral) |
| 1527 |
|
or first_time_day_of_month < 1 |
| 1528 |
|
or first_time_day_of_month > 31 |
| 1529 |
|
): |
| 1530 |
|
raise InvalidArgument( |
| 1531 |
|
"first_time_day_of_month argument of create_schedule needs " |
| 1532 |
|
"to be an integer between 1 and 31" |
| 1533 |
|
) |
| 1534 |
|
|
| 1535 |
|
if first_time_month is None: |
| 1536 |
|
raise RequiredArgument( |
| 1537 |
|
"Setting first_time requires first_time_month argument" |
| 1538 |
|
) |
| 1539 |
|
elif ( |
| 1540 |
|
not isinstance(first_time_month, numbers.Integral) |
| 1541 |
|
or first_time_month < 1 |
| 1542 |
|
or first_time_month > 12 |
| 1543 |
|
): |
| 1544 |
|
raise InvalidArgument( |
| 1545 |
|
"first_time_month argument of create_schedule needs " |
| 1546 |
|
"to be an integer between 1 and 12" |
| 1547 |
|
) |
| 1548 |
|
|
| 1549 |
|
if first_time_year is None: |
| 1550 |
|
raise RequiredArgument( |
| 1551 |
|
"Setting first_time requires first_time_year argument" |
| 1552 |
|
) |
| 1553 |
|
elif ( |
| 1554 |
|
not isinstance(first_time_year, numbers.Integral) |
| 1555 |
|
or first_time_year < 1970 |
| 1556 |
|
): |
| 1557 |
|
raise InvalidArgument( |
| 1558 |
|
"first_time_year argument of create_schedule needs " |
| 1559 |
|
"to be an integer greater or equal 1970" |
| 1560 |
|
) |
| 1561 |
|
|
| 1562 |
|
_xmlftime = cmd.add_element("first_time") |
| 1563 |
|
_xmlftime.add_element("minute", str(first_time_minute)) |
| 1564 |
|
_xmlftime.add_element("hour", str(first_time_hour)) |
| 1565 |
|
_xmlftime.add_element("day_of_month", str(first_time_day_of_month)) |
| 1566 |
|
_xmlftime.add_element("month", str(first_time_month)) |
| 1567 |
|
_xmlftime.add_element("year", str(first_time_year)) |
| 1568 |
|
|
| 1569 |
|
if duration is not None: |
| 1570 |
|
if not duration_unit: |
| 1571 |
|
raise RequiredArgument( |
| 1572 |
|
"Setting duration requires duration_unit argument" |
| 1573 |
|
) |
| 1574 |
|
|
| 1575 |
|
if not duration_unit in TIME_UNITS: |
| 1576 |
|
raise InvalidArgument( |
| 1577 |
|
"duration_unit must be one of {units}. But {actual} has " |
| 1578 |
|
"been passed".format( |
| 1579 |
|
units=", ".join(TIME_UNITS), actual=duration_unit |
| 1580 |
|
) |
| 1581 |
|
) |
|
@@ 5028-5180 (lines=153) @@
|
| 5025 |
|
|
| 5026 |
|
return self._send_xml_command(cmd) |
| 5027 |
|
|
| 5028 |
|
def modify_schedule( |
| 5029 |
|
self, |
| 5030 |
|
schedule_id, |
| 5031 |
|
*, |
| 5032 |
|
comment=None, |
| 5033 |
|
name=None, |
| 5034 |
|
first_time_minute=None, |
| 5035 |
|
first_time_hour=None, |
| 5036 |
|
first_time_day_of_month=None, |
| 5037 |
|
first_time_month=None, |
| 5038 |
|
first_time_year=None, |
| 5039 |
|
duration=None, |
| 5040 |
|
duration_unit=None, |
| 5041 |
|
period=None, |
| 5042 |
|
period_unit=None, |
| 5043 |
|
timezone=None |
| 5044 |
|
): |
| 5045 |
|
"""Modifies an existing schedule. |
| 5046 |
|
|
| 5047 |
|
Arguments: |
| 5048 |
|
schedule_id (str): UUID of schedule to modify. |
| 5049 |
|
name (str, optional): Name of the schedule |
| 5050 |
|
comment (str, optional): Comment for the schedule |
| 5051 |
|
first_time_minute (int, optional): First time minute the schedule |
| 5052 |
|
will run. Must be an integer >= 0. |
| 5053 |
|
first_time_hour (int, optional): First time hour the schedule |
| 5054 |
|
will run. Must be an integer >= 0. |
| 5055 |
|
first_time_day_of_month (int, optional): First time day of month the |
| 5056 |
|
schedule will run. Must be an integer > 0 <= 31. |
| 5057 |
|
first_time_month (int, optional): First time month the schedule |
| 5058 |
|
will run. Must be an integer >= 1 <= 12. |
| 5059 |
|
first_time_year (int, optional): First time year the schedule |
| 5060 |
|
will run |
| 5061 |
|
duration (int, optional): How long the Manager will run the |
| 5062 |
|
scheduled task for until it gets paused if not finished yet. |
| 5063 |
|
duration_unit (str, optional): Unit of the duration. One of second, |
| 5064 |
|
minute, hour, day, week, month, year, decade. Required if |
| 5065 |
|
duration is set. |
| 5066 |
|
period (int, optional): How often the Manager will repeat the |
| 5067 |
|
scheduled task. Must be an integer > 0. |
| 5068 |
|
period_unit (str, optional): Unit of the period. One of second, |
| 5069 |
|
minute, hour, day, week, month, year, decade. Required if |
| 5070 |
|
period is set. |
| 5071 |
|
timezone (str, optional): The timezone the schedule will follow |
| 5072 |
|
|
| 5073 |
|
Returns: |
| 5074 |
|
The response. See :py:meth:`send_command` for details. |
| 5075 |
|
""" |
| 5076 |
|
if not schedule_id: |
| 5077 |
|
raise RequiredArgument( |
| 5078 |
|
"modify_schedule requires a schedule_id" "argument" |
| 5079 |
|
) |
| 5080 |
|
|
| 5081 |
|
cmd = XmlCommand("modify_schedule") |
| 5082 |
|
cmd.set_attribute("schedule_id", schedule_id) |
| 5083 |
|
|
| 5084 |
|
if comment: |
| 5085 |
|
cmd.add_element("comment", comment) |
| 5086 |
|
|
| 5087 |
|
if name: |
| 5088 |
|
cmd.add_element("name", name) |
| 5089 |
|
|
| 5090 |
|
if ( |
| 5091 |
|
first_time_minute is not None |
| 5092 |
|
or first_time_hour is not None |
| 5093 |
|
or first_time_day_of_month is not None |
| 5094 |
|
or first_time_month is not None |
| 5095 |
|
or first_time_year is not None |
| 5096 |
|
): |
| 5097 |
|
|
| 5098 |
|
if first_time_minute is None: |
| 5099 |
|
raise RequiredArgument( |
| 5100 |
|
"Setting first_time requires first_time_minute argument" |
| 5101 |
|
) |
| 5102 |
|
elif ( |
| 5103 |
|
not isinstance(first_time_minute, numbers.Integral) |
| 5104 |
|
or first_time_minute < 0 |
| 5105 |
|
): |
| 5106 |
|
raise InvalidArgument( |
| 5107 |
|
"first_time_minute argument of modify_schedule needs to be " |
| 5108 |
|
"an integer greater or equal 0" |
| 5109 |
|
) |
| 5110 |
|
|
| 5111 |
|
if first_time_hour is None: |
| 5112 |
|
raise RequiredArgument( |
| 5113 |
|
"Setting first_time requires first_time_hour argument" |
| 5114 |
|
) |
| 5115 |
|
elif ( |
| 5116 |
|
not isinstance(first_time_hour, numbers.Integral) |
| 5117 |
|
or first_time_hour < 0 |
| 5118 |
|
): |
| 5119 |
|
raise InvalidArgument( |
| 5120 |
|
"first_time_hour argument of modify_schedule needs to be " |
| 5121 |
|
"an integer greater or equal 0" |
| 5122 |
|
) |
| 5123 |
|
|
| 5124 |
|
if first_time_day_of_month is None: |
| 5125 |
|
raise RequiredArgument( |
| 5126 |
|
"Setting first_time requires first_time_day_of_month " |
| 5127 |
|
"argument" |
| 5128 |
|
) |
| 5129 |
|
elif ( |
| 5130 |
|
not isinstance(first_time_day_of_month, numbers.Integral) |
| 5131 |
|
or first_time_day_of_month < 1 |
| 5132 |
|
or first_time_day_of_month > 31 |
| 5133 |
|
): |
| 5134 |
|
raise InvalidArgument( |
| 5135 |
|
"first_time_day_of_month argument of modify_schedule needs " |
| 5136 |
|
"to be an integer between 1 and 31" |
| 5137 |
|
) |
| 5138 |
|
|
| 5139 |
|
if first_time_month is None: |
| 5140 |
|
raise RequiredArgument( |
| 5141 |
|
"Setting first_time requires first_time_month argument" |
| 5142 |
|
) |
| 5143 |
|
elif ( |
| 5144 |
|
not isinstance(first_time_month, numbers.Integral) |
| 5145 |
|
or first_time_month < 1 |
| 5146 |
|
or first_time_month > 12 |
| 5147 |
|
): |
| 5148 |
|
raise InvalidArgument( |
| 5149 |
|
"first_time_month argument of modify_schedule needs " |
| 5150 |
|
"to be an integer between 1 and 12" |
| 5151 |
|
) |
| 5152 |
|
|
| 5153 |
|
if first_time_year is None: |
| 5154 |
|
raise RequiredArgument( |
| 5155 |
|
"Setting first_time requires first_time_year argument" |
| 5156 |
|
) |
| 5157 |
|
elif ( |
| 5158 |
|
not isinstance(first_time_year, numbers.Integral) |
| 5159 |
|
or first_time_year < 1970 |
| 5160 |
|
): |
| 5161 |
|
raise InvalidArgument( |
| 5162 |
|
"first_time_year argument of create_schedule needs " |
| 5163 |
|
"to be an integer greater or equal 1970" |
| 5164 |
|
) |
| 5165 |
|
|
| 5166 |
|
_xmlftime = cmd.add_element("first_time") |
| 5167 |
|
_xmlftime.add_element("minute", str(first_time_minute)) |
| 5168 |
|
_xmlftime.add_element("hour", str(first_time_hour)) |
| 5169 |
|
_xmlftime.add_element("day_of_month", str(first_time_day_of_month)) |
| 5170 |
|
_xmlftime.add_element("month", str(first_time_month)) |
| 5171 |
|
_xmlftime.add_element("year", str(first_time_year)) |
| 5172 |
|
|
| 5173 |
|
if duration is not None: |
| 5174 |
|
if not duration_unit: |
| 5175 |
|
raise RequiredArgument( |
| 5176 |
|
"Setting duration requires duration_unit argument" |
| 5177 |
|
) |
| 5178 |
|
|
| 5179 |
|
if not duration_unit in TIME_UNITS: |
| 5180 |
|
raise InvalidArgument( |
| 5181 |
|
"duration_unit must be one of {units} but {actual} has " |
| 5182 |
|
"been passed".format( |
| 5183 |
|
units=", ".join(TIME_UNITS), actual=duration_unit |