Exemplo n.º 1
0
def connection_attributes(cloudify_agent):

    if 'local' not in cloudify_agent:
        cloudify_agent['local'] = ctx.type == context.DEPLOYMENT

    if cloudify_agent['local']:

        # if installing an agent locally, we auto-detect which
        # os the agent is dedicated for
        cloudify_agent['windows'] = os.name == 'nt'

        # if installing locally, we install the agent with the same user the
        # current agent is running under. we don't care about any other
        # connection details
        if 'user' not in cloudify_agent:
            cloudify_agent['user'] = getpass.getuser()
    else:

        if 'windows' not in cloudify_agent:

            if ctx.plugin == 'windows_agent_installer':
                # 3.2 Compute node, installing windows
                cloudify_agent['windows'] = True
            if ctx.plugin == 'agent_installer':
                # 3.2 Compute node, installing linux
                cloudify_agent['windows'] = False
            if ctx.plugin == 'agent':
                # 3.3 Compute node, determine by new property 'os'
                cloudify_agent['windows'] = ctx.node.properties[
                    'os']['type'].lower() == 'windows'

        if 'ip' not in cloudify_agent:

            # support 'ip' attribute as direct node property or runtime
            # property (as opposed to nested inside the cloudify_agent dict)
            ip = ctx.instance.runtime_properties.get('ip')
            if not ip:
                ip = ctx.node.properties.get('ip')
            if not ip:
                raise_missing_attribute('ip')
            cloudify_agent['ip'] = ip

        if 'password' not in cloudify_agent:

            # support password as direct node property or runtime
            # property (as opposed to nested inside the cloudify_agent dict)
            password = ctx.instance.runtime_properties.get('password')
            if not password:
                password = ctx.node.properties.get('password')
            if not password and cloudify_agent['windows']:
                # a remote windows installation requires a
                # password to connect to the machine
                raise_missing_attribute('password')
            cloudify_agent['password'] = password

        # a remote installation requires the username
        # that the agent will run under.
        if 'user' not in cloudify_agent:
            raise_missing_attribute('user')

        # a remote installation requires the ip to connect to.
        if 'ip' not in cloudify_agent:
            raise_missing_attribute('ip')

        # a remote linux installation requires either a password or a key file
        # in order to connect to the remote machine.
        if not cloudify_agent['windows'] and 'password' not in \
                cloudify_agent and 'key' not in cloudify_agent:
            raise_missing_attributes('key', 'password')
Exemplo n.º 2
0
def connection_attributes(cloudify_agent):

    if 'local' not in cloudify_agent:
        cloudify_agent['local'] = ctx.type == context.DEPLOYMENT

    if cloudify_agent['local']:

        # if installing an agent locally, we auto-detect which
        # os the agent is dedicated for
        cloudify_agent['windows'] = os.name == 'nt'

        # if installing locally, we install the agent with the same user the
        # current agent is running under. we don't care about any other
        # connection details
        cloudify_agent['user'] = getpass.getuser()

        if 'remote_execution' not in cloudify_agent:
            cloudify_agent['remote_execution'] = True
    else:
        if 'remote_execution' not in cloudify_agent:
            install_method = cloudify_utils.internal.get_install_method(
                ctx.node.properties)
            if install_method not in constants.AGENT_INSTALL_METHODS:
                raise exceptions.AgentInstallerConfigurationError(
                    'agent_config.install_method must be one of {0}'
                    ' but found: {1}'.format(constants.AGENT_INSTALL_METHODS,
                                             install_method))
            remote_execution = (
                install_method == constants.AGENT_INSTALL_METHOD_REMOTE)
            cloudify_agent.update({
                'remote_execution': remote_execution,
                'install_method': install_method
            })

        if 'windows' not in cloudify_agent:
            if ctx.plugin == 'windows_agent_installer':
                # 3.2 Compute node, installing windows
                cloudify_agent['windows'] = True
            elif ctx.plugin == 'agent_installer':
                # 3.2 Compute node, installing linux
                cloudify_agent['windows'] = False
            else:
                # 3.3 Compute node, determine by new property 'os_family'
                cloudify_agent['windows'] = ctx.node.properties[
                    'os_family'].lower() == 'windows'

        # support 'ip' attribute as direct node property or runtime
        # property (as opposed to nested inside the cloudify_agent dict)
        ip = ctx.instance.runtime_properties.get('ip')
        if not ip:
            ip = ctx.node.properties.get('ip')
        if not ip:
            ip = cloudify_agent.get('ip')
        if not ip and cloudify_agent['remote_execution']:
            # a remote installation requires the ip to connect to.
            raise_missing_attribute('ip')
        if ip:
            cloudify_agent['ip'] = ip

        # support password as direct node property or runtime
        # property (as opposed to nested inside the cloudify_agent dict)
        password = ctx.instance.runtime_properties.get('password')
        if not password:
            password = ctx.node.properties.get('password')
        if not password:
            password = cloudify_agent.get('password')
        if not password and cloudify_agent['windows'] \
                and cloudify_agent['remote_execution']:
            # a remote windows installation requires a
            # password to connect to the machine
            raise_missing_attribute('password')
        if password:
            cloudify_agent['password'] = password

        # a remote installation requires the username
        # that the agent will run under.
        if not cloudify_agent.get('user'):
            raise_missing_attribute('user')

        # a remote linux installation requires either a password or a key file
        # in order to connect to the remote machine.
        if not cloudify_agent['windows'] and \
                not cloudify_agent.get('password') and \
                not cloudify_agent.get('key') and \
                cloudify_agent['remote_execution']:
            raise_missing_attributes('key', 'password')
Exemplo n.º 3
0
def connection_attributes(cloudify_agent):

    if 'local' not in cloudify_agent:
        cloudify_agent['local'] = ctx.type == context.DEPLOYMENT

    if cloudify_agent['local']:

        # if installing an agent locally, we auto-detect which
        # os the agent is dedicated for
        cloudify_agent['windows'] = os.name == 'nt'

        # if installing locally, we install the agent with the same user the
        # current agent is running under. we don't care about any other
        # connection details
        cloudify_agent['user'] = getpass.getuser()

        if 'remote_execution' not in cloudify_agent:
            cloudify_agent['remote_execution'] = True
    else:
        if 'remote_execution' not in cloudify_agent:
            install_method = cloudify_utils.internal.get_install_method(
                ctx.node.properties)
            if install_method not in constants.AGENT_INSTALL_METHODS:
                raise exceptions.AgentInstallerConfigurationError(
                    'agent_config.install_method must be one of {0}'
                    ' but found: {1}'.format(constants.AGENT_INSTALL_METHODS,
                                             install_method))
            remote_execution = (install_method ==
                                constants.AGENT_INSTALL_METHOD_REMOTE)
            cloudify_agent.update({
                'remote_execution': remote_execution,
                'install_method': install_method
            })

        if 'windows' not in cloudify_agent:
            if ctx.plugin == 'windows_agent_installer':
                # 3.2 Compute node, installing windows
                cloudify_agent['windows'] = True
            elif ctx.plugin == 'agent_installer':
                # 3.2 Compute node, installing linux
                cloudify_agent['windows'] = False
            else:
                # 3.3 Compute node, determine by new property 'os_family'
                cloudify_agent['windows'] = ctx.node.properties[
                    'os_family'].lower() == 'windows'

        # support 'ip' attribute as direct node property or runtime
        # property (as opposed to nested inside the cloudify_agent dict)
        ip = ctx.instance.runtime_properties.get('ip')
        if not ip:
            ip = ctx.node.properties.get('ip')
        if not ip:
            ip = cloudify_agent.get('ip')
        if not ip and cloudify_agent['remote_execution']:
            # a remote installation requires the ip to connect to.
            raise_missing_attribute('ip')
        if ip:
            cloudify_agent['ip'] = ip

        # support password as direct node property or runtime
        # property (as opposed to nested inside the cloudify_agent dict)
        password = ctx.instance.runtime_properties.get('password')
        if not password:
            password = ctx.node.properties.get('password')
        if not password:
            password = cloudify_agent.get('password')
        if not password and cloudify_agent['windows'] \
                and cloudify_agent['remote_execution']:
            # a remote windows installation requires a
            # password to connect to the machine
            raise_missing_attribute('password')
        if password:
            cloudify_agent['password'] = password

        # a remote installation requires the username
        # that the agent will run under.
        if not cloudify_agent.get('user'):
            raise_missing_attribute('user')

        # a remote linux installation requires either a password or a key file
        # in order to connect to the remote machine.
        if not cloudify_agent['windows'] and \
                not cloudify_agent.get('password') and \
                not cloudify_agent.get('key') and \
                cloudify_agent['remote_execution']:
            raise_missing_attributes('key', 'password')