Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compute.rb: suggest to store the id or the object itself instead of name for RbVmomi object in props_to_attr_hash #181

Open
manchiu opened this issue Nov 28, 2018 · 0 comments
Assignees

Comments

@manchiu
Copy link
Contributor

manchiu commented Nov 28, 2018

In the current implementation, it stores the name of the RbVmomi object in props_to_attr_hash method. However, in my vCenter, some RbVmomi objects have the same name like datacenter, cluster, resource pool etc as they are stored in different folders. It will be hard to distinguish for those RbVmomi objects with the same name. Therefore, I suggest to store the ID or the object itself for differentiation.
Below is my code suggestion:

attrs['datacenter'] = proc {
  begin
    if has_permission_to_access_host
      parent_attribute(host.path, :datacenter)[0] # or parent_attribute(host.path, :datacenter)[0]._ref
    else
      parent_attribute(vm_mob_ref.path, :datacenter)[0] # or parent_attribute(vm_mob_ref.path, :datacenter)[0]._ref
    end
  rescue
    nil
  end
}
attrs['cluster'] = proc {
  begin
    parent_attribute(host.path, :cluster)[0] # or parent_attribute(host.path, :cluster)[0]._ref
  rescue
    nil
  end
}
attrs['hypervisor'] = proc {
  begin
    host._ref
  rescue
    nil
  end
}
attrs['resource_pool'] = proc {
  begin
    (vm_mob_ref.resourcePool || host.resourcePool)._ref
  rescue
    nil
  end
}
@chris1984 chris1984 self-assigned this Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants