[one-users] XML RPC call authentication error

Miguel Morillo Iruela miguel.morillo at gmail.com
Tue Aug 9 07:59:19 PDT 2011


Thanks Carlos!

I got it!

I attach two examples in python and perl:

*prueba-xml-rpc.pl*

#!/usr/bin/perl

use warnings;
use strict;
use Digest::SHA1  qw(sha1 sha1_hex sha1_base64);
use Frontier::Client;

#
--------------------------------------------------------------------------------------#

my $server_url = "http://localhost:2633/RPC2";
my $user = "oneadmin";
my $password = "oneadmin";
my $server= Frontier::Client->new(url => $server_url);

$password = sha1_hex($password);

my $one_auth = "$user:$password";

#
---------------------------------------------------------------------------------------#

&getVMInfo(37);

#
---------------------------------------------------------------------------------------#

sub getVMInfo {
    my $id;
    ($id) = @_;

    my @response = $server->call('one.vm.info', $one_auth, $id);

    foreach my $line (@response) {
            print $line->[1], "\n";
    }

}





*prueba-xml-rpc.py*

#! /usr/bin/python
#
# based on script of  Chris Usher June 2009

import xmlrpclib
import re
import hashlib

server = 'http://localhost:2633/RPC2'
user = "oneadmin"
password = "oneadmin"
password = hashlib.sha1(password).hexdigest()
one_auth = '{0}:{1}'.format(user, password)

def getProxy():
    return xmlrpclib.ServerProxy(server)

def getVMInfo(id):
    response = getProxy().one.vm.info(one_auth,id)
    if response[0]:
        return response[1]
    else:
        raise Exception(response[1])

print getVMInfo(37)




Gracias
Miguel




El 8 de agosto de 2011 12:10, Carlos Martín Sánchez
<cmartin at opennebula.org>escribió:

> Hi Miguel,
>
> I'm sure you can get an idea reading the python OCA bindings [1] code.
>
> Regards.
>
> [1] http://opennebula.org/software:ecosystem:python_bindings
>
> --
> Carlos Martín, MSc
> Project Major Contributor
> OpenNebula - The Open Source Toolkit for Cloud Computing
> www.OpenNebula.org | cmartin at opennebula.org
>
>
>
> On Sun, Aug 7, 2011 at 11:13 PM, Miguel Morillo Iruela
> <miguel.morillo at gmail.com> wrote:
> > Hello,
> >
> > I'm trying to deploy and get information of some VM deployed with ONE,
> I'd
> > like to obtain this information with the XML-RPC API, when I try to
> invoice
> > some commands I always get an authentication error:
> >
> > The example script:
> >
> > #!/usr/bin/python
> >
> > import xmlrpclib
> > import os
> >
> > #server=xmlrpclib.ServerProxy('http://localhost:2633/RPC2')
> >
> server=xmlrpclib.ServerProxy('http://oneadmin:7bc8559a8fe509e680562b85c337f170956fcb06@localhost
> :2633/RPC2')
> >
> > #-------Get Info about VM ----------
> > vm=37
> > vminfo=server.one.vm.info("",vm)
> > print  vminfo[1]
> >
> >
> >
> >  oneadmin at opennebula:~$ ./test.py
> > [VirtualMachineInfo] User couldn't be authenticated, aborting call.
> >
> >
> > one_xmlrpc.log
> > .
> > .
> > .
> > 127.0.0.1:18874 - no_user - [07/Aug/2011:23:07:16 -0200] "POST" 200 2097
> > 127.0.0.1:18874 - no_user - [07/Aug/2011:23:07:16 -0200] "POST" 200 468
> > 127.0.0.1:18874 - no_user - [07/Aug/2011:23:07:46 -0200] "POST" 200 2097
> > 127.0.0.1:18874 - no_user - [07/Aug/2011:23:07:46 -0200] "POST" 200 468
> >
> >
> >
> > If some body knows how to connect with python or perl and the correct way
> to
> > authenticate the connection. I have tested with username/password and
> > without.
> >
> > Thanks
> > Miguel
> >
> > _______________________________________________
> > Users mailing list
> > Users at lists.opennebula.org
> > http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opennebula.org/pipermail/users-opennebula.org/attachments/20110809/2815f0c7/attachment-0002.htm>


More information about the Users mailing list