Method: Service.list_to_id

Defined in:
lib/opennebula/oneflow_client.rb

.list_to_id(names, poolname) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/opennebula/oneflow_client.rb', line 241

def self.list_to_id(names, poolname)

    client = Service::Client.new()

    resource_path = case poolname
    when "SERVICE"          then "/service"
    when "SERVICE TEMPLATE" then "/service_template"
    end

    response = client.get(resource_path)

    if CloudClient::is_error?(response)
        return -1, "OpenNebula #{poolname} name not found," <<
                   " use the ID instead"
    end

    pool = JSON.parse(response.body)

    result = names.split(',').collect { |name|
        if name.match(/^[0123456789]+$/)
            name.to_i
        else
            rc = name_to_id(name, pool, poolname)

            if rc.first == -1
                return rc[0], rc[1]
            end

            rc[1]
        end
    }

    return 0, result
end