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
0710edb3
Commit
0710edb3
authored
Dec 23, 2011
by
Dietmar Maurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ipmlement proxy code for pvesh
parent
16283a5a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
19 deletions
+50
-19
pvesh
bin/pvesh
+50
-19
No files found.
bin/pvesh
View file @
0710edb3
...
@@ -16,8 +16,6 @@ use PVE::RPCEnvironment;
...
@@ -16,8 +16,6 @@ use PVE::RPCEnvironment;
use
PVE::
API2
;
use
PVE::
API2
;
use
JSON
;
use
JSON
;
use
Data::
Dumper
;
# fixme: remove
PVE::INotify::
inotify_init
();
PVE::INotify::
inotify_init
();
my
$rpcenv
=
PVE::
RPCEnvironment
->
init
('
cli
');
my
$rpcenv
=
PVE::
RPCEnvironment
->
init
('
cli
');
...
@@ -29,21 +27,37 @@ my $basedir = '/api2/json';
...
@@ -29,21 +27,37 @@ my $basedir = '/api2/json';
my
$cdir
=
'';
my
$cdir
=
'';
my
$cmd
=
shift
;
if
(
$cmd
&&
$cmd
eq
'
verifyapi
')
{
PVE::RESTHandler::
validate_method_schemas
();
exit
0
;
}
sub
print_usage
{
sub
print_usage
{
my
$msg
=
shift
;
my
$msg
=
shift
;
print
STDERR
"
ERROR:
$msg
\n
"
if
$msg
;
print
STDERR
"
ERROR:
$msg
\n
"
if
$msg
;
print
STDERR
"
USAGE: pvesh [verifyapi]
\n
";
print
STDERR
"
USAGE: pvesh [verifyapi]
\n
";
print
STDERR
"
pvesh CMD [OPTIONS]
\n
";
}
}
my
$disable_proxy
=
0
;
my
$cmd
=
shift
;
if
(
$cmd
eq
'
--noproxy
')
{
$cmd
=
shift
;
$disable_proxy
=
1
;
}
if
(
$cmd
)
{
if
(
$cmd
eq
'
verifyapi
')
{
PVE::RESTHandler::
validate_method_schemas
();
exit
0
;
}
elsif
(
$cmd
eq
'
ls
'
||
$cmd
eq
'
get
'
||
$cmd
eq
'
create
'
||
$cmd
eq
'
set
'
||
$cmd
eq
'
delete
'
||
$cmd
eq
'
help
'
)
{
pve_command
([
$cmd
,
@ARGV
]);
exit
(
0
);
}
else
{
print_usage
("
unknown command '
$cmd
'
");
exit
(
-
1
);
}
}
if
(
scalar
(
@ARGV
)
!=
0
)
{
if
(
scalar
(
@ARGV
)
!=
0
)
{
print_usage
();
print_usage
();
exit
(
-
1
);
exit
(
-
1
);
...
@@ -200,11 +214,25 @@ sub check_proxyto {
...
@@ -200,11 +214,25 @@ sub check_proxyto {
if
(
$info
->
{
proxyto
})
{
if
(
$info
->
{
proxyto
})
{
my
$pn
=
$info
->
{
proxyto
};
my
$pn
=
$info
->
{
proxyto
};
my
$node
=
$uri_param
->
{
$pn
};
my
$node
=
$uri_param
->
{
$pn
};
die
"
proxy parameter '
$pn
' does not exists
"
if
!
$node
;
if
(
$node
ne
'
localhost
'
&&
(
$node
ne
PVE::INotify::
nodename
()))
{
if
(
$node
ne
'
localhost
'
&&
(
$node
ne
PVE::INotify::
nodename
()))
{
die
"
can't proxy to remote node - not implemented
";
die
"
proxy loop detected - aborting
\n
"
if
$disable_proxy
;
my
$remip
=
PVE::Cluster::
remote_node_ip
(
$node
);
return
(
$node
,
$remip
);
}
}
}
}
return
undef
;
}
sub
proxy_handler
{
my
(
$node
,
$remip
,
$dir
,
$cmd
,
$args
)
=
@_
;
my
$remcmd
=
['
ssh
',
'
-o
',
'
BatchMode=yes
',
"
root
\
@
$remip
",
'
pvesh
',
'
--noproxy
',
$cmd
,
$dir
,
@$args
];
system
(
@$remcmd
)
==
0
||
die
"
proxy handler failed
\n
";
}
}
sub
call_method
{
sub
call_method
{
...
@@ -218,7 +246,8 @@ sub call_method {
...
@@ -218,7 +246,8 @@ sub call_method {
die
"
no '
$cmd
' handler for '
$dir
'
\n
";
die
"
no '
$cmd
' handler for '
$dir
'
\n
";
}
}
check_proxyto
(
$info
,
$uri_param
);
my
(
$node
,
$remip
)
=
check_proxyto
(
$info
,
$uri_param
);
return
proxy_handler
(
$node
,
$remip
,
$dir
,
$cmd
,
$args
)
if
$node
;
my
$data
=
$handler
->
cli_handler
("
$cmd
$dir
",
$info
->
{
name
},
$args
,
[]
,
$uri_param
,
$read_password
);
my
$data
=
$handler
->
cli_handler
("
$cmd
$dir
",
$info
->
{
name
},
$args
,
[]
,
$uri_param
,
$read_password
);
...
@@ -231,13 +260,13 @@ sub call_method {
...
@@ -231,13 +260,13 @@ sub call_method {
if
(
$rtype
eq
'
string
')
{
if
(
$rtype
eq
'
string
')
{
print
$data
if
$data
;
print
$data
if
$data
;
return
$data
;
return
;
}
}
}
}
print
to_json
(
$data
,
{
allow_nonref
=>
1
,
canonical
=>
1
,
pretty
=>
1
});
print
to_json
(
$data
,
{
allow_nonref
=>
1
,
canonical
=>
1
,
pretty
=>
1
});
return
$data
;
return
;
}
}
sub
find_resource_methods
{
sub
find_resource_methods
{
...
@@ -380,12 +409,14 @@ sub list_dir {
...
@@ -380,12 +409,14 @@ sub list_dir {
die
"
no such resource
\n
";
die
"
no such resource
\n
";
}
}
check_proxyto
(
$info
,
$uri_param
);
if
(
!
PVE::JSONSchema::
method_get_child_link
(
$info
))
{
if
(
!
PVE::JSONSchema::
method_get_child_link
(
$info
))
{
die
"
resource does not define child links
\n
";
die
"
resource does not define child links
\n
";
}
}
my
(
$node
,
$remip
)
=
check_proxyto
(
$info
,
$uri_param
);
return
proxy_handler
(
$node
,
$remip
,
$dir
,
'
ls
',
$args
)
if
$node
;
my
$data
=
$handler
->
cli_handler
("
ls
$dir
",
$info
->
{
name
},
$args
,
[]
,
$uri_param
,
$read_password
);
my
$data
=
$handler
->
cli_handler
("
ls
$dir
",
$info
->
{
name
},
$args
,
[]
,
$uri_param
,
$read_password
);
my
$lnk
=
PVE::JSONSchema::
method_get_child_link
(
$info
);
my
$lnk
=
PVE::JSONSchema::
method_get_child_link
(
$info
);
my
$children
=
extract_children
(
$lnk
,
$data
);
my
$children
=
extract_children
(
$lnk
,
$data
);
...
@@ -396,15 +427,14 @@ sub list_dir {
...
@@ -396,15 +427,14 @@ sub list_dir {
}
}
}
}
sub
pve_command
{
sub
pve_command
{
my
$
input
=
shift
;
my
$
args
=
shift
;
PVE::Cluster::
cfs_update
();
PVE::Cluster::
cfs_update
();
$rpcenv
->
init_request
();
$rpcenv
->
init_request
();
my
$args
=
[
shellwords
(
$input
)
];
my
$cmd
=
shift
@$args
;
my
$cmd
=
shift
@$args
;
if
(
$cmd
eq
'
cd
')
{
if
(
$cmd
eq
'
cd
')
{
...
@@ -508,7 +538,8 @@ while (defined ($input = $term->readline("pve:/$cdir> "))) {
...
@@ -508,7 +538,8 @@ while (defined ($input = $term->readline("pve:/$cdir> "))) {
$term
->
addhistory
(
$input
);
$term
->
addhistory
(
$input
);
eval
{
eval
{
pve_command
(
$input
);
my
$args
=
[
shellwords
(
$input
)
];
pve_command
(
$args
);
};
};
warn
$@
if
$@
;
warn
$@
if
$@
;
}
}
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