Refactored and commented utils/tasks
This commit is contained in:
		
					parent
					
						
							
								666cf187ea
							
						
					
				
			
			
				commit
				
					
						a4a2b2a803
					
				
			
		
					 1 changed files with 12 additions and 3 deletions
				
			
		| 
						 | 
					@ -15,13 +15,22 @@ def save_ssh_key(self, hosts, keys):
 | 
				
			||||||
    Saves ssh key into the VMs of a user using cdist
 | 
					    Saves ssh key into the VMs of a user using cdist
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    :param hosts: A list of hosts to be configured
 | 
					    :param hosts: A list of hosts to be configured
 | 
				
			||||||
    :param keys: A list of keys to be added
 | 
					    :param keys: A list of keys to be added. A key should be dict of the
 | 
				
			||||||
 | 
					           form    {
 | 
				
			||||||
 | 
					                       'value': 'sha-.....', # public key as string
 | 
				
			||||||
 | 
					                       'state': True         # whether key is to be added or
 | 
				
			||||||
 | 
					                    }                        # removed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    return_value = True
 | 
					    return_value = True
 | 
				
			||||||
    with tempfile.NamedTemporaryFile(delete=True) as tmp_manifest:
 | 
					    with tempfile.NamedTemporaryFile(delete=True) as tmp_manifest:
 | 
				
			||||||
        # Generate manifest to be used for configuring the hosts
 | 
					        # Generate manifest to be used for configuring the hosts
 | 
				
			||||||
        lines_list = ['  --key "{key}"\\\n'.format(key=key).encode('utf-8') for
 | 
					        lines_list = [
 | 
				
			||||||
                      key in keys]
 | 
					            '  --key "{key}" --state {state} \\\n'.format(
 | 
				
			||||||
 | 
					                key=key['value'],
 | 
				
			||||||
 | 
					                state='present' if key['state'] else 'absent'
 | 
				
			||||||
 | 
					            ).encode('utf-8')
 | 
				
			||||||
 | 
					            for key in keys]
 | 
				
			||||||
        lines_list.insert(0, b'__ssh_authorized_keys root \\\n')
 | 
					        lines_list.insert(0, b'__ssh_authorized_keys root \\\n')
 | 
				
			||||||
        tmp_manifest.writelines(lines_list)
 | 
					        tmp_manifest.writelines(lines_list)
 | 
				
			||||||
        tmp_manifest.flush()
 | 
					        tmp_manifest.flush()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue