简体   繁体   English

如何在vijava中获得vm权限

[英]how to get vm permissions in vijava

I'm trying to get permissions of virtual machine using vijava like this: 我正在尝试使用vijava获得虚拟机的权限,如下所示:

ManagedEntity me = new
InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", vmName);
                VirtualMachine vm = (VirtualMachine) me;
for (Permission permission : vm.getPermission()) {
                System.out.println(permission.getPrincipal());
}

With this I get permissions applied only for This vm. 有了这个,我获得的权限仅适用于此虚拟机。

How can I get total permissions on virtual machine including inherited? 如何获得对虚拟机(包括继承的虚拟机)的总权限?

I'm not sure if that's possible, because each list of permissions is associated with a specific entity (ie VirtualMachine, HostSystem, etc..). 我不确定是否可行,因为每个权限列表都与一个特定实体(即VirtualMachine,HostSystem等)相关联。

The way I'd do this is I'd get the underlying entities for the virtual machine and get their permissions as well. 我这样做的方法是获取虚拟机的基础实体,并获取其权限。 For example, since you have the VirtualMachine object, get the underlying HostSystem and retrieve it's permissions, and so on. 例如,由于您具有VirtualMachine对象,因此获取基础HostSystem并检索其权限,依此类推。

ManagedEntity me = new
InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", vmName);
                VirtualMachine vm = (VirtualMachine) me;

// Assuming that you have a ServiceInstance object si.
HostSystem host = (HostSystem)MorUtil.createExactManagedEntity(si
                        .getServerConnection(),vm.getRuntime().host);
Permission[] hostPermissions = host.getPermission();

I hope that helps. 希望对您有所帮助。

To get all inherited permissions you should get all parents permissions like this: 要获得所有继承的权限,您应该这样获得所有父母权限:

  while (me.getParent() != null) {
        me = me.getParent();
        Permission[] permissions = me.getPermission();
        if (permissions != null) {
            for (Permission p : permissions) {
                // do stuff....
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM