diff --git a/pyfastogt/exe/request_fastogt_license_key_input b/pyfastogt/exe/set_fastogt_license_key similarity index 75% rename from pyfastogt/exe/request_fastogt_license_key_input rename to pyfastogt/exe/set_fastogt_license_key index 1c724e6..bcd7fa8 100755 --- a/pyfastogt/exe/request_fastogt_license_key_input +++ b/pyfastogt/exe/set_fastogt_license_key @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import configparser import subprocess import sys from datetime import datetime @@ -24,9 +25,10 @@ def print_usage(): PROJECTS = ['fastocloud', 'fastocloud_pro', 'fastocloud_pro_ml', 'fastocloud_load_balance', 'fastocloud_epg'] if __name__ == "__main__": - project_line = 'Please select project number: \n' + project_line = 'Please choose project: \n' for i, proj in enumerate(PROJECTS): project_line += '{0} ({1})\n'.format(proj, i) + project_line += 'Select appropriate number [0-{0}]: '.format(len(PROJECTS) - 1) while True: email = input('Please input your email: ') @@ -57,7 +59,16 @@ if __name__ == "__main__": response = {'error': 'Invalid response'} if r.status_code == 200 or r.status_code == 201: - print(response['exp_license']) + exp_license = response['exp_license'] + print('license_key={0}'.format(exp_license)) + config = configparser.ConfigParser() + config_path = '/etc/{0}.conf'.format(project) + config.read(config_path) + config.set('settings', 'license_key', exp_license) + with open(config_path, 'w') as f: + config.write(f, space_around_delimiters=False) + + print('Successful installed license key for {0}'.format(project)) sys.exit(0) print('Request failed, status code: {0}, error: {1}'.format(r.status_code, response['error'])) diff --git a/setup.py b/setup.py index 9e0520c..75c5759 100644 --- a/setup.py +++ b/setup.py @@ -121,6 +121,6 @@ setup( cmdclass={ 'upload': UploadCommand }, - scripts=['pyfastogt/exe/request_fastogt_license_key', 'pyfastogt/exe/request_fastogt_license_key_input', + scripts=['pyfastogt/exe/request_fastogt_license_key', 'pyfastogt/exe/set_fastogt_license_key', 'pyfastogt/exe/regenerate_machine_id'] )