]> git.proxmox.com Git - pve-ha-manager.git/blobdiff - src/PVE/API2/HA/Resources.pm
treewide trailing whitespace cleanup
[pve-ha-manager.git] / src / PVE / API2 / HA / Resources.pm
index d57824bc8c854798b9a12615230b23f1bccadffd..1ffdf2ef488f75833b140a71285275152105489a 100644 (file)
@@ -12,7 +12,6 @@ use HTTP::Status qw(:constants);
 use Storable qw(dclone);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RPCEnvironment;
-use Data::Dumper;
 
 use PVE::RESTHandler;
 
@@ -107,13 +106,50 @@ __PACKAGE__->register_method ({
                                      { completion => \&PVE::HA::Tools::complete_sid }),
        },
     },
-    returns => {},
+    returns => {
+       type => 'object',
+       properties => {
+           sid => get_standard_option('pve-ha-resource-or-vm-id'),
+           digest => {
+               type => 'string',
+               description => 'Can be used to prevent concurrent modifications.',
+           },
+           type => {
+               type => 'string',
+               description => 'The type of the resources.',
+           },
+           state => {
+               type => 'string',
+               enum => ['started', 'stopped', 'enabled', 'disabled', 'ignored'],
+               optional => 1,
+               description => "Requested resource state.",
+           },
+           group => get_standard_option('pve-ha-group-id', { optional => 1, }),
+           max_restart => {
+               description => "Maximal number of tries to restart the service on".
+               " a node after its start failed.",
+               type => 'integer',
+               optional => 1,
+           },
+           max_relocate => {
+               description => "Maximal number of service relocate tries when a".
+               " service failes to start.",
+               type => 'integer',
+               optional => 1,
+           },
+           comment => {
+               description => "Description.",
+               type => 'string',
+               optional => 1,
+           },
+       },
+    },
     code => sub {
        my ($param) = @_;
 
        my $cfg = PVE::HA::Config::read_resources_config();
 
-       my $sid = PVE::HA::Tools::parse_sid($param->{sid});
+       my $sid = PVE::HA::Config::parse_sid($param->{sid});
 
        return &$api_copy_config($cfg, $sid);
     }});
@@ -135,8 +171,8 @@ __PACKAGE__->register_method ({
        # create /etc/pve/ha directory
        PVE::Cluster::check_cfs_quorum();
        mkdir("/etc/pve/ha");
-       
-       my ($sid, $type, $name) = PVE::HA::Tools::parse_sid(extract_param($param, 'sid'));
+
+       my ($sid, $type, $name) = PVE::HA::Config::parse_sid(extract_param($param, 'sid'));
 
        if (my $param_type = extract_param($param, 'type')) {
            # useless, but do it anyway
@@ -185,7 +221,7 @@ __PACKAGE__->register_method ({
        my $digest = extract_param($param, 'digest');
        my $delete = extract_param($param, 'delete');
 
-       my ($sid, $type, $name) = PVE::HA::Tools::parse_sid(extract_param($param, 'sid'));
+       my ($sid, $type, $name) = PVE::HA::Config::parse_sid(extract_param($param, 'sid'));
 
        if (my $param_type = extract_param($param, 'type')) {
            # useless, but do it anyway
@@ -258,20 +294,23 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       my ($sid, $type, $name) = PVE::HA::Tools::parse_sid(extract_param($param, 'sid'));
-
-       PVE::HA::Config::service_is_ha_managed($sid);
+       my ($sid, $type, $name) = PVE::HA::Config::parse_sid(extract_param($param, 'sid'));
 
-       PVE::HA::Config::lock_ha_domain(
-           sub {
+       my $cfg = PVE::HA::Config::read_resources_config();
 
-               my $cfg = PVE::HA::Config::read_resources_config();
+       # cannot use service_is_ha_managed as it ignores 'ignored' services,
+       # see bug report #1602
+       if (!defined($cfg->{ids}) || !defined($cfg->{ids}->{$sid})) {
+           die "cannot delete service '$sid', not HA managed!\n";
+       }
 
-               delete $cfg->{ids}->{$sid};
+       PVE::HA::Config::lock_ha_domain(sub {
 
-               PVE::HA::Config::write_resources_config($cfg)
+           $cfg = PVE::HA::Config::read_resources_config();
+           delete $cfg->{ids}->{$sid} or die "'$sid' not configured!\n";
+           PVE::HA::Config::write_resources_config($cfg);
 
-           }, "delete resource failed");
+       }, "delete resource failed");
 
        return undef;
     }});
@@ -290,22 +329,24 @@ __PACKAGE__->register_method ({
        properties => {
            sid => get_standard_option('pve-ha-resource-or-vm-id',
                                      { completion => \&PVE::HA::Tools::complete_sid }),
-           node => get_standard_option('pve-node',
-                                      { completion => \&PVE::Cluster::get_nodelist }),
+           node => get_standard_option('pve-node', {
+               completion =>  \&PVE::Cluster::complete_migration_target,
+               description => "Target node.",
+           }),
        },
     },
     returns => { type => 'null' },
     code => sub {
        my ($param) = @_;
 
-       my ($sid, $type, $name) = PVE::HA::Tools::parse_sid(extract_param($param, 'sid'));
+       my ($sid, $type, $name) = PVE::HA::Config::parse_sid(extract_param($param, 'sid'));
 
        PVE::HA::Config::service_is_ha_managed($sid);
 
        check_service_state($sid);
 
        PVE::HA::Config::queue_crm_commands("migrate $sid $param->{node}");
-           
+
        return undef;
     }});
 
@@ -323,22 +364,24 @@ __PACKAGE__->register_method ({
        properties => {
            sid => get_standard_option('pve-ha-resource-or-vm-id',
                                      { completion => \&PVE::HA::Tools::complete_sid }),
-           node => get_standard_option('pve-node',
-                                      { completion => \&PVE::Cluster::get_nodelist }),
+           node => get_standard_option('pve-node', {
+               completion =>  \&PVE::Cluster::complete_migration_target,
+               description => "Target node.",
+           }),
        },
     },
     returns => { type => 'null' },
     code => sub {
        my ($param) = @_;
 
-       my ($sid, $type, $name) = PVE::HA::Tools::parse_sid(extract_param($param, 'sid'));
+       my ($sid, $type, $name) = PVE::HA::Config::parse_sid(extract_param($param, 'sid'));
 
        PVE::HA::Config::service_is_ha_managed($sid);
 
        check_service_state($sid);
 
        PVE::HA::Config::queue_crm_commands("relocate $sid $param->{node}");
-           
+
        return undef;
     }});