Revision 58ad9620

View differences:

src/oca/java/src/org/opennebula/client/Client.java
129 129
        return call("system.version");
130 130
    }
131 131

  
132
    /**
133
     * Calls OpenNebula and retrieves oned configuration
134
     *
135
     * @return The server's xml-rpc response encapsulated
136
     */
137
    public OneResponse get_config()
138
    {
139
        return call("system.config");
140
    }
141

  
142 132
    //--------------------------------------------------------------------------
143 133
    //  PRIVATE ATTRIBUTES AND METHODS
144 134
    //--------------------------------------------------------------------------
src/oca/java/src/org/opennebula/client/OneSystem.java
32 32
    private static final String GROUP_QUOTA_INFO    = "groupquota.info";
33 33
    private static final String GROUP_QUOTA_UPDATE  = "groupquota.update";
34 34

  
35
    public static final String VERSION = "3.9.0";
35 36

  
36 37
    public OneSystem(Client client)
37 38
    {
......
39 40
    }
40 41

  
41 42
    /**
43
     * Calls OpenNebula and retrieves the oned version
44
     *
45
     * @return The server's xml-rpc response encapsulated
46
     */
47
    public OneResponse getOnedVersion()
48
    {
49
        return client.call("system.version");
50
    }
51

  
52
    /**
53
     * Returns whether of not the oned version is the same as the OCA version
54
     *
55
     * @return true if oned is the same version
56
     */
57
    public boolean compatibleVersion()
58
    {
59
        OneResponse r = getOnedVersion();
60

  
61
        if (r.isError())
62
        {
63
            return false;
64
        }
65

  
66
        String[] ocaVersion =  VERSION.split("\\.", 3);
67
        String[] onedVersion = r.getMessage().split("\\.", 3);
68

  
69
        return ocaVersion.length == onedVersion.length &&
70
                ocaVersion[0].equals(onedVersion[0]) &&
71
                ocaVersion[1].equals(onedVersion[1]);
72
    }
73

  
74
    /**
75
     * Calls OpenNebula and retrieves oned configuration
76
     *
77
     * @return The server's xml-rpc response encapsulated
78
     */
79
    public OneResponse getConfiguration()
80
    {
81
        return client.call("system.config");
82
    }
83

  
84
    /**
85
     * Calls OpenNebula and retrieves oned configuration
86
     *
87
     * @return The xml root node in case of success, null otherwise
88
     */
89
    public Node getConfigurationXML()
90
    {
91
        OneResponse r = getConfiguration();
92
        Node xml = null;
93

  
94
        if (r.isError())
95
        {
96
            return null;
97
        }
98

  
99
        try
100
        {
101
            DocumentBuilder builder =
102
                DocumentBuilderFactory.newInstance().newDocumentBuilder();
103
            Document doc = builder.parse(
104
                new ByteArrayInputStream(r.getMessage().getBytes()));
105

  
106
            xml = doc.getDocumentElement();
107
        }
108
        catch (Exception e) {}
109

  
110
        return xml;
111
    }
112

  
113
    /**
42 114
     * Gets the default user quota limits
43 115
     *
44 116
     * @return the default user quota in case of success, Error otherwise
src/oca/java/test/SessionTest.java
1 1
/*******************************************************************************
2 2
 * Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)
3
 * 
3
 *
4 4
 * Licensed under the Apache License, Version 2.0 (the "License");
5 5
 * you may not use this file except in compliance with the License.
6 6
 * You may obtain a copy of the License at
7
 * 
7
 *
8 8
 *   http://www.apache.org/licenses/LICENSE-2.0
9
 * 
9
 *
10 10
 * Unless required by applicable law or agreed to in writing, software
11 11
 * distributed under the License is distributed on an "AS IS" BASIS,
12 12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......
17 17

  
18 18
import org.junit.Test;
19 19
import org.opennebula.client.*;
20
import org.w3c.dom.Node;
20 21

  
21 22
public class SessionTest {
22 23

  
......
51 52
        }
52 53

  
53 54
        assertNull("Client should complain about misspelled url", oneClient);
54
	}	
55
	}
55 56

  
56 57
    @Test
57 58
    public void version()
......
63 64
        }
64 65
        catch (Exception e)
65 66
        {
66
            System.out.println(e.getMessage());
67
            assertTrue( e.getMessage(), false );
67 68
        }
68 69

  
69
        OneResponse res = oneClient.get_version();
70
        OneSystem system = new OneSystem(oneClient);
71

  
72
        OneResponse res = system.getOnedVersion();
73
        assertTrue( res.getErrorMessage(), !res.isError() );
70 74

  
75
        res = system.getConfiguration();
71 76
        assertTrue( res.getErrorMessage(), !res.isError() );
77

  
78
        Node config = system.getConfigurationXML();
79
        assertTrue( "XML configuration is null", config != null );
80

  
81
        boolean compatible = system.compatibleVersion();
82
        assertTrue(
83
                "Incompatible version reported, " +
84
                OneSystem.VERSION + ", " + system.getOnedVersion().getMessage(),
85
                compatible );
72 86
    }
73 87
}
src/oca/ruby/OpenNebula.rb
172 172
        def get_version()
173 173
            call("system.version")
174 174
        end
175

  
176
        def get_config()
177
            call("system.config")
178
        end
179 175
    end
180 176
end
src/oca/ruby/OpenNebula/System.rb
27 27
            :userquotainfo      => "userquota.info",
28 28
            :userquotaupdate    => "userquota.update",
29 29
            :groupquotainfo     => "groupquota.info",
30
            :groupquotaupdate   => "groupquota.update"
30
            :groupquotaupdate   => "groupquota.update",
31
            :version            => "system.version",
32
            :config             => "system.config"
31 33
        }
32 34

  
33 35
        #######################################################################
......
44 46
        # XML-RPC Methods
45 47
        #######################################################################
46 48

  
49
        # Gets the oned version
50
        #
51
        # @return [String, OpenNebula::Error] the oned version in case
52
        #   of success, Error otherwise
53
        def get_oned_version()
54
            return @client.call("system.version")
55
        end
56

  
57
        # Returns whether of not the oned version is the same as the OCA version
58
        #
59
        # @return [true, false, OpenNebula::Error] true if oned is the same
60
        #   version
61
        def compatible_version()
62
            no_revision = VERSION[/^\d+\.\d+\./]
63
            oned_v = get_oned_version
64

  
65
            if OpenNebula.is_error?(oned_v)
66
                return oned_v
67
            end
68

  
69
            return (oned_v =~ /#{no_revision}/) != nil
70
        end
71

  
72
        # Gets the oned configuration
73
        #
74
        # @return [XMLElement, OpenNebula::Error] the oned configuration in case
75
        #   of success, Error otherwise
76
        def get_configuration()
77
            rc = @client.call(SYSTEM_METHODS[:config])
78

  
79
            if OpenNebula.is_error?(rc)
80
                return rc
81
            end
82

  
83
            config = XMLElement.new
84
            config.initialize_xml(rc, 'TEMPLATE')
85

  
86
            return config
87
        end
88

  
47 89
        # Gets the default user quota limits
48 90
        #
49 91
        # @return [XMLElement, OpenNebula::Error] the default user quota in case

Also available in: Unified diff