示例#1
0
    def invoke(self, ctx):
        try:
            self._check_for_new_version()
            self._check_for_error_collection_permission()
            return super(FandoghCommand, self).invoke(ctx)
        except CommandParameterException as exp:
            click.echo(format_text(exp.message, TextStyle.FAIL), err=True)
            exit(1)
        except FandoghAPIError as exp:
            debug('APIError. status code: {}, content: {}'.format(
                exp.response.status_code, exp.response.content))
            click.echo(format_text(exp.message, TextStyle.FAIL), err=True)
            exit(1)
        except VersionException as exp:
            click.echo(format_text(
                "New Version of {} is available, please update to continue "
                "using Fandogh services using : `pip install {} --upgrade`".
                format(NAME, NAME), TextStyle.FAIL),
                       err=True)
        except AuthenticationError:
            click.echo(format_text(
                "Please login first. You can do it by running 'fandogh login' command",
                TextStyle.FAIL),
                       err=True)

        except requests.exceptions.RequestException as req_err:
            click.echo(format_text(
                'Error in your network connection! trying again might help to fix this issue \n'
                'if it is keep happening, please inform us!', TextStyle.FAIL),
                       err=True)
            collect(self, ctx, req_err)
        except Exception as exp:
            collect(self, ctx, exp)
            raise exp
示例#2
0
def collect(cmd, ctx, exception=None):
    try:
        let_collection = get_user_config().get('collect_error', 'NO')
        if let_collection == 'YES':
            info = dict(_static_info)
            info['cmd'] = cmd.name
            info['params'] = ctx.params
            info['error'] = exception.message if hasattr(exception, 'message') else str(exception)

            report(info)

    except Exception as e:
        click.echo(format_text('Error in reporting problem. Please share this error with to help us to improve the service.', TextStyle.FAIL), err=True)
        click.echo(format_text('Caused by {}'.format(exception), TextStyle.FAIL), err=True)
        click.echo(format_text('Report error: {}'.format(e), TextStyle.FAIL), err=True)
示例#3
0
def delete_volume(name):
    if click.confirm(
            format_text(
                'If you proceed all your data will be deleted, do you want to continue?',
                TextStyle.WARNING)):
        click.echo('Volume delete may take some times, please wait...')
        click.echo(delete_volume_claim(name))
示例#4
0
def requirements_hint():
    req_path = os.path.join(os.getcwd(), 'requirements.txt')
    if os.path.isfile(req_path):
        return
    click.echo(format_text(
        'Please consider to add a requirements.txt file contains all the dependencies your project has and try again.',
        TextStyle.FAIL),
               err=True)
    sys.exit(401)
示例#5
0
def deploy_manifest(manifest):
    response = get_session().post(base_services_url + '/manifests',
                                  json=manifest)
    if response.status_code != 200:
        if response.status_code == 400:
            document = _get_manifest_document(list(response.json().keys())[0])
            click.echo(format_text(document, TextStyle.WARNING))
        raise get_exception(response)
    else:
        return response.json()
 def invoke(self, ctx):
     try:
         self._check_for_new_version()
         self._check_for_error_collection_permission()
         return super(FandoghCommand, self).invoke(ctx)
     except (FandoghAPIError, AuthenticationError) as exp:
         debug('APIError. status code: {}, content: {}'.format(
             exp.response.status_code, exp.response.content))
         click.echo(format_text(exp.message, TextStyle.FAIL), err=True)
         exit(1)
     except VersionException as exp:
         click.echo(
             format_text(
                 "New Version of {} is available, please update to continue "
                 "using Fandogh services using : `pip install {} --upgrade`"
                 .format(NAME, NAME), TextStyle.FAIL))
     except Exception as exp:
         collect(self, ctx, exp)
         raise exp
示例#7
0
 def _check_for_new_version(self):
     latest_version = self._get_latest_version()
     version_diff = get_current_version().compare(latest_version)
     if version_diff < -2:  # -1:Major -2:Minor -3:Patch
         click.echo(
             format_text(
                 "New version is available, "
                 "please update to new version"
                 " using `pip install {} --upgrade` to access latest bugfixes"
                 .format(NAME), TextStyle.WARNING))
         debug("New Version is available: {}".format(latest_version))
     elif version_diff < 0:
         debug("New Version is available: {}".format(latest_version))
         raise VersionException()
示例#8
0
def upload_source(workspace_path, manifest, monitor_callback):
    with open(workspace_path, 'rb') as file:
        e = encoder.MultipartEncoder(
            fields={
                'source': ('workspace', file, 'text/plain'),
                'manifest': manifest
            })
        m = encoder.MultipartEncoderMonitor(e, monitor_callback)

        response = get_session().post(base_sources_url,
                                      data=m,
                                      headers={'Content-Type': m.content_type})

        if response.status_code != 200:
            if response.status_code == 400:
                document = get_manifest_document(
                    list(response.json().keys())[0])
                click.echo(format_text(document, TextStyle.WARNING))
            raise get_exception(response)
        else:
            return response.json()
示例#9
0
def _check_for_manifest_errors(response):
    document = get_manifest_document(list(response.json().keys())[0])
    click.echo(format_text(document, TextStyle.WARNING))
示例#10
0
def present_service_detail(details):
    if details.get('env'):
        click.echo('Environment Variables:')
        click.echo(
            present(lambda: details.get('env'),
                    renderer='table',
                    headers=['Name', 'Value'],
                    columns=['name', 'value']))

    if details.get('urls'):
        click.echo('Domains:')

        for url in details['urls']:
            click.echo(' - {}'.format(url))

    if details.get('volumes'):
        click.echo('Volumes:')
        click.echo(
            present(lambda: details.get('volumes'),
                    renderer='table',
                    headers=['No', 'Volume'],
                    columns=['no', 'volume']))

    click.echo('Pods:')
    for pod in details['pods']:
        click.echo('  Name: {}'.format(pod['name']))
        click.echo('  Created at: {}'.format(pod.get("created_at", "UNKNOWN")))
        click.echo('  Phase: {}'.format(
            format_text(pod['phase'], TextStyle.OKGREEN) if pod['phase'] ==
            'Running' else format_text(pod['phase'], TextStyle.WARNING)))
        containers = pod.get('containers', [])
        containers_length = len(containers)
        ready_containers = list(
            filter(lambda c: c.get('ready', False), containers))
        ready_containers_length = len(ready_containers)
        if ready_containers_length != containers_length:
            pod_ready_message = '  Ready containers:' + format_text(
                ' {}/{}'.format(ready_containers_length, containers_length),
                TextStyle.WARNING)
        else:
            pod_ready_message = '  Ready containers:' + format_text(
                ' {}/{}'.format(containers_length, containers_length),
                TextStyle.OKGREEN)
        click.echo(pod_ready_message)
        click.echo('  Containers:')
        for container in pod['containers']:
            click.echo('    Name: {}'.format(container['name']))
            click.echo('    Image: {}'.format(container['image']))
            click.echo('    Status: {}'.format(
                format_text('Ready', TextStyle.OKGREEN
                            ) if container['ready'] else format_text((
                                container.get('waiting', {}) or {}
                            ).get('reason', 'Pending'), TextStyle.WARNING)))

        click.echo('    ---------------------')

        if pod.get('events',
                   []) and containers_length != ready_containers_length:
            click.echo('    Events:')
            click.echo(
                present(lambda: pod.get('events'),
                        renderer='table',
                        headers=[
                            'Reason', 'Message', 'Count', 'First Seen',
                            'Last Seen'
                        ],
                        columns=[
                            'reason', 'message', 'count', 'first_timestamp',
                            'last_timestamp'
                        ]))