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.



879
880
881
882
# File 'lib/datastore.rb', line 879

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

Instance Method Details

#add_cluster(cid, eid) ⇒ Object



917
918
919
920
921
922
# File 'lib/datastore.rb', line 917

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



884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
# File 'lib/datastore.rb', line 884

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



935
936
937
938
939
940
941
942
943
944
945
946
947
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
# File 'lib/datastore.rb', line 935

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



924
925
926
927
928
929
930
931
932
933
# File 'lib/datastore.rb', line 924

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