def build_entity(self): entity = self._group( ) if self._module.params['group_name'] else self._user() return otypes.Permission( user=otypes.User( id=entity.id) if self._module.params['user_name'] else None, group=otypes.Group( id=entity.id) if self._module.params['group_name'] else None, role=otypes.Role(name=self._module.params['role']), )
def serialconsole(self, name): """ :param name: :return: """ # localport1 = common.get_free_port() # command = "ssh -o LogLevel=QUIET -f -p %s -L %s:127.0.0.1:2222 ovirt-vmconsole@%s sleep 10"\ # % (self.port, localport, self.host) # os.popen(command) system_service = self.conn.system_service() users_service = system_service.users_service() user = users_service.list(search='usrname=%s-authz' % self.user)[0] user_service = users_service.user_service(user.id) vmsearch = self.vms_service.list(search='name=%s' % name) if not vmsearch: common.pprint("VM %s not found" % name, color='red') return {'result': 'failure', 'reason': "VM %s not found" % name} vm = vmsearch[0] # if not vm.console.enabled: # vm_service = self.vms_service.vm_service(vm.id) # vm_service.update(types.Vm(console=types.Console(enabled=True))) # common.pprint("Enabling Serial Console. You will need to reboot VM" % name, color='green') # return permissions_service = self.vms_service.vm_service( vm.id).permissions_service() permissions_service.add( types.Permission(user=types.User(id=user.id), role=types.Role(name='UserVmManager'))) keys_service = user_service.ssh_public_keys_service() key = get_home_ssh_key() if key is None: common.print( "neither id_rsa.pub or id_dsa public keys found in your .ssh directory. This is required" ) return try: keys_service.add(key=types.SshPublicKey(content=key)) except: pass command = "ssh -t -p 2222 ovirt-vmconsole@%s connect --vm-name %s" % ( self.host, name) call(command, shell=True) return
connection = sdk.Connection( url='https://engine40.example.com/ovirt-engine/api', username='******', password='******', ca_file='ca.pem', debug=True, log=logging.getLogger(), ) # Locate the networks service and use it to find the network: networks_service = connection.system_service().networks_service() network = networks_service.list(search='name=mynetwork')[0] # Locate the users service and use it to find the user: users_service = connection.system_service().users_service() user = users_service.list(search='usrname=myuser@mydomain-authz')[0] # Locate the service that manages the permissions of the network: permissions_service = networks_service.network_service( network.id).permissions_service() # Use the "add" method to assign GlusterAdmin role to user on network: permissions_service.add( types.Permission( user=types.User(id=user.id, ), role=types.Role(name='GlusterAdmin'), ), ) # Close the connection to the server: connection.close()
ca_file='ca.pem', debug=True, log=logging.getLogger(), ) # Locate the users service and use it to find the user: users_service = connection.system_service().users_service() user = users_service.list(search='usrname=%s' % USERNAME)[0] # Iterate via the list of virtual machines: for vm_name in MY_VMS: # Locate the virtual machine service and use it to find the specific # virtual machines: vms_service = connection.system_service().vms_service() vm = vms_service.list(search='name=%s' % vm_name)[0] # Locate the service that manages the permissions of the virtual machine: permissions_service = vms_service.vm_service(vm.id).permissions_service() # Use the "add" method to assign UserVmManager role to user on virtual # machine: permissions_service.add( types.Permission( user=types.User(id=user.id, ), role=types.Role(name=ROLENAME, ), ), ) # Close the connection to the server: connection.close()