コード例 #1
0
def main():
    # Get the Ansible parameters.
    module = AnsibleModule(argument_spec=dict(server=dict(required=True,
                                                          type='str'),
                                              user=dict(required=True,
                                                        type='str'),
                                              password=dict(required=True,
                                                            type='str',
                                                            no_log=True)),
                           supports_check_mode=True)

    m_args = module.params

    try:
        # Instantiate the Tintri VMStore.
        tintri = Tintri(m_args['server'])

        # Login to VMStore.
        tintri.login(m_args['user'], m_args['password'])

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())

    try:
        tintri.restart_webserver(DEFAULT_DATASTORE)

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())
        tintri.logout()

    # Log out VMSTore.
    tintri.logout()

    # Return the result to Ansible.
    module.exit_json(changed=True)
コード例 #2
0
def main():
    module = AnsibleModule(argument_spec=dict(server=dict(required=True,
                                                          type='str'),
                                              user=dict(required=True,
                                                        type='str'),
                                              password=dict(required=True,
                                                            type='str',
                                                            no_log=True),
                                              timezone=dict(required=True,
                                                            type='str'),
                                              useNtp=dict(required=False,
                                                          type='bool'),
                                              ntpPrimary=dict(required=False,
                                                              type='str'),
                                              ntpSecondary=dict(required=False,
                                                                type='str'),
                                              year=dict(required=False,
                                                        type='int'),
                                              month=dict(required=False,
                                                         type='int'),
                                              day=dict(required=False,
                                                       type='int'),
                                              time=dict(required=False,
                                                        type='str')),
                           supports_check_mode=True)

    m_args = module.params
    param_skip = ['server', 'user', 'password']

    try:
        # Instantiate the Tintri VMStore.
        tintri = Tintri(m_args['server'])

        # Login to VMStore.
        tintri.login(m_args['user'], m_args['password'])

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())

    remove_dict_keys(m_args, param_skip)

    try:
        update_datetime(tintri, m_args)

        results = obj_to_str(get_datetime(tintri))

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())
        tintri.logout()

    # Log out VMSTore.
    tintri.logout()

    # Return the result to Ansible.
    module.exit_json(changed=True, meta=results)
コード例 #3
0
def main():
    # Get the Ansible parameters.
    # Note: that some of the parameters names are the same as the HypervisorConfig DTO attributes.
    module = AnsibleModule(
        argument_spec = dict(
            server = dict(required=True, type='str'),
            user = dict(required=True, type='str'),
            password = dict(required=True, type='str', no_log=True),
            host = dict(required=True, type='str'),
            hypervisorType = dict(required=True, choices=['VMWARE'], type='str'),
            #hypervisorType = dict(required=True,choices=['VMWARE','RHEV','HYPERV','UNKNOWN','OPENSTACK','XENSERVER','VMWARE_VVOL'], type='str'),
            username = dict(required=True,type='str'),
            hypervisor_password = dict(required=True, type='str', no_log=True)),
        supports_check_mode=True)

    m_args = module.params
    param_skip = ['server', 'user', 'password']

    try:
        # Instantiate the Tintri VMStore.
        tintri = Tintri(m_args['server'])

        # Login to VMStore.
        tintri.login(m_args['user'], m_args['password'])

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())

    # Forge the hypervisor manager configuration DTO.
    hypervisor_config = HypervisorManagerConfig()
    for key, value in m_args.iteritems():
    	if key not in param_skip:
    		if key == 'hypervisor_password':
    			setattr(hypervisor_config, 'password', value)
    		else:
    			setattr(hypervisor_config, key, value)

    # Add the hypervisor manager configuration.
    try:
        add_hypervisor_config(tintri, hypervisor_config)

        hyper_configs = get_hypervisor_configs(tintri)

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())
        tintri.logout()

    # Log out VMSTore.
    tintri.logout()

    # Return the result to Ansible.
    results = customize_output(hyper_configs)
    module.exit_json(changed=True, meta=results)
コード例 #4
0
def main():
    # Get the Ansible parameters.
    # Note: that some of the parameters names are the same as the ApplianceIP DTO attributes.
    module = AnsibleModule(argument_spec=dict(
        server=dict(required=True, type='str'),
        user=dict(required=True, type='str'),
        password=dict(required=True, type='str', no_log=True),
        ip=dict(required=True, type='str'),
        netmask=dict(required=True, type='str'),
        gateway=dict(required=True, type='str'),
        isJumboFrameEnabled=dict(required=False, type='bool', default=True),
        vlanId=dict(required=False, type='str', default='untagged'),
        networkBond=dict(required=False, type='str', default='NET_BOND_DATA')),
                           supports_check_mode=True)

    m_args = module.params
    param_skip = ['server', 'user', 'password']

    try:
        # Instantiate the Tintri VMStore.
        tintri = Tintri(m_args['server'])

        # Login to VMStore.
        tintri.login(m_args['user'], m_args['password'])

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())

    # Forge the DTO to update the IP network configuration.
    new_network = ApplianceIp()
    m_args['serviceType'] = DATA_SERVICE_TYPE

    for key, value in m_args.iteritems():
        if key not in param_skip:
            setattr(new_network, key, value)

    # Append the new data IP network configuration.
    try:
        add_data_network_config(tintri, new_network)

        ip_configs = get_ip_configs(tintri)

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())
        tintri.logout()

    # Log out VMstore.
    tintri.logout()

    # Return the result to Ansible.
    results = customize_output(ip_configs)
    module.exit_json(changed=True, meta=results)
コード例 #5
0
def main():
    # Get the Ansible parameters.
    # Note: that some of the parameters names are the same as the contact DTO attributes.
    module = AnsibleModule(argument_spec=dict(
        server=dict(required=True, type='str'),
        user=dict(required=True, type='str'),
        password=dict(required=True, type='str', no_log=True),
        contact=dict(required=False, type='str'),
        email=dict(required=False, type='str'),
        isEnabled=dict(required=False, type='bool', default=True),
        location=dict(required=False, type='str'),
        phone=dict(required=False, type='str'),
        webProxyHostname=dict(required=False, type='str'),
        webProxyUsername=dict(required=False, type='str'),
        webProxyPassword=dict(required=False, type='str'),
        webProxyPort=dict(required=False, type='int')),
                           supports_check_mode=True)

    m_args = module.params
    param_skip = ['server', 'user', 'password']

    try:
        # Instantiate the Tintri VMStore.
        tintri = Tintri(m_args['server'])

        # Login to VMStore.
        tintri.login(m_args['user'], m_args['password'])

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())

    remove_dict_keys(m_args, param_skip)

    try:
        update_contact_config(tintri, m_args)

        contact_conf = get_contact_config(tintri)

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())
        tintri.logout()

    # Log out VMSTore.
    tintri.logout()

    # Return the result to Ansible.
    results = obj_to_str(contact_conf)
    module.exit_json(changed=True, meta=results)
コード例 #6
0
def main():
    # Get the Ansible parameters.
    # Note: that some of the parameters names are the same dictionary keys to get POSTed.
    module = AnsibleModule(argument_spec=dict(server=dict(required=True,
                                                          type='str'),
                                              user=dict(required=True,
                                                        type='str'),
                                              password=dict(required=True,
                                                            type='str',
                                                            no_log=True),
                                              newPassword=dict(required=True,
                                                               type='str',
                                                               no_log=True)),
                           supports_check_mode=True)

    m_args = module.params
    param_skip = ['server', 'user']

    try:
        # Instantiate the Tintri VMStore.
        tintri = Tintri(m_args['server'])

        # Login to VMStore.
        tintri.login(m_args['user'], m_args['password'])

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())

    # Create the dictionary for the raw API post.
    remove_dict_keys(m_args, param_skip)
    m_args['typeId'] = TYPE_ID
    m_args['username'] = m_args['user']

    try:
        results = api_post(tintri, "resetPassword", m_args)

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())

    #Log out VMSTore
    tintri.logout()

    # Return the result to Ansible.
    module.exit_json(changed=True, meta=results)
コード例 #7
0
def main():
    # Get the Ansible parameters.
    # Note: that some of the parameters names are the same as the DNS configuration dictionary.
    module = AnsibleModule(
        argument_spec = dict(
            server = dict(required=True, type='str'),
            user = dict(required=True, type='str'),
            password = dict(required=True, type='str', no_log=True),
            dnsPrimary = dict(required=True, type='str'),
            dnsSecondary = dict(required=False, type='str')),
        supports_check_mode=True)

    m_args = module.params
    param_skip = ['server', 'user', 'password']

    try:
        # Instantiate the Tintri VMStore.
        tintri = Tintri(m_args['server'])

        # Login to VMStore.
        tintri.login(m_args['user'], m_args['password'])

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())

    remove_dict_keys(m_args, param_skip)
    try:
        update_dns_config(tintri, m_args)

        dns_conf = get_dns_config(tintri)

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())
        tintri.logout()

    # Log out VMSTore.
    tintri.logout()

    # Return the result to Ansible.
    results = obj_to_str(dns_conf)
    module.exit_json(changed=True, meta=results)
コード例 #8
0
    product_name = version_info.productName
    print_info("API Version: " + version_info.preferredVersion)

    # Login to VMstore
    tintri.login(user_name, password)

except TintriServerError as tse:
    print_error(tse.__str__())
    sys.exit(-2)

try:
    vms = get_vms(tintri, page_size)

except TintriServerError as tse:
    print_error(tse.__str__())
    tintri.logout()
    sys.exit(-3)

print_info("Statistics collected")
tintri.logout()

# Define the statistic fields to display.  The fields can be changed
# without modifying the print code below.  See the API documentation
# for more statistic fields.
stat_fields = ['spaceUsedGiB', 'operationsTotalIops', 'latencyTotalMs']

# Create the table header with the fields
table_header = ["VM name"]
for field in stat_fields:
    table_header.append(field)
コード例 #9
0
def main():
    # Get the Ansible parameters.
    # Note: that some of the parameters names are the same as the e-mail configuration dictionary.
    module = AnsibleModule(argument_spec=dict(
        server=dict(required=True, type='str'),
        user=dict(required=True, type='str'),
        password=dict(required=True, type='str', no_log=True),
        toEmail=dict(required=False, type='str',
                     default='*****@*****.**'),
        smtpHost=dict(required=True, type='str'),
        emailNoticeLevel=dict(required=False,
                              choices=[
                                  'ALERTS_ONLY', 'ALERTS_AND_SOME_NOTICES',
                                  'ALERTS_AND_ALL_NOTICES'
                              ],
                              type='str'),
        fromEmail=dict(required=True, type='str'),
        smtpIsLoginRequired=dict(required=False, type='bool'),
        smtpConnection=dict(required=False,
                            choices=['NO_SECURE_CONNECTION', 'TLS', 'SSL'],
                            type='str',
                            default='NO_SECURE_CONNECTION'),
        smtpPort=dict(required=False, type='int', default=25),
        smtpSSLPort=dict(required=False, type='int'),
        username=dict(required=False, type='str'),
        email_password=dict(required=False, type='str', no_log=True)),
                           supports_check_mode=True)

    m_args = module.params
    param_skip = ['server', 'user', 'password']

    try:
        # Instantiate the Tintri VMStore.
        tintri = Tintri(m_args['server'])

        # Login to VMStore.
        tintri.login(m_args['user'], m_args['password'])

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())

    remove_dict_keys(m_args, param_skip)

    if m_args['email_password'] is not None:
        m_args['password'] = m_args.pop('email_password')

    try:
        update_email_config(tintri, m_args)

        email_conf = get_email_config(tintri)

    except TintriServerError as tse:
        module.fail_json(msg=tse.__str__())
        tintri.logout()

    # Log out VMSTore.
    tintri.logout()

    # Return the result to Ansible.
    results = obj_to_str(email_conf)
    module.exit_json(changed=True, meta=results)
コード例 #10
0
except TintriServerError as tse:
    print_error(tse.__str__())
    sys.exit(2)

try:
    # Create the report filter.
    report_filter = VirtualMachineDownloadableReportFilter()
    report_filter.attachment = csv_file_name
    report_filter.attributes = attributes
    report_filter.since = ""
    report_filter.until = ""
    report_filter.format = "CSV"

    # Invoke API to get a useable report URL.
    report_url = tgc.create_vm_list_report(report_filter)

    # Print the URL.
    print("URL: {" + report_url + "} is good for 30 days")

    # Get the report.
    tgc.download_file(report_url, csv_file_name)

    print(csv_file_name + " is ready")

except TintriServerError as tse:
    print_error(tse.__str__())

finally:
    tgc.logout()