Пример #1
0
def main():
    module = AnsibleModule(argument_spec=dict(
        k8s_cluster_id=dict(type='str'),
        config_file=dict(type='str'),
        api_url=dict(type='str',
                     default=None,
                     fallback=(env_fallback, ['IONOS_API_URL'])),
        username=dict(type='str',
                      required=True,
                      aliases=['subscription_user'],
                      fallback=(env_fallback, ['IONOS_USERNAME'])),
        password=dict(type='str',
                      required=True,
                      aliases=['subscription_password'],
                      fallback=(env_fallback, ['IONOS_PASSWORD']),
                      no_log=True),
        wait=dict(type='bool', default=True),
        wait_timeout=dict(type='int', default=600),
        state=dict(type='str', default='present'),
    ),
                           supports_check_mode=True)
    if not HAS_SDK:
        module.fail_json(
            msg=
            'ionoscloud is required for this module, run `pip install ionoscloud`'
        )

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')
    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

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

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent
        if state == 'present':
            try:
                (response) = get_config(module, api_client)
                module.exit_json(response=response)
            except Exception as e:
                module.fail_json(
                    msg='failed to get the k8s cluster config: %s' %
                    to_native(e))
Пример #2
0
def main():
    module = AnsibleModule(argument_spec=dict(
        datacenter=dict(type='str'),
        volume=dict(type='str'),
        name=dict(type='str', default=''),
        description=dict(type='str', default=''),
        licence_type=dict(type='str', choices=LICENCE_TYPES, default=None),
        cpu_hot_plug=dict(type='bool', default=None),
        cpu_hot_unplug=dict(type='bool', default=None),
        ram_hot_plug=dict(type='bool', default=None),
        ram_hot_unplug=dict(type='bool', default=None),
        nic_hot_plug=dict(type='bool', default=None),
        nic_hot_unplug=dict(type='bool', default=None),
        disc_virtio_hot_plug=dict(type='bool', default=None),
        disc_virtio_hot_unplug=dict(type='bool', default=None),
        disc_scsi_hot_plug=dict(type='bool', default=None),
        disc_scsi_hot_unplug=dict(type='bool', default=None),
        api_url=dict(type='str',
                     default=None,
                     fallback=(env_fallback, ['IONOS_API_URL'])),
        username=dict(type='str',
                      required=True,
                      aliases=['subscription_user'],
                      fallback=(env_fallback, ['IONOS_USERNAME'])),
        password=dict(type='str',
                      required=True,
                      aliases=['subscription_password'],
                      fallback=(env_fallback, ['IONOS_PASSWORD']),
                      no_log=True),
        wait=dict(type='bool', default=True),
        wait_timeout=dict(type='int', default=600),
        state=dict(type='str', default='present'),
    ),
                           supports_check_mode=True)

    if not HAS_SDK:
        module.fail_json(
            msg=
            'ionoscloud is required for this module, run `pip install ionoscloud`'
        )

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')

    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

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

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent

        if state == 'absent':
            try:
                (changed) = delete_snapshot(module, api_client)
                module.exit_json(changed=changed)
            except Exception as e:
                module.fail_json(msg='failed to set snapshot state: %s' %
                                 to_native(e))

        elif state == 'present':
            if not module.params.get('datacenter'):
                module.fail_json(msg='datacenter parameter is required')
            if not module.params.get('volume'):
                module.fail_json(msg='volume parameter is required')

            try:
                (snapshot_dict) = create_snapshot(module, api_client)
                module.exit_json(**snapshot_dict)
            except Exception as e:
                module.fail_json(msg='failed to set snapshot state: %s' %
                                 to_native(e))

        elif state == 'restore':
            if not module.params.get('datacenter'):
                module.fail_json(msg='datacenter parameter is required')
            if not module.params.get('volume'):
                module.fail_json(msg='volume parameter is required')

            try:
                (changed) = restore_snapshot(module, api_client)
                module.exit_json(changed=changed)
            except Exception as e:
                module.fail_json(msg='failed to restore snapshot: %s' %
                                 to_native(e))

        elif state == 'update':
            try:
                (snapshot_dict) = update_snapshot(module, api_client)
                module.exit_json(**snapshot_dict)
            except Exception as e:
                module.fail_json(msg='failed to update snapshot: %s' %
                                 to_native(e))
Пример #3
0
def main():
    module = AnsibleModule(
        argument_spec=dict(
            cluster_name=dict(type='str'),
            k8s_cluster_id=dict(type='str'),
            k8s_version=dict(type='str'),
            maintenance_window=dict(
                type='dict',
                day_of_the_week=dict(type='str'),
                time=dict(type='str')
            ),
            api_url=dict(type='str', default=None, fallback=(env_fallback, ['IONOS_API_URL'])),
            username=dict(
                type='str',
                required=True,
                aliases=['subscription_user'],
                fallback=(env_fallback, ['IONOS_USERNAME'])
            ),
            password=dict(
                type='str',
                required=True,
                aliases=['subscription_password'],
                fallback=(env_fallback, ['IONOS_PASSWORD']),
                no_log=True
            ),
            wait=dict(type='bool', default=True),
            wait_timeout=dict(type='int', default=600),
            state=dict(type='str', default='present'),
        ),
        supports_check_mode=True
    )
    if not HAS_SDK:
        module.fail_json(
            msg='ionoscloud is required for this module, run `pip install ionoscloud`')

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')
    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

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

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent
        if state == 'present':
            if not module.params.get('cluster_name'):
                module.fail_json(
                    msg='cluster_name parameter is required for a new k8s cluster')
            try:
                (k8s_cluster_dict_array) = create_k8s_cluster(module, api_client)
                module.exit_json(**k8s_cluster_dict_array)
            except Exception as e:
                module.fail_json(
                    msg='failed to set k8s cluster state: %s' % to_native(e))

        elif state == 'absent':
            if not module.params.get('k8s_cluster_id'):
                module.fail_json(
                    msg='k8s_cluster_id parameter is required for deleting a k8s cluster.')
            try:
                (changed) = delete_k8s_cluster(module, api_client)
                module.exit_json(changed=changed)
            except Exception as e:
                module.fail_json(
                    msg='failed to set k8s cluster state: %s' % to_native(e))

        elif state == 'update':
            error_message = "%s parameter is required updating a k8s cluster."
            if not module.params.get('k8s_cluster_id'):
                module.fail_json(msg=error_message % 'k8s_cluster_id')
            if not module.params.get('cluster_name'):
                module.fail_json(msg=error_message % 'cluster_name')

            try:
                (changed) = update_k8s_cluster(module, api_client)
                module.exit_json(
                    changed=changed)
            except Exception as e:
                module.fail_json(
                    msg='failed to set k8s cluster state: %s' % to_native(e))
Пример #4
0
def main():
    module = AnsibleModule(argument_spec=dict(
        name=dict(type='str'),
        description=dict(type='str'),
        location=dict(type='str', choices=LOCATIONS, default='us/las'),
        id=dict(type='str'),
        api_url=dict(type='str',
                     default=None,
                     fallback=(env_fallback, ['IONOS_API_URL'])),
        username=dict(type='str',
                      required=True,
                      aliases=['subscription_user'],
                      fallback=(env_fallback, ['IONOS_USERNAME'])),
        password=dict(type='str',
                      required=True,
                      aliases=['subscription_password'],
                      fallback=(env_fallback, ['IONOS_PASSWORD']),
                      no_log=True),
        wait=dict(type='bool', default=True),
        wait_timeout=dict(type='int', default=600),
        state=dict(type='str', default='present'),
    ),
                           supports_check_mode=True)
    if not HAS_SDK:
        module.fail_json(
            msg=
            'ionoscloud is required for this module, run `pip install ionoscloud`'
        )

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')
    state = module.params.get('state')
    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent
        if state == 'absent':
            if not module.params.get('name') and not module.params.get('id'):
                module.fail_json(
                    msg=
                    'name parameter or id parameter are required deleting a virtual datacenter.'
                )

            try:
                (result) = remove_datacenter(module, api_client)
                module.exit_json(**result)
            except Exception as e:
                module.fail_json(msg='failed to set datacenter state: %s' %
                                 to_native(e))

        elif state == 'present':
            if not module.params.get('name'):
                module.fail_json(
                    msg='name parameter is required for a new datacenter')
            if not module.params.get('location'):
                module.fail_json(
                    msg='location parameter is required for a new datacenter')

            if module.check_mode:
                module.exit_json(changed=True)

            try:
                (datacenter_dict_array) = create_datacenter(module, api_client)
                module.exit_json(**datacenter_dict_array)
            except Exception as e:
                module.fail_json(msg='failed to set datacenter state: %s' %
                                 to_native(e))

        elif state == 'update':
            try:
                (datacenter_dict_array) = update_datacenter(module, api_client)
                module.exit_json(**datacenter_dict_array)
            except Exception as e:
                module.fail_json(msg='failed to update datacenter: %s' %
                                 to_native(e))
Пример #5
0
def main():
    module = AnsibleModule(argument_spec=dict(
        datacenter=dict(type='str'),
        server=dict(type='str'),
        name=dict(type='str'),
        id=dict(type='str', default=str(uuid4()).replace('-', '')[:10]),
        lan=dict(type='int', default=None),
        dhcp=dict(type='bool', default=None),
        nat=dict(type='bool', default=None),
        firewall_active=dict(type='bool', default=None),
        ips=dict(type='list', default=None),
        api_url=dict(type='str',
                     default=None,
                     fallback=(env_fallback, ['IONOS_API_URL'])),
        username=dict(type='str',
                      required=True,
                      aliases=['subscription_user'],
                      fallback=(env_fallback, ['IONOS_USERNAME'])),
        password=dict(type='str',
                      required=True,
                      aliases=['subscription_password'],
                      fallback=(env_fallback, ['IONOS_PASSWORD']),
                      no_log=True),
        wait=dict(type='bool', default=True),
        wait_timeout=dict(type='int', default=600),
        state=dict(type='str', default='present'),
    ),
                           supports_check_mode=True)

    if not HAS_SDK:
        module.fail_json(
            msg=
            'ionoscloud is required for this module, run `pip install ionoscloud`'
        )

    if not module.params.get('datacenter'):
        module.fail_json(msg='datacenter parameter is required')
    if not module.params.get('server'):
        module.fail_json(msg='server parameter is required')

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')
    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

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

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent

        if state == 'absent':
            if not module.params.get('name'):
                module.fail_json(msg='name parameter is required')

            try:
                (changed) = delete_nic(module, api_client)
                module.exit_json(changed=changed)
            except Exception as e:
                module.fail_json(msg='failed to set nic state: %s' %
                                 to_native(e))

        elif state == 'present':
            if not module.params.get('lan'):
                module.fail_json(msg='lan parameter is required')

            try:
                (nic_dict) = create_nic(module, api_client)
                module.exit_json(**nic_dict)
            except Exception as e:
                module.fail_json(msg='failed to set nic state: %s' %
                                 to_native(e))

        elif state == 'update':
            try:
                (nic_dict) = update_nic(module, api_client)
                module.exit_json(**nic_dict)
            except Exception as e:
                module.fail_json(msg='failed to update nic: %s' % to_native(e))
Пример #6
0
def main():
    module = AnsibleModule(
        argument_spec=dict(
            group=dict(type='str', required=True),
            edit_privilege=dict(type='bool', default=None),
            share_privilege=dict(type='bool', default=None),
            resource_ids=dict(type='list', required=True),
            api_url=dict(type='str', default=None, fallback=(env_fallback, ['IONOS_API_URL'])),
            username=dict(
                type='str',
                required=True,
                aliases=['subscription_user'],
                fallback=(env_fallback, ['IONOS_USERNAME'])
            ),
            password=dict(
                type='str',
                required=True,
                aliases=['subscription_password'],
                fallback=(env_fallback, ['IONOS_PASSWORD']),
                no_log=True
            ),
            wait=dict(type='bool', default=True),
            wait_timeout=dict(type='int', default=600),
            state=dict(type='str', default='present'),
        ),
        supports_check_mode=True
    )

    if not HAS_SDK:
        module.fail_json(msg='ionoscloud is required for this module, run `pip install ionoscloud`')

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')
    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

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

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent

        if state == 'absent':
            try:
                (result) = delete_shares(module, api_client)
                module.exit_json(**result)
            except Exception as e:
                module.fail_json(msg='failed to set state of the shares: %s' % to_native(e))

        elif state == 'present':
            try:
                (share_dict) = create_shares(module, api_client)
                module.exit_json(**share_dict)
            except Exception as e:
                module.fail_json(msg='failed to set state of the shares: %s' % to_native(e))

        elif state == 'update':
            try:
                (share_dict) = update_shares(module, api_client)
                module.exit_json(**share_dict)
            except Exception as e:
                module.fail_json(msg='failed to update share: %s' % to_native(e))
Пример #7
0
def main():
    module = AnsibleModule(argument_spec=dict(
        firstname=dict(type='str'),
        lastname=dict(type='str'),
        email=dict(type='str', required=True),
        user_password=dict(type='str', default=None, no_log=True),
        administrator=dict(type='bool', default=None),
        force_sec_auth=dict(type='bool', default=None),
        groups=dict(type='list', default=None),
        api_url=dict(type='str',
                     default=None,
                     fallback=(env_fallback, ['IONOS_API_URL'])),
        sec_auth_active=dict(type='bool', default=False),
        s3_canonical_user_id=dict(type='str'),
        username=dict(type='str',
                      required=True,
                      aliases=['subscription_user'],
                      fallback=(env_fallback, ['IONOS_USERNAME'])),
        password=dict(type='str',
                      required=True,
                      aliases=['subscription_password'],
                      fallback=(env_fallback, ['IONOS_PASSWORD']),
                      no_log=True),
        wait=dict(type='bool', default=True),
        wait_timeout=dict(type='int', default=600),
        state=dict(type='str', default='present'),
    ),
                           supports_check_mode=True)

    if not HAS_SDK:
        module.fail_json(
            msg=
            'ionoscloud is required for this module, run `pip install ionoscloud`'
        )

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')

    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

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

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent
        api_instance = ionoscloud.UserManagementApi(api_client)

        if state == 'absent':
            try:
                (result) = delete_user(module, api_instance)
                module.exit_json(**result)
            except Exception as e:
                module.fail_json(msg='failed to set user state: %s' %
                                 to_native(e))

        elif state == 'present':
            try:
                (user_dict) = create_user(module, api_instance, api_client)
                module.exit_json(**user_dict)
            except Exception as e:
                module.fail_json(msg='failed to set user state: %s' %
                                 to_native(e))

        elif state == 'update':
            try:
                (user_dict) = update_user(module, api_instance, api_client)
                module.exit_json(**user_dict)
            except Exception as e:
                module.fail_json(msg='failed to update user: %s' %
                                 to_native(e))
Пример #8
0
def main():
    module = AnsibleModule(
        argument_spec=dict(
            datacenter=dict(type='str'),
            server=dict(type='str'),
            name=dict(type='str'),
            size=dict(type='int', default=10),
            image=dict(type='str'),
            backupunit_id=dict(type='str'),
            user_data=dict(type='str'),
            image_password=dict(type='str', default=None, no_log=True),
            ssh_keys=dict(type='list', default=[]),
            cpu_hot_plug=dict(type='bool'),
            ram_hot_plug=dict(type='bool'),
            nic_hot_plug=dict(type='bool'),
            nic_hot_unplug=dict(type='bool'),
            disc_virtio_hot_plug=dict(type='bool'),
            disc_virtio_hot_unplug=dict(type='bool'),
            bus=dict(type='str', choices=BUS_TYPES, default='VIRTIO'),
            disk_type=dict(type='str', choices=DISK_TYPES, default='HDD'),
            licence_type=dict(type='str', choices=LICENCE_TYPES),
            availability_zone=dict(type='str', choices=AVAILABILITY_ZONES, default=None),
            count=dict(type='int', default=1),
            auto_increment=dict(type='bool', default=True),
            instance_ids=dict(type='list', default=[]),
            api_url=dict(type='str', default=None, fallback=(env_fallback, ['IONOS_API_URL'])),
            username=dict(
                type='str',
                required=True,
                aliases=['subscription_user'],
                fallback=(env_fallback, ['IONOS_USERNAME'])
            ),
            password=dict(
                type='str',
                required=True,
                aliases=['subscription_password'],
                fallback=(env_fallback, ['IONOS_PASSWORD']),
                no_log=True
            ),
            wait=dict(type='bool', default=True),
            wait_timeout=dict(type='int', default=600),
            state=dict(type='str', default='present'),
        ),
        supports_check_mode=True
    )

    if not HAS_SDK:
        module.fail_json(msg='ionoscloud is required for this module, run `pip install ionoscloud`')

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')

    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

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

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent

        if state == 'absent':
            if not module.params.get('datacenter'):
                module.fail_json(msg='datacenter parameter is required for creating, updating or deleting volumes.')

            try:
                (result) = delete_volume(module, api_client)
                module.exit_json(**result)
            except Exception as e:
                module.fail_json(msg='failed to set volume state: %s' % to_native(e))

        elif state == 'present':
            if not module.params.get('datacenter'):
                module.fail_json(msg='datacenter parameter is required for new instance')
            if not module.params.get('name'):
                module.fail_json(msg='name parameter is required for new instance')

            try:
                (volume_dict_array) = create_volume(module, api_client)
                module.exit_json(**volume_dict_array)
            except Exception as e:
                module.fail_json(msg='failed to set volume state: %s' % to_native(e))

        elif state == 'update':
            try:
                (volume_dict_array) = update_volume(module, api_client)
                module.exit_json(**volume_dict_array)
            except Exception as e:
                module.fail_json(msg='failed to update volume: %s' % to_native(e))
Пример #9
0
def main():
    module = AnsibleModule(argument_spec=dict(
        datacenter=dict(type='str'),
        name=dict(type='str'),
        image=dict(type='str'),
        cores=dict(type='int', default=2),
        ram=dict(type='int', default=2048),
        cpu_family=dict(type='str',
                        choices=CPU_FAMILIES,
                        default='AMD_OPTERON'),
        volume_size=dict(type='int', default=10),
        disk_type=dict(type='str', choices=DISK_TYPES, default='HDD'),
        availability_zone=dict(type='str',
                               choices=AVAILABILITY_ZONES,
                               default='AUTO'),
        volume_availability_zone=dict(type='str',
                                      choices=AVAILABILITY_ZONES,
                                      default=None),
        image_password=dict(type='str', default=None, no_log=True),
        ssh_keys=dict(type='list', default=[]),
        bus=dict(type='str', choices=BUS_TYPES, default='VIRTIO'),
        nic_ips=dict(type='list', elements='str'),
        lan=dict(type='raw', required=False),
        nat=dict(type='bool', default=None),
        count=dict(type='int', default=1),
        auto_increment=dict(type='bool', default=True),
        instance_ids=dict(type='list', default=[]),
        api_url=dict(type='str',
                     default=None,
                     fallback=(env_fallback, ['IONOS_API_URL'])),
        username=dict(type='str',
                      required=True,
                      aliases=['subscription_user'],
                      fallback=(env_fallback, ['IONOS_USERNAME'])),
        password=dict(type='str',
                      required=True,
                      aliases=['subscription_password'],
                      fallback=(env_fallback, ['IONOS_PASSWORD']),
                      no_log=True),
        location=dict(type='str', choices=LOCATIONS, default='us/las'),
        assign_public_ip=dict(type='bool', default=False),
        wait=dict(type='bool', default=True),
        wait_timeout=dict(type='int', default=600),
        remove_boot_volume=dict(type='bool', default=True),
        state=dict(type='str', default='present'),
    ),
                           supports_check_mode=True)

    if module.params.get('lan') is not None and not (
            isinstance(module.params.get('lan'), str)
            or isinstance(module.params.get('lan'), int)):
        module.fail_json(msg='lan should either be a string or a number')

    if not HAS_PB_SDK:
        module.fail_json(
            msg=
            'ionoscloud is required for this module, run `pip install ionoscloud`'
        )

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')
    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

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

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent

        if state == 'absent':
            if not module.params.get('datacenter'):
                module.fail_json(
                    msg=
                    'datacenter parameter is required for running or stopping machines.'
                )

            try:
                (result) = remove_virtual_machine(module, api_client)
                module.exit_json(**result)
            except Exception as e:
                module.fail_json(msg='failed to set instance state: %s' %
                                 to_native(e),
                                 exception=traceback.format_exc())

        elif state in ('running', 'stopped'):
            if not module.params.get('datacenter'):
                module.fail_json(
                    msg=
                    'datacenter parameter is required for running or stopping machines.'
                )
            try:
                (result) = startstop_machine(module, api_client, state)
                module.exit_json(**result)
            except Exception as e:
                module.fail_json(msg='failed to set instance state: %s' %
                                 to_native(e),
                                 exception=traceback.format_exc())

        elif state == 'present':
            if not module.params.get('name'):
                module.fail_json(
                    msg='name parameter is required for new instance')
            if not module.params.get('image'):
                module.fail_json(
                    msg='image parameter is required for new instance')

            if module.check_mode:
                module.exit_json(changed=True)

            try:
                (machine_dict_array) = create_virtual_machine(
                    module, api_client)
                module.exit_json(**machine_dict_array)
            except Exception as e:
                module.fail_json(msg='failed to set instance state: %s' %
                                 to_native(e),
                                 exception=traceback.format_exc())

        elif state == 'update':
            try:
                (machine_dict_array) = update_server(module, api_client)
                module.exit_json(**machine_dict_array)
            except Exception as e:
                module.fail_json(msg='failed to update server: %s' %
                                 to_native(e),
                                 exception=traceback.format_exc())
Пример #10
0
def get_class_and_method(operation):
    classes = get_request_classes()
    searched_method = '%s_with_http_info' % re.sub(r'(?<!^)(?=[A-Z])', '_', operation).lower()
    for request_class in classes:
        method_list = {func: getattr(request_class, func) for func in dir(request_class) if callable(getattr(request_class, func))}
        for method_name, method in method_list.items():
            # camelcase to underscore for python standard
            if method_name == searched_method:
                return request_class, method
    return None, None


if __name__ == "__main__":
    configuration = ionoscloud.Configuration(
        username=os.environ.get('IONOS_USERNAME'),
        password=os.environ.get('IONOS_PASSWORD'),
    )
    api_client = ionoscloud.ApiClient(configuration)

    input = sys.stdin.readlines()
    testing_data = json.loads(input[0])

    operation = testing_data['operation']
    params = {re.sub(r'(?<!^)(?=[A-Z])', '_', p['name']).lower(): p['value'] for p in testing_data['params']}

    try:
        if operation == 'waitForRequest':
            request_id = re.search('/requests/([-A-Fa-f0-9]+)/', params['request']).group(1)
            api_client.wait_for_completion(request_id)
            sys.stdout.write(json.dumps({}))
        else:
Пример #11
0
def main():
    module = AnsibleModule(argument_spec=dict(
        datacenter=dict(type='str', required=True),
        server=dict(type='str', required=True),
        nic=dict(type='str', required=True),
        name=dict(type='str', required=True),
        protocol=dict(type='str', choices=PROTOCOLS, required=False),
        source_mac=dict(type='str', default=None),
        source_ip=dict(type='str', default=None),
        target_ip=dict(type='str', default=None),
        port_range_start=dict(type='int', default=None),
        port_range_end=dict(type='int', default=None),
        icmp_type=dict(type='int', default=None),
        icmp_code=dict(type='int', default=None),
        api_url=dict(type='str',
                     default=None,
                     fallback=(env_fallback, ['IONOS_API_URL'])),
        username=dict(type='str',
                      required=True,
                      aliases=['subscription_user'],
                      fallback=(env_fallback, ['IONOS_USERNAME'])),
        password=dict(type='str',
                      required=True,
                      aliases=['subscription_password'],
                      fallback=(env_fallback, ['IONOS_PASSWORD']),
                      no_log=True),
        wait=dict(type='bool', default=True),
        wait_timeout=dict(type='int', default=600),
        state=dict(type='str', default='present'),
    ),
                           supports_check_mode=True)

    if not HAS_SDK:
        module.fail_json(
            msg=
            'ionoscloud is required for this module, run `pip install ionoscloud`'
        )

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')
    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

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

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent

        if state == 'absent':
            try:
                (result) = delete_firewall_rule(module, api_client)
                module.exit_json(**result)
            except Exception as e:
                module.fail_json(msg='failed to set firewall rule state: %s' %
                                 to_native(e))

        elif state == 'present':
            try:
                (firewall_rule_dict) = create_firewall_rule(module, api_client)
                module.exit_json(**firewall_rule_dict)
            except Exception as e:
                module.fail_json(msg='failed to set firewall rules state: %s' %
                                 to_native(e))

        elif state == 'update':
            try:
                (firewall_rule_dict) = update_firewall_rule(module, api_client)
                module.exit_json(**firewall_rule_dict)
            except Exception as e:
                module.fail_json(msg='failed to update firewall rule: %s' %
                                 to_native(e))
Пример #12
0
def main():
    module = AnsibleModule(argument_spec=dict(
        nodepool_name=dict(type='str'),
        k8s_cluster_id=dict(type='str'),
        k8s_version=dict(type='str'),
        nodepool_id=dict(type='str'),
        datacenter_id=dict(type='str'),
        lan_ids=dict(type='list', elements='int'),
        node_count=dict(type='int'),
        cpu_family=dict(type='str'),
        cores_count=dict(type='str'),
        ram_size=dict(type='str'),
        availability_zone=dict(type='str'),
        storage_type=dict(type='str'),
        storage_size=dict(type='str'),
        maintenance_window=dict(type='dict',
                                day_of_the_week=dict(type='int'),
                                time=dict(type='int')),
        labels=dict(type='dict'),
        annotations=dict(type='dict'),
        auto_scaling=dict(type='dict',
                          min_node_count=dict(type='str'),
                          max_node_count=dict(type='str')),
        public_ips=dict(type='list', elements='str'),
        api_url=dict(type='str',
                     default=None,
                     fallback=(env_fallback, ['IONOS_API_URL'])),
        username=dict(type='str',
                      required=True,
                      aliases=['subscription_user'],
                      fallback=(env_fallback, ['IONOS_USERNAME'])),
        password=dict(type='str',
                      required=True,
                      aliases=['subscription_password'],
                      fallback=(env_fallback, ['IONOS_PASSWORD']),
                      no_log=True),
        wait=dict(type='bool', default=True),
        wait_timeout=dict(type='int', default=600),
        state=dict(type='str', default='present'),
    ),
                           supports_check_mode=True)
    if not HAS_SDK:
        module.fail_json(
            msg=
            'ionoscloud is required for this module, run `pip install ionoscloud`'
        )

    username = module.params.get('username')
    password = module.params.get('password')
    api_url = module.params.get('api_url')
    user_agent = 'ionoscloud-python/%s Ansible/%s' % (sdk_version, __version__)

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

    conf = {
        'username': username,
        'password': password,
    }

    if api_url is not None:
        conf['host'] = api_url
        conf['server_index'] = None

    configuration = ionoscloud.Configuration(**conf)

    with ApiClient(configuration) as api_client:
        api_client.user_agent = user_agent

        if state == 'present':
            error_message = "%s parameter is required updating a k8s nodepool"
            if not module.params.get('nodepool_name'):
                module.fail_json(msg=error_message % 'nodepool_name')
            if not module.params.get('k8s_cluster_id'):
                module.fail_json(msg=error_message % 'k8s_cluster_id')
            if not module.params.get('datacenter_id'):
                module.fail_json(msg=error_message % 'datacenter_id')
            if not (module.params.get('node_count')
                    or module.params.get('auto_scaling')):
                module.fail_json(msg=error_message %
                                 'node_count or auto_scaling')
            if not module.params.get('cpu_family'):
                module.fail_json(msg=error_message % 'cpu_family')
            if not module.params.get('cores_count'):
                module.fail_json(msg=error_message % 'cores_count')
            if not module.params.get('ram_size'):
                module.fail_json(msg=error_message % 'ram_size')
            if not module.params.get('availability_zone'):
                module.fail_json(msg=error_message % 'availability_zone')
            if not module.params.get('storage_type'):
                module.fail_json(msg=error_message % 'storage_type')
            if not module.params.get('storage_size'):
                module.fail_json(msg=error_message % 'storage_size')
            try:
                (k8s_nodepool_dict_array) = create_k8s_cluster_nodepool(
                    module, api_client)
                module.exit_json(**k8s_nodepool_dict_array)
            except Exception as e:
                module.fail_json(
                    msg='failed to set k8s cluster nodepool state: %s' %
                    to_native(e))

        elif state == 'absent':
            if not module.params.get('k8s_cluster_id'):
                module.fail_json(
                    msg=
                    'k8s_cluster_id parameter is required deleting a k8s nodepool.'
                )
            if not module.params.get('nodepool_id'):
                module.fail_json(
                    msg=
                    'nodepool_id parameter is required deleting a k8s nodepool.'
                )

            try:
                (result) = delete_k8s_cluster_nodepool(module, api_client)
                module.exit_json(**result)
            except Exception as e:
                module.fail_json(msg='failed to set k8s nodepool state: %s' %
                                 to_native(e))

        elif state == 'update':
            if not module.params.get('k8s_cluster_id'):
                module.fail_json(
                    msg=
                    'k8s_cluster_id parameter is required updating a nodepool.'
                )
            if not module.params.get('nodepool_id'):
                module.fail_json(
                    msg='nodepool_id parameter is required updating a nodepool.'
                )
            try:
                (k8s_nodepool_dict_array) = update_k8s_cluster_nodepool(
                    module, api_client)
                module.exit_json(**k8s_nodepool_dict_array)
            except Exception as e:
                module.fail_json(msg='failed to set k8s nodepool state: %s' %
                                 to_native(e))
 def get_api_client(self):
     return ionoscloud.ApiClient(ionoscloud.Configuration(
         username = self.username,
         password = self.password
     ))