]>
git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Sim/Resources.pm
1 package PVE
::HA
::Sim
::Resources
;
6 use base
qw(PVE::HA::Resources);
8 # provides some base methods for virtual resources (used in simulation/testing).
9 # reduces code reuse and it's targeted for the main PVE service types, namely
10 # virtual machines (VM) and container (CT)
13 my ($class, $id) = @_;
15 die "invalid VMID '$id'\n" if $id !~ m/^[1-9][0-9]+$/;
20 state => { optional
=> 1 },
21 group
=> { optional
=> 1 },
22 comment
=> { optional
=> 1 },
23 max_restart
=> { optional
=> 1 },
24 max_relocate
=> { optional
=> 1 },
29 my ($class, $id, $nodename) = @_;
31 my $service_type = $class->type();
34 return "$nodename/$service_type:$id";
38 my ($class, $haenv, $id) = @_;
40 my $sid = $class->type() . ":$id";
41 my $nodename = $haenv->nodename();
42 my $hardware = $haenv->hardware();
43 my $ss = $hardware->read_service_status($nodename);
45 if (my $lock = $hardware->service_has_lock($sid)) {
46 $haenv->log('err', "service '$sid' locked ($lock), unable to start!");
54 $hardware->write_service_status($nodename, $ss);
59 my ($class, $haenv, $id) = @_;
61 my $sid = $class->type() . ":$id";
62 my $nodename = $haenv->nodename();
63 my $hardware = $haenv->hardware();
64 my $ss = $hardware->read_service_status($nodename);
66 if (my $lock = $hardware->service_has_lock($sid)) {
67 $haenv->log('err', "service '$sid' locked ($lock), unable to shutdown!");
75 $hardware->write_service_status($nodename, $ss);
79 my ($class, $haenv, $id) = @_;
81 my $service_type = $class->type();
82 my $nodename = $haenv->nodename();
83 my $hardware = $haenv->hardware();
85 my $ss = $hardware->read_service_status($nodename);
87 return ($ss->{"$service_type:$id"}) ?
1 : 0;
92 my ($class, $haenv, $id, $target, $online) = @_;
94 my $sid = $class->type() . ":$id";
95 my $nodename = $haenv->nodename();
96 my $hardware = $haenv->hardware();
97 my $ss = $hardware->read_service_status($nodename);
99 my $cmd = $online ?
"migrate" : "relocate";
100 $haenv->log("info", "service $sid - start $cmd to node '$target'");
102 if (my $lock = $hardware->service_has_lock($sid)) {
103 $haenv->log('err', "service '$sid' locked ($lock), unable to $cmd!");
107 # explicitly shutdown if $online isn't true (relocate)
108 if (!$online && $class->check_running($haenv, $id)) {
109 $haenv->log("info", "stopping service $sid (relocate)");
110 $class->shutdown($haenv, $id);
111 $haenv->log("info", "service status $sid stopped");
113 $haenv->sleep(2); # (live) migration time
116 $hardware->change_service_location($sid, $nodename, $target);
117 $haenv->log("info", "service $sid - end $cmd to node '$target'");
118 # ensure that the old node doesn't has the service anymore
120 $hardware->write_service_status($nodename, $ss);
122 # check if resource really moved
123 return defined($ss->{$sid}) ?
0 : 1;
128 my ($self, $haenv, $id, $locks, $service_node) = @_;
130 my $sid = $self->type() . ":$id";
131 my $hardware = $haenv->hardware();
133 foreach my $lock (@$locks) {
134 if (my $removed_lock = $hardware->unlock_service($sid, $lock)) {
135 return $removed_lock;