Bonjour,
J'ai un problème que je n'arrive pas à résoudre. un script du nom de listvz.htm composé comme suit : Le principe général. La page .htm lancée, lance des requêtes sur des machines virtuelles qui renvoient un fichier XML. C'est analysé puis affiché.
le fichier XML ressemble a ceci (le fichier n'est pas complet).Citation:
[$ var $req $vznodes $sessions $]
[-
$req = shift;
$vznodes = $req->{vznodes};
$sessions = $req->open_sessions();
-]
<table>
[$ var $host $]
[$ foreach $host ( sort keys %$sessions ) $]
<tr span="6"><td> </td></tr>
<tr span="6"><th align="left">[+ $host +]</th></tr>
<tr>
<th align="left">[= state =]</th>
<th align="left">[= alert =]</th>
<th align="left">[= on boot =]</th>
<th align="left">[= veid =]</th>
<th align="left">[= ip address =]</th>
<th align="left">[= hostname =]</th>
<th align="left">[= espace disque =]</th>
<th align="left">[= os template =]</th>
</tr>
[$ var $info $]
[-
my $vza = $sessions->{$host};
my $eid_list = $vza->send_msg( 'vzaenvm', 'get_list' );
my @eid_list;
push @eid_list, $_->string_value()
foreach $eid_list->findnodes( '/packet/vzlp:data/vzle:vzaenvm/vzle:eid' );
$info = $vza->send_msg( 'vzaenvm', 'get_info'
, { eid => \@eid_list, config => '' });
-]
[$ var $vz $]
[$ foreach $vz ( $info->findnodes( '/packet/vzlp:data/vzle:vzaenvm/vzle:env' )) $]
<tr>
<td>[+ $info->findvalue( 'vzlt:status/vzlt:state', $vz ) +]</td>
<td>[+ $info->findvalue( 'vzlt:alert', $vz ) +]</td>
<td>[+ $info->findvalue( 'vzlt:virtual_config/vzat:on_boot', $vz ) +]</td>
<td>[+ $info->findvalue( 'vzlt:virtual_config/vzat:veid', $vz ) +]</td>
<td>[+ $info->findvalue( 'vzlt:virtual_config/vzlt:address/vzlt:ip', $vz ) +]</td>
<td>[+ $info->findvalue( 'vzlt:virtual_config/vzlt:hostname', $vz ) +]</td>
<td>[+ $info->findvalue( 'vzlt:virtual_config/qos/@diskspace/following', $vz ) +]</td>
<td>[+ $info->findvalue( 'vzlt:virtual_config/vzat:os_template/vzat:name', $vz ) +]</td>
</tr>
[$ endforeach $]
[$ endforeach $]
</table>
Code:
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 <?xml version="1.0" encoding="UTF-8"?><packet xmlns:ns4="http://www.swsoft.com/webservices/vzl/4.0.0/types" xmlns:ns1="http://www.swsoft.com/webservices/vzl/4.0.0/protocol" xmlns:ns2="http://www.swsoft.com/webservices/vzl/4.0.0/envm" xmlns:ns3="http://www.swsoft.com/webservices/vza/4.0.0/vzatypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" time="2010-11-04T11:13:12+0000" id="13" priority="0" version="4.0.0"> <ns1:origin>vzaenvm</ns1:origin> <ns1:target>vzclient1406-de1d858b-b3e8-b7d2-428f-f893a3469581</ns1:target> <ns1:dst> <director>gend</director> </ns1:dst> <ns1:data> <ns2:vzaenvm> <ns2:env xsi:type="ns3:envType"> <ns4:parent_eid>de1d858b-b3e8-b7d2-428f-f893a3469581</ns4:parent_eid> <ns4:eid>a26861cc-2c27-41fb-8087-c636e04480bb</ns4:eid> <ns4:status xsi:type="ns4:env_statusType"> <ns4:state>6</ns4:state> </ns4:status> <ns4:alert>0</ns4:alert> <ns4:config xsi:type="ns4:env_configType"/> <ns4:virtual_config xsi:type="ns3:venv_configType"> <ns3:veid>188092</ns3:veid> <ns4:type>virtuozzo</ns4:type> <ns3:ve_private>D:\vz\Private\188092</ns3:ve_private> <ns3:ve_root>D:\vz\Private\188092\root</ns3:ve_root> <ns4:qos> <ns4:id>cpuguarantee</ns4:id> <ns4:hard>0</ns4:hard> </ns4:qos> <ns4:qos> <ns4:id>cpulimit</ns4:id> <ns4:hard>100</ns4:hard> </ns4:qos> <ns4:qos> <ns4:id>diskspace</ns4:id> <ns4:hard>10485760</ns4:hard> </ns4:qos>
Mon problème est de récupérer la valeur par exemple de :
contenus dans les balise qosCode:
1
2
3
4 <ns4:qos> <ns4:id>diskspace</ns4:id> <ns4:hard>10485760</ns4:hard> </ns4:qos>
Comment dois-je faire pour récupérer la valeur 10485760de la balise hard ? La ligne correspondante dans le script perl est la suivante : On me dis d'utiliser Xpath (ce que j'essaie) mais ça ne marche pas. Les autres "affichage" dans le script perl fonctionne bien (exemple le status) car se sont des balises XML "simple".
Citation:
<td>[+ $info->findvalue( 'vzlt:virtual_config/qos/@diskspace/following', $vz ) +]</td>
Quelqu'un peut m'aider ?
Merci