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 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426
|
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Service_WindowsAzure
* @subpackage Management
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Service_WindowsAzure_Management_OperationStatusInstance
*/
require_once 'Zend/Service/WindowsAzure/Management/OperationStatusInstance.php';
/**
* @see Zend_Service_WindowsAzure_Management_SubscriptionOperationInstance
*/
require_once 'Zend/Service/WindowsAzure/Management/SubscriptionOperationInstance.php';
/**
* @see Zend_Service_WindowsAzure_Management_DeploymentInstance
*/
require_once 'Zend/Service/WindowsAzure/Management/DeploymentInstance.php';
/**
* @see Zend_Service_WindowsAzure_Storage_Blob
*/
require_once 'Zend/Service/WindowsAzure/Storage/Blob.php';
/**
* @see Zend_Service_WindowsAzure_Storage_Table
*/
require_once 'Zend/Service/WindowsAzure/Storage/Table.php';
/**
* @see Zend_Service_WindowsAzure_Management_HostedServiceInstance
*/
require_once 'Zend/Service/WindowsAzure/Management/HostedServiceInstance.php';
/**
* @see Zend_Service_WindowsAzure_Management_CertificateInstance
*/
require_once 'Zend/Service/WindowsAzure/Management/CertificateInstance.php';
/**
* @see Zend_Service_WindowsAzure_Management_AffinityGroupInstance
*/
require_once 'Zend/Service/WindowsAzure/Management/AffinityGroupInstance.php';
/**
* @see Zend_Service_WindowsAzure_Management_LocationInstance
*/
require_once 'Zend/Service/WindowsAzure/Management/LocationInstance.php';
/**
* @see Zend_Service_WindowsAzure_Management_OperatingSystemInstance
*/
require_once 'Zend/Service/WindowsAzure/Management/OperatingSystemInstance.php';
/**
* @see Zend_Service_WindowsAzure_Management_OperatingSystemFamilyInstance
*/
require_once 'Zend/Service/WindowsAzure/Management/OperatingSystemFamilyInstance.php';
/** @see Zend_Xml_Security */
require_once 'Zend/Xml/Security.php';
/**
* @category Zend
* @package Zend_Service_WindowsAzure
* @subpackage Management
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_WindowsAzure_Management_Client
{
/**
* Management service URL
*/
const URL_MANAGEMENT = "https://management.core.windows.net";
/**
* Operations
*/
const OP_OPERATIONS = "operations";
const OP_STORAGE_ACCOUNTS = "services/storageservices";
const OP_HOSTED_SERVICES = "services/hostedservices";
const OP_AFFINITYGROUPS = "affinitygroups";
const OP_LOCATIONS = "locations";
const OP_OPERATINGSYSTEMS = "operatingsystems";
const OP_OPERATINGSYSTEMFAMILIES = "operatingsystemfamilies";
/**
* Current API version
*
* @var string
*/
protected $_apiVersion = '2011-02-25';
/**
* Subscription ID
*
* @var string
*/
protected $_subscriptionId = '';
/**
* Management certificate path (.PEM)
*
* @var string
*/
protected $_certificatePath = '';
/**
* Management certificate passphrase
*
* @var string
*/
protected $_certificatePassphrase = '';
/**
* Zend_Http_Client channel used for communication with REST services
*
* @var Zend_Http_Client
*/
protected $_httpClientChannel = null;
/**
* Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract instance
*
* @var Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract
*/
protected $_retryPolicy = null;
/**
* Returns the last request ID
*
* @var string
*/
protected $_lastRequestId = null;
/**
* Creates a new Zend_Service_WindowsAzure_Management instance
*
* @param string $subscriptionId Subscription ID
* @param string $certificatePath Management certificate path (.PEM)
* @param string $certificatePassphrase Management certificate passphrase
* @param Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
*/
public function __construct(
$subscriptionId,
$certificatePath,
$certificatePassphrase,
Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null
) {
$this->_subscriptionId = $subscriptionId;
$this->_certificatePath = $certificatePath;
$this->_certificatePassphrase = $certificatePassphrase;
$this->_retryPolicy = $retryPolicy;
if (is_null($this->_retryPolicy)) {
$this->_retryPolicy = Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract::noRetry();
}
// Setup default Zend_Http_Client channel
$options = array(
'adapter' => 'Zend_Http_Client_Adapter_Socket',
'ssltransport' => 'ssl',
'sslcert' => $this->_certificatePath,
'sslpassphrase' => $this->_certificatePassphrase,
'sslusecontext' => true,
);
if (function_exists('curl_init')) {
// Set cURL options if cURL is used afterwards
$options['curloptions'] = array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 120,
);
}
$this->_httpClientChannel = new Zend_Http_Client(null, $options);
}
/**
* Set the HTTP client channel to use
*
* @param Zend_Http_Client_Adapter_Interface|string $adapterInstance Adapter instance or adapter class name.
*/
public function setHttpClientChannel($adapterInstance = 'Zend_Http_Client_Adapter_Socket')
{
$this->_httpClientChannel->setAdapter($adapterInstance);
}
/**
* Retrieve HTTP client channel
*
* @return Zend_Http_Client_Adapter_Interface
*/
public function getHttpClientChannel()
{
return $this->_httpClientChannel;
}
/**
* Returns the Windows Azure subscription ID
*
* @return string
*/
public function getSubscriptionId()
{
return $this->_subscriptionId;
}
/**
* Returns the last request ID.
*
* @return string
*/
public function getLastRequestId()
{
return $this->_lastRequestId;
}
/**
* Get base URL for creating requests
*
* @return string
*/
public function getBaseUrl()
{
return self::URL_MANAGEMENT . '/' . $this->_subscriptionId;
}
/**
* Perform request using Zend_Http_Client channel
*
* @param string $path Path
* @param string $queryString Query string
* @param string $httpVerb HTTP verb the request will use
* @param array $headers x-ms headers to add
* @param mixed $rawData Optional RAW HTTP data to be sent over the wire
* @return Zend_Http_Response
*/
protected function _performRequest(
$path = '/',
$queryString = '',
$httpVerb = Zend_Http_Client::GET,
$headers = array(),
$rawData = null
) {
// Clean path
if (strpos($path, '/') !== 0) {
$path = '/' . $path;
}
// Clean headers
if (is_null($headers)) {
$headers = array();
}
// Ensure cUrl will also work correctly:
// - disable Content-Type if required
// - disable Expect: 100 Continue
if (!isset($headers["Content-Type"])) {
$headers["Content-Type"] = '';
}
//$headers["Expect"] = '';
// Add version header
$headers['x-ms-version'] = $this->_apiVersion;
// URL encoding
$path = self::urlencode($path);
$queryString = self::urlencode($queryString);
// Generate URL and sign request
$requestUrl = $this->getBaseUrl() . $path . $queryString;
$requestHeaders = $headers;
// Prepare request
$this->_httpClientChannel->resetParameters(true);
$this->_httpClientChannel->setUri($requestUrl);
$this->_httpClientChannel->setHeaders($requestHeaders);
$this->_httpClientChannel->setRawData($rawData);
// Execute request
$response = $this->_retryPolicy->execute(
array($this->_httpClientChannel, 'request'),
array($httpVerb)
);
// Store request id
$this->_lastRequestId = $response->getHeader('x-ms-request-id');
return $response;
}
/**
* Parse result from Zend_Http_Response
*
* @param Zend_Http_Response $response Response from HTTP call
* @return object
* @throws Zend_Service_WindowsAzure_Exception
*/
protected function _parseResponse(Zend_Http_Response $response = null)
{
if (is_null($response)) {
require_once 'Zend/Service/WindowsAzure/Exception.php';
throw new Zend_Service_WindowsAzure_Exception('Response should not be null.');
}
$xml = Zend_Xml_Security::scan($response->getBody());
if ($xml !== false) {
// Fetch all namespaces
$namespaces = array_merge($xml->getNamespaces(true), $xml->getDocNamespaces(true));
// Register all namespace prefixes
foreach ($namespaces as $prefix => $ns) {
if ($prefix != '') {
$xml->registerXPathNamespace($prefix, $ns);
}
}
}
return $xml;
}
/**
* URL encode function
*
* @param string $value Value to encode
* @return string Encoded value
*/
public static function urlencode($value)
{
return str_replace(' ', '%20', $value);
}
/**
* Builds a query string from an array of elements
*
* @param array Array of elements
* @return string Assembled query string
*/
public static function createQueryStringFromArray($queryString)
{
return count($queryString) > 0 ? '?' . implode('&', $queryString) : '';
}
/**
* Get error message from Zend_Http_Response
*
* @param Zend_Http_Response $response Repsonse
* @param string $alternativeError Alternative error message
* @return string
*/
protected function _getErrorMessage(Zend_Http_Response $response, $alternativeError = 'Unknown error.')
{
$response = $this->_parseResponse($response);
if ($response && $response->Message) {
return (string)$response->Message;
} else {
return $alternativeError;
}
}
/**
* The Get Operation Status operation returns the status of the specified operation.
* After calling an asynchronous operation, you can call Get Operation Status to
* determine whether the operation has succeed, failed, or is still in progress.
*
* @param string $requestId The request ID. If omitted, the last request ID will be used.
* @return Zend_Service_WindowsAzure_Management_OperationStatusInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function getOperationStatus($requestId = '')
{
if ($requestId == '') {
$requestId = $this->getLastRequestId();
}
$response = $this->_performRequest(self::OP_OPERATIONS . '/' . $requestId);
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
if (!is_null($result)) {
return new Zend_Service_WindowsAzure_Management_OperationStatusInstance(
(string)$result->ID,
(string)$result->Status,
($result->Error ? (string)$result->Error->Code : ''),
($result->Error ? (string)$result->Error->Message : '')
);
}
return null;
} else {
require_once 'Zend/Service/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The List Subscription Operations operation returns a list of create, update,
* and delete operations that were performed on a subscription during the specified timeframe.
* Documentation on the parameters can be found at http://msdn.microsoft.com/en-us/library/gg715318.aspx.
*
* @param string $startTime The start of the timeframe to begin listing subscription operations in UTC format. This parameter and the $endTime parameter indicate the timeframe to retrieve subscription operations. This parameter cannot indicate a start date of more than 90 days in the past.
* @param string $endTime The end of the timeframe to begin listing subscription operations in UTC format. This parameter and the $startTime parameter indicate the timeframe to retrieve subscription operations.
* @param string $objectIdFilter Returns subscription operations only for the specified object type and object ID.
* @param string $operationResultFilter Returns subscription operations only for the specified result status, either Succeeded, Failed, or InProgress.
* @param string $continuationToken Internal usage.
* @return array Array of Zend_Service_WindowsAzure_Management_SubscriptionOperationInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function listSubscriptionOperations($startTime, $endTime, $objectIdFilter = null, $operationResultFilter = null, $continuationToken = null)
{
if ($startTime == '' || is_null($startTime)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Start time should be specified.');
}
if ($endTime == '' || is_null($endTime)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('End time should be specified.');
}
if ($operationResultFilter != '' && !is_null($operationResultFilter)) {
$operationResultFilter = strtolower($operationResultFilter);
if ($operationResultFilter != 'succeeded' && $operationResultFilter != 'failed' && $operationResultFilter != 'inprogress') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('OperationResultFilter should be succeeded|failed|inprogress.');
}
}
$parameters = array();
$parameters[] = 'StartTime=' . $startTime;
$parameters[] = 'EndTime=' . $endTime;
if ($objectIdFilter != '' && !is_null($objectIdFilter)) {
$parameters[] = 'ObjectIdFilter=' . $objectIdFilter;
}
if ($operationResultFilter != '' && !is_null($operationResultFilter)) {
$parameters[] = 'OperationResultFilter=' . ucfirst($operationResultFilter);
}
if ($continuationToken != '' && !is_null($continuationToken)) {
$parameters[] = 'ContinuationToken=' . $continuationToken;
}
$response = $this->_performRequest(self::OP_OPERATIONS, '?' . implode('&', $parameters));
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
$namespaces = $result->getDocNamespaces();
$result->registerXPathNamespace('__empty_ns', $namespaces['']);
$xmlOperations = $result->xpath('//__empty_ns:SubscriptionOperation');
// Create return value
$returnValue = array();
foreach ($xmlOperations as $xmlOperation) {
// Create operation instance
$operation = new Zend_Service_WindowsAzure_Management_SubscriptionOperationInstance(
$xmlOperation->OperationId,
$xmlOperation->OperationObjectId,
$xmlOperation->OperationName,
array(),
(array)$xmlOperation->OperationCaller,
(array)$xmlOperation->OperationStatus
);
// Parse parameters
$xmlOperation->registerXPathNamespace('__empty_ns', $namespaces['']);
$xmlParameters = $xmlOperation->xpath('.//__empty_ns:OperationParameter');
foreach ($xmlParameters as $xmlParameter) {
$xmlParameterDetails = $xmlParameter->children('http://schemas.datacontract.org/2004/07/Microsoft.Samples.WindowsAzure.ServiceManagement');
$operation->addOperationParameter((string)$xmlParameterDetails->Name, (string)$xmlParameterDetails->Value);
}
// Add to result
$returnValue[] = $operation;
}
// More data?
if (!is_null($result->ContinuationToken) && $result->ContinuationToken != '') {
$returnValue = array_merge($returnValue, $this->listSubscriptionOperations($startTime, $endTime, $objectIdFilter, $operationResultFilter, (string)$result->ContinuationToken));
}
// Return
return $returnValue;
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* Wait for an operation to complete
*
* @param string $requestId The request ID. If omitted, the last request ID will be used.
* @param int $sleepInterval Sleep interval in milliseconds.
* @return Zend_Service_WindowsAzure_Management_OperationStatusInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function waitForOperation($requestId = '', $sleepInterval = 250)
{
if ($requestId == '') {
$requestId = $this->getLastRequestId();
}
if ($requestId == '' || is_null($requestId)) {
return null;
}
$status = $this->getOperationStatus($requestId);
while ($status->Status == 'InProgress') {
$status = $this->getOperationStatus($requestId);
usleep($sleepInterval);
}
return $status;
}
/**
* Creates a new Zend_Service_WindowsAzure_Storage_Blob instance for the current account
*
* @param string $serviceName the service name to create a storage client for.
* @param Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
* @return Zend_Service_WindowsAzure_Storage_Blob
*/
public function createBlobClientForService($serviceName, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null)
{
if ($serviceName == '' || is_null($serviceName)) {
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$storageKeys = $this->getStorageAccountKeys($serviceName);
return new Zend_Service_WindowsAzure_Storage_Blob(
Zend_Service_WindowsAzure_Storage::URL_CLOUD_BLOB,
$serviceName,
$storageKeys[0],
false,
$retryPolicy
);
}
/**
* Creates a new Zend_Service_WindowsAzure_Storage_Table instance for the current account
*
* @param string $serviceName the service name to create a storage client for.
* @param Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
* @return Zend_Service_WindowsAzure_Storage_Table
*/
public function createTableClientForService($serviceName, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$storageKeys = $this->getStorageAccountKeys($serviceName);
return new Zend_Service_WindowsAzure_Storage_Table(
Zend_Service_WindowsAzure_Storage::URL_CLOUD_TABLE,
$serviceName,
$storageKeys[0],
false,
$retryPolicy
);
}
/**
* Creates a new Zend_Service_WindowsAzure_Storage_Queue instance for the current account
*
* @param string $serviceName the service name to create a storage client for.
* @param Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy Retry policy to use when making requests
* @return Zend_Service_WindowsAzure_Storage_Queue
*/
public function createQueueClientForService($serviceName, Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract $retryPolicy = null)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$storageKeys = $this->getStorageAccountKeys($serviceName);
require_once 'Zend/Service/WindowsAzure/Storage/Queue.php';
return new Zend_Service_WindowsAzure_Storage_Queue(
Zend_Service_WindowsAzure_Storage::URL_CLOUD_QUEUE,
$serviceName,
$storageKeys[0],
false,
$retryPolicy
);
}
/**
* The List Storage Accounts operation lists the storage accounts available under
* the current subscription.
*
* @return array An array of Zend_Service_WindowsAzure_Management_StorageServiceInstance
*/
public function listStorageAccounts()
{
$response = $this->_performRequest(self::OP_STORAGE_ACCOUNTS);
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
if (!$result->StorageService) {
return array();
}
if (count($result->StorageService) > 1) {
$xmlServices = $result->StorageService;
} else {
$xmlServices = array($result->StorageService);
}
$services = array();
if (!is_null($xmlServices)) {
for ($i = 0; $i < count($xmlServices); $i++) {
$services[] = new Zend_Service_WindowsAzure_Management_StorageServiceInstance(
(string)$xmlServices[$i]->Url,
(string)$xmlServices[$i]->ServiceName
);
}
}
return $services;
} else {
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Get Storage Account Properties operation returns the system properties for the
* specified storage account. These properties include: the address, description, and
* label of the storage account; and the name of the affinity group to which the service
* belongs, or its geo-location if it is not part of an affinity group.
*
* @param string $serviceName The name of your service.
* @return Zend_Service_WindowsAzure_Management_StorageServiceInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function getStorageAccountProperties($serviceName)
{
if ($serviceName == '' || is_null($serviceName)) {
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$response = $this->_performRequest(self::OP_STORAGE_ACCOUNTS . '/' . $serviceName);
if ($response->isSuccessful()) {
$xmlService = $this->_parseResponse($response);
if (!is_null($xmlService)) {
require_once 'Zend/Service/WindowsAzure/Management/StorageServiceInstance.php';
return new Zend_Service_WindowsAzure_Management_StorageServiceInstance(
(string)$xmlService->Url,
(string)$xmlService->ServiceName,
(string)$xmlService->StorageServiceProperties->Description,
(string)$xmlService->StorageServiceProperties->AffinityGroup,
(string)$xmlService->StorageServiceProperties->Location,
(string)$xmlService->StorageServiceProperties->Label
);
}
return null;
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Get Storage Keys operation returns the primary
* and secondary access keys for the specified storage account.
*
* @param string $serviceName The name of your service.
* @return array An array of strings
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function getStorageAccountKeys($serviceName)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$response = $this->_performRequest(self::OP_STORAGE_ACCOUNTS . '/' . $serviceName . '/keys');
if ($response->isSuccessful()) {
$xmlService = $this->_parseResponse($response);
if (!is_null($xmlService)) {
return array(
(string)$xmlService->StorageServiceKeys->Primary,
(string)$xmlService->StorageServiceKeys->Secondary
);
}
return array();
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Regenerate Keys operation regenerates the primary
* or secondary access key for the specified storage account.
*
* @param string $serviceName The name of your service.
* @param string $key The key to regenerate (primary or secondary)
* @return array An array of strings
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function regenerateStorageAccountKey($serviceName, $key = 'primary')
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$key = strtolower($key);
if ($key != 'primary' && $key != 'secondary') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Key identifier should be primary|secondary.');
}
$response = $this->_performRequest(
self::OP_STORAGE_ACCOUNTS . '/' . $serviceName . '/keys', '?action=regenerate',
Zend_Http_Client::POST,
array('Content-Type' => 'application/xml'),
'<?xml version="1.0" encoding="utf-8"?>
<RegenerateKeys xmlns="http://schemas.microsoft.com/windowsazure">
<KeyType>' . ucfirst($key) . '</KeyType>
</RegenerateKeys>');
if ($response->isSuccessful()) {
$xmlService = $this->_parseResponse($response);
if (!is_null($xmlService)) {
return array(
(string)$xmlService->StorageServiceKeys->Primary,
(string)$xmlService->StorageServiceKeys->Secondary
);
}
return array();
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The List Hosted Services operation lists the hosted services available
* under the current subscription.
*
* @return array An array of Zend_Service_WindowsAzure_Management_HostedServiceInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function listHostedServices()
{
$response = $this->_performRequest(self::OP_HOSTED_SERVICES);
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
if (!$result->HostedService) {
return array();
}
if (count($result->HostedService) > 1) {
$xmlServices = $result->HostedService;
} else {
$xmlServices = array($result->HostedService);
}
$services = array();
if (!is_null($xmlServices)) {
for ($i = 0; $i < count($xmlServices); $i++) {
$services[] = new Zend_Service_WindowsAzure_Management_HostedServiceInstance(
(string)$xmlServices[$i]->Url,
(string)$xmlServices[$i]->ServiceName
);
}
}
return $services;
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Create Hosted Service operation creates a new hosted service in Windows Azure.
*
* @param string $serviceName A name for the hosted service that is unique to the subscription.
* @param string $label A label for the hosted service. The label may be up to 100 characters in length.
* @param string $description A description for the hosted service. The description may be up to 1024 characters in length.
* @param string $location Required if AffinityGroup is not specified. The location where the hosted service will be created.
* @param string $affinityGroup Required if Location is not specified. The name of an existing affinity group associated with this subscription.
*/
public function createHostedService($serviceName, $label, $description = '', $location = null, $affinityGroup = null)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($label == '' || is_null($label)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label should be specified.');
}
if (strlen($label) > 100) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label is too long. The maximum length is 100 characters.');
}
if (strlen($description) > 1024) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Description is too long. The maximum length is 1024 characters.');
}
if ( (is_null($location) && is_null($affinityGroup)) || (!is_null($location) && !is_null($affinityGroup)) ) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Please specify a location -or- an affinity group for the service.');
}
$locationOrAffinityGroup = is_null($location)
? '<AffinityGroup>' . $affinityGroup . '</AffinityGroup>'
: '<Location>' . $location . '</Location>';
$response = $this->_performRequest(self::OP_HOSTED_SERVICES, '',
Zend_Http_Client::POST,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<CreateHostedService xmlns="http://schemas.microsoft.com/windowsazure"><ServiceName>' . $serviceName . '</ServiceName><Label>' . base64_encode($label) . '</Label><Description>' . $description . '</Description>' . $locationOrAffinityGroup . '</CreateHostedService>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Update Hosted Service operation updates the label and/or the description for a hosted service in Windows Azure.
*
* @param string $serviceName A name for the hosted service that is unique to the subscription.
* @param string $label A label for the hosted service. The label may be up to 100 characters in length.
* @param string $description A description for the hosted service. The description may be up to 1024 characters in length.
*/
public function updateHostedService($serviceName, $label, $description = '')
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($label == '' || is_null($label)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label should be specified.');
}
if (strlen($label) > 100) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label is too long. The maximum length is 100 characters.');
}
$response = $this->_performRequest(self::OP_HOSTED_SERVICES . '/' . $serviceName, '',
Zend_Http_Client::PUT,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<UpdateHostedService xmlns="http://schemas.microsoft.com/windowsazure"><Label>' . base64_encode($label) . '</Label><Description>' . $description . '</Description></UpdateHostedService>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Delete Hosted Service operation deletes the specified hosted service in Windows Azure.
*
* @param string $serviceName A name for the hosted service that is unique to the subscription.
*/
public function deleteHostedService($serviceName)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$response = $this->_performRequest(self::OP_HOSTED_SERVICES . '/' . $serviceName, '', Zend_Http_Client::DELETE);
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Get Hosted Service Properties operation retrieves system properties
* for the specified hosted service. These properties include the service
* name and service type; the name of the affinity group to which the service
* belongs, or its location if it is not part of an affinity group; and
* optionally, information on the service's deployments.
*
* @param string $serviceName The name of your service.
* @return Zend_Service_WindowsAzure_Management_HostedServiceInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function getHostedServiceProperties($serviceName)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$response = $this->_performRequest(self::OP_HOSTED_SERVICES . '/' . $serviceName, '?embed-detail=true');
if ($response->isSuccessful()) {
$xmlService = $this->_parseResponse($response);
if (!is_null($xmlService)) {
$returnValue = new Zend_Service_WindowsAzure_Management_HostedServiceInstance(
(string)$xmlService->Url,
(string)$xmlService->ServiceName,
(string)$xmlService->HostedServiceProperties->Description,
(string)$xmlService->HostedServiceProperties->AffinityGroup,
(string)$xmlService->HostedServiceProperties->Location,
(string)$xmlService->HostedServiceProperties->Label
);
// Deployments
if (count($xmlService->Deployments->Deployment) > 1) {
$xmlServices = $xmlService->Deployments->Deployment;
} else {
$xmlServices = array($xmlService->Deployments->Deployment);
}
$deployments = array();
foreach ($xmlServices as $xmlDeployment) {
$deployments[] = $this->_convertXmlElementToDeploymentInstance($xmlDeployment);
}
$returnValue->Deployments = $deployments;
return $returnValue;
}
return null;
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Create Deployment operation uploads a new service package
* and creates a new deployment on staging or production.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @param string $name The name for the deployment. The deployment ID as listed on the Windows Azure management portal must be unique among other deployments for the hosted service.
* @param string $label A URL that refers to the location of the service package in the Blob service. The service package must be located in a storage account beneath the same subscription.
* @param string $packageUrl The service configuration file for the deployment.
* @param string $configuration A label for this deployment, up to 100 characters in length.
* @param boolean $startDeployment Indicates whether to start the deployment immediately after it is created.
* @param boolean $treatWarningsAsErrors Indicates whether to treat package validation warnings as errors.
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function createDeployment($serviceName, $deploymentSlot, $name, $label, $packageUrl, $configuration, $startDeployment = false, $treatWarningsAsErrors = false)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$deploymentSlot = strtolower($deploymentSlot);
if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
}
if ($name == '' || is_null($name)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Name should be specified.');
}
if ($label == '' || is_null($label)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label should be specified.');
}
if (strlen($label) > 100) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label is too long. The maximum length is 100 characters.');
}
if ($packageUrl == '' || is_null($packageUrl)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Package URL should be specified.');
}
if ($configuration == '' || is_null($configuration)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Configuration should be specified.');
}
if (@file_exists($configuration)) {
$configuration = utf8_decode(file_get_contents($configuration));
}
// Clean up the configuration
$conformingConfiguration = $this->_cleanConfiguration($configuration);
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot;
$response = $this->_performRequest($operationUrl, '',
Zend_Http_Client::POST,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<CreateDeployment xmlns="http://schemas.microsoft.com/windowsazure"><Name>' . $name . '</Name><PackageUrl>' . $packageUrl . '</PackageUrl><Label>' . base64_encode($label) . '</Label><Configuration>' . base64_encode($conformingConfiguration) . '</Configuration><StartDeployment>' . ($startDeployment ? 'true' : 'false') . '</StartDeployment><TreatWarningsAsError>' . ($treatWarningsAsErrors ? 'true' : 'false') . '</TreatWarningsAsError></CreateDeployment>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Get Deployment operation returns configuration information, status,
* and system properties for the specified deployment.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @return Zend_Service_WindowsAzure_Management_DeploymentInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function getDeploymentBySlot($serviceName, $deploymentSlot)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$deploymentSlot = strtolower($deploymentSlot);
if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot;
return $this->_getDeployment($operationUrl);
}
/**
* The Get Deployment operation returns configuration information, status,
* and system properties for the specified deployment.
*
* @param string $serviceName The service name
* @param string $deploymentId The deployment ID as listed on the Windows Azure management portal
* @return Zend_Service_WindowsAzure_Management_DeploymentInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function getDeploymentByDeploymentId($serviceName, $deploymentId)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($deploymentId == '' || is_null($deploymentId)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deployments/' . $deploymentId;
return $this->_getDeployment($operationUrl);
}
/**
* The Get Deployment operation returns configuration information, status,
* and system properties for the specified deployment.
*
* @param string $operationUrl The operation url
* @return Zend_Service_WindowsAzure_Management_DeploymentInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
protected function _getDeployment($operationUrl)
{
$response = $this->_performRequest($operationUrl);
if ($response->isSuccessful()) {
$xmlService = $this->_parseResponse($response);
return $this->_convertXmlElementToDeploymentInstance($xmlService);
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Swap Deployment operation initiates a virtual IP swap between
* the staging and production deployment environments for a service.
* If the service is currently running in the staging environment,
* it will be swapped to the production environment. If it is running
* in the production environment, it will be swapped to staging.
*
* @param string $serviceName The service name.
* @param string $productionDeploymentName The name of the production deployment.
* @param string $sourceDeploymentName The name of the source deployment.
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function swapDeployment($serviceName, $productionDeploymentName, $sourceDeploymentName)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($productionDeploymentName == '' || is_null($productionDeploymentName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Production Deployment ID should be specified.');
}
if ($sourceDeploymentName == '' || is_null($sourceDeploymentName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Source Deployment ID should be specified.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName;
$response = $this->_performRequest($operationUrl, '',
Zend_Http_Client::POST,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<Swap xmlns="http://schemas.microsoft.com/windowsazure"><Production>' . $productionDeploymentName . '</Production><SourceDeployment>' . $sourceDeploymentName . '</SourceDeployment></Swap>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Delete Deployment operation deletes the specified deployment.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function deleteDeploymentBySlot($serviceName, $deploymentSlot)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$deploymentSlot = strtolower($deploymentSlot);
if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot;
return $this->_deleteDeployment($operationUrl);
}
/**
* The Delete Deployment operation deletes the specified deployment.
*
* @param string $serviceName The service name
* @param string $deploymentId The deployment ID as listed on the Windows Azure management portal
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function deleteDeploymentByDeploymentId($serviceName, $deploymentId)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($deploymentId == '' || is_null($deploymentId)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deployments/' . $deploymentId;
return $this->_deleteDeployment($operationUrl);
}
/**
* The Delete Deployment operation deletes the specified deployment.
*
* @param string $operationUrl The operation url
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
protected function _deleteDeployment($operationUrl)
{
$response = $this->_performRequest($operationUrl, '', Zend_Http_Client::DELETE);
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Update Deployment Status operation initiates a change in deployment status.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @param string $status The deployment status (running|suspended)
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function updateDeploymentStatusBySlot($serviceName, $deploymentSlot, $status = 'running')
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$deploymentSlot = strtolower($deploymentSlot);
if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
}
$status = strtolower($status);
if ($status != 'running' && $status != 'suspended') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Status should be running|suspended.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot;
return $this->_updateDeploymentStatus($operationUrl, $status);
}
/**
* The Update Deployment Status operation initiates a change in deployment status.
*
* @param string $serviceName The service name
* @param string $deploymentId The deployment ID as listed on the Windows Azure management portal
* @param string $status The deployment status (running|suspended)
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function updateDeploymentStatusByDeploymentId($serviceName, $deploymentId, $status = 'running')
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($deploymentId == '' || is_null($deploymentId)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
}
$status = strtolower($status);
if ($status != 'running' && $status != 'suspended') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Status should be running|suspended.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deployments/' . $deploymentId;
return $this->_updateDeploymentStatus($operationUrl, $status);
}
/**
* The Update Deployment Status operation initiates a change in deployment status.
*
* @param string $operationUrl The operation url
* @param string $status The deployment status (running|suspended)
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
protected function _updateDeploymentStatus($operationUrl, $status = 'running')
{
$response = $this->_performRequest($operationUrl . '/', '?comp=status',
Zend_Http_Client::POST,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<UpdateDeploymentStatus xmlns="http://schemas.microsoft.com/windowsazure"><Status>' . ucfirst($status) . '</Status></UpdateDeploymentStatus>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* Converts an XmlElement into a Zend_Service_WindowsAzure_Management_DeploymentInstance
*
* @param object $xmlService The XML Element
* @return Zend_Service_WindowsAzure_Management_DeploymentInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
protected function _convertXmlElementToDeploymentInstance($xmlService)
{
if (!is_null($xmlService)) {
$returnValue = new Zend_Service_WindowsAzure_Management_DeploymentInstance(
(string)$xmlService->Name,
(string)$xmlService->DeploymentSlot,
(string)$xmlService->PrivateID,
(string)$xmlService->Label,
(string)$xmlService->Url,
(string)$xmlService->Configuration,
(string)$xmlService->Status,
(string)$xmlService->UpgradeStatus,
(string)$xmlService->UpgradeType,
(string)$xmlService->CurrentUpgradeDomainState,
(string)$xmlService->CurrentUpgradeDomain,
(string)$xmlService->UpgradeDomainCount
);
// Append role instances
if ($xmlService->RoleInstanceList && $xmlService->RoleInstanceList->RoleInstance) {
$xmlRoleInstances = $xmlService->RoleInstanceList->RoleInstance;
if (count($xmlService->RoleInstanceList->RoleInstance) == 1) {
$xmlRoleInstances = array($xmlService->RoleInstanceList->RoleInstance);
}
$roleInstances = array();
if (!is_null($xmlRoleInstances)) {
for ($i = 0; $i < count($xmlRoleInstances); $i++) {
$roleInstances[] = array(
'rolename' => (string)$xmlRoleInstances[$i]->RoleName,
'instancename' => (string)$xmlRoleInstances[$i]->InstanceName,
'instancestatus' => (string)$xmlRoleInstances[$i]->InstanceStatus
);
}
}
$returnValue->RoleInstanceList = $roleInstances;
}
// Append roles
if ($xmlService->RoleList && $xmlService->RoleList->Role) {
$xmlRoles = $xmlService->RoleList->Role;
if (count($xmlService->RoleList->Role) == 1) {
$xmlRoles = array($xmlService->RoleList->Role);
}
$roles = array();
if (!is_null($xmlRoles)) {
for ($i = 0; $i < count($xmlRoles); $i++) {
$roles[] = array(
'rolename' => (string)$xmlRoles[$i]->RoleName,
'osversion' => (!is_null($xmlRoles[$i]->OsVersion) ? (string)$xmlRoles[$i]->OsVersion : (string)$xmlRoles[$i]->OperatingSystemVersion)
);
}
}
$returnValue->RoleList = $roles;
}
return $returnValue;
}
return null;
}
/**
* Updates a deployment's role instance count.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @param string|array $roleName The role name
* @param string|array $instanceCount The instance count
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function setInstanceCountBySlot($serviceName, $deploymentSlot, $roleName, $instanceCount) {
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$deploymentSlot = strtolower($deploymentSlot);
if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
}
if ($roleName == '' || is_null($roleName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Role name name should be specified.');
}
// Get configuration
$deployment = $this->getDeploymentBySlot($serviceName, $deploymentSlot);
$configuration = $deployment->Configuration;
$configuration = $this->_updateInstanceCountInConfiguration($roleName, $instanceCount, $configuration);
// Update configuration
$this->configureDeploymentBySlot($serviceName, $deploymentSlot, $configuration);
}
/**
* Updates a deployment's role instance count.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @param string|array $roleName The role name
* @param string|array $instanceCount The instance count
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function setInstanceCountByDeploymentId($serviceName, $deploymentId, $roleName, $instanceCount)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($deploymentId == '' || is_null($deploymentId)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
}
if ($roleName == '' || is_null($roleName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Role name name should be specified.');
}
// Get configuration
$deployment = $this->getDeploymentByDeploymentId($serviceName, $deploymentId);
$configuration = $deployment->Configuration;
$configuration = $this->_updateInstanceCountInConfiguration($roleName, $instanceCount, $configuration);
// Update configuration
$this->configureDeploymentByDeploymentId($serviceName, $deploymentId, $configuration);
}
/**
* Updates instance count in configuration XML.
*
* @param string|array $roleName The role name
* @param string|array $instanceCount The instance count
* @param string $configuration XML configuration represented as a string
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
protected function _updateInstanceCountInConfiguration($roleName, $instanceCount, $configuration) {
// Change variables
if (!is_array($roleName)) {
$roleName = array($roleName);
}
if (!is_array($instanceCount)) {
$instanceCount = array($instanceCount);
}
$configuration = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $configuration);
//$configuration = '<?xml version="1.0">' . substr($configuration, strpos($configuration, '>') + 2);
$xml = Zend_Xml_Security::scan($configuration);
// http://www.php.net/manual/en/simplexmlelement.xpath.php#97818
$namespaces = $xml->getDocNamespaces();
$xml->registerXPathNamespace('__empty_ns', $namespaces['']);
for ($i = 0; $i < count($roleName); $i++) {
$elements = $xml->xpath('//__empty_ns:Role[@name="' . $roleName[$i] . '"]/__empty_ns:Instances');
if (count($elements) == 1) {
$element = $elements[0];
$element['count'] = $instanceCount[$i];
}
}
$configuration = $xml->asXML();
//$configuration = preg_replace('/(<\?xml[^?]+?)utf-8/i', '$1utf-16', $configuration);
return $configuration;
}
/**
* The Change Deployment Configuration request may be specified as follows.
* Note that you can change a deployment's configuration either by specifying the deployment
* environment (staging or production), or by specifying the deployment's unique name.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @param string $configuration XML configuration represented as a string
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function configureDeploymentBySlot($serviceName, $deploymentSlot, $configuration)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$deploymentSlot = strtolower($deploymentSlot);
if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
}
if ($configuration == '' || is_null($configuration)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Configuration name should be specified.');
}
if (@file_exists($configuration)) {
$configuration = utf8_decode(file_get_contents($configuration));
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot;
return $this->_configureDeployment($operationUrl, $configuration);
}
/**
* The Change Deployment Configuration request may be specified as follows.
* Note that you can change a deployment's configuration either by specifying the deployment
* environment (staging or production), or by specifying the deployment's unique name.
*
* @param string $serviceName The service name
* @param string $deploymentId The deployment ID as listed on the Windows Azure management portal
* @param string $configuration XML configuration represented as a string
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function configureDeploymentByDeploymentId($serviceName, $deploymentId, $configuration)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($deploymentId == '' || is_null($deploymentId)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
}
if ($configuration == '' || is_null($configuration)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Configuration name should be specified.');
}
if (@file_exists($configuration)) {
$configuration = utf8_decode(file_get_contents($configuration));
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deployments/' . $deploymentId;
return $this->_configureDeployment($operationUrl, $configuration);
}
/**
* The Change Deployment Configuration request may be specified as follows.
* Note that you can change a deployment's configuration either by specifying the deployment
* environment (staging or production), or by specifying the deployment's unique name.
*
* @param string $operationUrl The operation url
* @param string $configuration XML configuration represented as a string
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
protected function _configureDeployment($operationUrl, $configuration)
{
// Clean up the configuration
$conformingConfiguration = $this->_cleanConfiguration($configuration);
$response = $this->_performRequest($operationUrl . '/', '?comp=config',
Zend_Http_Client::POST,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<ChangeConfiguration xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Configuration>' . base64_encode($conformingConfiguration) . '</Configuration></ChangeConfiguration>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Upgrade Deployment operation initiates an upgrade.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @param string $label A URL that refers to the location of the service package in the Blob service. The service package must be located in a storage account beneath the same subscription.
* @param string $packageUrl The service configuration file for the deployment.
* @param string $configuration A label for this deployment, up to 100 characters in length.
* @param string $mode The type of upgrade to initiate. Possible values are Auto or Manual.
* @param string $roleToUpgrade The name of the specific role to upgrade.
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function upgradeDeploymentBySlot($serviceName, $deploymentSlot, $label, $packageUrl, $configuration, $mode = 'auto', $roleToUpgrade = null)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$deploymentSlot = strtolower($deploymentSlot);
if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
}
if ($label == '' || is_null($label)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label should be specified.');
}
if (strlen($label) > 100) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label is too long. The maximum length is 100 characters.');
}
if ($packageUrl == '' || is_null($packageUrl)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Package URL should be specified.');
}
if ($configuration == '' || is_null($configuration)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Configuration should be specified.');
}
$mode = strtolower($mode);
if ($mode != 'auto' && $mode != 'manual') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Mode should be auto|manual.');
}
if (@file_exists($configuration)) {
$configuration = utf8_decode(file_get_contents($configuration));
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot;
return $this->_upgradeDeployment($operationUrl, $label, $packageUrl, $configuration, $mode, $roleToUpgrade);
}
/**
* The Upgrade Deployment operation initiates an upgrade.
*
* @param string $serviceName The service name
* @param string $deploymentId The deployment ID as listed on the Windows Azure management portal
* @param string $label A URL that refers to the location of the service package in the Blob service. The service package must be located in a storage account beneath the same subscription.
* @param string $packageUrl The service configuration file for the deployment.
* @param string $configuration A label for this deployment, up to 100 characters in length.
* @param string $mode The type of upgrade to initiate. Possible values are Auto or Manual.
* @param string $roleToUpgrade The name of the specific role to upgrade.
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function upgradeDeploymentByDeploymentId($serviceName, $deploymentId, $label, $packageUrl, $configuration, $mode = 'auto', $roleToUpgrade = null)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($deploymentId == '' || is_null($deploymentId)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
}
if ($label == '' || is_null($label)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label should be specified.');
}
if (strlen($label) > 100) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label is too long. The maximum length is 100 characters.');
}
if ($packageUrl == '' || is_null($packageUrl)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Package URL should be specified.');
}
if ($configuration == '' || is_null($configuration)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Configuration should be specified.');
}
$mode = strtolower($mode);
if ($mode != 'auto' && $mode != 'manual') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Mode should be auto|manual.');
}
if (@file_exists($configuration)) {
$configuration = utf8_decode(file_get_contents($configuration));
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deployments/' . $deploymentId;
return $this->_upgradeDeployment($operationUrl, $label, $packageUrl, $configuration, $mode, $roleToUpgrade);
}
/**
* The Upgrade Deployment operation initiates an upgrade.
*
* @param string $operationUrl The operation url
* @param string $label A URL that refers to the location of the service package in the Blob service. The service package must be located in a storage account beneath the same subscription.
* @param string $packageUrl The service configuration file for the deployment.
* @param string $configuration A label for this deployment, up to 100 characters in length.
* @param string $mode The type of upgrade to initiate. Possible values are Auto or Manual.
* @param string $roleToUpgrade The name of the specific role to upgrade.
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
protected function _upgradeDeployment($operationUrl, $label, $packageUrl, $configuration, $mode, $roleToUpgrade)
{
// Clean up the configuration
$conformingConfiguration = $this->_cleanConfiguration($configuration);
$response = $this->_performRequest($operationUrl . '/', '?comp=upgrade',
Zend_Http_Client::POST,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<UpgradeDeployment xmlns="http://schemas.microsoft.com/windowsazure"><Mode>' . ucfirst($mode) . '</Mode><PackageUrl>' . $packageUrl . '</PackageUrl><Configuration>' . base64_encode($conformingConfiguration) . '</Configuration><Label>' . base64_encode($label) . '</Label>' . (!is_null($roleToUpgrade) ? '<RoleToUpgrade>' . $roleToUpgrade . '</RoleToUpgrade>' : '') . '</UpgradeDeployment>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Walk Upgrade Domain operation specifies the next upgrade domain to be walked during an in-place upgrade.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @param int $upgradeDomain An integer value that identifies the upgrade domain to walk. Upgrade domains are identified with a zero-based index: the first upgrade domain has an ID of 0, the second has an ID of 1, and so on.
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function walkUpgradeDomainBySlot($serviceName, $deploymentSlot, $upgradeDomain = 0)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$deploymentSlot = strtolower($deploymentSlot);
if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot;
return $this->_walkUpgradeDomain($operationUrl, $upgradeDomain);
}
/**
* The Walk Upgrade Domain operation specifies the next upgrade domain to be walked during an in-place upgrade.
*
* @param string $serviceName The service name
* @param string $deploymentId The deployment ID as listed on the Windows Azure management portal
* @param int $upgradeDomain An integer value that identifies the upgrade domain to walk. Upgrade domains are identified with a zero-based index: the first upgrade domain has an ID of 0, the second has an ID of 1, and so on.
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function walkUpgradeDomainByDeploymentId($serviceName, $deploymentId, $upgradeDomain = 0)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($deploymentId == '' || is_null($deploymentId)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deployments/' . $deploymentId;
return $this->_walkUpgradeDomain($operationUrl, $upgradeDomain);
}
/**
* The Walk Upgrade Domain operation specifies the next upgrade domain to be walked during an in-place upgrade.
*
* @param string $operationUrl The operation url
* @param int $upgradeDomain An integer value that identifies the upgrade domain to walk. Upgrade domains are identified with a zero-based index: the first upgrade domain has an ID of 0, the second has an ID of 1, and so on.
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
protected function _walkUpgradeDomain($operationUrl, $upgradeDomain = 0)
{
$response = $this->_performRequest($operationUrl . '/', '?comp=walkupgradedomain',
Zend_Http_Client::POST,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<WalkUpgradeDomain xmlns="http://schemas.microsoft.com/windowsazure"><UpgradeDomain>' . $upgradeDomain . '</UpgradeDomain></WalkUpgradeDomain>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Reboot Role Instance operation requests a reboot of a role instance
* that is running in a deployment.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @param string $roleInstanceName The role instance name
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function rebootRoleInstanceBySlot($serviceName, $deploymentSlot, $roleInstanceName)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$deploymentSlot = strtolower($deploymentSlot);
if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
}
if ($roleInstanceName == '' || is_null($roleInstanceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Role instance name should be specified.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot . '/roleinstances/' . $roleInstanceName;
return $this->_rebootOrReimageRoleInstance($operationUrl, 'reboot');
}
/**
* The Reboot Role Instance operation requests a reboot of a role instance
* that is running in a deployment.
*
* @param string $serviceName The service name
* @param string $deploymentId The deployment ID as listed on the Windows Azure management portal
* @param string $roleInstanceName The role instance name
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function rebootRoleInstanceByDeploymentId($serviceName, $deploymentId, $roleInstanceName)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($deploymentId == '' || is_null($deploymentId)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
}
if ($roleInstanceName == '' || is_null($roleInstanceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Role instance name should be specified.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deployments/' . $deploymentId . '/roleinstances/' . $roleInstanceName;
return $this->_rebootOrReimageRoleInstance($operationUrl, 'reboot');
}
/**
* The Reimage Role Instance operation requests a reimage of a role instance
* that is running in a deployment.
*
* @param string $serviceName The service name
* @param string $deploymentSlot The deployment slot (production or staging)
* @param string $roleInstanceName The role instance name
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function reimageRoleInstanceBySlot($serviceName, $deploymentSlot, $roleInstanceName)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$deploymentSlot = strtolower($deploymentSlot);
if ($deploymentSlot != 'production' && $deploymentSlot != 'staging') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment slot should be production|staging.');
}
if ($roleInstanceName == '' || is_null($roleInstanceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Role instance name should be specified.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deploymentslots/' . $deploymentSlot . '/roleinstances/' . $roleInstanceName;
return $this->_rebootOrReimageRoleInstance($operationUrl, 'reimage');
}
/**
* The Reimage Role Instance operation requests a reimage of a role instance
* that is running in a deployment.
*
* @param string $serviceName The service name
* @param string $deploymentId The deployment ID as listed on the Windows Azure management portal
* @param string $roleInstanceName The role instance name
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function reimageRoleInstanceByDeploymentId($serviceName, $deploymentId, $roleInstanceName)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($deploymentId == '' || is_null($deploymentId)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Deployment ID should be specified.');
}
if ($roleInstanceName == '' || is_null($roleInstanceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Role instance name should be specified.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/deployments/' . $deploymentId . '/roleinstances/' . $roleInstanceName;
return $this->_rebootOrReimageRoleInstance($operationUrl, 'reimage');
}
/**
* Reboots or reimages a role instance.
*
* @param string $operationUrl The operation url
* @param string $operation The operation (reboot|reimage)
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
protected function _rebootOrReimageRoleInstance($operationUrl, $operation = 'reboot')
{
$response = $this->_performRequest($operationUrl, '?comp=' . $operation, Zend_Http_Client::POST);
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The List Certificates operation lists all certificates associated with
* the specified hosted service.
*
* @param string $serviceName The service name
* @return array Array of Zend_Service_WindowsAzure_Management_CertificateInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function listCertificates($serviceName)
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/certificates';
$response = $this->_performRequest($operationUrl);
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
if (!$result->Certificate) {
return array();
}
if (count($result->Certificate) > 1) {
$xmlServices = $result->Certificate;
} else {
$xmlServices = array($result->Certificate);
}
$services = array();
if (!is_null($xmlServices)) {
for ($i = 0; $i < count($xmlServices); $i++) {
$services[] = new Zend_Service_WindowsAzure_Management_CertificateInstance(
(string)$xmlServices[$i]->CertificateUrl,
(string)$xmlServices[$i]->Thumbprint,
(string)$xmlServices[$i]->ThumbprintAlgorithm,
(string)$xmlServices[$i]->Data
);
}
}
return $services;
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Get Certificate operation returns the public data for the specified certificate.
*
* @param string $serviceName|$certificateUrl The service name -or- the certificate URL
* @param string $algorithm Algorithm
* @param string $thumbprint Thumbprint
* @return Zend_Service_WindowsAzure_Management_CertificateInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function getCertificate($serviceName, $algorithm = '', $thumbprint = '')
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name or certificate URL should be specified.');
}
if (strpos($serviceName, 'https') === false && ($algorithm == '' || is_null($algorithm)) && ($thumbprint == '' || is_null($thumbprint))) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Algorithm and thumbprint should be specified.');
}
$operationUrl = str_replace($this->getBaseUrl(), '', $serviceName);
if (strpos($serviceName, 'https') === false) {
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/certificates/' . $algorithm . '-' . strtoupper($thumbprint);
}
$response = $this->_performRequest($operationUrl);
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
return new Zend_Service_WindowsAzure_Management_CertificateInstance(
$this->getBaseUrl() . $operationUrl,
$algorithm,
$thumbprint,
(string)$result->Data
);
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Add Certificate operation adds a certificate to the subscription.
*
* @param string $serviceName The service name
* @param string $certificateData Certificate data
* @param string $certificatePassword The certificate password
* @param string $certificateFormat The certificate format. Currently, only 'pfx' is supported.
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function addCertificate($serviceName, $certificateData, $certificatePassword, $certificateFormat = 'pfx')
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name should be specified.');
}
if ($certificateData == '' || is_null($certificateData)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Certificate data should be specified.');
}
if ($certificatePassword == '' || is_null($certificatePassword)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Certificate password should be specified.');
}
if ($certificateFormat != 'pfx') {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Certificate format should be "pfx".');
}
if (@file_exists($certificateData)) {
$certificateData = file_get_contents($certificateData);
}
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/certificates';
$response = $this->_performRequest($operationUrl, '',
Zend_Http_Client::POST,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<CertificateFile xmlns="http://schemas.microsoft.com/windowsazure"><Data>' . base64_encode($certificateData) . '</Data><CertificateFormat>' . $certificateFormat . '</CertificateFormat><Password>' . $certificatePassword . '</Password></CertificateFile>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Delete Certificate operation deletes a certificate from the subscription's certificate store.
*
* @param string $serviceName|$certificateUrl The service name -or- the certificate URL
* @param string $algorithm Algorithm
* @param string $thumbprint Thumbprint
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function deleteCertificate($serviceName, $algorithm = '', $thumbprint = '')
{
if ($serviceName == '' || is_null($serviceName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Service name or certificate URL should be specified.');
}
if (strpos($serviceName, 'https') === false && ($algorithm == '' || is_null($algorithm)) && ($thumbprint == '' || is_null($thumbprint))) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Algorithm and thumbprint should be specified.');
}
$operationUrl = str_replace($this->getBaseUrl(), '', $serviceName);
if (strpos($serviceName, 'https') === false) {
$operationUrl = self::OP_HOSTED_SERVICES . '/' . $serviceName . '/certificates/' . $algorithm . '-' . strtoupper($thumbprint);
}
$response = $this->_performRequest($operationUrl, '', Zend_Http_Client::DELETE);
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The List Affinity Groups operation lists the affinity groups associated with
* the specified subscription.
*
* @return array Array of Zend_Service_WindowsAzure_Management_AffinityGroupInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function listAffinityGroups()
{
$response = $this->_performRequest(self::OP_AFFINITYGROUPS);
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
if (!$result->AffinityGroup) {
return array();
}
if (count($result->AffinityGroup) > 1) {
$xmlServices = $result->AffinityGroup;
} else {
$xmlServices = array($result->AffinityGroup);
}
$services = array();
if (!is_null($xmlServices)) {
for ($i = 0; $i < count($xmlServices); $i++) {
$services[] = new Zend_Service_WindowsAzure_Management_AffinityGroupInstance(
(string)$xmlServices[$i]->Name,
(string)$xmlServices[$i]->Label,
(string)$xmlServices[$i]->Description,
(string)$xmlServices[$i]->Location
);
}
}
return $services;
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Create Affinity Group operation creates a new affinity group for the specified subscription.
*
* @param string $name A name for the affinity group that is unique to the subscription.
* @param string $label A label for the affinity group. The label may be up to 100 characters in length.
* @param string $description A description for the affinity group. The description may be up to 1024 characters in length.
* @param string $location The location where the affinity group will be created. To list available locations, use the List Locations operation.
*/
public function createAffinityGroup($name, $label, $description = '', $location = '')
{
if ($name == '' || is_null($name)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Affinity group name should be specified.');
}
if ($label == '' || is_null($label)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label should be specified.');
}
if (strlen($label) > 100) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label is too long. The maximum length is 100 characters.');
}
if (strlen($description) > 1024) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Description is too long. The maximum length is 1024 characters.');
}
if ($location == '' || is_null($location)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Location should be specified.');
}
$response = $this->_performRequest(self::OP_AFFINITYGROUPS, '',
Zend_Http_Client::POST,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<CreateAffinityGroup xmlns="http://schemas.microsoft.com/windowsazure"><Name>' . $name . '</Name><Label>' . base64_encode($label) . '</Label><Description>' . $description . '</Description><Location>' . $location . '</Location></CreateAffinityGroup>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Update Affinity Group operation updates the label and/or the description for an affinity group for the specified subscription.
*
* @param string $name The name for the affinity group that should be updated.
* @param string $label A label for the affinity group. The label may be up to 100 characters in length.
* @param string $description A description for the affinity group. The description may be up to 1024 characters in length.
*/
public function updateAffinityGroup($name, $label, $description = '')
{
if ($name == '' || is_null($name)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Affinity group name should be specified.');
}
if ($label == '' || is_null($label)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label should be specified.');
}
if (strlen($label) > 100) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Label is too long. The maximum length is 100 characters.');
}
if (strlen($description) > 1024) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Description is too long. The maximum length is 1024 characters.');
}
$response = $this->_performRequest(self::OP_AFFINITYGROUPS . '/' . $name, '',
Zend_Http_Client::PUT,
array('Content-Type' => 'application/xml; charset=utf-8'),
'<UpdateAffinityGroup xmlns="http://schemas.microsoft.com/windowsazure"><Label>' . base64_encode($label) . '</Label><Description>' . $description . '</Description></UpdateAffinityGroup>');
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Delete Affinity Group operation deletes an affinity group in the specified subscription.
*
* @param string $name The name for the affinity group that should be deleted.
*/
public function deleteAffinityGroup($name)
{
if ($name == '' || is_null($name)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Affinity group name should be specified.');
}
$response = $this->_performRequest(self::OP_AFFINITYGROUPS . '/' . $name, '',
Zend_Http_Client::DELETE);
if (!$response->isSuccessful()) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The Get Affinity Group Properties operation returns the
* system properties associated with the specified affinity group.
*
* @param string $affinityGroupName The affinity group name.
* @return Zend_Service_WindowsAzure_Management_AffinityGroupInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function getAffinityGroupProperties($affinityGroupName)
{
if ($affinityGroupName == '' || is_null($affinityGroupName)) {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception('Affinity group name should be specified.');
}
$response = $this->_performRequest(self::OP_AFFINITYGROUPS . '/' . $affinityGroupName);
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
$affinityGroup = new Zend_Service_WindowsAzure_Management_AffinityGroupInstance(
$affinityGroupName,
(string)$result->Label,
(string)$result->Description,
(string)$result->Location
);
// Hosted services
if (count($result->HostedServices->HostedService) > 1) {
$xmlService = $result->HostedServices->HostedService;
} else {
$xmlService = array($result->HostedServices->HostedService);
}
$services = array();
if (!is_null($xmlService)) {
for ($i = 0; $i < count($xmlService); $i++) {
$services[] = array(
'url' => (string)$xmlService[$i]->Url,
'name' => (string)$xmlService[$i]->ServiceName
);
}
}
$affinityGroup->HostedServices = $services;
// Storage services
if (count($result->StorageServices->StorageService) > 1) {
$xmlService = $result->StorageServices->StorageService;
} else {
$xmlService = array($result->StorageServices->StorageService);
}
$services = array();
if (!is_null($xmlService)) {
for ($i = 0; $i < count($xmlService); $i++) {
$services[] = array(
'url' => (string)$xmlService[$i]->Url,
'name' => (string)$xmlService[$i]->ServiceName
);
}
}
$affinityGroup->StorageServices = $services;
return $affinityGroup;
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The List Locations operation lists all of the data center locations
* that are valid for your subscription.
*
* @return array Array of Zend_Service_WindowsAzure_Management_LocationInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function listLocations()
{
$response = $this->_performRequest(self::OP_LOCATIONS);
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
if (!$result->Location) {
return array();
}
if (count($result->Location) > 1) {
$xmlServices = $result->Location;
} else {
$xmlServices = array($result->Location);
}
$services = array();
if (!is_null($xmlServices)) {
for ($i = 0; $i < count($xmlServices); $i++) {
$services[] = new Zend_Service_WindowsAzure_Management_LocationInstance(
(string)$xmlServices[$i]->Name
);
}
}
return $services;
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The List Operating Systems operation lists the versions of the guest operating system
* that are currently available in Windows Azure. The 2010-10-28 version of List Operating
* Systems also indicates what family an operating system version belongs to.
* Currently Windows Azure supports two operating system families: the Windows Azure guest
* operating system that is substantially compatible with Windows Server 2008 SP2,
* and the Windows Azure guest operating system that is substantially compatible with
* Windows Server 2008 R2.
*
* @return array Array of Zend_Service_WindowsAzure_Management_OperatingSystemInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function listOperatingSystems()
{
$response = $this->_performRequest(self::OP_OPERATINGSYSTEMS);
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
if (!$result->OperatingSystem) {
return array();
}
if (count($result->OperatingSystem) > 1) {
$xmlServices = $result->OperatingSystem;
} else {
$xmlServices = array($result->OperatingSystem);
}
$services = array();
if (!is_null($xmlServices)) {
for ($i = 0; $i < count($xmlServices); $i++) {
$services[] = new Zend_Service_WindowsAzure_Management_OperatingSystemInstance(
(string)$xmlServices[$i]->Version,
(string)$xmlServices[$i]->Label,
((string)$xmlServices[$i]->IsDefault == 'true'),
((string)$xmlServices[$i]->IsActive == 'true'),
(string)$xmlServices[$i]->Family,
(string)$xmlServices[$i]->FamilyLabel
);
}
}
return $services;
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* The List OS Families operation lists the guest operating system families
* available in Windows Azure, and also lists the operating system versions
* available for each family. Currently Windows Azure supports two operating
* system families: the Windows Azure guest operating system that is
* substantially compatible with Windows Server 2008 SP2, and the Windows
* Azure guest operating system that is substantially compatible with
* Windows Server 2008 R2.
*
* @return array Array of Zend_Service_WindowsAzure_Management_OperatingSystemFamilyInstance
* @throws Zend_Service_WindowsAzure_Management_Exception
*/
public function listOperatingSystemFamilies()
{
$response = $this->_performRequest(self::OP_OPERATINGSYSTEMFAMILIES);
if ($response->isSuccessful()) {
$result = $this->_parseResponse($response);
if (!$result->OperatingSystemFamily) {
return array();
}
if (count($result->OperatingSystemFamily) > 1) {
$xmlServices = $result->OperatingSystemFamily;
} else {
$xmlServices = array($result->OperatingSystemFamily);
}
$services = array();
if (!is_null($xmlServices)) {
for ($i = 0; $i < count($xmlServices); $i++) {
$services[] = new Zend_Service_WindowsAzure_Management_OperatingSystemFamilyInstance(
(string)$xmlServices[$i]->Name,
(string)$xmlServices[$i]->Label
);
if (count($xmlServices[$i]->OperatingSystems->OperatingSystem) > 1) {
$xmlOperatingSystems = $xmlServices[$i]->OperatingSystems->OperatingSystem;
} else {
$xmlOperatingSystems = array($xmlServices[$i]->OperatingSystems->OperatingSystem);
}
$operatingSystems = array();
if (!is_null($xmlOperatingSystems)) {
require_once 'Zend/Service/WindowsAzure/Management/OperatingSystemInstance.php';
for ($i = 0; $i < count($xmlOperatingSystems); $i++) {
$operatingSystems[] = new Zend_Service_WindowsAzure_Management_OperatingSystemInstance(
(string)$xmlOperatingSystems[$i]->Version,
(string)$xmlOperatingSystems[$i]->Label,
((string)$xmlOperatingSystems[$i]->IsDefault == 'true'),
((string)$xmlOperatingSystems[$i]->IsActive == 'true'),
(string)$xmlServices[$i]->Name,
(string)$xmlServices[$i]->Label
);
}
}
$services[ count($services) - 1 ]->OperatingSystems = $operatingSystems;
}
}
return $services;
} else {
require_once 'Zend/Service/WindowsAzure/Management/Exception.php';
throw new Zend_Service_WindowsAzure_Management_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
}
}
/**
* Clean configuration
*
* @param string $configuration Configuration to clean.
* @return string
*/
public function _cleanConfiguration($configuration) {
$configuration = str_replace('?<?', '<?', $configuration);
$configuration = str_replace("\r", "", $configuration);
$configuration = str_replace("\n", "", $configuration);
return $configuration;
}
}
|