/usr/share/pcsd/remote.rb is in pcs 0.9.149-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 | require 'json'
require 'uri'
require 'open4'
require 'set'
require 'timeout'
require 'rexml/document'
require 'pcs.rb'
require 'resource.rb'
require 'config.rb'
require 'cfgsync.rb'
require 'cluster_entity.rb'
require 'permissions.rb'
require 'auth.rb'
# Commands for remote access
def remote(params, request, auth_user)
remote_cmd_without_pacemaker = {
:status => method(:node_status),
:status_all => method(:status_all),
:cluster_status => method(:cluster_status_remote),
:auth => method(:auth),
:check_auth => method(:check_auth),
:setup_cluster => method(:setup_cluster),
:create_cluster => method(:create_cluster),
:get_quorum_info => method(:get_quorum_info),
:get_cib => method(:get_cib),
:get_corosync_conf => method(:get_corosync_conf_remote),
:set_cluster_conf => method(:set_cluster_conf),
:set_corosync_conf => method(:set_corosync_conf),
:get_sync_capabilities => method(:get_sync_capabilities),
:set_sync_options => method(:set_sync_options),
:get_configs => method(:get_configs),
:set_configs => method(:set_configs),
:set_certs => method(:set_certs),
:pcsd_restart => method(:remote_pcsd_restart),
:get_permissions => method(:get_permissions_remote),
:set_permissions => method(:set_permissions_remote),
:cluster_start => method(:cluster_start),
:cluster_stop => method(:cluster_stop),
:config_backup => method(:config_backup),
:config_restore => method(:config_restore),
:node_restart => method(:node_restart),
:node_standby => method(:node_standby),
:node_unstandby => method(:node_unstandby),
:cluster_enable => method(:cluster_enable),
:cluster_disable => method(:cluster_disable),
:resource_status => method(:resource_status),
:get_sw_versions => method(:get_sw_versions),
:node_available => method(:remote_node_available),
:add_node_all => lambda { |params_, request_, auth_user_|
remote_add_node(params_, request_, auth_user_, true)
},
:add_node => lambda { |params_, request_, auth_user_|
remote_add_node(params_, request_, auth_user_, false)
},
:remove_nodes => method(:remote_remove_nodes),
:remove_node => method(:remote_remove_node),
:cluster_destroy => method(:cluster_destroy),
:get_wizard => method(:get_wizard),
:wizard_submit => method(:wizard_submit),
:get_tokens => method(:get_tokens),
:get_cluster_tokens => method(:get_cluster_tokens),
:save_tokens => method(:save_tokens),
:get_cluster_properties_definition => method(:get_cluster_properties_definition)
}
remote_cmd_with_pacemaker = {
:resource_start => method(:resource_start),
:resource_stop => method(:resource_stop),
:resource_cleanup => method(:resource_cleanup),
:resource_form => method(:resource_form),
:fence_device_form => method(:fence_device_form),
:update_resource => method(:update_resource),
:update_fence_device => method(:update_fence_device),
:resource_metadata => method(:resource_metadata),
:fence_device_metadata => method(:fence_device_metadata),
:get_avail_resource_agents => method(:get_avail_resource_agents),
:get_avail_fence_agents => method(:get_avail_fence_agents),
:remove_resource => method(:remove_resource),
:add_constraint_remote => method(:add_constraint_remote),
:add_constraint_rule_remote => method(:add_constraint_rule_remote),
:add_constraint_set_remote => method(:add_constraint_set_remote),
:remove_constraint_remote => method(:remove_constraint_remote),
:remove_constraint_rule_remote => method(:remove_constraint_rule_remote),
:add_meta_attr_remote => method(:add_meta_attr_remote),
:add_group => method(:add_group),
:update_cluster_settings => method(:update_cluster_settings),
:add_fence_level_remote => method(:add_fence_level_remote),
:add_node_attr_remote => method(:add_node_attr_remote),
:add_acl_role => method(:add_acl_role_remote),
:remove_acl_roles => method(:remove_acl_roles_remote),
:add_acl => method(:add_acl_remote),
:remove_acl => method(:remove_acl_remote),
:resource_change_group => method(:resource_change_group),
:resource_master => method(:resource_master),
:resource_clone => method(:resource_clone),
:resource_unclone => method(:resource_unclone),
:resource_ungroup => method(:resource_ungroup),
:set_resource_utilization => method(:set_resource_utilization),
:set_node_utilization => method(:set_node_utilization)
}
command = params[:command].to_sym
if remote_cmd_without_pacemaker.include? command
return remote_cmd_without_pacemaker[command].call(
params, request, auth_user
)
elsif remote_cmd_with_pacemaker.include? command
if pacemaker_running?
return remote_cmd_with_pacemaker[command].call(params, request, auth_user)
else
return [200,'{"pacemaker_not_running":true}']
end
else
return [404, "Unknown Request"]
end
end
# provides remote cluster status to a local gui
def cluster_status_gui(auth_user, cluster_name, dont_update_config=false)
cluster_nodes = get_cluster_nodes(cluster_name)
status = cluster_status_from_nodes(auth_user, cluster_nodes, cluster_name)
unless status
return 403, 'Permission denied'
end
new_cluster_nodes = []
new_cluster_nodes += status[:corosync_offline] if status[:corosync_offline]
new_cluster_nodes += status[:corosync_online] if status[:corosync_online]
new_cluster_nodes += status[:pacemaker_offline] if status[:pacemaker_offline]
new_cluster_nodes += status[:pacemaker_online] if status[:pacemaker_online]
new_cluster_nodes.uniq!
if new_cluster_nodes.length > 0
config = PCSConfig.new(Cfgsync::PcsdSettings.from_file('{}').text())
if !(dont_update_config or config.cluster_nodes_equal?(cluster_name, new_cluster_nodes))
old_cluster_nodes = config.get_nodes(cluster_name)
$logger.info("Updating node list for: #{cluster_name} #{old_cluster_nodes}->#{new_cluster_nodes}")
config.update_cluster(cluster_name, new_cluster_nodes)
sync_config = Cfgsync::PcsdSettings.from_text(config.text())
# on version conflict just go on, config will be corrected eventually
# by displaying the cluster in the web UI
Cfgsync::save_sync_new_version(
sync_config, get_corosync_nodes(), $cluster_name, true
)
return cluster_status_gui(auth_user, cluster_name, true)
end
end
return JSON.generate(status)
end
# get cluster status and return it to a remote gui or other client
def cluster_status_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
cluster_name = $cluster_name
# If node is not in a cluster, return empty data
if not cluster_name or cluster_name.empty?
overview = {
:cluster_name => nil,
:error_list => [],
:warning_list => [],
:quorate => nil,
:status => 'unknown',
:node_list => [],
:resource_list => [],
}
return JSON.generate(overview)
end
cluster_nodes = get_nodes().flatten
status = cluster_status_from_nodes(auth_user, cluster_nodes, cluster_name)
unless status
return 403, 'Permission denied'
end
return JSON.generate(status)
end
def cluster_start(params, request, auth_user)
if params[:name]
code, response = send_request_with_token(
auth_user, params[:name], 'cluster_start', true
)
else
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
$logger.info "Starting Daemons"
output = `#{PCS} cluster start`
$logger.debug output
return output
end
end
def cluster_stop(params, request, auth_user)
if params[:name]
params_without_name = params.reject {|key, value|
key == "name" or key == :name
}
code, response = send_request_with_token(
auth_user, params[:name], 'cluster_stop', true, params_without_name
)
else
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
options = []
if params.has_key?("component")
if params["component"].downcase == "pacemaker"
options << "--pacemaker"
elsif params["component"].downcase == "corosync"
options << "--corosync"
end
end
options << "--force" if params["force"]
$logger.info "Stopping Daemons"
stdout, stderr, retval = run_cmd(
auth_user, PCS, "cluster", "stop", *options
)
if retval != 0
return [400, stderr.join]
else
return stdout.join
end
end
end
def config_backup(params, request, auth_user)
if params[:name]
code, response = send_request_with_token(
auth_user, params[:name], 'config_backup', true
)
else
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
$logger.info "Backup node configuration"
stdout, stderr, retval = run_cmd(auth_user, PCS, "config", "backup")
if retval == 0
$logger.info "Backup successful"
return [200, stdout]
end
$logger.info "Error during backup: #{stderr.join(' ').strip()}"
return [400, "Unable to backup node: #{stderr.join(' ')}"]
end
end
def config_restore(params, request, auth_user)
if params[:name]
code, response = send_request_with_token(
auth_user, params[:name], 'config_restore', true,
{:tarball => params[:tarball]}
)
else
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
$logger.info "Restore node configuration"
if params[:tarball] != nil and params[:tarball] != ""
out = ""
errout = ""
status = Open4::popen4(PCS, "config", "restore", "--local") { |pid, stdin, stdout, stderr|
stdin.print(params[:tarball])
stdin.close()
out = stdout.readlines()
errout = stderr.readlines()
}
retval = status.exitstatus
if retval == 0
$logger.info "Restore successful"
return "Succeeded"
else
$logger.info "Error during restore: #{errout.join(' ').strip()}"
return errout.length > 0 ? errout.join(' ').strip() : "Error"
end
else
$logger.info "Error: Invalid tarball"
return "Error: Invalid tarball"
end
end
end
def node_restart(params, request, auth_user)
if params[:name]
code, response = send_request_with_token(
auth_user, params[:name], 'node_restart', true
)
else
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
$logger.info "Restarting Node"
output = `/sbin/reboot`
$logger.debug output
return output
end
end
def node_standby(params, request, auth_user)
if params[:name]
code, response = send_request_with_token(
auth_user, params[:name], 'node_standby', true, {"node"=>params[:name]}
)
# data={"node"=>params[:name]} for backward compatibility with older versions of pcs/pcsd
else
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
$logger.info "Standby Node"
stdout, stderr, retval = run_cmd(auth_user, PCS, "cluster", "standby")
return stdout
end
end
def node_unstandby(params, request, auth_user)
if params[:name]
code, response = send_request_with_token(
auth_user, params[:name], 'node_unstandby', true, {"node"=>params[:name]}
)
# data={"node"=>params[:name]} for backward compatibility with older versions of pcs/pcsd
else
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
$logger.info "Unstandby Node"
stdout, stderr, retval = run_cmd(auth_user, PCS, "cluster", "unstandby")
return stdout
end
end
def cluster_enable(params, request, auth_user)
if params[:name]
code, response = send_request_with_token(
auth_user, params[:name], 'cluster_enable', true
)
else
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
success = enable_cluster(auth_user)
if not success
return JSON.generate({"error" => "true"})
end
return "Cluster Enabled"
end
end
def cluster_disable(params, request, auth_user)
if params[:name]
code, response = send_request_with_token(
auth_user, params[:name], 'cluster_disable', true
)
else
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
success = disable_cluster(auth_user)
if not success
return JSON.generate({"error" => "true"})
end
return "Cluster Disabled"
end
end
def get_quorum_info(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
if ISRHEL6
stdout_status, stderr_status, retval = run_cmd(
PCSAuth.getSuperuserAuth(), CMAN_TOOL, "status"
)
stdout_nodes, stderr_nodes, retval = run_cmd(
PCSAuth.getSuperuserAuth(),
CMAN_TOOL, "nodes", "-F", "id,type,votes,name"
)
if stderr_status.length > 0
return stderr_status.join
elsif stderr_nodes.length > 0
return stderr_nodes.join
else
return stdout_status.join + "\n---Votes---\n" + stdout_nodes.join
end
else
stdout, stderr, retval = run_cmd(
PCSAuth.getSuperuserAuth(), COROSYNC_QUORUMTOOL, "-p", "-s"
)
# retval is 0 on success if node is not in partition with quorum
# retval is 1 on error OR on success if node has quorum
if stderr.length > 0
return stderr.join
else
return stdout.join
end
end
end
def get_cib(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
cib, stderr, retval = run_cmd(auth_user, CIBADMIN, "-Ql")
if retval != 0
if not pacemaker_running?
return [400, '{"pacemaker_not_running":true}']
end
return [500, "Unable to get CIB: " + cib.to_s + stderr.to_s]
else
return [200, cib]
end
end
def get_corosync_conf_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
return get_corosync_conf()
end
def set_cluster_conf(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
if params[:cluster_conf] != nil and params[:cluster_conf].strip != ""
Cfgsync::ClusterConf.backup()
Cfgsync::ClusterConf.from_text(params[:cluster_conf]).save()
return 200, 'Updated cluster.conf...'
else
$logger.info "Invalid cluster.conf file"
return 400, 'Failed to update cluster.conf...'
end
end
def set_corosync_conf(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
if params[:corosync_conf] != nil and params[:corosync_conf].strip != ""
Cfgsync::CorosyncConf.backup()
Cfgsync::CorosyncConf.from_text(params[:corosync_conf]).save()
return 200, "Succeeded"
else
$logger.info "Invalid corosync.conf file"
return 400, "Failed"
end
end
def get_sync_capabilities(params, request, auth_user)
return JSON.generate({
'syncable_configs' => Cfgsync::get_cfg_classes_by_name().keys,
})
end
def set_sync_options(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
options = [
'sync_thread_pause', 'sync_thread_resume',
'sync_thread_disable', 'sync_thread_enable',
]
if params.keys.count { |key| options.include?(key) } != 1
return [400, 'Exactly one option has to be specified']
end
if params['sync_thread_disable']
if Cfgsync::ConfigSyncControl.sync_thread_disable($semaphore_cfgsync)
return 'sync thread disabled'
else
return [400, 'sync thread disable error']
end
end
if params['sync_thread_enable']
if Cfgsync::ConfigSyncControl.sync_thread_enable()
return 'sync thread enabled'
else
return [400, 'sync thread enable error']
end
end
if params['sync_thread_resume']
if Cfgsync::ConfigSyncControl.sync_thread_resume()
return 'sync thread resumed'
else
return [400, 'sync thread resume error']
end
end
if params['sync_thread_pause']
if Cfgsync::ConfigSyncControl.sync_thread_pause(
$semaphore_cfgsync, params['sync_thread_pause']
)
return 'sync thread paused'
else
return [400, 'sync thread pause error']
end
end
return [400, 'Exactly one option has to be specified']
end
def get_configs(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
if not $cluster_name or $cluster_name.empty?
return JSON.generate({'status' => 'not_in_cluster'})
end
if params[:cluster_name] != $cluster_name
return JSON.generate({'status' => 'wrong_cluster_name'})
end
out = {
'status' => 'ok',
'cluster_name' => $cluster_name,
'configs' => {},
}
Cfgsync::get_configs_local.each { |name, cfg|
out['configs'][cfg.class.name] = {
'type' => 'file',
'text' => cfg.text,
}
}
return JSON.generate(out)
end
def set_configs(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
return JSON.generate({'status' => 'bad_json'}) if not params['configs']
begin
configs_json = JSON.parse(params['configs'])
rescue JSON::ParserError
return JSON.generate({'status' => 'bad_json'})
end
has_cluster = !($cluster_name == nil or $cluster_name.empty?)
if has_cluster and $cluster_name != configs_json['cluster_name']
return JSON.generate({'status' => 'wrong_cluster_name'})
end
$semaphore_cfgsync.synchronize {
force = configs_json['force']
remote_configs, unknown_cfg_names = Cfgsync::sync_msg_to_configs(configs_json)
local_configs = Cfgsync::get_configs_local
result = {}
unknown_cfg_names.each { |name| result[name] = 'not_supported' }
remote_configs.each { |name, remote_cfg|
begin
# Save a remote config if it is a newer version than local. If the config
# is not present on a local node, the node is beeing added to a cluster,
# so we need to save the config as well.
if force or not local_configs.key?(name) or remote_cfg > local_configs[name]
local_configs[name].class.backup() if local_configs.key?(name)
remote_cfg.save()
result[name] = 'accepted'
elsif remote_cfg == local_configs[name]
# Someone wants this node to have a config that it already has.
# So the desired state is met and the result is a success then.
result[name] = 'accepted'
else
result[name] = 'rejected'
end
rescue => e
$logger.error("Error saving config '#{name}': #{e}")
result[name] = 'error'
end
}
return JSON.generate({'status' => 'ok', 'result' => result})
}
end
def set_certs(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
ssl_cert = (params['ssl_cert'] || '').strip
ssl_key = (params['ssl_key'] || '').strip
if ssl_cert.empty? and !ssl_key.empty?
return [400, 'cannot save ssl certificate without ssl key']
end
if !ssl_cert.empty? and ssl_key.empty?
return [400, 'cannot save ssl key without ssl certificate']
end
if !ssl_cert.empty? and !ssl_key.empty?
ssl_errors = verify_cert_key_pair(ssl_cert, ssl_key)
if ssl_errors and !ssl_errors.empty?
return [400, ssl_errors.join]
end
begin
write_file_lock(CRT_FILE, 0700, ssl_cert)
write_file_lock(KEY_FILE, 0700, ssl_key)
rescue => e
# clean the files if we ended in the middle
# the files will be regenerated on next pcsd start
FileUtils.rm(CRT_FILE, {:force => true})
FileUtils.rm(KEY_FILE, {:force => true})
return [400, "cannot save ssl files: #{e}"]
end
end
if params['cookie_secret']
cookie_secret = params['cookie_secret'].strip
if !cookie_secret.empty?
begin
write_file_lock(COOKIE_FILE, 0700, cookie_secret)
rescue => e
return [400, "cannot save cookie secret: #{e}"]
end
end
end
return [200, 'success']
end
def get_permissions_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::GRANT)
return 403, 'Permission denied'
end
pcs_config = PCSConfig.new(Cfgsync::PcsdSettings.from_file('{}').text())
data = {
'user_types' => Permissions::get_user_types(),
'permission_types' => Permissions::get_permission_types(),
'permissions_dependencies' => Permissions::permissions_dependencies(),
'users_permissions' => pcs_config.permissions_local.to_hash(),
}
return [200, JSON.generate(data)]
end
def set_permissions_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::GRANT)
return 403, 'Permission denied'
end
begin
data = JSON.parse(params['json_data'])
rescue JSON::ParserError
return 400, JSON.generate({'status' => 'bad_json'})
end
user_set = {}
perm_list = []
full_users_new = Set.new
perm_deps = Permissions.permissions_dependencies
if data['permissions']
data['permissions'].each { |key, perm|
name = (perm['name'] || '').strip
type = (perm['type'] || '').strip
return [400, 'Missing user name'] if '' == name
return [400, 'Missing user type'] if '' == type
if not Permissions::is_user_type(type)
return [400, "Unknown user type '#{type}'"]
end
if user_set.key?([name, type])
return [400, "Duplicate permissions for #{type} #{name}"]
end
user_set[[name, type]] = true
allow = []
if perm['allow']
perm['allow'].each { |perm_allow, enabled|
next if "1" != enabled
if not Permissions::is_permission_type(perm_allow)
return [400, "Unknown permission '#{perm_allow}'"]
end
if Permissions::FULL == perm_allow
full_users_new << [type, name]
end
allow << perm_allow
# Explicitly save dependant permissions. That way if the dependency is
# changed in the future it won't revoke permissions which were once
# granted.
if perm_deps['also_allows'] and perm_deps['also_allows'][perm_allow]
allow += perm_deps['also_allows'][perm_allow]
end
}
end
perm_list << Permissions::EntityPermissions.new(type, name, allow.uniq())
}
end
perm_set = Permissions::PermissionsSet.new(perm_list)
full_users_old = Set.new
pcs_config = PCSConfig.new(Cfgsync::PcsdSettings.from_file('{}').text())
pcs_config.permissions_local.entity_permissions_list.each{ |entity_perm|
if entity_perm.allow_list.include?(Permissions::FULL)
full_users_old << [entity_perm.type, entity_perm.name]
end
}
if full_users_new != full_users_old
label = 'Full'
Permissions.get_permission_types.each { |perm_type|
if Permissions::FULL == perm_type['code']
label = perm_type['label']
break
end
}
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return [
403,
"Permission denied\nOnly #{SUPERUSER} and users with #{label} "\
+ "permission can grant or revoke #{label} permission."
]
end
end
2.times {
pcs_config = PCSConfig.new(Cfgsync::PcsdSettings.from_file('{}').text())
pcs_config.permissions_local = perm_set
sync_config = Cfgsync::PcsdSettings.from_text(pcs_config.text())
pushed, _ = Cfgsync::save_sync_new_version(
sync_config, get_corosync_nodes(), $cluster_name, true
)
return [200, 'Permissions saved'] if pushed
}
return 400, 'Unable to save permissions'
end
def remote_pcsd_restart(params, request, auth_user)
pcsd_restart()
return [200, 'success']
end
def get_sw_versions(params, request, auth_user)
versions = {
"rhel" => get_rhel_version(),
"pcs" => get_pcsd_version(),
"pacemaker" => get_pacemaker_version(),
"corosync" => get_corosync_version(),
"cman" => get_cman_version(),
}
return JSON.generate(versions)
end
def remote_node_available(params, request, auth_user)
if (not ISRHEL6 and File.exist?(Cfgsync::CorosyncConf.file_path)) or (ISRHEL6 and File.exist?(Cfgsync::ClusterConf.file_path)) or File.exist?("/var/lib/pacemaker/cib/cib.xml")
return JSON.generate({:node_available => false})
end
return JSON.generate({:node_available => true})
end
def remote_add_node(params, request, auth_user, all=false)
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
auto_start = false
if params[:auto_start] and params[:auto_start] == "1"
auto_start = true
end
if params[:new_nodename] != nil
node = params[:new_nodename]
if params[:new_ring1addr] != nil
node += ',' + params[:new_ring1addr]
end
retval, output = add_node(auth_user, node, all, auto_start)
end
if retval == 0
return [200, JSON.generate([retval, get_corosync_conf()])]
end
return [400,output]
end
def remote_remove_nodes(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
count = 0
out = ""
node_list = []
options = []
while params["nodename-" + count.to_s]
node_list << params["nodename-" + count.to_s]
count = count + 1
end
options << "--force" if params["force"]
cur_node = get_current_node_name()
if i = node_list.index(cur_node)
node_list.push(node_list.delete_at(i))
end
# stop the nodes at once in order to:
# - prevent resources from moving pointlessly
# - get possible quorum loss warning
stop_params = node_list + options
stdout, stderr, retval = run_cmd(
auth_user, PCS, "cluster", "stop", *stop_params
)
if retval != 0
return [400, stderr.join]
end
node_list.each {|node|
retval, output = remove_node(auth_user, node, true)
out = out + output.join("\n")
}
config = PCSConfig.new(Cfgsync::PcsdSettings.from_file('{}').text())
if config.get_nodes($cluster_name) == nil or config.get_nodes($cluster_name).length == 0
return [200,"No More Nodes"]
end
return out
end
def remote_remove_node(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
if params[:remove_nodename] != nil
retval, output = remove_node(auth_user, params[:remove_nodename])
else
return 400, "No nodename specified"
end
if retval == 0
return JSON.generate([retval, get_corosync_conf()])
end
return JSON.generate([retval,output])
end
def setup_cluster(params, request, auth_user)
if not allowed_for_superuser(auth_user)
return 403, 'Permission denied'
end
$logger.info("Setting up cluster: " + params.inspect)
nodes_rrp = params[:nodes].split(';')
options = []
myoptions = JSON.parse(params[:options])
transport_udp = false
options_udp = []
myoptions.each { |o,v|
if ["wait_for_all", "last_man_standing", "auto_tie_breaker"].include?(o)
options << "--" + o + "=1"
end
options << "--" + o + "=" + v if [
"token", "token_coefficient", "join", "consensus", "miss_count_const",
"fail_recv_const", "last_man_standing_window",
].include?(o)
if o == "transport" and v == "udp"
options << "--transport=udp"
transport_udp = true
end
if o == "transport" and v == "udpu"
options << "--transport=udpu"
transport_udp = false
end
if ["addr0", "addr1", "mcast0", "mcast1", "mcastport0", "mcastport1", "ttl0", "ttl1"].include?(o)
options_udp << "--" + o + "=" + v
end
if ["broadcast0", "broadcast1"].include?(o)
options_udp << "--" + o
end
if o == "ipv6"
options << "--ipv6"
end
}
if transport_udp
nodes = []
nodes_rrp.each { |node| nodes << node.split(',')[0] }
else
nodes = nodes_rrp
end
nodes_options = nodes + options
nodes_options += options_udp if transport_udp
stdout, stderr, retval = run_cmd(
auth_user, PCS, "cluster", "setup", "--enable", "--start",
"--name", params[:clustername], *nodes_options
)
if retval != 0
return [
400,
(stdout + [''] + stderr).collect { |line| line.rstrip() }.join("\n")
]
end
return 200
end
def create_cluster(params, request, auth_user)
if not allowed_for_superuser(auth_user)
return 403, 'Permission denied'
end
if set_corosync_conf(params, request, auth_user)
cluster_start(params, request, auth_user)
else
return "Failed"
end
end
def node_status(params, request, auth_user)
if params[:node] and params[:node] != '' and params[:node] !=
$cur_node_name and !params[:redirected]
return send_request_with_token(
auth_user,
params[:node],
'status?redirected=1',
false,
params.select { |k,_|
[:version, :operations].include?(k)
}
)
end
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
cib_dom = get_cib_dom(auth_user)
crm_dom = get_crm_mon_dom(auth_user)
status = get_node_status(auth_user, cib_dom)
resources = get_resources(
cib_dom,
crm_dom,
(params[:operations] and params[:operations] == '1')
)
node = ClusterEntity::Node.load_current_node(crm_dom)
_,_,not_authorized_nodes = check_gui_status_of_nodes(
auth_user,
status[:known_nodes],
false,
3
)
if not_authorized_nodes.length > 0
node.warning_list << {
:message => 'Not authorized against node(s) ' +
not_authorized_nodes.join(', '),
:type => 'nodes_not_authorized',
:node_list => not_authorized_nodes,
}
end
version = params[:version] || '1'
if version == '2'
status[:node] = node.to_status(version)
resource_list = nil
if resources
resource_list = []
resources.each do |r|
resource_list << r.to_status(version)
end
end
status[:resource_list] = resource_list
return JSON.generate(status)
end
resource_list = []
resources.each do |r|
resource_list.concat(r.to_status('1'))
end
cluster_settings = (status[:cluster_settings].empty?) ?
{'error' => 'Unable to get configuration settings'} :
status[:cluster_settings]
node_attr = {}
status[:node_attr].each { |node, attrs|
node_attr[node] = []
attrs.each { |attr|
node_attr[node] << {
:key => attr[:name],
:value => attr[:value]
}
}
}
old_status = {
:uptime => node.uptime,
:corosync => node.corosync,
:pacemaker => node.pacemaker,
:cman => node.cman,
:corosync_enabled => node.corosync_enabled,
:pacemaker_enabled => node.pacemaker_enabled,
:pcsd_enabled => node.pcsd_enabled,
:corosync_online => status[:corosync_online],
:corosync_offline => status[:corosync_offline],
:pacemaker_online => status[:pacemaker_online],
:pacemaker_offline => status[:pacemaker_offline],
:pacemaker_standby => status[:pacemaker_standby],
:cluster_name => status[:cluster_name],
:resources => resource_list,
:groups => status[:groups],
:constraints => status[:constraints],
:cluster_settings => cluster_settings,
:node_id => node.id,
:node_attr => node_attr,
:fence_levels => status[:fence_levels],
:need_ring1_address => status[:need_ring1_address],
:is_cman_with_udpu_transport => status[:is_cman_with_udpu_transport],
:acls => status[:acls],
:username => status[:username]
}
return JSON.generate(old_status)
end
def status_all(params, request, auth_user, nodes=[], dont_update_config=false)
if nodes == nil
return JSON.generate({"error" => "true"})
end
final_response = {}
threads = []
forbidden_nodes = {}
nodes.each {|node|
threads << Thread.new {
code, response = send_request_with_token(auth_user, node, 'status')
if 403 == code
forbidden_nodes[node] = true
end
begin
final_response[node] = JSON.parse(response)
rescue JSON::ParserError => e
final_response[node] = {"bad_json" => true}
$logger.info("ERROR: Parse Error when parsing status JSON from #{node}")
end
if final_response[node] and final_response[node]["notoken"] == true
$logger.error("ERROR: bad token for #{node}")
end
}
}
threads.each { |t| t.join }
if forbidden_nodes.length > 0
return 403, 'Permission denied'
end
# Get full list of nodes and see if we need to update the configuration
node_list = []
final_response.each { |fr,n|
node_list += n["corosync_offline"] if n["corosync_offline"]
node_list += n["corosync_online"] if n["corosync_online"]
node_list += n["pacemaker_offline"] if n["pacemaker_offline"]
node_list += n["pacemaker_online"] if n["pacemaker_online"]
}
node_list.uniq!
if node_list.length > 0
config = PCSConfig.new(Cfgsync::PcsdSettings.from_file('{}').text())
old_node_list = config.get_nodes(params[:cluster])
if !(dont_update_config or config.cluster_nodes_equal?(params[:cluster], node_list))
$logger.info("Updating node list for: #{params[:cluster]} #{old_node_list}->#{node_list}")
config.update_cluster(params[:cluster], node_list)
sync_config = Cfgsync::PcsdSettings.from_text(config.text())
# on version conflict just go on, config will be corrected eventually
# by displaying the cluster in the web UI
Cfgsync::save_sync_new_version(
sync_config, get_corosync_nodes(), $cluster_name, true
)
return status_all(params, request, auth_user, node_list, true)
end
end
$logger.debug("NODE LIST: " + node_list.inspect)
return JSON.generate(final_response)
end
def clusters_overview(params, request, auth_user)
cluster_map = {}
forbidden_clusters = {}
threads = []
config = PCSConfig.new(Cfgsync::PcsdSettings.from_file('{}').text())
config.clusters.each { |cluster|
threads << Thread.new {
cluster_map[cluster.name] = {
'cluster_name' => cluster.name,
'error_list' => [
{'message' => 'Unable to connect to the cluster. Request timeout.'}
],
'warning_list' => [],
'status' => 'unknown',
'node_list' => get_default_overview_node_list(cluster.name),
'resource_list' => []
}
overview_cluster = nil
online, offline, not_authorized_nodes = check_gui_status_of_nodes(
auth_user,
get_cluster_nodes(cluster.name),
false,
3
)
not_supported = false
forbidden = false
cluster_nodes_auth = (online + offline).uniq
cluster_nodes_all = (cluster_nodes_auth + not_authorized_nodes).uniq
nodes_not_in_cluster = []
for node in cluster_nodes_auth
code, response = send_request_with_token(
auth_user, node, 'cluster_status', true, {}, true, nil, 8
)
if code == 404
not_supported = true
next
end
if 403 == code
forbidden = true
forbidden_clusters[cluster.name] = true
break
end
begin
parsed_response = JSON.parse(response)
if parsed_response['noresponse'] or parsed_response['pacemaker_not_running']
next
elsif parsed_response['notoken'] or parsed_response['notauthorized']
next
elsif parsed_response['cluster_name'] != cluster.name
# queried node is not in the cluster (any more)
nodes_not_in_cluster << node
next
else
overview_cluster = parsed_response
break
end
rescue JSON::ParserError
end
end
if cluster_nodes_all.sort == nodes_not_in_cluster.sort
overview_cluster = {
'cluster_name' => cluster.name,
'error_list' => [],
'warning_list' => [],
'status' => 'unknown',
'node_list' => [],
'resource_list' => []
}
end
if not overview_cluster
overview_cluster = {
'cluster_name' => cluster.name,
'error_list' => [],
'warning_list' => [],
'status' => 'unknown',
'node_list' => get_default_overview_node_list(cluster.name),
'resource_list' => []
}
if not_supported
overview_cluster['warning_list'] = [
{
'message' => 'Cluster is running an old version of pcs/pcsd which does not provide data for the dashboard.',
},
]
else
if forbidden
overview_cluster['error_list'] = [
{
'message' => 'You do not have permissions to view the cluster.',
'type' => 'forbidden',
},
]
overview_cluster['node_list'] = []
else
overview_cluster['error_list'] = [
{
'message' => 'Unable to connect to the cluster.',
},
]
end
end
end
if not_authorized_nodes.length > 0
overview_cluster['warning_list'] << {
'message' => 'GUI is not authorized against node(s) '\
+ not_authorized_nodes.join(', '),
'type' => 'nodes_not_authorized',
'node_list' => not_authorized_nodes,
}
end
overview_cluster['node_list'].each { |node|
if node['status_version'] == '1'
overview_cluster['warning_list'] << {
:message => 'Some nodes are running old version of pcs/pcsd.'
}
break
end
}
cluster_map[cluster.name] = overview_cluster
}
}
begin
Timeout::timeout(18) {
threads.each { |t| t.join }
}
rescue Timeout::Error
threads.each { |t| t.exit }
end
# update clusters in PCSConfig
not_current_data = false
config = PCSConfig.new(Cfgsync::PcsdSettings.from_file('{}').text())
cluster_map.each { |cluster, values|
next if forbidden_clusters[cluster]
nodes = []
values['node_list'].each { |node|
nodes << node['name']
}
if !config.cluster_nodes_equal?(cluster, nodes)
$logger.info("Updating node list for: #{cluster} #{config.get_nodes(cluster)}->#{nodes}")
config.update_cluster(cluster, nodes)
not_current_data = true
end
}
if not_current_data
sync_config = Cfgsync::PcsdSettings.from_text(config.text())
# on version conflict just go on, config will be corrected eventually
# by displaying the cluster in the web UI
Cfgsync::save_sync_new_version(
sync_config, get_corosync_nodes(), $cluster_name, true
)
end
overview = {
'not_current_data' => not_current_data,
'cluster_list' => cluster_map.values.sort { |a, b|
a['clustername'] <=> b['clustername']
}
}
return JSON.generate(overview)
end
def auth(params, request, auth_user)
token = PCSAuth.validUser(params['username'],params['password'], true)
# If we authorized to this machine, attempt to authorize everywhere
node_list = []
if token and params["bidirectional"]
params.each { |k,v|
if k.start_with?("node-")
node_list.push(v)
end
}
if node_list.length > 0
pcs_auth(
auth_user, node_list, params['username'], params['password'],
params["force"] == "1"
)
end
end
return token
end
# If we get here, we're already authorized
def check_auth(params, request, auth_user)
if params.include?("check_auth_only")
return [200, "{\"success\":true}"]
end
return JSON.generate({
'success' => true,
'node_list' => get_token_node_list,
})
end
# not used anymore, left here for backward compatability reasons
def resource_status(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
resource_id = params[:resource]
@resources,@groups = getResourcesGroups(auth_user)
location = ""
res_status = ""
@resources.each {|r|
if r.id == resource_id
if r.failed
res_status = "Failed"
elsif !r.active
res_status = "Inactive"
else
res_status = "Running"
end
if r.nodes.length != 0
location = r.nodes[0].name
break
end
end
}
status = {"location" => location, "status" => res_status}
return JSON.generate(status)
end
def resource_stop(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
stdout, stderr, retval = run_cmd(
auth_user, PCS, "resource", "disable", params[:resource]
)
if retval == 0
return JSON.generate({"success" => "true"})
else
return JSON.generate({"error" => "true", "stdout" => stdout, "stderror" => stderr})
end
end
def resource_cleanup(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
stdout, stderr, retval = run_cmd(
auth_user, PCS, "resource", "cleanup", params[:resource]
)
if retval == 0
return JSON.generate({"success" => "true"})
else
return JSON.generate({"error" => "true", "stdout" => stdout, "stderror" => stderr})
end
end
def resource_start(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
stdout, stderr, retval = run_cmd(
auth_user, PCS, "resource", "enable", params[:resource]
)
if retval == 0
return JSON.generate({"success" => "true"})
else
return JSON.generate({"error" => "true", "stdout" => stdout, "stderror" => stderr})
end
end
def resource_form(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
cib_dom = get_cib_dom(auth_user)
@cur_resource = get_resource_by_id(params[:resource], cib_dom)
@groups = get_resource_groups(cib_dom)
@version = params[:version]
if @cur_resource.instance_of?(ClusterEntity::Primitive) and !@cur_resource.stonith
@cur_resource_group = @cur_resource.get_group
@cur_resource_clone = @cur_resource.get_clone
@cur_resource_ms = @cur_resource.get_master
@resource = ResourceAgent.new(@cur_resource.agentname)
if @cur_resource.provider == 'heartbeat'
@resource.required_options, @resource.optional_options, @resource.info = getResourceMetadata(auth_user, HEARTBEAT_AGENTS_DIR + @cur_resource.type)
elsif @cur_resource.provider == 'pacemaker'
@resource.required_options, @resource.optional_options, @resource.info = getResourceMetadata(auth_user, PACEMAKER_AGENTS_DIR + @cur_resource.type)
elsif @cur_resource._class == 'nagios'
@resource.required_options, @resource.optional_options, @resource.info = getResourceMetadata(auth_user, NAGIOS_METADATA_DIR + @cur_resource.type + '.xml')
end
@existing_resource = true
if @resource
erb :resourceagentform
else
"Can't find resource"
end
else
"Resource #{params[:resource]} doesn't exist"
end
end
def fence_device_form(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
@cur_resource = get_resource_by_id(params[:resource], get_cib_dom(auth_user))
if @cur_resource.instance_of?(ClusterEntity::Primitive) and @cur_resource.stonith
@resource_agents = getFenceAgents(auth_user, @cur_resource.agentname)
@existing_resource = true
@fenceagent = @resource_agents[@cur_resource.type]
erb :fenceagentform
else
"Can't find fence device"
end
end
# Creates resource if params[:resource_id] is not set
def update_resource (params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
param_line = getParamList(params)
if not params[:resource_id]
out, stderr, retval = run_cmd(
auth_user,
PCS, "resource", "create", params[:name], params[:resource_type],
*param_line
)
if retval != 0
return JSON.generate({"error" => "true", "stderr" => stderr, "stdout" => out})
end
if params[:resource_group] and params[:resource_group] != ""
run_cmd(
auth_user,
PCS, "resource","group", "add", params[:resource_group], params[:name]
)
resource_group = params[:resource_group]
end
if params[:resource_clone] and params[:resource_clone] != ""
name = resource_group ? resource_group : params[:name]
run_cmd(auth_user, PCS, "resource", "clone", name)
elsif params[:resource_ms] and params[:resource_ms] != ""
name = resource_group ? resource_group : params[:name]
run_cmd(auth_user, PCS, "resource", "master", name)
end
return JSON.generate({})
end
if param_line.length != 0
# If it's a clone resource we strip off everything after the last ':'
if params[:resource_clone]
params[:resource_id].sub!(/(.*):.*/,'\1')
end
run_cmd(
auth_user, PCS, "resource", "update", params[:resource_id], *param_line
)
end
if params[:resource_group]
if params[:resource_group] == ""
if params[:_orig_resource_group] != ""
run_cmd(
auth_user, PCS, "resource", "group", "remove",
params[:_orig_resource_group], params[:resource_id]
)
end
else
run_cmd(
auth_user, PCS, "resource", "group", "add", params[:resource_group],
params[:resource_id]
)
end
end
if params[:resource_clone] and params[:_orig_resource_clone] == "false"
run_cmd(auth_user, PCS, "resource", "clone", params[:resource_id])
end
if params[:resource_ms] and params[:_orig_resource_ms] == "false"
run_cmd(auth_user, PCS, "resource", "master", params[:resource_id])
end
if params[:_orig_resource_clone] == "true" and not params[:resource_clone]
run_cmd(
auth_user, PCS, "resource", "unclone", params[:resource_id].sub(/:.*/,'')
)
end
if params[:_orig_resource_ms] == "true" and not params[:resource_ms]
run_cmd(
auth_user, PCS, "resource", "unclone", params[:resource_id].sub(/:.*/,'')
)
end
return JSON.generate({})
end
def update_fence_device(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
$logger.info "Updating fence device"
$logger.info params
param_line = getParamList(params)
$logger.info param_line
if not params[:resource_id]
out, stderr, retval = run_cmd(
auth_user,
PCS, "stonith", "create", params[:name], params[:resource_type],
*param_line
)
if retval != 0
return JSON.generate({"error" => "true", "stderr" => stderr, "stdout" => out})
end
return "{}"
end
if param_line.length != 0
out, stderr, retval = run_cmd(
auth_user, PCS, "stonith", "update", params[:resource_id], *param_line
)
if retval != 0
return JSON.generate({"error" => "true", "stderr" => stderr, "stdout" => out})
end
end
return "{}"
end
def get_avail_resource_agents(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
agents = getResourceAgents(auth_user)
return JSON.generate(agents)
end
def get_avail_fence_agents(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
agents = getFenceAgents(auth_user)
return JSON.generate(agents)
end
def resource_metadata(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
return 200 if not params[:resourcename] or params[:resourcename] == ""
resource_name = params[:resourcename][params[:resourcename].rindex(':')+1..-1]
class_provider = params[:resourcename][0,params[:resourcename].rindex(':')]
@resource = ResourceAgent.new(params[:resourcename])
if class_provider == "ocf:heartbeat"
@resource.required_options, @resource.optional_options, @resource.info = getResourceMetadata(auth_user, HEARTBEAT_AGENTS_DIR + resource_name)
elsif class_provider == "ocf:pacemaker"
@resource.required_options, @resource.optional_options, @resource.info = getResourceMetadata(auth_user, PACEMAKER_AGENTS_DIR + resource_name)
elsif class_provider == 'nagios'
@resource.required_options, @resource.optional_options, @resource.info = getResourceMetadata(auth_user, NAGIOS_METADATA_DIR + resource_name + '.xml')
end
@new_resource = params[:new]
@resources, @groups = getResourcesGroups(auth_user)
erb :resourceagentform
end
def fence_device_metadata(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
return 200 if not params[:resourcename] or params[:resourcename] == ""
@fenceagent = FenceAgent.new(params[:resourcename])
@fenceagent.required_options, @fenceagent.optional_options, @fenceagent.advanced_options, @fenceagent.info = getFenceAgentMetadata(auth_user, params[:resourcename])
@new_fenceagent = params[:new]
erb :fenceagentform
end
def remove_resource(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
force = params['force']
no_error_if_not_exists = params.include?('no_error_if_not_exists')
errors = ""
params.each { |k,v|
if k.index("resid-") == 0
resid = k.gsub('resid-', '')
command = [PCS, 'resource', 'delete', resid]
command << '--force' if force
out, errout, retval = run_cmd(auth_user, *command)
if retval != 0
unless out.index(" does not exist.") != -1 and no_error_if_not_exists
errors += errout.join(' ').strip + "\n"
end
end
end
}
errors.strip!
if errors == ""
return 200
else
$logger.info("Remove resource errors:\n"+errors)
return [400, errors]
end
end
def add_fence_level_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
retval, stdout, stderr = add_fence_level(
auth_user, params["level"], params["devices"], params["node"], params["remove"]
)
if retval == 0
return [200, "Successfully added fence level"]
else
return [400, stderr]
end
end
def add_node_attr_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
retval = add_node_attr(
auth_user, params["node"], params["key"], params["value"]
)
# retval = 2 if removing attr which doesn't exist
if retval == 0 or retval == 2
return [200, "Successfully added attribute to node"]
else
return [400, "Error adding attribute to node"]
end
end
def add_acl_role_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::GRANT)
return 403, 'Permission denied'
end
retval = add_acl_role(auth_user, params["name"], params["description"])
if retval == ""
return [200, "Successfully added ACL role"]
else
return [
400,
retval.include?("cib_replace failed") ? "Error adding ACL role" : retval
]
end
end
def remove_acl_roles_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::GRANT)
return 403, 'Permission denied'
end
errors = ""
params.each { |name, value|
if name.index("role-") == 0
out, errout, retval = run_cmd(
auth_user, PCS, "acl", "role", "delete", value.to_s, "--autodelete"
)
if retval != 0
errors += "Unable to remove role #{value}"
unless errout.include?("cib_replace failure")
errors += ": #{errout.join(" ").strip()}"
end
errors += "\n"
$logger.info errors
end
end
}
if errors == ""
return [200, "Successfully removed ACL roles"]
else
return [400, errors]
end
end
def add_acl_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::GRANT)
return 403, 'Permission denied'
end
if params["item"] == "permission"
retval = add_acl_permission(
auth_user,
params["role_id"], params["type"], params["xpath_id"], params["query_id"]
)
elsif (params["item"] == "user") or (params["item"] == "group")
retval = add_acl_usergroup(
auth_user, params["role_id"], params["item"], params["usergroup"]
)
else
retval = "Error: Unknown adding request"
end
if retval == ""
return [200, "Successfully added permission to role"]
else
return [
400,
retval.include?("cib_replace failed") ? "Error adding permission" : retval
]
end
end
def remove_acl_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::GRANT)
return 403, 'Permission denied'
end
if params["item"] == "permission"
retval = remove_acl_permission(auth_user, params["acl_perm_id"])
elsif params["item"] == "usergroup"
retval = remove_acl_usergroup(
auth_user, params["role_id"],params["usergroup_id"]
)
else
retval = "Error: Unknown removal request"
end
if retval == ""
return [200, "Successfully removed permission from role"]
else
return [400, retval]
end
end
def add_meta_attr_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
retval = add_meta_attr(
auth_user, params["res_id"], params["key"],params["value"]
)
if retval == 0
return [200, "Successfully added meta attribute"]
else
return [400, "Error adding meta attribute"]
end
end
def add_constraint_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
case params["c_type"]
when "loc"
retval, error = add_location_constraint(
auth_user,
params["res_id"], params["node_id"], params["score"], params["force"],
!params['disable_autocorrect']
)
when "ord"
resA = params["res_id"]
resB = params["target_res_id"]
actionA = params['res_action']
actionB = params['target_action']
if params["order"] == "before"
resA, resB = resB, resA
actionA, actionB = actionB, actionA
end
retval, error = add_order_constraint(
auth_user,
resA, resB, actionA, actionB, params["score"], true, params["force"],
!params['disable_autocorrect']
)
when "col"
resA = params["res_id"]
resB = params["target_res_id"]
score = params["score"]
if params["colocation_type"] == "apart"
if score.length > 0 and score[0] != "-"
score = "-" + score
elsif score == ""
score = "-INFINITY"
end
end
retval, error = add_colocation_constraint(
auth_user,
resA, resB, score, params["force"], !params['disable_autocorrect']
)
else
return [400, "Unknown constraint type: #{params['c_type']}"]
end
if retval == 0
return [200, "Successfully added constraint"]
else
return [400, "Error adding constraint: #{error}"]
end
end
def add_constraint_rule_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
if params["c_type"] == "loc"
retval, error = add_location_constraint_rule(
auth_user,
params["res_id"], params["rule"], params["score"], params["force"],
!params['disable_autocorrect']
)
else
return [400, "Unknown constraint type: #{params["c_type"]}"]
end
if retval == 0
return [200, "Successfully added constraint"]
else
return [400, "Error adding constraint: #{error}"]
end
end
def add_constraint_set_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
case params["c_type"]
when "ord"
retval, error = add_order_set_constraint(
auth_user,
params["resources"].values, params["force"], !params['disable_autocorrect']
)
else
return [400, "Unknown constraint type: #{params["c_type"]}"]
end
if retval == 0
return [200, "Successfully added constraint"]
else
return [400, "Error adding constraint: #{error}"]
end
end
def remove_constraint_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
if params[:constraint_id]
retval = remove_constraint(auth_user, params[:constraint_id])
if retval == 0
return "Constraint #{params[:constraint_id]} removed"
else
return [400, "Error removing constraint: #{params[:constraint_id]}"]
end
else
return [400,"Bad Constraint Options"]
end
end
def remove_constraint_rule_remote(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
if params[:rule_id]
retval = remove_constraint_rule(auth_user, params[:rule_id])
if retval == 0
return "Constraint rule #{params[:rule_id]} removed"
else
return [400, "Error removing constraint rule: #{params[:rule_id]}"]
end
else
return [400, "Bad Constraint Rule Options"]
end
end
def add_group(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
rg = params["resource_group"]
resources = params["resources"]
output, errout, retval = run_cmd(
auth_user, PCS, "resource", "group", "add", rg, *(resources.split(" "))
)
if retval == 0
return 200
else
return 400, errout
end
end
def update_cluster_settings(params, request, auth_user)
properties = params['config']
to_update = []
current = getAllSettings(auth_user)
# We need to be able to set cluster properties also from older version GUI.
# This code handles proper processing of checkboxes.
# === backward compatibility layer start ===
params['hidden'].each { |prop, val|
next if prop == 'hidden_input'
unless properties.include?(prop)
properties[prop] = val
to_update << prop
end
}
# === backward compatibility layer end ===
properties.each { |prop, val|
val.strip!
if not current.include?(prop) and val != '' # add
to_update << prop
elsif current.include?(prop) and val == '' # remove
to_update << prop
elsif current.include?(prop) and current[prop] != val # update
to_update << prop
end
}
if to_update.count { |x| x.downcase == 'enable-acl' } > 0
if not allowed_for_local_cluster(auth_user, Permissions::GRANT)
return 403, 'Permission denied'
end
end
if to_update.count { |x| x.downcase != 'enable-acl' } > 0
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
end
if to_update.empty?
$logger.info('No properties to update')
else
cmd_args = []
to_update.each { |prop|
cmd_args << "#{prop.downcase}=#{properties[prop]}"
}
stdout, stderr, retval = run_cmd(
auth_user, PCS, 'property', 'set', *cmd_args
)
if retval != 0
return [400, stderr.join('').gsub(', (use --force to override)', '')]
end
end
return [200, "Update Successful"]
end
def cluster_destroy(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
out, errout, retval = run_cmd(auth_user, PCS, "cluster", "destroy")
if retval == 0
return [200, "Successfully destroyed cluster"]
else
return [400, "Error destroying cluster:\n#{out}\n#{errout}\n#{retval}\n"]
end
end
def get_wizard(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
wizard = PCSDWizard.getWizard(params["wizard"])
if wizard != nil
return erb wizard.collection_page
else
return "Error finding Wizard - #{params["wizard"]}"
end
end
def wizard_submit(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
wizard = PCSDWizard.getWizard(params["wizard"])
if wizard != nil
return erb wizard.process_responses(params)
else
return "Error finding Wizard - #{params["wizard"]}"
end
end
# not used anymore, left here for backward compatability reasons
def get_tokens(params, request, auth_user)
# pcsd runs as root thus always returns hacluster's tokens
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, 'Permission denied'
end
return [200, JSON.generate(read_tokens)]
end
def get_cluster_tokens(params, request, auth_user)
# pcsd runs as root thus always returns hacluster's tokens
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, "Permission denied"
end
on, off = get_nodes
nodes = on + off
nodes.uniq!
return [200, JSON.generate(get_tokens_of_nodes(nodes))]
end
def save_tokens(params, request, auth_user)
# pcsd runs as root thus always returns hacluster's tokens
if not allowed_for_local_cluster(auth_user, Permissions::FULL)
return 403, "Permission denied"
end
new_tokens = {}
params.each{|nodes|
if nodes[0].start_with?"node:" and nodes[0].length > 5
node = nodes[0][5..-1]
token = nodes[1]
new_tokens[node] = token
end
}
tokens_cfg = Cfgsync::PcsdTokens.from_file('')
sync_successful, sync_responses = Cfgsync::save_sync_new_tokens(
tokens_cfg, new_tokens, get_corosync_nodes(), $cluster_name
)
if sync_successful
return [200, JSON.generate(read_tokens())]
else
return [400, "Cannot update tokenfile."]
end
end
def resource_master(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
unless params[:resource_id]
return [400, 'resource_id has to be specified.']
end
_, stderr, retval = run_cmd(
auth_user, PCS, 'resource', 'master', params[:resource_id]
)
if retval != 0
return [400, 'Unable to create master/slave resource from ' +
"'#{params[:resource_id]}': #{stderr.join('')}"
]
end
return 200
end
def resource_change_group(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
if params[:resource_id].nil? or params[:group_id].nil?
return [400, 'resource_id and group_id have to be specified.']
end
if params[:group_id].empty?
if params[:old_group_id]
_, stderr, retval = run_cmd(
auth_user, PCS, 'resource', 'group', 'remove', params[:old_group_id],
params[:resource_id]
)
if retval != 0
return [400, "Unable to remove resource '#{params[:resource_id]}' " +
"from group '#{params[:old_group_id]}': #{stderr.join('')}"
]
end
end
return 200
end
_, stderr, retval = run_cmd(
auth_user,
PCS, 'resource', 'group', 'add', params[:group_id], params[:resource_id]
)
if retval != 0
return [400, "Unable to add resource '#{params[:resource_id]}' to " +
"group '#{params[:group_id]}': #{stderr.join('')}"
]
end
return 200
end
def resource_ungroup(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
unless params[:group_id]
return [400, 'group_id has to be specified.']
end
_, stderr, retval = run_cmd(
auth_user, PCS, 'resource', 'ungroup', params[:group_id]
)
if retval != 0
return [400, 'Unable to ungroup group ' +
"'#{params[:group_id]}': #{stderr.join('')}"
]
end
return 200
end
def resource_clone(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
unless params[:resource_id]
return [400, 'resource_id has to be specified.']
end
_, stderr, retval = run_cmd(
auth_user, PCS, 'resource', 'clone', params[:resource_id]
)
if retval != 0
return [400, 'Unable to create clone resource from ' +
"'#{params[:resource_id]}': #{stderr.join('')}"
]
end
return 200
end
def resource_unclone(params, request, auth_user)
if not allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
unless params[:resource_id]
return [400, 'resource_id has to be specified.']
end
_, stderr, retval = run_cmd(
auth_user, PCS, 'resource', 'unclone', params[:resource_id]
)
if retval != 0
return [400, 'Unable to unclone ' +
"'#{params[:resource_id]}': #{stderr.join('')}"
]
end
return 200
end
def set_resource_utilization(params, reqest, auth_user)
unless allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
unless params[:resource_id] and params[:name]
return 400, 'resource_id and name are required'
end
res_id = params[:resource_id]
name = params[:name]
value = params[:value] || ''
_, stderr, retval = run_cmd(
auth_user, PCS, 'resource', 'utilization', res_id, "#{name}=#{value}"
)
if retval != 0
return [400, "Unable to set utilization '#{name}=#{value}' for " +
"resource '#{res_id}': #{stderr.join('')}"
]
end
return 200
end
def set_node_utilization(params, reqest, auth_user)
unless allowed_for_local_cluster(auth_user, Permissions::WRITE)
return 403, 'Permission denied'
end
unless params[:node] and params[:name]
return 400, 'node and name are required'
end
node = params[:node]
name = params[:name]
value = params[:value] || ''
_, stderr, retval = run_cmd(
auth_user, PCS, 'node', 'utilization', node, "#{name}=#{value}"
)
if retval != 0
return [400, "Unable to set utilization '#{name}=#{value}' for node " +
"'#{res_id}': #{stderr.join('')}"
]
end
return 200
end
def get_cluster_properties_definition(params, request, auth_user)
unless allowed_for_local_cluster(auth_user, Permissions::READ)
return 403, 'Permission denied'
end
stdout, _, retval = run_cmd(
auth_user, PCS, 'property', 'get_cluster_properties_definition'
)
if retval == 0
return [200, stdout]
end
return [400, '{}']
end
|