示例#1
0
def main():
    module = AnsibleMetalModule(project_id_arg=False,
                                argument_spec=dict(
                                    state=dict(choices=['present', 'absent'],
                                               default='present'),
                                    name=dict(type='str'),
                                    id=dict(type='str'),
                                    org_id=dict(type='str'),
                                    payment_method=dict(type='str'),
                                    custom_data=dict(type='str'),
                                ),
                                supports_check_mode=True,
                                required_one_of=[(
                                    "name",
                                    "id",
                                )],
                                mutually_exclusive=[
                                    ('name', 'id'),
                                ])
    if not HAS_METAL_SDK:
        module.fail_json(msg='packet-python required for this module')

    state = module.params.get('state')

    # TODO: implement proper check mode
    if module.check_mode:
        module.exit_json(changed=False)

    try:
        module.exit_json(**act_on_project(state, module))
    except Exception as e:
        module.fail_json(msg="failed to set project state {0}: {1}".format(
            state, to_native(e)))
示例#2
0
def test_get_api_token_param_not_specified(stdin, capsys):
    with pytest.raises(SystemExit) as e:
        AnsibleMetalModule(argument_spec=dict(), project_id_arg=False)
    assert e.type == SystemExit

    out, _ = capsys.readouterr()  # pylint: disable=blacklisted-name
    assert "missing required arguments: api_token" in out
def main():
    module = AnsibleMetalModule(project_id_arg=False,
                                argument_spec=dict(
                                    state=dict(choices=['present', 'absent'],
                                               default='present'),
                                    label=dict(type='str',
                                               aliases=['name'],
                                               default=None),
                                    id=dict(type='str', default=None),
                                    fingerprint=dict(type='str', default=None),
                                    key=dict(type='str',
                                             default=None,
                                             no_log=True),
                                    key_file=dict(type='path', default=None),
                                ),
                                mutually_exclusive=[
                                    ('label', 'id'),
                                    ('label', 'fingerprint'),
                                    ('id', 'fingerprint'),
                                    ('key', 'fingerprint'),
                                    ('key', 'id'),
                                    ('key_file', 'key'),
                                ])

    state = module.params.get('state')

    try:
        module.exit_json(**act_on_sshkeys(state, module))
    except Exception as e:
        module.fail_json(msg='failed to set sshkey state: %s' % to_native(e))
def main():
    module = AnsibleMetalModule(
        argument_spec=dict(),
        supports_check_mode=True,
    )

    try:
        module.exit_json(**get_ip_info(module))
    except Exception as e:
        module.fail_json(
            msg="failed to get project IP info, error: {0}".format(to_native(e)))
def main():
    module = AnsibleMetalModule(
        project_id_arg=False,
        argument_spec=dict(include_legacy=dict(type='bool'), ),
        supports_check_mode=True,
    )

    try:
        module.exit_json(**get_capacity_info(module))
    except Exception as e:
        module.fail_json(msg="failed to get capacity info, error:  {0}".format(
            to_native(e)))
示例#6
0
def main():
    module = AnsibleMetalModule(argument_spec=dict(
        count=dict(type='int', default=1),
        count_offset=dict(type='int', default=1),
        device_ids=dict(type='list', elements='str'),
        facility=dict(),
        features=dict(type='dict'),
        hostnames=dict(type='list', elements='str', aliases=['name']),
        tags=dict(type='list', elements='str'),
        locked=dict(type='bool', default=False, aliases=['lock']),
        operating_system=dict(),
        plan=dict(),
        state=dict(choices=ALLOWED_STATES, default='present'),
        user_data=dict(default=None),
        wait_for_public_IPv=dict(type='int', choices=[4, 6]),
        wait_timeout=dict(type='int', default=900),
        ipxe_script_url=dict(default=''),
        always_pxe=dict(type='bool', default=False),
    ),
                                required_one_of=[(
                                    'device_ids',
                                    'hostnames',
                                )],
                                mutually_exclusive=[
                                    ('hostnames', 'device_ids'),
                                    ('count', 'device_ids'),
                                    ('count_offset', 'device_ids'),
                                ])

    if not HAS_METAL_SDK:
        module.fail_json(msg='packet-python required for this module')

    state = module.params.get('state')

    try:
        module.exit_json(**act_on_devices(module, state))
    except Exception as e:
        module.fail_json(msg='failed to set device state %s, error: %s' %
                         (state, to_native(e)),
                         exception=traceback.format_exc())
示例#7
0
def main():
    module = AnsibleMetalModule(project_id_arg=False,
                                argument_spec=dict(
                                    ids=dict(type='list', elements='str'),
                                    codes=dict(type='list', elements='str'),
                                ),
                                supports_check_mode=True,
                                mutually_exclusive=[
                                    ('codes', 'ids'),
                                ])

    try:
        module.exit_json(**get_facility_info(module))
    except Exception as e:
        module.fail_json(msg="failed to get facility info, error:  {0}".format(
            to_native(e)))
def main():
    module = AnsibleMetalModule(argument_spec=dict(
        device_ids=dict(type='list', elements='str'),
        hostnames=dict(type='list', elements='str'),
    ),
                                supports_check_mode=True,
                                mutually_exclusive=[
                                    ('hostnames', 'device_ids'),
                                ])

    try:
        module.exit_json(**get_device_info(module))
    except Exception as e:
        module.fail_json(msg='failed to get device info, error: %s' %
                         (to_native(e)),
                         exception=traceback.format_exc())
示例#9
0
def main():
    module = AnsibleMetalModule(project_id_arg=False,
                                argument_spec=dict(
                                    slugs=dict(type='list', elements='str'),
                                    distros=dict(type='list', elements='str'),
                                ),
                                supports_check_mode=True,
                                mutually_exclusive=[
                                    ('slugs', 'distros'),
                                ])

    try:
        module.exit_json(**get_operating_system_info(module))
    except Exception as e:
        module.fail_json(
            msg="failed to get operating_system info, error:  {0}".format(
                to_native(e)))
示例#10
0
def main():
    module = AnsibleMetalModule(project_id_arg=False,
                                argument_spec=dict(
                                    ids=dict(type='list', elements='str'),
                                    labels=dict(type='list',
                                                elements='str',
                                                aliases=['names']),
                                    fingerprints=dict(type='list',
                                                      elements='str'),
                                ),
                                supports_check_mode=True,
                                mutually_exclusive=[
                                    ('labels', 'ids'),
                                    ('labels', 'fingerprints'),
                                    ('ids', 'fingerprints'),
                                ])

    try:
        module.exit_json(**get_sshkey_info(module))
    except Exception as e:
        module.fail_json(msg='failed to get sshkey info: %s' % to_native(e))
示例#11
0
def main():
    module = AnsibleMetalModule(
        project_id_required=False,
        argument_spec=dict(
            device_id=dict(type='str'),
            hostname=dict(type='str'),
            cidr=dict(type='str', required=True, aliases=['name']),
            state=dict(choices=['present', 'absent'], default='present'),
        ),
        supports_check_mode=True,
        mutually_exclusive=[('hostname', 'device_id')],
        # TODO: sort this out, is project_id only sometimes needed?
        required_one_of=[['hostname', 'device_id', 'project_id']],
        required_by=dict(hostname=('project_id', ), ),
    )

    state = module.params.get('state')

    try:
        module.exit_json(**act_on_assignment(state, module))
    except Exception as e:
        module.fail_json(
            msg="failed to set IP subnet to state {0}, error: {1}".format(
                state, to_native(e)))
示例#12
0
def test_get_api_token_param_stdin_pref(stdin):
    os.environ['PACKET_TOKEN'] = 'donotwant'
    module = AnsibleMetalModule(argument_spec=dict(), project_id_arg=False)
    assert module.params.get('api_token') == 'deadbeef'
示例#13
0
def test_get_api_token_param_from_env_fallback_more(stdin):
    os.environ['PACKET_TOKEN'] = 'deadbeef'
    module = AnsibleMetalModule(argument_spec=dict(), project_id_arg=False)
    assert module.params.get('api_token') == 'deadbeef'
示例#14
0
def test_get_api_token_param_from_stdin_fallback(stdin):
    module = AnsibleMetalModule(argument_spec=dict(), project_id_arg=False)
    assert module.params.get('api_token') == 'deadbeef'