]>
Commit | Line | Data |
---|---|---|
1 | ==================================== | |
2 | Setup PVE v2 Development Environment | |
3 | ==================================== | |
4 | ||
5 | 1. Install Debian 'squeeze' | |
6 | 2. Install prerequisites for development environment: | |
7 | ||
8 | apt-get -y install build-essential git-core debhelper autotools-dev \ | |
9 | doxygen check pkg-config libnss3-dev groff quilt dpatch libxml2-dev \ | |
10 | libncurses5-dev libslang2-dev libldap2-dev xsltproc python-pexpect \ | |
11 | python-pycurl libdbus-1-dev openipmi sg3-utils libnet-snmp-perl \ | |
12 | libnet-telnet-perl snmp python-openssl libxml2-utils automake autoconf \ | |
13 | libsqlite3-dev sqlite3 libfuse-dev libglib2.0-dev librrd-dev \ | |
14 | librrds-perl rrdcached lintian libdevel-cycle-perl libjson-perl \ | |
15 | liblinux-inotify2-perl libio-stringy-perl unzip fuse-utils \ | |
16 | libcrypt-openssl-random-perl libcrypt-openssl-rsa-perl \ | |
17 | libauthen-pam-perl libterm-readline-gnu-perl libssl-dev open-iscsi \ | |
18 | libapache2-mod-perl2 libfilesys-df-perl libfile-readbackwards-perl \ | |
19 | libpci-dev texi2html libgnutls-dev libsdl1.2-dev bridge-utils \ | |
20 | libvncserver0 rpm2cpio apache2-mpm-prefork libintl-perl \ | |
21 | libapache2-request-perl libnet-dns-perl vlan libio-socket-ssl-perl \ | |
22 | libfile-sync-perl ifenslave-2.6 libnet-ldap-perl console-data | |
23 | ||
24 | 3. Download and install the following git modules in order from top to bottom: | |
25 | ||
26 | # git clone git://git.proxmox.com/git/<PACKAGE.git> | |
27 | ||
28 | You currently need the following packages: | |
29 | ||
30 | libqb.git | |
31 | corosync-pve.git | |
32 | openais-pve.git | |
33 | pve-common.git | |
34 | pve-cluster.git | |
35 | redhat-cluster-pve.git | |
36 | lvm.git | |
37 | pve-access-control.git | |
38 | pve-storage.git | |
39 | pve-qemu-kvm.git | |
40 | qemu-server.git | |
41 | vncterm.git | |
42 | pve-manager.git | |
43 | pve-kernel-2.6.32.git | |
44 | fence-agents-pve.git | |
45 | ||
46 | Most source can be installed with 'make dinstall' command. | |
47 | ||
48 | 4. Reboot the system. | |
49 | 5. Learn to use the quilt patch scripts. | |
50 | 6. Happy coding. | |
51 | ||
52 | There is an experimental package containing the API documentation | |
53 | as ExtJS application: | |
54 | ||
55 | pve2-api-doc.git | |
56 | ||
57 | You can view the source code at: | |
58 | ||
59 | https://git.proxmox.com | |
60 | ||
61 | ||
62 | REST vs. SOAP | |
63 | ============= | |
64 | ||
65 | We decided to change our SOAP API (1.X) and use a REST like API. The | |
66 | concept is described in [1] (Resource Oriented Architecture | |
67 | (ROA)). The main advantage is that we are able to remove a lot of code | |
68 | (the whole SOAP stack) to reduce software complexity. | |
69 | ||
70 | We also moved away from server side content generation. Instead we use | |
71 | the ExtJS Rich Internet Application Framework | |
72 | (http://www.sencha.com). | |
73 | ||
74 | That framework, like any other AJAX toolkit, can talk directly to the | |
75 | REST API using JSON. So we were able to remove the server side | |
76 | template toolkit completely. | |
77 | ||
78 | JSON and JSON Schema | |
79 | ==================== | |
80 | ||
81 | We use JSON as data format, because it is simple and parse-able by any | |
82 | web browser. | |
83 | ||
84 | Additionally, we use JSON Schema [2] to formally describe our API. So | |
85 | we can automatically generate the whole API Documentation, and we can | |
86 | verify all parameters and return values. | |
87 | ||
88 | An great side effect was that we are able to use JSON Schema to | |
89 | produce command line argument parsers automatically. In fact, the REST | |
90 | API and the command line tools use the same code. | |
91 | ||
92 | Object linkage is done using the JSON Hyper Schema (links property). | |
93 | ||
94 | A small utility called 'pvesh' exposes the whole REST API on the command | |
95 | line. | |
96 | ||
97 | So here is a summary of the advantage: | |
98 | ||
99 | - easy, human readable data format (native web browser format) | |
100 | - automatic parameter verification (we can also verify return values) | |
101 | - automatic generation of API documentation | |
102 | - easy way to create command line tools (using same API). | |
103 | ||
104 | API Implementation (PVE::RESTHandler) | |
105 | ===================================== | |
106 | ||
107 | All classes exposing methods on the API use PVE::RESTHandler as base class. | |
108 | ||
109 | use base qw(PVE::RESTHandler); | |
110 | ||
111 | To expose methods, one needs to call register_method(): | |
112 | ||
113 | __PACKAGE__->register_method ($schema); | |
114 | ||
115 | Where $schema is a PVE method schema as described in | |
116 | PVE::JSONSchema. It includes a description of parameters and return | |
117 | values, and a reference to the actual code | |
118 | ||
119 | __PACKAGE__->register_method ({ | |
120 | name => 'echo', | |
121 | path => 'echo', | |
122 | method => 'GET', | |
123 | description => "simple return value of parameter 'text'", | |
124 | parameters => { | |
125 | additionalProperties => 0, | |
126 | properties => { | |
127 | text => { | |
128 | type => 'string', | |
129 | } | |
130 | }, | |
131 | }, | |
132 | returns => { | |
133 | type => 'string', | |
134 | }, | |
135 | code => sub { | |
136 | my ($conn, $resp, $param) = @_; | |
137 | ||
138 | return $param->{text}; | |
139 | } | |
140 | }); | |
141 | ||
142 | The 'name' property is only used if you want to call the method | |
143 | directly from Perl. You can do that using: | |
144 | ||
145 | print __PACKAGE__->echo({ text => "a test" }); | |
146 | ||
147 | We use Perl's AUTOLOAD feature to implement this. Note: You need to | |
148 | pass parameters a HASH reference. | |
149 | ||
150 | There is a special helper method called cli_handler(). This is used by | |
151 | the CLIHandler Class for command line tools, where you want to pass | |
152 | arguments as array of strings. This uses Getopt::Long to parse parameters. | |
153 | ||
154 | There is a second way to map names to methods - using the 'path' | |
155 | property. And you can register subclasses. That way you can set up a | |
156 | filesystem like hierarchy to access methods. | |
157 | ||
158 | Here is an example: | |
159 | ---------------------------- | |
160 | package C1; | |
161 | ||
162 | __PACKAGE__->register_method ({ | |
163 | subclass => "C2", | |
164 | path => 'sub2', | |
165 | }); | |
166 | ||
167 | ||
168 | __PACKAGE__->register_method ({ | |
169 | name => 'list1', | |
170 | path => 'index', | |
171 | method => 'GET', | |
172 | ... | |
173 | }); | |
174 | ||
175 | package C2; | |
176 | ||
177 | __PACKAGE__->register_method ({ | |
178 | name => 'list2', | |
179 | path => 'index', | |
180 | method => 'GET', | |
181 | ... | |
182 | }); | |
183 | ------------------------------- | |
184 | ||
185 | The utily method find_handler (in PVE::RESTHandler) can be use to do | |
186 | 'path' related method lookups. | |
187 | ||
188 | C1->find_handler('GET', "/index") => C1::list1 | |
189 | C1->find_handler('GET', "/sub2/index") => C2::list2 | |
190 | ||
191 | The HTTP server use the URL (a path) to find the corresponding method. | |
192 | ||
193 | ||
194 | References | |
195 | ========== | |
196 | [1] RESTful Web Services | |
197 | Web services for the real world | |
198 | ||
199 | By | |
200 | Leonard Richardson, Sam Ruby | |
201 | Publisher: | |
202 | O'Reilly Media | |
203 | Released: | |
204 | May 2007 | |
205 | ||
206 | [2] JSON Schema links: http://json-schema.org/ |