<commit_before>#!/usr/bin/env python
# encoding: utf-8

from ec2stack import helpers
from flask import request
from ec2stack.helpers import authentication_required
from ec2stack.core import Ec2stackError
from ec2stack.controllers.cloudstack import requester


@authentication_required
def create_keypair():
    helpers.require_parameters(['KeyName'])
    response = _create_keypair_request()
    return _create_keypair_format_response(response)


def _create_keypair_request():
    args = {}
    args['command'] = 'createSSHKeyPair'
    args['name'] = helpers.get('KeyName', request.form)

    response = requester.make_request(args)

    response = response['createsshkeypairresponse']

    return response


def _create_keypair_format_response(response):
    if 'errortext' in response:
        keyname = helpers.get('KeyName', request.form)
        raise Ec2stackError(
            '400',
            'InvalidKeyPair.Duplicate',
            'The keypair \'%s\' already exists.' % keyname
        )
    else:
        response = response['keypair']
        return {
            'template_name_or_list': 'keypair.xml',
            'response_type': 'CreateKeyPairResponse',
            'key_name': response['name'],
            'key_fingerprint': response['fingerprint'],
            'key_material': response['privatekey']
        }
<commit_msg>Minor change to create-keypair response so awscli can display it<commit_after>#!/usr/bin/env python
# encoding: utf-8

from ec2stack import helpers
from flask import request
from ec2stack.helpers import authentication_required
from ec2stack.core import Ec2stackError
from ec2stack.controllers.cloudstack import requester


@authentication_required
def create_keypair():
    helpers.require_parameters(['KeyName'])
    response = _create_keypair_request()
    return _create_keypair_format_response(response)


def _create_keypair_request():
    args = {}
    args['command'] = 'createSSHKeyPair'
    args['name'] = helpers.get('KeyName', request.form)

    response = requester.make_request(args)

    response = response['createsshkeypairresponse']

    return response


def _create_keypair_format_response(response):
    if 'errortext' in response:
        keyname = helpers.get('KeyName', request.form)
        raise Ec2stackError(
            '400',
            'InvalidKeyPair.Duplicate',
            'The keypair \'%s\' already exists.' % keyname
        )
    else:
        response = response['keypair']
        return {
            'template_name_or_list': 'keypair.xml',
            'response_type': 'CreateKeyPairResponse',
            'key_name': response['name'],
            'key_fingerprint': response['fingerprint'],
            'key_material': response['privateKey']
        }

{'fraction_non_alphanumeric': 0.10332238043081417, 'fraction_numerical': 0.007301935012778387, 'mean_word_length': 3.342313787638669, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4204533', 'n_tokens_mistral': 816, 'n_tokens_neox': 781, 'n_words': 167}