Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pve-manager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
pve-manager
Commits
f2040340
Commit
f2040340
authored
Dec 15, 2011
by
Dietmar Maurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve ocf agent and openvz api
parent
7a9373bd
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
181 additions
and
45 deletions
+181
-45
OpenVZ.pm
PVE/API2/OpenVZ.pm
+77
-8
pvevm
bin/ocf/pvevm
+90
-33
pvectl
bin/pvectl
+1
-0
changelog.Debian
debian/changelog.Debian
+8
-0
defines.mk
defines.mk
+1
-1
Utils.js
www/manager/Utils.js
+1
-0
CmdMenu.js
www/manager/openvz/CmdMenu.js
+1
-1
Config.js
www/manager/openvz/Config.js
+2
-2
No files found.
PVE/API2/OpenVZ.pm
View file @
f2040340
...
...
@@ -254,7 +254,7 @@ __PACKAGE__->register_method({
if
(
$param
->
{
force
})
{
die
"
cant overwrite mounted container
\n
"
if
PVE::OpenVZ::
check_mounted
(
$conf
,
$vmid
);
}
else
{
die
"
container
$vmid
already exists
\n
"
if
-
f
$basecfg_fn
;
die
"
CT
$vmid
already exists
\n
"
if
-
f
$basecfg_fn
;
}
my
$ostemplate
=
extract_param
(
$param
,
'
ostemplate
');
...
...
@@ -925,10 +925,12 @@ __PACKAGE__->register_method({
my
$vmid
=
extract_param
(
$param
,
'
vmid
');
die
"
CT
$vmid
already running
\n
"
if
PVE::OpenVZ::
check_running
(
$vmid
);
my
$realcmd
=
sub
{
my
$upid
=
shift
;
syslog
('
info
',
"
starting
container
$vmid
:
$upid
\n
");
syslog
('
info
',
"
starting
CT
$vmid
:
$upid
\n
");
my
$cmd
=
['
vzctl
',
'
start
',
$vmid
];
...
...
@@ -952,10 +954,64 @@ __PACKAGE__->register_method({
properties
=>
{
node
=>
get_standard_option
('
pve-node
'),
vmid
=>
get_standard_option
('
pve-vmid
'),
fast
=>
{
},
},
returns
=>
{
type
=>
'
string
',
},
code
=>
sub
{
my
(
$param
)
=
@_
;
my
$rpcenv
=
PVE::RPCEnvironment::
get
();
my
$user
=
$rpcenv
->
get_user
();
my
$node
=
extract_param
(
$param
,
'
node
');
my
$vmid
=
extract_param
(
$param
,
'
vmid
');
die
"
CT
$vmid
not running
\n
"
if
!
PVE::OpenVZ::
check_running
(
$vmid
);
my
$realcmd
=
sub
{
my
$upid
=
shift
;
syslog
('
info
',
"
stoping CT
$vmid
:
$upid
\n
");
my
$cmd
=
['
vzctl
',
'
stop
',
$vmid
,
'
--fast
'];
run_command
(
$cmd
);
return
;
};
my
$upid
=
$rpcenv
->
fork_worker
('
vzstop
',
$vmid
,
$user
,
$realcmd
);
return
$upid
;
}});
__PACKAGE__
->
register_method
({
name
=>
'
vm_shutdown
',
path
=>
'
{vmid}/status/shutdown
',
method
=>
'
POST
',
protected
=>
1
,
proxyto
=>
'
node
',
description
=>
"
Shutdown the container.
",
parameters
=>
{
additionalProperties
=>
0
,
properties
=>
{
node
=>
get_standard_option
('
pve-node
'),
vmid
=>
get_standard_option
('
pve-vmid
'),
timeout
=>
{
description
=>
"
Wait maximal timeout seconds.
",
type
=>
'
integer
',
minimum
=>
0
,
optional
=>
1
,
default
=>
60
,
},
forceStop
=>
{
description
=>
"
Make sure the Container stops.
",
type
=>
'
boolean
',
description
=>
"
This is faster but can lead to unclean container shutdown.
",
optional
=>
1
,
default
=>
0
,
}
},
},
...
...
@@ -973,21 +1029,34 @@ __PACKAGE__->register_method({
my
$vmid
=
extract_param
(
$param
,
'
vmid
');
my
$timeout
=
extract_param
(
$param
,
'
timeout
');
die
"
CT
$vmid
not running
\n
"
if
!
PVE::OpenVZ::
check_running
(
$vmid
);
my
$realcmd
=
sub
{
my
$upid
=
shift
;
syslog
('
info
',
"
s
toping container
$vmid
:
$upid
\n
");
syslog
('
info
',
"
s
hutdown CT
$vmid
:
$upid
\n
");
my
$cmd
=
['
vzctl
',
'
stop
',
$vmid
];
push
@$cmd
,
'
--fast
'
if
$param
->
{
fast
};
$timeout
=
60
if
!
defined
(
$timeout
);
eval
{
run_command
(
$cmd
,
timeout
=>
$timeout
);
};
my
$err
=
$@
;
return
if
!
$err
;
die
$err
if
!
$param
->
{
forceStop
};
warn
"
shutdown failed - forcing stop now
\n
";
push
@$cmd
,
'
--fast
';
run_command
(
$cmd
);
return
;
};
my
$upid
=
$rpcenv
->
fork_worker
('
vzs
top
',
$vmid
,
$user
,
$realcmd
);
my
$upid
=
$rpcenv
->
fork_worker
('
vzs
hutdown
',
$vmid
,
$user
,
$realcmd
);
return
$upid
;
}});
...
...
bin/ocf/pvevm
View file @
f2040340
...
...
@@ -29,9 +29,19 @@ use constant OCF_FAILED_MASTER => 9;
$ENV
{'
PATH
'}
=
'
/sbin:/bin:/usr/sbin:/usr/bin
';
my
$ocf_ressource_type
=
$0
;
my
$prio_hash
=
{
err
=>
3
,
note
=>
5
,
info
=>
6
,
debug
=>
7
,
};
$SIG
{
__DIE__
}
=
sub
{
die
@_
if
$^S
;
# skip if inside eval
$!
=
OCF_ERR_GENERIC
;
ocf_log
('
err
',
@_
);
exit
(
$!
);
};
if
(
$>
!=
0
)
{
...
...
@@ -55,11 +65,30 @@ my @ssh_cmd = ('ssh', @ssh_opts);
sub
ocf_log
{
my
(
$level
,
$msg
)
=
@_
;
# fixme:
chomp
$msg
;
chomp
$msg
;
print
"
$level
:
$msg
\n
";
my
$level_n
=
$prio_hash
->
{
$level
};
$level_n
=
$prio_hash
->
{
note
}
if
!
defined
(
$level_n
);
my
$cmd
=
['
clulog
',
'
-m
',
$ocf_ressource_type
,
'
-s
',
$level_n
,
$msg
];
eval
{
PVE::Tools::
run_command
(
$cmd
);
};
# ignore errors
}
sub
get_timeout
{
my
$default_timeout
=
60
;
my
$tout
=
$default_timeout
;
if
(
$ENV
{
OCF_RESKEY_RGMANAGER_meta_timeout
})
{
$tout
=
$ENV
{
OCF_RESKEY_RGMANAGER_meta_timeout
};
}
elsif
(
$ENV
{
OCF_RESKEY_CRM_meta_timeout
})
{
$tout
=
$ENV
{
OCF_RESKEY_CRM_meta_timeout
};
}
return
$default_timeout
if
$tout
<=
0
;
return
$tout
;
}
sub
check_running
{
...
...
@@ -92,8 +121,6 @@ sub validate_all {
$status
->
{
type
}
=
$data
->
{
type
};
$status
->
{
node
}
=
$data
->
{
node
};
ocf_log
('
debug
',
"
VM
$vmid
(
$status
->{type}) on node
$status
->{node}
\n
");
check_running
(
$status
);
};
if
(
my
$err
=
$@
)
{
...
...
@@ -156,7 +183,25 @@ if ($cmd eq 'start') {
check_running
(
$status
);
exit
(
$status
->
{
running
}
?
OCF_SUCCESS
:
OCF_ERR_GENERIC
);
exit
(
OCF_ERR_GENERIC
)
if
!
$status
->
{
running
};
if
(
my
$testprog
=
$ENV
{
OCF_RESKEY_status_program
})
{
my
$timeout
=
get_timeout
();
my
$wait_func
=
sub
{
while
(
system
(
$testprog
)
!=
0
)
{
sleep
(
3
);
}
};
eval
{
PVE::Tools::
run_with_timeout
(
$timeout
,
$wait_func
);
};
if
(
my
$err
=
$@
)
{
ocf_log
('
err
',
"
Start of VM
$status
->{vmid} has failed
");
ocf_log
('
err
',
"
error while waiting for '
$testprog
' -
$err
");
exit
(
OCF_ERR_GENERIC
);
}
}
exit
(
OCF_SUCCESS
);
}
elsif
(
$cmd
eq
'
stop
')
{
my
$status
=
validate_all
();
...
...
@@ -166,12 +211,21 @@ if ($cmd eq 'start') {
exit
(
OCF_SUCCESS
);
}
my
$timeout
=
get_timeout
();
my
$upid
;
my
$param
=
{
node
=>
$nodename
,
vmid
=>
$status
->
{
vmid
},
timeout
=>
$timeout
,
forceStop
=>
1
,
};
if
(
$status
->
{
type
}
eq
'
qemu
')
{
$upid
=
PVE::API2::
Qemu
->
vm_s
top
({
node
=>
$nodename
,
vmid
=>
$status
->
{
vmid
}}
);
$upid
=
PVE::API2::
Qemu
->
vm_s
hutdown
(
$param
);
}
else
{
$upid
=
PVE::API2::
OpenVZ
->
vm_s
top
({
node
=>
$nodename
,
vmid
=>
$status
->
{
vmid
},
fast
=>
1
}
);
$upid
=
PVE::API2::
OpenVZ
->
vm_s
hutdown
(
$param
);
}
upid_wait
(
$upid
);
...
...
@@ -187,14 +241,25 @@ if ($cmd eq 'start') {
}
elsif
(
$cmd
eq
'
status
'
||
$cmd
eq
'
monitor
')
{
my
$status
=
validate_all
();
if
(
$status
->
{
running
})
{
ocf_log
('
debug
',
"
Resource is running
");
exit
(
OCF_SUCCESS
);
}
else
{
if
(
!
$status
->
{
running
})
{
ocf_log
('
debug
',
"
Resource is not running
");
exit
(
OCF_NOT_RUNNING
);
}
ocf_log
('
debug
',
"
Resource is running
");
my
$testprog
=
$ENV
{
OCF_RESKEY_status_program
};
my
$checklevel
=
$ENV
{
OCF_CHECK_LEVEL
};
if
(
$testprog
&&
$checklevel
&&
$checklevel
>=
10
)
{
if
(
system
(
$testprog
)
!=
0
)
{
exit
(
OCF_NOT_RUNNING
);
}
}
exit
(
OCF_SUCCESS
);
}
elsif
(
$cmd
eq
'
migrate
')
{
my
$status
=
validate_all
();
if
(
!
$status
->
{
running
})
{
...
...
@@ -208,29 +273,11 @@ if ($cmd eq 'start') {
};
# test ssh connection and try to detect node name
my
@rem_ssh
=
(
@ssh_cmd
,
"
root
\
@
$migratetarget
");
my
$cmd
=
[
@rem_ssh
,
'
/bin/hostname
'
];
my
$targetnode
=
'';
eval
{
PVE::Tools::
run_command
(
$cmd
,
outfunc
=>
sub
{
$targetnode
=
shift
if
!
$targetnode
;
});
};
if
(
my
$err
=
$@
)
{
ocf_log
('
err
',
"
can't connect to target '
$migratetarget
' -
$err
");
exit
(
OCF_ERR_GENERIC
);
}
if
(
!
PVE::Cluster::
check_node_exists
(
$targetnode
,
1
))
{
ocf_log
('
err
',
"
target hostname '
$targetnode
' is no cluster member
");
exit
(
OCF_ERR_GENERIC
);
}
my
$upid
;
my
$params
=
{
node
=>
$nodename
,
vmid
=>
$status
->
{
vmid
},
target
=>
$
targetnode
,
target
=>
$
migratetarget
,
online
=>
1
,
};
...
...
@@ -365,6 +412,16 @@ __DATA__
<
content
type
=
"
string
"
/>
</
parameter
>
<
parameter
name
=
"
migrate
"
>
<
longdesc
lang
=
"
en
"
>
Migration
type
(
live
or
pause
,
default
=
live
)
.
</
longdesc
>
<
shortdesc
lang
=
"
en
"
>
Migration
type
(
live
or
pause
,
default
=
live
)
.
</
shortdesc
>
<
content
type
=
"
string
"
default
=
"
live
"
/>
</
parameter
>
<
parameter
name
=
"
depend
"
>
<
longdesc
lang
=
"
en
"
>
Service
dependency
;
will
not
start
without
the
specified
...
...
bin/pvectl
View file @
f2040340
...
...
@@ -73,6 +73,7 @@ my $cmddef = {
}],
start
=>
[
'
PVE::API2::OpenVZ
',
'
vm_start
',
['
vmid
'],
{
node
=>
$nodename
},
$upid_exit
],
shutdown
=>
[
'
PVE::API2::OpenVZ
',
'
vm_shutdown
',
['
vmid
'],
{
node
=>
$nodename
},
$upid_exit
],
stop
=>
[
'
PVE::API2::OpenVZ
',
'
vm_stop
',
['
vmid
'],
{
node
=>
$nodename
},
$upid_exit
],
migrate
=>
[
"
PVE::API2::OpenVZ
",
'
migrate_vm
',
['
vmid
',
'
target
'],
{
node
=>
$nodename
},
$upid_exit
],
...
...
debian/changelog.Debian
View file @
f2040340
pve-manager (2.0-16) unstable; urgency=low
* improve OpenVZ API (impl. shutdown)
* improve HA resource agent
-- Proxmox Support Team <support@proxmox.com> Thu, 15 Dec 2011 13:48:39 +0100
pve-manager (2.0-15) unstable; urgency=low
* add HA resource agent
...
...
defines.mk
View file @
f2040340
...
...
@@ -2,7 +2,7 @@ RELEASE=2.0
VERSION=2.0
PACKAGE=pve-manager
PACKAGERELEASE=1
5
PACKAGERELEASE=1
6
BINDIR=${DESTDIR}/usr/bin
PERLLIBDIR=${DESTDIR}/usr/share/perl5
...
...
www/manager/Utils.js
View file @
f2040340
...
...
@@ -389,6 +389,7 @@ Ext.define('PVE.Utils', { statics: {
vzmigrate
:
[
'
CT
'
,
gettext
(
'
Migrate
'
)
],
vzstart
:
[
'
CT
'
,
gettext
(
'
Start
'
)
],
vzstop
:
[
'
CT
'
,
gettext
(
'
Stop
'
)
],
vzshutdown
:
[
'
CT
'
,
gettext
(
'
Shutdown
'
)
],
srvstart
:
[
'
SRV
'
,
gettext
(
'
Start
'
)
],
srvstop
:
[
'
SRV
'
,
gettext
(
'
Stop
'
)
],
srvrestart
:
[
'
SRV
'
,
gettext
(
'
Restart
'
)
],
...
...
www/manager/openvz/CmdMenu.js
View file @
f2040340
...
...
@@ -47,7 +47,7 @@ Ext.define('PVE.openvz.CmdMenu', {
return
;
}
vm_command
(
'
s
top
'
);
vm_command
(
'
s
hutdown
'
);
});
}
},
...
...
www/manager/openvz/Config.js
View file @
f2040340
...
...
@@ -43,7 +43,7 @@ Ext.define('PVE.openvz.Config', {
text
:
gettext
(
'
Stop
'
),
confirmMsg
:
Ext
.
String
.
format
(
gettext
(
"
Do you really want to stop VM {0}?
"
),
vmid
),
handler
:
function
()
{
vm_command
(
"
stop
"
,
{
fast
:
1
}
);
vm_command
(
"
stop
"
);
}
});
...
...
@@ -51,7 +51,7 @@ Ext.define('PVE.openvz.Config', {
text
:
gettext
(
'
Shutdown
'
),
confirmMsg
:
Ext
.
String
.
format
(
gettext
(
"
Do you really want to shutdown VM {0}?
"
),
vmid
),
handler
:
function
()
{
vm_command
(
'
s
top
'
);
vm_command
(
'
s
hutdown
'
);
}
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment