コード例 #1
0
def main():
    argument_spec = xenserver_common_argument_spec()
    argument_spec.update(
        name=dict(type='str', aliases=['name_label']),
        uuid=dict(type='str'),
    )

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True,
                           required_one_of=[
                               ['name', 'uuid'],
                           ],
                           )

    if module._name == 'xenserver_guest_facts':
        module.deprecate("The 'xenserver_guest_facts' module has been renamed to 'xenserver_guest_info'", version='2.13')

    result = {'failed': False, 'changed': False}

    # Module will exit with an error message if no VM is found.
    vm = XenServerVM(module)

    # Gather facts.
    result['instance'] = vm.gather_facts()

    if result['failed']:
        module.fail_json(**result)
    else:
        module.exit_json(**result)
コード例 #2
0
def main():
    argument_spec = xenserver_common_argument_spec()
    argument_spec.update(
        state=dict(type='str',
                   default='present',
                   choices=[
                       'powered-on', 'powered-off', 'restarted',
                       'shutdown-guest', 'reboot-guest', 'suspended', 'present'
                   ]),
        name=dict(type='str', aliases=['name_label']),
        uuid=dict(type='str'),
        wait_for_ip_address=dict(type='bool', default=False),
        state_change_timeout=dict(type='int', default=0),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_one_of=[
            ['name', 'uuid'],
        ],
    )

    result = {'failed': False, 'changed': False}

    # Module will exit with an error message if no VM is found.
    vm = XenServerVM(module)

    # Set VM power state.
    if module.params['state'] != "present":
        result['changed'] = vm.set_power_state(module.params['state'])

    if module.params['wait_for_ip_address']:
        vm.wait_for_ip_address()

    result['instance'] = vm.gather_facts()

    if result['failed']:
        module.fail_json(**result)
    else:
        module.exit_json(**result)