Ejemplo n.º 1
0
def _update_progress(current, total):
    HOOK = APPLICATION.get_progress_controller(True)

    if total:
        HOOK.add(message='Alive', value=current, total_val=total)
        if total == current:
            HOOK.end()
def _add_role_assignment(role, service_principal, delay=2):
    # AAD can have delays in propagating data, so sleep and retry
    hook = APPLICATION.get_progress_controller(True)
    hook.add(message='Waiting for AAD role to propagate',
             value=0,
             total_val=1.0)
    logger.info('Waiting for AAD role to propagate')
    for x in range(0, 10):
        hook.add(message='Waiting for AAD role to propagate',
                 value=0.1 * x,
                 total_val=1.0)
        try:
            # TODO: break this out into a shared utility library
            create_role_assignment(role, service_principal)
            # Sleep for a while to get role assignment propagated
            time.sleep(delay + delay * x)
            break
        except CloudError as ex:
            if ex.message == 'The role assignment already exists.':
                break
            logger.info(ex.message)
        except:  # pylint: disable=bare-except
            pass
        time.sleep(delay + delay * x)
    else:
        return False
    hook.add(message='AAD role propagation done', value=1.0, total_val=1.0)
    logger.info('AAD role propagation done')
    return True
Ejemplo n.º 3
0
def _add_role_assignment(role, service_principal, delay=2):
    # AAD can have delays in propagating data, so sleep and retry
    hook = APPLICATION.get_progress_controller(True)
    hook.add(message='Waiting for AAD role to propagate', value=0, total_val=1.0)
    logger.info('Waiting for AAD role to propagate')
    for x in range(0, 10):
        hook.add(message='Waiting for AAD role to propagate', value=0.1 * x, total_val=1.0)
        try:
            # TODO: break this out into a shared utility library
            create_role_assignment(role, service_principal)
            # Sleep for a while to get role assignment propagated
            time.sleep(delay + delay * x)
            break
        except CloudError as ex:
            if ex.message == 'The role assignment already exists.':
                break
            logger.info(ex.message)
        except:  # pylint: disable=bare-except
            pass
        time.sleep(delay + delay * x)
    else:
        return False
    hook.add(message='AAD role propagation done', value=1.0, total_val=1.0)
    logger.info('AAD role propagation done')
    return True
Ejemplo n.º 4
0
def _update_progress(current, total):
    HOOK = APPLICATION.get_progress_controller(True)

    if total:
        HOOK.add(message='Alive', value=current, total_val=total)
        if total == current:
            HOOK.end()
Ejemplo n.º 5
0
def _update_progress(current, total):
    hook = APPLICATION.get_progress_controller(det=True)

    if total:
        hook.add(message='Alive', value=current, total_val=total)
        if total == current:
            hook.end()
def _build_service_principal(client, name, url, client_secret):
    # use get_progress_controller
    hook = APPLICATION.get_progress_controller(True)
    hook.add(messsage='Creating service principal', value=0, total_val=1.0)
    logger.info('Creating service principal')
    result = create_application(client.applications,
                                name,
                                url, [url],
                                password=client_secret)
    service_principal = result.app_id  # pylint: disable=no-member
    for x in range(0, 10):
        hook.add(message='Creating service principal',
                 value=0.1 * x,
                 total_val=1.0)
        try:
            create_service_principal(service_principal, client=client)
            break
        # TODO figure out what exception AAD throws here sometimes.
        except Exception as ex:  # pylint: disable=broad-except
            logger.info(ex)
            time.sleep(2 + 2 * x)
    else:
        return False
    hook.add(message='Finished service principal creation',
             value=1.0,
             total_val=1.0)
    logger.info('Finished service principal creation')
    return service_principal
Ejemplo n.º 7
0
def wait_for_blob_copy_operation(blob_name, target_container_name, target_storage_account_name,
                                 azure_pool_frequency, location):
    progress_controller = APPLICATION.get_progress_controller()
    copy_status = "pending"
    prev_progress = -1
    while copy_status == "pending":
        cmd = prepare_cli_command(['storage', 'blob', 'show',
                                   '--name', blob_name,
                                   '--container-name', target_container_name,
                                   '--account-name', target_storage_account_name])

        json_output = run_cli_command(cmd, return_as_json=True)
        copy_status = json_output["properties"]["copy"]["status"]
        copy_progress_1, copy_progress_2 = json_output["properties"]["copy"]["progress"].split("/")
        current_progress = round(int(copy_progress_1) / int(copy_progress_2), 1)

        if current_progress != prev_progress:
            msg = "{0} - copy progress: {1}%"\
                .format(location, str(current_progress))\
                .ljust(PROGRESS_LINE_LENGTH)  # need to justify since messages overide each other
            progress_controller.add(message=msg)

        prev_progress = current_progress

        try:
            time.sleep(azure_pool_frequency)
        except KeyboardInterrupt:
            progress_controller.stop()
            return

    if copy_status == 'success':
        progress_controller.stop()
    else:
        logger.error("The copy operation didn't succeed. Last status: %s", copy_status)
        raise CLIError('Blob copy failed')
Ejemplo n.º 8
0
    def __init__(self, start_msg='', finish_msg='',
                 poller_done_interval_ms=1000.0, progress_controller=None):

        self.start_msg = start_msg
        self.finish_msg = finish_msg
        self.poller_done_interval_ms = poller_done_interval_ms
        from azure.cli.core.application import APPLICATION
        self.progress_controller = progress_controller or APPLICATION.get_progress_controller()
Ejemplo n.º 9
0
    def __init__(self, start_msg='', finish_msg='',
                 poller_done_interval_ms=1000.0, progress_controller=None):

        self.start_msg = start_msg
        self.finish_msg = finish_msg
        self.poller_done_interval_ms = poller_done_interval_ms
        from azure.cli.core.application import APPLICATION
        self.progress_controller = progress_controller or APPLICATION.get_progress_controller()
        self.deploy_dict = {}
Ejemplo n.º 10
0
    def __init__(self, start_msg='', finish_msg='',
                 poller_done_interval_ms=1000.0, progress_controller=None):

        self.start_msg = start_msg
        self.finish_msg = finish_msg
        self.poller_done_interval_ms = poller_done_interval_ms
        from azure.cli.core.application import APPLICATION
        self.progress_controller = progress_controller or APPLICATION.get_progress_controller()
        self.deploy_dict = {}
        self.last_progress_report = datetime.datetime.now()
Ejemplo n.º 11
0
def _build_service_principal(client, name, url, client_secret):
    # use get_progress_controller
    hook = APPLICATION.get_progress_controller(True)
    hook.add(messsage='Creating service principal', value=0, total_val=1.0)
    logger.info('Creating service principal')
    result = create_application(client.applications, name, url, [url], password=client_secret)
    service_principal = result.app_id  # pylint: disable=no-member
    for x in range(0, 10):
        hook.add(message='Creating service principal', value=0.1 * x, total_val=1.0)
        try:
            create_service_principal(service_principal, client=client)
            break
        # TODO figure out what exception AAD throws here sometimes.
        except Exception as ex:  # pylint: disable=broad-except
            logger.info(ex)
            time.sleep(2 + 2 * x)
    else:
        return False
    hook.add(message='Finished service principal creation', value=1.0, total_val=1.0)
    logger.info('Finished service principal creation')
    return service_principal
Ejemplo n.º 12
0
def _update_progress(current, total):
    hook = APPLICATION.get_progress_controller(det=True)
    if total:
        hook.add(message='Alive', value=current, total_val=total)
        if total == current:
            hook.end()