This file is indexed.

/usr/lib/one/ruby/zona/OZonesElement.rb is in opennebula 3.2.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
# -------------------------------------------------------------------------- #
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)             #
#                                                                            #
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
# not use this file except in compliance with the License. You may obtain    #
# a copy of the License at                                                   #
#                                                                            #
# http://www.apache.org/licenses/LICENSE-2.0                                 #
#                                                                            #
# Unless required by applicable law or agreed to in writing, software        #
# distributed under the License is distributed on an "AS IS" BASIS,          #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
# See the License for the specific language governing permissions and        #
# limitations under the License.                                             #
#--------------------------------------------------------------------------- #


module Zona

    # Standard abstraction of an OZones element. To be inherited.
    class OZonesElement < JSONElement

        protected

        # Initializes an OZones Element instance. Tries to set @pe_id and @name
        # @param [Hash] hash element description
        # @param [Zona::Client] client OZones client
        # @return [String] Element's name or nil
        def initialize(hash, client)
            @client = client
            @json_hash = hash

            @pe_id = self[:ID] ? self[:ID].to_i : nil
            @name = self[:NAME] ? self[:NAME] : nil
        end

        # Retrieves details about an object and fills in
        # the information hash
        # @param [String] kind element kind: zone, vdc...
        # @param [String] root_element root element of the JSON object description
        # @return [Zona::Error] nil or Error
        def info(kind, root_element)
            return Error.new('ID not defined') if !@pe_id

            rc = @client.get_resource(kind,@pe_id)
            if !Zona.is_error?(rc)
                initialize_json(rc.body,root_element)

                rc = nil

                @pe_id = self[:ID] ? self[:ID].to_i : nil
                @name = self[:NAME] ? self[:NAME] : nil

            end
            rc
        end

        # Allocates a new element from a hash description
        # @param [String] kind element kind: zone, vdc...
        # @param [Hash] tmpl_hash element template hash
        # @return [Zona::Error] nil or Error
        def allocate_hash(kind, tmpl_hash)
            allocate(kind, tmpl_hash.to_json)
        end

        # Allocates a new element from a JSON description
        # @param [String] kind element kind: zone, vdc...
        # @param [String] tmpl_json element JSON template
        # @return [Zona::Error] nil or Error
        def allocate(kind, tmpl_json)
            rc = @client.post_resource(kind, tmpl_json)

            if !Zona.is_error?(rc)
                initialize_json(rc.body,kind.upcase)
                @pe_id = self[:ID].to_i
                rc = nil
            end
            rc
        end

        # Deletes current element
        # @param [String] kind element kind: zone, vdc...
        # @return [Zona::Error] nil or Error
        def delete(kind)
            return Error.new('ID not defined') if !@pe_id

            rc = @client.delete_resource(kind,@pe_id)
            return rc if Zona.is_error?(rc)
            nil
        end

        public

        attr_reader :pe_id, :name

        # Creates a new element with the custom ID
        # @param [#to_i] id element ID
        # @param [Zona::Client] client OZones Client for this element
        # @return [OZonesElement] A new element object
        def self.new_with_id(id, client=nil)
            self.new(self.build_json(id.to_i),client)
        end

    end
end