def _get_role_mappings(module): roleMappings = list() for roleMapping in module.params['role_mappings']: roleMappings.append( otypes.RegistrationRoleMapping( from_=otypes.Role(name=roleMapping['source_name'], ) if roleMapping['source_name'] else None, to=otypes.Role(name=roleMapping['dest_name'], ) if roleMapping['dest_name'] else None, )) return roleMappings
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 build_entity(self): if 'login' not in self.param('permits'): self.param('permits').append('login') all_permits = self.get_all_permits() return otypes.Role( id=self.param('id'), name=self.param('name'), administrative=self.param('administrative') if self.param( 'administrative') else None, permits=[ otypes.Permit(id=all_permits.get(new_permit)) for new_permit in self.param('permits') ] if self.param('permits') else None, description=self.param('description') if self.param('administrative') else None, )
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()
# Create the connection to the server: connection = sdk.Connection( url='https://engine40.example.com/ovirt-engine/api', username='******', password='******', ca_file='ca.pem', debug=True, log=logging.getLogger(), ) # Get the reference to the roles service: roles_service = connection.system_service().roles_service() # Use the "add" method to create new role (note that you need to pass # permit id not the name, when creating new role): role = roles_service.add( types.Role( name='myrole', administrative=False, description='My custom role to create virtual machines', permits=[ # create_vm permit types.Permit(id='1'), # login permit types.Permit(id='1300'), ], ), ) # Close the connection to the server: connection.close()