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
690e72cd
Commit
690e72cd
authored
Jun 12, 2013
by
Dietmar Maurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement apt-get update
parent
92ebf7e0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
20 deletions
+71
-20
APT.pm
PVE/API2/APT.pm
+71
-20
No files found.
PVE/API2/APT.pm
View file @
690e72cd
...
@@ -91,6 +91,35 @@ my $assemble_pkginfo = sub {
...
@@ -91,6 +91,35 @@ my $assemble_pkginfo = sub {
return
$data
;
return
$data
;
};
};
# we try to cache results
my
$pve_pkgstatus_fn
=
"
/var/lib/pve-manager/pkgupdates
";
my
$update_pve_pkgstatus
=
sub
{
my
$pkglist
=
[]
;
my
$cache
=
&
$get_apt_cache
();
my
$policy
=
$cache
->
policy
;
my
$pkgrecords
=
$cache
->
packages
();
foreach
my
$pkgname
(
keys
%
$cache
)
{
my
$p
=
$cache
->
{
$pkgname
};
next
if
$p
->
{
SelectedState
}
ne
'
Install
';
my
$current_ver
=
$p
->
{
CurrentVer
};
my
$candidate_ver
=
$policy
->
candidate
(
$p
);
if
(
$current_ver
->
{
VerStr
}
ne
$candidate_ver
->
{
VerStr
})
{
my
$info
=
$pkgrecords
->
lookup
(
$pkgname
);
my
$res
=
&
$assemble_pkginfo
(
$pkgname
,
$info
,
$current_ver
,
$candidate_ver
);
push
@$pkglist
,
$res
;
}
}
PVE::Tools::
file_set_contents
(
$pve_pkgstatus_fn
,
encode_json
(
$pkglist
));
return
$pkglist
;
};
__PACKAGE__
->
register_method
({
__PACKAGE__
->
register_method
({
name
=>
'
list_updates
',
name
=>
'
list_updates
',
path
=>
'
update
',
path
=>
'
update
',
...
@@ -117,9 +146,6 @@ __PACKAGE__->register_method({
...
@@ -117,9 +146,6 @@ __PACKAGE__->register_method({
code
=>
sub
{
code
=>
sub
{
my
(
$param
)
=
@_
;
my
(
$param
)
=
@_
;
# we try to cache results
my
$pve_pkgstatus_fn
=
"
/var/lib/pve-manager/pkgupdates
";
if
(
my
$st1
=
File::stat::
stat
(
$pve_pkgstatus_fn
))
{
if
(
my
$st1
=
File::stat::
stat
(
$pve_pkgstatus_fn
))
{
my
$st2
=
File::stat::
stat
("
/var/cache/apt/pkgcache.bin
");
my
$st2
=
File::stat::
stat
("
/var/cache/apt/pkgcache.bin
");
my
$st3
=
File::stat::
stat
("
/var/lib/dpkg/status
");
my
$st3
=
File::stat::
stat
("
/var/lib/dpkg/status
");
...
@@ -139,28 +165,53 @@ __PACKAGE__->register_method({
...
@@ -139,28 +165,53 @@ __PACKAGE__->register_method({
}
}
}
}
my
$pkglist
=
[]
;
my
$pkglist
=
&
$update_pve_pkgstatus
()
;
my
$cache
=
&
$get_apt_cache
();
return
$pkglist
;
my
$policy
=
$cache
->
policy
;
}});
my
$pkgrecords
=
$cache
->
packages
();
foreach
my
$pkgname
(
keys
%
$cache
)
{
__PACKAGE__
->
register_method
({
my
$p
=
$cache
->
{
$pkgname
};
name
=>
'
update_database
',
next
if
$p
->
{
SelectedState
}
ne
'
Install
';
path
=>
'
update
',
my
$current_ver
=
$p
->
{
CurrentVer
};
method
=>
'
POST
',
my
$candidate_ver
=
$policy
->
candidate
(
$p
);
description
=>
"
This is used to resynchronize the package index files from their sources (apt-get update).
",
permissions
=>
{
check
=>
['
perm
',
'
/nodes/{node}
',
[
'
Sys.Modify
'
]],
},
protected
=>
1
,
proxyto
=>
'
node
',
parameters
=>
{
additionalProperties
=>
0
,
properties
=>
{
node
=>
get_standard_option
('
pve-node
'),
},
},
returns
=>
{
type
=>
'
string
',
},
code
=>
sub
{
my
(
$param
)
=
@_
;
if
(
$current_ver
->
{
VerStr
}
ne
$candidate_ver
->
{
VerStr
})
{
my
$rpcenv
=
PVE::RPCEnvironment::
get
();
my
$info
=
$pkgrecords
->
lookup
(
$pkgname
);
my
$res
=
&
$assemble_pkginfo
(
$pkgname
,
$info
,
$current_ver
,
$candidate_ver
);
push
@$pkglist
,
$res
;
}
}
PVE::Tools::
file_set_contents
(
$pve_pkgstatus_fn
,
encode_json
(
$pkglist
));
my
$authuser
=
$rpcenv
->
get_user
();
my
$realcmd
=
sub
{
my
$upid
=
shift
;
my
$cmd
=
['
apt-get
',
'
update
'];
print
"
starting apt-get update
\n
";
PVE::Tools::
run_command
(
$cmd
);
&
$update_pve_pkgstatus
();
return
;
};
return
$rpcenv
->
fork_worker
('
apt
',
undef
,
$authuser
,
$realcmd
);
return
$pkglist
;
}});
}});
1
;
1
;
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