'Check if control service certificate already exist in current
directory. If it does, error out. Also check if root key and
certificate files (either default or as specified on the command line)
exist in the path and error out if they do not. If there are no path
errors, create a new control service certificate signed by the root
and write it out to the current directory.'

def run(self):

    if (self['inputpath'] is None):
        self['inputpath'] = os.getcwd()
    if (self['outputpath'] is None):
        self['outputpath'] = os.getcwd()
    self['inputpath'] = FilePath(self['inputpath'])
    self['outputpath'] = FilePath(self['outputpath'])
    try:
        try:
            ca = RootCredential.from_path(self['inputpath'])
            ControlCredential.initialize(self['outputpath'], ca, self['hostname'])
            output_certificate_filename = (('control-' + self['hostname']) + '.crt').decode('utf-8')
            output_key_filename = (('control-' + self['hostname']) + '.key').decode('utf-8')
            success_message = u'Created    {certificate}    and    {key}\nCopy    these    files    to    the    directory    /etc/flocker    on    your    control    service    machine.\nRename    the    files    to    control-service.crt    and    control-service.key    and    set    the    correct    permissions    by    running    chmod    0600    on    both    files.\n'.format(certificate=output_certificate_filename, key=output_key_filename).encode('utf-8')
            self._sys_module.stdout.write(success_message)
        except (CertificateAlreadyExistsError, KeyAlreadyExistsError, PathError) as e:
            raise UsageError(str(e))
    except UsageError as e:
        raise SystemExit(u'Error:    {error}'.format(error=str(e)))
    return succeed(None)
