if key in constants.INSTANCE_REQUIRED_PROPERTIES + ('machine_id', ):
            node_properties['parameters'][key] = params[key]
            ctx.logger.info('Added %s=%s to node parameters', key, params[key])

    # Generate a somewhat random machine name. NOTE that we need the name at
    # this early point in order to be passed into cloud-init, if used, so that
    # we may use it later on to match log entries.
    name = generate_name(
        get_stack_name(),
        'master' if ctx.node.properties['master'] else 'worker'
    )
    node_properties['parameters']['name'] = name
    ctx.instance.runtime_properties['machine_name'] = name

    # Get the cloud based on the node's properties.
    cloud = conn.get_cloud(get_cloud_id(node_properties))

    # Generate cloud-init, if supported.
    # TODO This is NOT going to work when use_external_resource is True. We
    # are using cloud-init to configure the newly provisioned nodes in case
    # the VMs are unreachable over SSH. If the VMs already exist, cloud-init
    # is not an option. Perhaps, we should allow to toggle cloud-init on/off
    # in some way after deciding if the VMs are accessible over the public
    # internet.
    if cloud.provider in constants.CLOUD_INIT_PROVIDERS:
        if is_resource_external(node_properties):
            raise NonRecoverableError('use_external_resource may not be set')
        prepare_cloud_init()
        cloud_init = ctx.instance.runtime_properties.get('cloud_init', '')
        node_properties['parameters']['cloud_init'] = cloud_init
    params += "-r 'node'"

    # Run the script.
    script = conn.client.run_script(
        script_id=ctx.instance.runtime_properties['script_id'], su=True,
        machine_id=machine.id,
        cloud_id=machine.cloud.id,
        script_params=params,
    )
    ctx.instance.runtime_properties['job_id'] = script['job_id']


if __name__ == '__main__':
    """Setup kubernetes on the machines defined by the blueprint."""
    conn = MistConnectionClient()
    cloud = conn.get_cloud(ctx.instance.runtime_properties['cloud_id'])
    if cloud.provider in constants.CLOUD_INIT_PROVIDERS:
        wait_for_event(
            job_id=ctx.instance.runtime_properties['job_id'],
            job_kwargs={
                'action': 'cloud_init_finished',
                'machine_name': ctx.instance.runtime_properties['machine_name']
            }
        )
    elif not ctx.node.properties['configured']:
        if not ctx.node.properties['master']:
            configure_kubernetes_worker()
        else:
            configure_kubernetes_master()
        try:
            wait_for_event(
Exemple #3
0
    # Run the script.
    script = conn.client.run_script(
        script_id=ctx.instance.runtime_properties['script_id'],
        su=True,
        machine_id=machine.id,
        cloud_id=machine.cloud.id,
        script_params=params,
    )
    ctx.instance.runtime_properties['job_id'] = script['job_id']


if __name__ == '__main__':
    """Setup kubernetes on the machines defined by the blueprint."""
    conn = MistConnectionClient()
    cloud = conn.get_cloud(ctx.instance.runtime_properties['cloud_id'])
    if cloud.provider in constants.CLOUD_INIT_PROVIDERS:
        wait_for_event(job_id=ctx.instance.runtime_properties['job_id'],
                       job_kwargs={
                           'action':
                           'cloud_init_finished',
                           'machine_name':
                           ctx.instance.runtime_properties['machine_name']
                       })
    elif not ctx.node.properties['configured']:
        if not ctx.node.properties['master']:
            configure_kubernetes_worker()
        else:
            configure_kubernetes_master()
        try:
            wait_for_event(job_id=ctx.instance.runtime_properties['job_id'],