Class: VCenterDriver::ImageImporter

Inherits:
VcImporter show all
Defined in:
lib/datastore.rb

Overview

Class ImageImporter

Instance Attribute Summary

Attributes inherited from VcImporter

#list

Instance Method Summary collapse

Methods inherited from VcImporter

#get_indexes, import_clusters, new_child, #one_str, #output, #process_import, #retrieve_resources, sanitize, #stdout

Constructor Details

#initialize(one_client, vi_client) ⇒ ImageImporter

Returns a new instance of ImageImporter.



996
997
998
999
# File 'lib/datastore.rb', line 996

def initialize(one_client, vi_client)
    super(one_client, vi_client)
    @one_class = OpenNebula::Image
end

Instance Method Details

#get_list(args = {}) ⇒ Object



1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
# File 'lib/datastore.rb', line 1001

def get_list(args = {})
    ds_ref   = args[:datastore][:ds_ref]
    one_ds   = args[:datastore][:one_item]

    unless ds_ref
        raise "can't retrieve ref info from openNebula datastore"
    end

    datastore = VCenterDriver::Datastore
                .new_from_ref(ds_ref, @vi_client)

    ds = datastore.tap do |spawn|
        spawn.one_item = one_ds
    end

    vc_uuid = @vi_client.vim.serviceContent.about.instanceUuid
    one_ds_instance_id = one_ds['TEMPLATE/VCENTER_INSTANCE_ID']

    if one_ds_instance_id != vc_uuid
        raise 'Datastore is not in the same vCenter \
            instance provided in credentials'
    end

    @list = ds.all_images
end

#import(selected) ⇒ Object



1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
# File 'lib/datastore.rb', line 1027

def import(selected)
    resource = VCenterDriver::VIHelper.new_one_item(@one_class)
    message = 'Error creating the OpenNebula resource'
    info = selected[:one]
    dsid = selected[:dsid].to_i
    name = VCenterDriver::VcImporter.sanitize(
        selected[:name]
    )

    rc = resource.allocate(info, dsid, false)
    VCenterDriver::VIHelper.check_error(rc, message)

    resource.info
    id = resource['ID']
    @rollback << Raction.new(resource, :delete)

    { :id => [id], :name => name }
end