Requests Datastores from VMDB over 'StorageCluster'


#1

Hey there,

i would like to request some VMware Datastores from the vmdb over the information about an SDRS-Cluster.
Found a model “StorageCluster” in rails console which provides the informations i need:

vmdb
bin/rails c
irb(main):001:0* StorageCluster.find_by_name("MYSDRSCluster").storages.count
  StorageCluster Load (0.9ms)  SELECT  "ems_folders".* FROM "ems_folders" WHERE "ems_folders"."type" IN ('StorageCluster') AND "ems_folders"."name" = $1 LIMIT $2  [["name", "MYSDRSCluster"], ["LIMIT", 1]]
  StorageCluster Inst Including Associations (0.4ms - 1rows)
  Relationship Load (0.6ms)  SELECT "relationships".* FROM "relationships" WHERE "relationships"."resource_id" = $1 AND "relationships"."resource_type" = $2 AND "relationships"."relationship" = $3  [["resource_id", 431], ["resource_type", "EmsFolder"], ["relationship", "ems_metadata"]]
  Relationship Inst Including Associations (0.3ms - 1rows)
  Relationship Load (0.7ms)  SELECT "relationships".* FROM "relationships" WHERE "relationships"."ancestry" = '4934/4935/4936/4939/4942'
  Relationship Inst Including Associations (0.3ms - 5rows)
  Storage Load (1.1ms)  SELECT "storages".* FROM "storages" WHERE "storages"."id" IN (447, 448, 439, 440, 495)
  Storage Inst Including Associations (0.8ms - 5rows)
=> 5

so i tried to accomplish this in my Inline Automation Statemachine by using:

storC      = $evm.vmdb('StorageCluster').find_by_name("MYSDRSCluster")
datastores = storC.storages.map{|s| s.name }

ERROR:
undefined method `storages' for #<MiqAeMethodService::MiqAeServiceStorageCluster:0x000000080fb1f0>

so i compared the result of Model (over Constant)

StorageCluster

and

$evm.vmdb(‘StorageCluster’)

irb(main):002:0* StorageCluster.find_by_name("MYSDRSCluster").class
  StorageCluster Load (1.3ms)  SELECT  "ems_folders".* FROM "ems_folders" WHERE "ems_folders"."type" IN ('StorageCluster') AND "ems_folders"."name" = $1 LIMIT $2  [["name", "MYSDRSCluster"], ["LIMIT", 1]]
  StorageCluster Inst Including Associations (0.4ms - 1rows)
=> StorageCluster(id: integer, name: string, ems_id: integer, created_on: datetime, updated_on: datetime, uid_ems: string, ems_ref_obj: string, ems_ref: string, type: string, hidden: boolean, href_slug: string, region_number: integer, region_description: string, aggregate_cpu_speed: integer, aggregate_cpu_total_cores: integer, aggregate_physical_cpus: integer, aggregate_memory: integer, aggregate_vm_cpus: integer, aggregate_vm_memory: integer, aggregate_disk_capacity: integer)

irb(main):003:0* evm = MiqAeMethodService::MiqAeService.new(MiqAeEngine::MiqAeWorkspaceRuntime.new)
irb(main):004:0* evm.vmdb('StorageCluster').find_by_name("MYSDRSCluster").class
PostgreSQLAdapter#log_after_checkout, connection_pool: size: 5, connections: 1, in use: 1, waiting_in_queue: 0
  StorageCluster Load (0.7ms)  SELECT  "ems_folders".* FROM "ems_folders" WHERE "ems_folders"."type" IN ('StorageCluster') AND "ems_folders"."name" = $1 LIMIT $2  [["name", "MYSDRSCluster"], ["LIMIT", 1]]
  StorageCluster Inst Including Associations (0.2ms - 1rows)
PostgreSQLAdapter#log_after_checkin, connection_pool: size: 5, connections: 1, in use: 0, waiting_in_queue: 0
=> MiqAeMethodService::MiqAeServiceStorageCluster

So my question now is:
is it possible to get all child datastores from a StorageCluster in my Statemachine ? any hint or trick ?

Would be great, thanks


#2

okay, maybe i found a solution about this missing relations in the vmdb(‘StorageCluster’) Object:

SDRSname    = "MYSDRSCluster"
SDRSmembers = Array.new
$evm.vmdb('Storage').all.each do |storage| 
  storage.storage_clusters.each do |sCluster| 
    SDRSmembers << storage if sCluster.name.casecmp(SDRSname)) == 0
end

SDRSmembers.count
=> 5

heavy load of resources to handle, but there is a way :slight_smile:


#3

Hi schmandforke,

as I can tell there is no better way to do this.

$evm.vmdb('StorageCluster').associations

shows only associations to Host’s and VM’s. You can’t get linked storages. If you don’t want to iterate through all storages, I would suggest to add all storages to a storagecluster via custom attributes. I didn’t test it and I can’ tell you if this way is faster or slower. It’s far from ideal anyway.

Kind Regards,
phospi


#4

Yeahr, i looked at the code in the models and haven’t found any associations to the Storages.
Anyway, i’m looking for a way without tagging any informations before the placement can run…