Пример #1
0
def create_ssh_config(working_dir=None):
   if working_dir is None:
      return      

   constants.set_working_dir(working_dir)
   constants.set_aws_credentials(None)
   constants.set_account_key(None)
   constants.set_logentries_logging()

   if working_dir is None:
      aws_conf_filename = 'aws.json'
   else:
      aws_conf_filename = '%s/aws.json'%working_dir

   # Open the updated version of the aws config file
   aws_conf = AWSConfFile(aws_conf_filename)
   aws_client = AWS_Client(aws_conf)
   aws_client.aws_create_ssh_config()
Пример #2
0
def main(working_dir=None, cmd='', group_name='AWS'):
    """
    Main function for the module. Calls other functions according to the parameters provided.
    """
    constants.set_working_dir(working_dir)
    constants.set_account_key(None)
    constants.set_logentries_logging()
      
    if working_dir is None:
        ssh_config_name = 'ssh_config'
    else:
        ssh_config_name = '%s/ssh_config'%working_dir

    env.use_ssh_config = True
    try:
        config_file = file(ssh_config_name)
    except IOError:
        pass
    else:
        config = SSHConfig()
        config.parse(config_file)
        env._ssh_config = config

    list_hosts = []
    for host_config in env._ssh_config._config:
        host_name = host_config['host'][0]
        if host_config['host'][0]!='*':
            ssh_config = host_config['config']['hostname']
            logger.info('Found instance ssh config. instance=%s, ssh_config=%s', host_name, ssh_config)
            list_hosts.extend(host_config['host'])

    if cmd == 'deprovision':
        execute(deprovision,hosts=list_hosts)
    elif cmd == 'clean':
        execute(set_instance_host_keys,hosts=list_hosts)
        execute(remove_hosts,group_name,hosts=list_hosts)
    elif cmd == '':
        execute(sync,hosts=list_hosts)
Пример #3
0
def create_ssh_config(working_dir=None):
   if working_dir is None:
      return      

   constants.set_working_dir(working_dir)
   constants.set_aws_credentials(None)
   constants.set_account_key(None)
   constants.set_logentries_logging()

   if working_dir is None:
      aws_conf_filename = 'aws.json'
   else:
      aws_conf_filename = '%s/aws.json'%working_dir

   # Open the updated version of the aws config file
   aws_conf = AWSConfFile(aws_conf_filename)
   aws_client = AWS_Client(aws_conf)
   aws_client.aws_create_ssh_config()
   

if __name__ == '__main__':
   if len(sys.argv) < 2:
      print 'You must specify the path to the AWS configuration file containing your AWS credentials'
   else:
      constants.set_working_dir(sys.argv[1])
      constants.set_aws_credentials(None)
      constants.set_account_key(None)
      constants.set_logentries_logging()
      main('%s/aws.json'%constants.WORKING_DIR)