Class: VCenterDriver::DsImporter

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

Overview

Class DsImporter

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) ⇒ DsImporter

Returns a new instance of DsImporter.



892
893
894
895
# File 'lib/datastore.rb', line 892

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

Instance Method Details

#add_cluster(cid, eid) ⇒ Object



930
931
932
933
934
935
# File 'lib/datastore.rb', line 930

def add_cluster(cid, eid)
    one_cluster = @info[:clusters][cid]
    raise 'no cluster defined' unless one_cluster

    one_cluster.adddatastore(eid)
end

#get_list(args = {}) ⇒ Object



897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
# File 'lib/datastore.rb', line 897

def get_list(args = {})
    dc_folder = VCenterDriver::DatacenterFolder.new(@vi_client)

    # one pool creation
    dpool = VCenterDriver::VIHelper
            .one_pool(
                OpenNebula::DatastorePool,
                false
            )
    if dpool.respond_to?(:message)
        raise "Could not get OpenNebula DatastorePool: #{dpool.message}"
    end

    # OpenNebula's HostPool
    hpool = VCenterDriver::VIHelper
            .one_pool(
                OpenNebula::HostPool,
                false
            )
    if hpool.respond_to?(:message)
        raise "Could not get OpenNebula HostPool: #{hpool.message}"
    end

    rs = dc_folder
         .get_unimported_datastores(
             dpool,
             @vi_client.vc_name,
             hpool,
             args
         )
    @list = rs
end

#import(selected) ⇒ Object



948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
# File 'lib/datastore.rb', line 948

def import(selected)
    inner = lambda {|object, auth|
        one = ''
        one << "VCENTER_HOST=\"#{auth[:host]}\"\n"

        object.update(one, true)
    }

    opts = @info[selected[:ref]][:opts]

    # Datastore info comes in a pair (SYS, IMG)
    pair     = selected[:ds]
    clusters = selected[:cluster]
    if opts && opts['selected_clusters']
        clusters = opts['selected_clusters'].each.map(&:to_i)
    end

    name = VCenterDriver::VcImporter.sanitize(
        selected[:simple_name]
    )

    res = { :id => [], :name => name }
    @info[:rollback] = []
    pair.each do |ds|
        create(ds[:one]) do |one_object, id|
            res[:id] << id

            add_clusters(id, clusters)

            inner.call(
                one_object,
                @vi_client.host_credentials(
                    @one_client
                )
            )
        end
    end

    res
end

#remove_default(id) ⇒ Object



937
938
939
940
941
942
943
944
945
946
# File 'lib/datastore.rb', line 937

def remove_default(id)
    cid = 0
    @info[:clusters][cid] ||= VCenterDriver::VIHelper
                              .one_item(
                                  OpenNebula::Cluster,
                                  cid.to_s,
                                  false
                              )
    @info[:clusters][cid].deldatastore(id.to_i)
end