Revision 347968ad src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb

View differences:

src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb
20 20
        end
21 21
    end
22 22

  
23
    def fetch_templates!
24
        VIClient.get_entities(@item, "VirtualMachine").each do |item|
25
            if item.config.template
26
                item_name = item._ref
27
                @items[item_name.to_sym] = VirtualMachine.new(item)
28
            end
29
        end
30
    end
31

  
23 32
    ########################################################################
24 33
    # Returns a Datastore. Uses the cache if available.
25 34
    # @param ref [Symbol] the vcenter ref
......
152 161

  
153 162
    # @return RbVmomi::VIM::ResourcePool
154 163
    def get_rp
155
        req_rp = one_item['USER_TEMPLATE/RESOURCE_POOL']
164
        req_rp = one_item['USER_TEMPLATE/VCENTER_RP_REF']
156 165

  
157 166
        if vi_client.rp_confined?
158 167
            if req_rp && req_rp != vi_client.rp
......
1200 1209
    # monitoring
1201 1210
    ############################################################################
1202 1211

  
1203
    # @param ccr_host Hash that holds the relationship between the vcenter's ref
1204
    # and the host in OpenNebula
1205
    def to_one(ccr_host)
1206
        cluster = self["runtime.host.parent.name"]
1212
    def to_one(template=false)
1213
        cluster  = self["runtime.host.parent.name"]
1214
        ccr_ref  = self["runtime.host.parent._ref"]
1215
        vc_uuid  = self["_connection.serviceContent.about.instanceUuid"]
1207 1216

  
1208
        ccr     = self["runtime.host.parent._ref"]
1209
        host_id = ccr_host[ccr]
1217
        # Get info of the host where the VM/template is located
1218
        host_id = nil
1219
        one_host = VCenterDriver::VIHelper.find_by_ref(OpenNebula::HostPool,
1220
                                                       "TEMPLATE/VCENTER_CCR_REF",
1221
                                                       ccr_ref,
1222
                                                       vc_uuid)
1223
        host_id = one_host["ID"] if one_host
1210 1224

  
1211 1225
        str = "NAME   = \"#{self["name"]} - #{cluster}\"\n"\
1212 1226
              "CPU    = \"#{self["config.hardware.numCPU"]}\"\n"\
1213 1227
              "vCPU   = \"#{self["config.hardware.numCPU"]}\"\n"\
1214 1228
              "MEMORY = \"#{self["config.hardware.memoryMB"]}\"\n"\
1215 1229
              "HYPERVISOR = \"vcenter\"\n"\
1216
              "IMPORT_VM_ID =\"#{self["config.uuid"]}\"\n"\
1217
              "IMPORT_STATE =\"#{@state}\"\n"\
1218 1230
              "SCHED_REQUIREMENTS=\"ID=\\\"#{host_id}\\\"\"\n"\
1219 1231
              "CONTEXT = [\n"\
1220 1232
              "    NETWORK = \"YES\",\n"\
1221 1233
              "    SSH_PUBLIC_KEY = \"$USER[SSH_PUBLIC_KEY]\"\n"\
1222
              "]\n"
1234
              "]\n"\
1235
              "VCENTER_INSTANCE_ID =\"#{vc_uuid}\"\n"
1236

  
1237
        if !template
1238
            str << "IMPORT_VM_ID =\"#{self["config.uuid"]}\"\n"
1239
            str << "IMPORT_STATE =\"#{@state}\"\n"
1240
        end
1241

  
1242
        if template
1243
            str << "VCENTER_CCR_REF =\"#{ccr_ref}\"\n"
1244
        end
1223 1245

  
1224 1246
        vnc_port = nil
1225 1247
        keymap = nil
1226
        self["config.extraConfig"].select do |xtra|
1227 1248

  
1228
            if xtra[:key].downcase=="remotedisplay.vnc.port"
1229
                vnc_port = xtra[:value]
1230
            end
1249
        if !template
1250
            self["config.extraConfig"].select do |xtra|
1251

  
1252
                if xtra[:key].downcase=="remotedisplay.vnc.port"
1253
                    vnc_port = xtra[:value]
1254
                end
1231 1255

  
1232
            if xtra[:key].downcase=="remotedisplay.vnc.keymap"
1233
                keymap = xtra[:value]
1256
                if xtra[:key].downcase=="remotedisplay.vnc.keymap"
1257
                    keymap = xtra[:value]
1258
                end
1234 1259
            end
1235 1260
        end
1236 1261

  
1237 1262
        if self["config.extraConfig"].size > 0
1238 1263
            str << "GRAPHICS = [\n"\
1239
                   "  TYPE     =\"vnc\",\n"\
1240
                   "  LISTEN   =\"0.0.0.0\",\n"
1264
                   "  TYPE     =\"vnc\",\n"
1241 1265
            str << "  PORT     =\"#{vnc_port}\",\n" if vnc_port
1242
            str << "  KEYMAP   =\"#{keymap}\"\n" if keymap
1266
            str << "  KEYMAP   =\"#{keymap}\",\n" if keymap
1267
            str << "  LISTEN   =\"0.0.0.0\"\n"
1243 1268
            str << "]\n"
1244 1269
        end
1245 1270

  
......
1253 1278

  
1254 1279
        case self["guest.guestFullName"]
1255 1280
            when /CentOS/i
1256
                str << "LOGO=images/logos/centos.png"
1281
                str << "LOGO=images/logos/centos.png\n"
1257 1282
            when /Debian/i
1258
                str << "LOGO=images/logos/debian.png"
1283
                str << "LOGO=images/logos/debian.png\n"
1259 1284
            when /Red Hat/i
1260
                str << "LOGO=images/logos/redhat.png"
1285
                str << "LOGO=images/logos/redhat.png\n"
1261 1286
            when /Ubuntu/i
1262
                str << "LOGO=images/logos/ubuntu.png"
1287
                str << "LOGO=images/logos/ubuntu.png\n"
1263 1288
            when /Windows XP/i
1264
                str << "LOGO=images/logos/windowsxp.png"
1289
                str << "LOGO=images/logos/windowsxp.png\n"
1265 1290
            when /Windows/i
1266
                str << "LOGO=images/logos/windows8.png"
1291
                str << "LOGO=images/logos/windows8.png\n"
1267 1292
            when /Linux/i
1268
                str << "LOGO=images/logos/linux.png"
1293
                str << "LOGO=images/logos/linux.png\n"
1269 1294
        end
1270 1295

  
1271 1296
        return str
1272 1297
    end
1273 1298

  
1299
    def to_one_template(template_name, template_ref, template_ccr, cluster_name,
1300
                        ds, ds_list, default_ds, rp, rp_list, vcenter_uuid)
1301
        one_tmp = {}
1302
        one_tmp[:name]                  = "#{template_name} - #{cluster_name}"
1303
        one_tmp[:vcenter_ccr_ref]       = template_ccr
1304
        one_tmp[:one]                   = to_one(true)
1305
        one_tmp[:vcenter_ref]           = template_ref
1306
        one_tmp[:vcenter_instance_uuid] = vcenter_uuid
1307
        one_tmp[:cluster_name]          = cluster_name
1308
        one_tmp[:ds]                    = ds
1309
        one_tmp[:ds_list]               = ds_list
1310
        one_tmp[:default_ds]            = default_ds
1311
        one_tmp[:rp]                    = rp
1312
        one_tmp[:rp_list]                = rp_list
1313
        return one_tmp
1314
    end
1315

  
1274 1316
    def monitor
1275 1317
        reset_monitor
1276 1318

  
......
1459 1501
        str_info << "VMWARETOOLS_RUNNING_STATUS=" << vmware_tools    << " "
1460 1502
        str_info << "VMWARETOOLS_VERSION="        << vmtools_ver     << " "
1461 1503
        str_info << "VMWARETOOLS_VERSION_STATUS=" << vmtools_verst   << " "
1462
        str_info << "RESOURCE_POOL=\""            << self["resourcePool.name"] << "\" "
1504
        str_info << "VCENTER_RP_REF=\""          << self["resourcePool"]._ref << "\" "
1463 1505
    end
1464 1506

  
1465 1507
    def reset_monitor

Also available in: Unified diff