+ my ($conf, $noerr) = @_;
+
+ if ($conf && $conf->{children} && $conf->{children}->[0]) {
+ my $cluster = $conf->{children}->[0];
+ if ($cluster && ($cluster->{text} eq 'cluster') &&
+ $cluster->{config_version}) {
+ if (my $version = int($cluster->{config_version})) {
+ return wantarray ? ($version, $cluster) : $version;
+ }
+ }
+ }
+
+ return undef if $noerr;
+
+ die "no cluster config - unable to read version\n";
+}
+
+sub cluster_conf_lookup_cluster_section {
+ my ($conf, $noerr) = @_;
+
+ my ($version, $cluster) = cluster_conf_version($conf, $noerr);
+
+ return $cluster;
+}
+
+sub cluster_conf_lookup_rm_section {
+ my ($conf, $create, $noerr) = @_;
+
+ my $cluster = cluster_conf_lookup_cluster_section($conf, $noerr);
+ return undef if !$cluster;
+
+ my $rmsec;
+ foreach my $child (@{$cluster->{children}}) {
+ if ($child->{text} eq 'rm') {
+ $rmsec = $child;
+ }
+ }
+ if (!$rmsec) {
+ if (!$create) {
+ return undef if $noerr;
+ die "no resource manager section\n";
+ }
+ $rmsec = { text => 'rm' };
+ push @{$cluster->{children}}, $rmsec;
+ }
+
+ return $rmsec;
+}
+
+sub cluster_conf_lookup_pvevm {
+ my ($conf, $create, $vmid, $noerr) = @_;