Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Python client for Webfaction API

View docs.txt
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
# API Reference¶
 
The WebFaction [XML-RPC](http://en.wikipedia.org/wiki/XML-RPC) API provides
methods to make many account tasks scriptable. This documentation is a
complete reference to all of the possible API methods.
 
Please note that XML-RPC parameters are positional (order matters), and many
parameters are required. Parameters may only be omitted if omitted parameters
have default values and follow all other parameters to which you have supplied
a value.
 
## General¶
 
`login`¶
 
 
Parameters:
 
* **username** (_string_) - a valid WebFaction control panel username
* **password** (_string_) - a valid WebFaction control panel user's password
* **machine** (_string_) - the case-sensitive machine name (for example, `Web55`); optional for accounts with only one machine
 
Log in a user and return credentials required to make requests for that user.
The method returns a session ID string and a struct containing following key-
value pairs:
 
_id_
 
account ID
_username_
 
username
_home_
 
home directory path
_web_server_
 
Web server associated with the logged in account (for example, `Web55`)
_mail_server_
 
mail server associated with the logged in account (for example, `Mailbox2`)
 
Note
 
The session ID is required for all subsequent API calls.
 
`list_disk_usage`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
List disk space usage statistics about your account (similar to usage
statistics shown [on the control
panel](https://my.webfaction.com/disk_usage)). The method returns a struct
containing the following members:
 
`home_directories`
 
 
A list of structs with details for each home directory associated with the
account. Each struct contains the following members:
 
`last_reading`
 
The date and time of the last recording of the home directory's size
`machine`
 
The server name (for example, `Web300`)
`name`
 
The username
`size`
 
The disk usage in kilobytes
`mailboxes`
 
 
A list of structs with details for each mailbox associated with the account.
Each struct contains the following members:
 
`last_reading`
 
The date and time of the last recording of the mailbox's size
`name`
 
The mailbox name
`size`
 
The disk usage in kilobytes
`mysql_databases`
 
 
A list of structs with details for each MySQL database associated with the
account. Each struct contains the following members:
 
`last_reading`
 
The date and time of the last recording of the database's size
`name`
 
The database name
`size`
 
The disk usage in kilobytes
`postgresql_databases`
 
 
A list of structs with details for each PostgreSQL database associated with
the account. Each struct contains the following members:
 
`last_reading`
 
The date and time of the last recording of the database's size
`name`
 
The database name
`size`
 
The disk usage in kilobytes
`total`
 
The account's total disk usage in kilobytes
`quota`
 
The account's total disk allotment in kilobytes
`percentage`
 
The account's total disk usage as a percentage of the quota (for example, an account using 3.1 GB of 100 GB would use `3.1` percent of its quota)
 
## Email¶
 
### Mailboxes¶
 
`change_mailbox_password`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **mailbox** (_string_) - a valid mailbox name
* **password** (_string_) - the new mailbox password
 
Change a mailbox password.
 
See also
 
See [Strengthening Passwords](http://docs.webfaction.com/user-
guide/passwords.html) for important information about choosing passwords.
 
`create_mailbox`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **mailbox** (_string_) - mailbox name
* **enable_spam_protection** (_boolean_) - whether spam protection is enabled for the mailbox (optional, default: true)
* **discard_spam** (_boolean_) - whether spam messages received by the new mailbox are discarded (optional, default: false)
* **spam_redirect_folder** (_string_) - name of the IMAP folder where messages identified as spam are stored (optional, default: an empty string)
* **use_manual_procmailrc** (_boolean_) - whether to use manual procmailrc rules as specified by the `manual_procmailrc` parameter (optional, default: false)
* **manual_procmailrc** (_string_) - the procmailrc rules for the mailbox (optional, default: an empty string)
 
Warning
 
If `discard_spam` is true, messages misidentified as spam--false positives--
may be lost permanently.
 
Create a mailbox and return a struct containing the following key-value pairs:
 
_id_
 
mailbox ID
_name_
 
mailbox name
_enable_spam_protection_
 
name of the folder where messages identified as spam are stored
_password_
 
a randomly generated password
_discard_spam_
 
a boolean indicating whether spam emails are be discarded
_spam_redirect_folder_
 
name of the IMAP folder where messages identified as spam are stored
_use_manual_procmailrc_
 
a boolean indicating whether manual procmailrc rules are enabled
_manual_procmailrc_
 
a string containing manual procmailrc rules
 
See also
 
`update_mailbox`
 
`delete_mailbox`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **mailbox** (_string_) - mailbox name
 
Delete a mailbox.
 
`list_mailboxes`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about the account's mailboxes. The method returns an array of
structs with the following key-value pairs:
 
_id_
 
mailbox ID
_name_
 
mailbox name
_enable_spam_protection_
 
name of the folder where messages identified as spam are stored
_password_
 
a randomly generated password
_discard_spam_
 
a boolean indicating whether spam emails are be discarded
_spam_redirect_folder_
 
name of the IMAP folder where messages identified as spam are stored
_use_manual_procmailrc_
 
a boolean indicating whether manual procmailrc rules are enabled
_manual_procmailrc_
 
a string containing manual procmailrc rules
 
`update_mailbox`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **mailbox** (_string_) - mailbox name
* **enable_spam_protection** (_boolean_) - whether spam protection is enabled for the mailbox (optional, default: true)
* **discard_spam** (_boolean_) - whether spam messages received by the new mailbox are discarded (optional, default: false)
* **spam_redirect_folder** (_string_) - name of the IMAP folder where messages identified as spam are stored (optional, default: an empty string)
* **use_manual_procmailrc** (_boolean_) - whether to use manual procmailrc rules as specified by the `manual_procmailrc` parameter (optional, default: false)
* **manual_procmailrc** (_string_) - the procmailrc rules for the mailbox (optional, default: an empty string)
 
Warning
 
If `discard_spam` is true, messages misidentified as spam--false positives--
may be lost permanently.
 
Change the details of an existing mailbox. The mailbox must exist before
calling the method. The method returns a struct containing the following key-
value pairs:
 
_id_
 
mailbox ID
_name_
 
mailbox name
_enable_spam_protection_
 
name of the folder where messages identified as spam are stored
_password_
 
a randomly generated password
_discard_spam_
 
a boolean indicating whether spam emails are be discarded
_spam_redirect_folder_
 
name of the IMAP folder where messages identified as spam are stored
_use_manual_procmailrc_
 
a boolean indicating whether manual procmailrc rules are enabled
_manual_procmailrc_
 
a string containing manual procmailrc rules
 
See also
 
`create_mailbox`
 
### Addresses¶
 
`create_email`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **email_address** (_string_) - an email address (for example, `name@example.com`)
* **targets** (_string_) - names of destination mailboxes or addresses, separated by commas
* **autoresponder_on** (_boolean_) - whether an autoresponder is enabled for the address (optional, default: false)
* **autoresponder_subject** (_string_) - subject line of the autoresponder message (optional, default: an empty string)
* **autoresponder_message** (_string_) - body of the autoresponder message (optional, default: an empty string)
* **autoresponder_from** (_string_) - originating address of the autoresponder message (optional, default: an empty string)
* **script_machine** (_string_) - a machine name for specifying a path to a script (optional, default: an empty string)
* **script_path** (_string_) - an absolute path to a script; see _[Sending Mail to a Script_](http://docs.webfaction.com/user-guide/email.html#email-sending-mail-to-a-script) for details (optional, default: an empty string)
 
Create an email address which delivers to the specified mailboxes.
 
If _autoresponder_on_ is true, then an autoresponder subject, message, and
from address may be specified.
 
See also
 
`update_email`
 
`delete_email`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **email_address** (_string_) - an email address (for example, `name@example.com`)
 
Delete an email address.
 
`list_emails`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about the account's email addresses. The method returns an
array of structs with the following key-value pairs:
 
_id_
 
email ID
_email_address_
 
email address
_targets_
 
mailboxes or email addresses to which the address is set to deliver
_autoresponder_on_
 
a boolean indicating whether an autoresponder is enabled for the address
_autoresponder_subject_
 
the autoresponder subject line (if applicable)
_autoresponder_message_
 
the autoresponder message body (if applicable)
_autoresponder_from_
 
the autoresponder from address (if applicable)
 
`update_email`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **email_address** (_string_) - an email address (for example, `name@example.com`)
* **targets** (_array_) - names of destination mailboxes or addresses
* **autoresponder_on** (_boolean_) - whether an autoresponder is enabled for the address (optional, default: false)
* **autoresponder_subject** (_string_) - subject line of the autoresponder message (optional, default: an empty string)
* **autoresponder_message** (_string_) - body of the autoresponder message (optional, default: an empty string)
* **autoresponder_from** (_string_) - originating address of the autoresponder message (optional, default: an empty string)
* **script_machine** (_string_) - a machine name for specifying a path to a script (optional, default: an empty string)
* **script_path** (_string_) - an absolute path to a script; see _[Sending Mail to a Script_](http://docs.webfaction.com/user-guide/email.html#email-sending-mail-to-a-script) for details (optional, default: an empty string)
 
Change the details of an existing email address. The email address must exist
before calling the method. The method returns a struct with the following key-
value pairs:
 
_id_
 
email ID
_email_address_
 
email address
_targets_
 
mailboxes or email addresses to which the address is set to deliver
 
See also
 
`create_email`
 
## Websites and Domains¶
 
`create_domain`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **domain** (_string_) - a domain name in the form of `example.com`
* **subdomain** (_string_) - each additional parameter provided after `domain`: a subdomain name of `domain`
 
Create a domain entry. If `domain` has already been created, you may supply
additional parameters to add subdomains. For example, if `example.com` already
exists, `create_domain` may be called with four parameters-- a session ID,
`example.com`, `www`, `private`--to create `www.example.com` and
`private.example.com`.
 
**Example**: Create a domain entry for `widgetcompany.example` using Python:
>>> import xmlrpclib
>>> server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
>>> session_id, account = server.login('widgetsco', 'widgetsrock')
>>> server.create_domain(session_id, 'widgetcompany.example', 'www', 'design')
{'domain': 'widgetcompany.example',
'id': 47255,
'subdomains': ['www', 'design']}
 
`create_website`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **website_name** (_string_) - the name of the new website entry
* **ip** (_string_) - IP address of the server where the entry resides
* **https** (_boolean_) - whether the website entry should use a secure connection
* **subdomains** (_array_) - an array of strings of (sub)domains to be associated with the website entry
* **site_apps** (_array_) - each additional parameter provided after `subdomains`: an array containing a valid application name (a string) and a URL path (a string)
 
Create a new website entry. Applications may be added to the website entry
with additional parameters supplied after `subdomains`. The additional
parameters must be arrays containing two elements: a valid application name
and a path (for example, `'htdocs'` and `'/'`).
 
**Example:** Create a website entry for `widgetcompany.example`'s new Django project over HTTPS using Python:
>>> import xmlrpclib
>>> server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
>>> session_id, account = server.login('widgetsco', 'widgetsrock')
>>> server.create_website(session_id,
... 'widgets_on_the_web',
... '174.133.82.194',
... True,
... ['widgetcompany.example', 'www.widgetcompany.example'],
... ['django', '/'])
{'https': True,
'id': 67074,
'ip': '174.133.82.194',
'name': 'widgets_on_the_web',
'site_apps': [['django', '/']],
'subdomains': ['widgetcompany.example', 'www.widgetcompany.example']}
 
`delete_domain`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **domain** (_string_) - name of the domain to be deleted or the parent domain of the subdomains to be deleted
* **subdomains** (_string_) - each additional parameter provided after `domain`: subdomains of `domain` to be deleted
 
Delete a domain record or subdomain records. Subdomains of a domain may be
deleted by supplying additional parameters after `domain`. If any subdomains
are provided, only subdomains are deleted and the parent domain remains.
 
`delete_website`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **website_name** (_string_) - name of website to be deleted
* **ip** (_string_) - IP address of the server where the website resides
* **https** (_boolean_) - whether the website uses a secure connection (optional, default: false)
 
Delete a website entry.
 
`list_bandwidth_usage`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
List bandwidth usage statistics for your websites (similar to usage statistics
shown [on the control panel](https://my.webfaction.com/bandwidth_usage)). The
method returns a struct containing two members:
 
`daily`: A struct containing members named for the dates for the past two
weeks (for example, `2014-02-15`, `2014-02-14`, `2014-02-13` and so on). The
value of each dated member is a struct containing members named for each
domain associated with the account (for example, `example.com`,
`www.example.com`, `somedomain.example`, `www.somedomain.example` and so on).
The value of each domain name member is the bandwidth usage for that domain
during that day in kilobytes.
 
`monthly`: A struct containing members named for the months for the past year
(for example, `2014-02`, `2014-01`, `2013-12` and so on). The value of each
month member is a struct containing members named for each domain associated
with the account (for example, `example.com`, `www.example.com`,
`somedomain.example`, `www.somedomain.example` and so on). The value of each
domain name member is the bandwidth usage for that domain during that month in
kilobytes.
 
Overall, the struct resembles this outline:
 
* `daily`
* today
* `www.example.com`: `1024`
* `example.com`: `512`
* …
* yesterday
* …
* two weeks ago
* `monthly`
* this month
* `www.example.com`: `2048`
* `example.com`: `1024`
* …
* last month
* …
* a year ago
 
`list_domains`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about the account's domains. The method returns an array of
structs with the following key-value pairs:
 
_id_
 
domain ID
_domain_
 
domain (for example, `example.com`)
_subdomains_
 
array of subdomains for the domain
 
`list_websites`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about the account's websites. The method returns an array of
structs with the following key-value pairs:
 
_id_
 
website ID
_name_
 
website name
_ip_
 
website IP address
_https_
 
whether the website is served over HTTPS
_subdomains_
 
array of website's subdomains
_website_apps_
 
array of the website's apps and their URL paths; each item in the array is a two-item array, containing an application name and URL path
 
`update_website`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **website_name** (_string_) - the name of the new website entry
* **ip** (_string_) - IP address of the server where the entry resides
* **https** (_boolean_) - whether the website entry should use a secure connection
* **subdomains** (_array_) - an array of strings of (sub)domains to be associated with the website entry
* **site_apps** (_array_) - each additional parameter provided after `subdomains`: an array containing a valid application name (a string) and a URL path (a string)
 
Update a website entry. Applications may be added to the website entry with
additional parameters supplied after `subdomains`. The additional parameters
must be arrays containing two elements: a valid application name and a path
(for example, `'htdocs'` and `'/'`).
 
**Example:** Update a website entry for `widgetcompany.example`'s new Django project over HTTPS using Python:
>>> import xmlrpclib
>>> server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
>>> session_id, account = server.login('widgetsco', 'widgetsrock')
>>> server.update_website(session_id,
... 'widgets_on_the_web',
... '174.133.82.195',
... True,
... ['widgetcompany.example', 'dev.widgetcompany.example'],
... ('django', '/'), ('wordpress', '/blog'))
{'https': True,
'id': 67074,
'ip': '174.133.82.195',
'name': 'widgets_on_the_web',
'site_apps': [['django', '/'], ['wordpress', '/blog']],
'subdomains': ['widgetcompany.example', 'dev.widgetcompany.example']}
 
## Applications¶
 
`create_app`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **name** (_string_) - name of the application
* **type** (_string_) - type of the application
* **autostart** (_boolean_) - whether the app should restart with an `autostart.cgi` script (optional, default: false)
* **extra_info** (_string_) - additional information required by the application; if _extra_info_ is not required or used by the application, it is ignored (optional, default: an empty string)
* **open_port** (_boolean_) - for applications that listen on a port, whether the port should be open on shared and dedicated IP addresses (optional, default: false)
 
Create a new application.
 
See also
 
For a complete list of application types, see _[Application Types_](apps.html
#application-types).
 
`delete_app`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **name** (_string_) - name of the application
 
Delete an application.
 
`list_apps`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about the account's applications. The method returns an array
of structs with the following key-value pairs:
 
_id_
 
app ID
_name_
 
app name
_type_
 
app type
_autostart_
 
whether the app uses autostart
_port_
 
port number if the app listens on a port, otherwise is `0`
_open_port_
 
for applications that listen on a port, whether the port is open on shared and dedicated IP addresses (`True` for open ports, `False` for closed ports, or for applications that do not listen to a port)
_extra_info_
 
extra info for the app if any
_machine_
 
name of the machine where the app resides
 
`list_app_types`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about available app types. The method returns an array of
structs with the following key-value pairs:
 
_description_
 
description of the application type
_name_
 
short identifier for the application type
_autostart_
 
`applicable` or an empty string, indicating whether the application uses an `autostart.cgi` file
_extra_info_
 
description of any additional information required by the application installer's _extra_info_ field
 
See also
 
`create_app`
 
## Cron¶
 
`create_cronjob`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **line** (_string_) - crontab line to be added
 
Create a new cron job.
 
See also
 
For more information about the cron syntax, please see the Wikipedia entry on
[cron](http://en.wikipedia.org/wiki/Cron#crontab_syntax).
 
`delete_cronjob`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **line** (_string_) - crontab line to be removed
 
Remove an existing cron job.
 
## DNS¶
 
`create_dns_override`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **domain** (_string_) - domain name to be overridden (for example, `sub.example.com`)
* **a_ip** (_string_) - A IP address (optional, default: an empty string)
* **cname** (_string_) - CNAME record (optional, default: an empty string)
* **mx_name** (_string_) - Mail exchanger record host name (optional, default: an empty string)
* **mx_priority** (_string_) - Mail exchanger record priority (optional, default: an empty string)
* **spf_record** (_string_) - TXT record (optional, default: an empty string)
* **aaaa_ip** (_string_) - An IPv6 address (optional, default: an empty string)
 
Create DNS records and return an array of the new records (as in the form of
`list_dns_overrides`).
 
`delete_dns_override`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **domain** (_string_) - domain name to be overridden (for example, `sub.example.com`)
* **a_ip** (_string_) - A IP address (optional, default: an empty string)
* **cname** (_string_) - CNAME record (optional, default: an empty string)
* **mx_name** (_string_) - Mail exchanger record host name (optional, default: an empty string)
* **mx_priority** (_string_) - Mail exchanger record priority (optional, default: an empty string)
* **spf_record** (_string_) - TXT record (optional, default: an empty string)
* **aaaa_ip** (_string_) - An IPv6 address (optional, default: an empty string)
 
Delete DNS records and return an array of the deleted records (as in the form
of `list_dns_overrides`).
 
`list_dns_overrides`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about the account's DNS overrides. The method returns an array
of structs with the following key-value pairs:
 
_id_
 
domain ID
_domain_
 
domain name to be overridden (for example, `sub.example.com`)
_a_ip_
 
A IP address
_aaaa_ip_
 
AAAA IP address (for IPv6)
_cname_
 
CNAME record
_mx_name_
 
Mail exchanger record host name
_mx_priority_
 
Mail exchanger record priority
_spf_record_
 
TXT record
_srv_record_
 
Service record
 
## Databases¶
 
`change_db_user_password`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **username** (_string_) - a databse user's username
* **password** (_string_) - the new password
* **db_type** (_string_) - the database type, either `mysql` or `postgresql`
 
Change a database user's password. The method returns a struct containing the
following key-value pairs:
 
_username_
 
database username
_machine_
 
database machine name
_db_type_
 
database type (MySQL or PostgreSQL)
_database_
 
database name
 
See also
 
See [Strengthening Passwords](http://docs.webfaction.com/user-
guide/passwords.html) for important information about choosing passwords.
 
`create_db`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **name** (_string_) - database name
* **db_type** (_string_) - the database type, either `mysql` or `postgresql`
* **password** (_string_) - password for the default database user
 
Create a database.
 
Note
 
MySQL database names may not exceed 16 characters.
 
See also
 
See [Strengthening Passwords](http://docs.webfaction.com/user-
guide/passwords.html) for important information about choosing passwords.
 
`create_db_user`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **username** (_string_) - the new database user's username
* **password** (_string_) - the new database user's password
* **db_type** (_string_) - the database type, either `mysql` or `postgresql`
 
Create a database user. The method returns a struct with the following key-
value pairs:
 
_machine_
 
machine name
_username_
 
database username
_db_type_
 
database type (MySQL or PostgreSQL)
 
See also
 
See [Strengthening Passwords](http://docs.webfaction.com/user-
guide/passwords.html) for important information about choosing passwords.
 
`delete_db`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **name** (_string_) - database name
* **db_type** (_string_) - the database type, either `mysql` or `postgresql`
 
Delete a database.
 
`delete_db_user`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **username** (_string_) - the database user's username
* **db_type** (strings `mysql` or `postgresql`) - the database type
 
Delete a database user. The method returns a struct with the following key-
value pairs:
 
_machine_
 
machine name
_username_
 
database username
_db_type_
 
database type (MySQL or PostgreSQL)
 
`enable_addon`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **database** (_string_) - a database name
* **db_type** (_string_) - the database type (always use `postgresql`)
* **addon** (_string_) - the addon to enable (`tsearch` or `postgis`)
 
Enable a database addon. The method returns a struct with the following key-
value pairs:
 
_machine_
 
machine name
_db_type_
 
database type (always PostgreSQL)
_addon_
 
addon enabled
_db_type_
 
database type (MySQL or PostgreSQL)
 
Note
 
This method applies to PostgreSQL databases only.
 
`grant_db_permissions`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **username** (_string_) - a databse user's username
* **database** (_string_) - a database name
* **db_type** (_string_) - the database type (`mysql` or `postgresql`)
 
Grant full database permissions to a user with respect to a database. The
method returns a struct with the following key-value pairs:
 
_machine_
 
machine name
_username_
 
database username
_db_type_
 
database type (MySQL or PostgreSQL)
_database_
 
database name
 
`list_dbs`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about the account's databases. The method returns an array of
structs with the following key-value pairs:
 
_id_
 
database ID
_name_
 
database name
_db_type_
 
database type (MySQL or PostgreSQL)
_machine_
 
machine name
 
`list_db_users`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about the account's database users. The method returns an
array of structs with the following key-value pairs:
 
_machine_
 
machine name
_username_
 
database username
_db_type_
 
database type (MySQL or PostgreSQL)
 
`make_user_owner_of_db`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **username** (_string_) - a databse user's username
* **database** (_string_) - a database name
* **db_type** (_string_) - the database type (`mysql` or `postgresql`)
 
Assign ownership of a database to a user. The method returns a struct with the
following key-value pairs:
 
_machine_
 
machine name
_username_
 
database username
_db_type_
 
database type (MySQL or PostgreSQL)
_database_
 
database name
 
`revoke_db_permissions`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **username** (_string_) - a databse user's username
* **database** (_string_) - a database name
* **db_type** (_string_) - the database type (`mysql` or `postgresql`)
 
Revoke a user's permissions with respect to a database. The method returns a
struct with the following key-value pairs:
 
_machine_
 
machine name
_username_
 
database username
_db_type_
 
database type (MySQL or PostgreSQL)
_database_
 
database name
 
## Files¶
 
`replace_in_file`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **filename** (_string_) - path to file from the user's home directory
* **changes** (_array_) - each additional parameter provided after `filename`: an array of two strings, where the first is the text to be replaced and the second is the replacement text
 
Find and replace strings in a file in the users's home directory tree.
 
Any parameters after `filename` must be arrays containing a pair of strings,
where the first is the string to be replaced and the second is the replacement
text.
 
**Example:** Find all appearances of the word "eggs" in a file in the user's home directory and replace them with the word "spam" using Python:
$ cat myfile.txt
eggs, spam, spam, and spam.
spam, spam, spam, and eggs.
>>> import xmlrpclib
>>> server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
>>> session_id, account = server.login('widgetsco', 'widgetsrock')
>>> server.replace_in_file(session_id, 'myfile.txt', ('eggs', 'spam'))
''
>>> exit()
$ cat myfile.txt
spam, spam, spam, and spam.
spam, spam, spam, and spam.
 
`replace_in_file`
 
`write_file`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **filename** (_string_) - path to file to be written from the user's home directory
* **str** (_string_) - string to be written
* **mode** (_string_) - write mode (optional, default: `wb`)
 
Write a string to a file in the user's home directory tree.
 
Note
 
Commonly, the write mode is `w` for plain text and `wb` for binaries. `a` and
`ab` can be used to append to files.
 
See also
 
For more information about write modes, please see
[open()](http://docs.python.org/library/functions.html#open).
 
## Shell Users¶
 
`change_user_password`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **username** (_string_) - username
* **password** (_string_) - a new passowrd
 
Change a shell user's password.
 
See also
 
See [Strengthening Passwords](http://docs.webfaction.com/user-
guide/passwords.html) for important information about choosing passwords.
 
`create_user`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **username** (_string_) - username
* **shell** (_string_) - the user's command line interpreter; one of `none`, `bash`, `sh`, `ksh`, `csh`, or `tcsh`.
* **groups** (_array_) - extra permission groups of which the new user is to be a member
 
Create a new shell user. If `shell` is `none`, the user has FTP access only.
All users are automatically a member of their own group; do not include the
user's own group in `groups`. Use an empty array to specify no extra groups.
 
`delete_user`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **username** (_string_) - username
 
Delete a user.
 
`list_users`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about the account's shell users. The method returns an array
of structs with the following key-value pairs:
 
_username_
 
username
_machine_
 
the user's server (for example, `Web100`)
_shell_
 
the user's configured command line interpreter (for example, `bash` or `tcsh`)
_groups_
 
extra permissions groups of which the user is a member
 
## Servers¶
 
`list_ips`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about all of the account's machines and their IP addresses.
This method returns an array of structs with the following key-value pairs:
 
_machine_
 
machine name (for example, `Web100`)
_ip_
 
IP address
_is_main_
 
a boolean value indicating whether the IP address is the primary address for the server (true) or an extra IP address provisioned to the account (false)
 
`list_machines`¶
 
 
Parameters:
 
**session_id** - session ID returned by `login`
 
Get information about the account's machines. This method returns an array of
structs with the following key-value pairs:
 
_name_
 
machine name (for example, `Web100`)
_operating_system_
 
the machine's operating system (for example, `Centos6-64bit`)
_location_
 
the machine's location (for example, `USA`)
 
## Miscellaneous¶
 
`run_php_script`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **script** (_string_) - an absolute path to script (or path to the script starting from the user's home directory)
* **code_before** (_string_) - PHP code to be executed before `script`
 
Run PHP code followed by a PHP script. The PHP code and script is run as the
user.
 
`set_apache_acl`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **paths** (_string or array of strings_) - path from home directory
* **permission** (_string_) - `r`, `w`, or `x` or a combination thereof (optional, default: `rwx`)
* **recursive** (_boolean_) - whether Apache's access is granted recursively (optional, default: false)
 
Grant the machine-wide Apache instance access to files or directories.
 
`system`¶
 
 
Parameters:
 
* **session_id** - session ID returned by `login`
* **cmd** (_string_) - a shell command to be executed
 
Execute a command as the user, as if through SSH. If an application was
installed previously in the session, the command will be run from the
directory where that application was installed.
 
Note
 
If `cmd` writes to standard error, the API method will return an XML-RPC
fault.
 
### [Table Of Contents](index.html)
 
* API Reference
* General
* Email
* Mailboxes
* Addresses
* Websites and Domains
* Applications
* Cron
* DNS
* Databases
* Files
* Shell Users
* Servers
* Miscellaneous
 
#### Previous topic
 
[ Tutorial ](tutorial.html)
 
#### Next topic
 
[ Application Types ](apps.html)
 
### Search the documentation
 
Example: "configure email" or "create database"
 
#### PDF download
 
[Download this document as PDF](http://docs.webfaction.com/xmlrpc-
api/WebFactionAPIDocumentation.pdf)
 
### Feedback
 
Send us your feedback on this documentation.
 
![](_static/ajax-loader.gif)
 
### Navigation
 
* [index](genindex.html)
* [next](apps.html)
* [previous](tutorial.html)
* [WebFaction API Documentation](index.html)
 
[Features & prices](https://www.webfaction.com/features) [Sign
up](https://www.webfaction.com/signup) [Contact
us](http://www.webfaction.com/contact) [Affiliate
program](http://www.webfaction.com/services/affiliate)
[Support](https://help.webfaction.com/)
[Legal](https://www.webfaction.com/tos)
[Jobs](http://www.webfaction.com/jobs) [Blog](http://blog.webfaction.com)
[Control panel login](https://my.webfaction.com)
(C) 2009-2014 Swarma Limited. WebFaction is a service of Swarma Limited.
Registered in England and Wales 5729350 - VAT registration number 877397162
View docs.txt
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
"""
CLI tools for webfaction API. The project seem abandoned already
so I've just fork it to my github account and start adding few
unimplemented command.
https://pypi.python.org/pypi/webf
https://github.com/k4ml/webf
After playing around with the API for a while, I realized
that we don't really need fancy library to access the API.
It pretty straightforward, the API only accept either plain
string, boolean or list as parameters and return either a dict
or list of dicts. So here a client to the whole APIs in just
106 lines of code:
Ping me @k4ml (twitter/github) if you need any help.
TODO:-
* Pull list of commands from http://docs.webfaction.com/xmlrpc-api/apiref.html
for easy reference.
"""
import re
import sys
import xmlrpclib
import logging
import os.path
import ConfigParser
 
API_URL = 'https://api.webfaction.com/'
CONF = os.path.expanduser('~/.webfrc')
 
class WebFactionXmlRpc(object):
 
'''WebFaction XML-RPC server proxy class'''
 
def __init__(self, login=True):
self.log = logging.getLogger('webf')
self.log.addHandler(logging.StreamHandler())
self.session_id = None
self.server = None
if login:
self.login()
 
def get_config(self):
'''Get configuration file from user's directory'''
if not os.path.exists(CONF):
self.log.error("Set your username/password in %s" % CONF)
self.log.error("The format is:")
self.log.error(" [main]")
self.log.error(" username=<username>")
self.log.error(" password=<password>")
sys.exit(1)
 
config = ConfigParser.ConfigParser()
config.readfp(open(CONF))
username = config.get('main', 'username')
password = config.get('main', 'password')
return (username, password)
 
def login(self):
'''Login to WebFaction and get a session_id'''
try:
http_proxy = os.environ['http_proxy']
except KeyError:
http_proxy = None
username, password = self.get_config()
self.server = xmlrpclib.Server(API_URL, transport=http_proxy)
self.session_id, account = self.server.login(username, password)
self.log.debug("self.session_id %s account %s" % (self.session_id,
account))
 
def _show(self, result, id_field='name', pattern=None):
for item in result:
if pattern and pattern != 'None':
to_match = item[id_field] + ' ' + item.get('description', '')
if not re.search(pattern, to_match):
continue
for key, value in item.items():
if key == id_field:
print value
else:
print "\t", "%s: " % key, value
 
def _call(self, command, *args):
'''Generic command'''
func = getattr(self.server, command)
try:
result = func(self.session_id, *args)
self.log.debug(result)
except xmlrpclib.Fault, errmsg:
self.log.error(errmsg)
return 1
 
return result
 
def main():
if len(sys.argv) < 2:
print 'Need command'
print 'Example: python webf.py list_ips'
print 'Example: python webf.py create_website web1 "216.185.102.19" true "web1.biz,store1" "store1:/,django:/admin"'
 
sys.exit(1)
command = sys.argv[1]
args = sys.argv[2:]
new_args = []
for argument in args:
if argument in ('true', 'false'):
argument = True if argument == 'true' else False
new_args.append(argument)
continue
 
if ':' in argument:
mapping_list = argument.split(',')
argument = [(key, val) for key, val in [mapping.split(':') for mapping in mapping_list]]
new_args += argument
continue
 
if ',' in argument:
argument = argument.split(',')
new_args.append(argument)
continue
 
new_args.append(argument)
 
print command, new_args
wf = WebFactionXmlRpc()
result = wf._call(command, *new_args)
wf._show(result)
 
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.