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 CreateSession(user, passw, TGC):
    session = Tintri(TGC)
    session.login(user, passw)
    if session.is_logged_in():
        return session
    else:
        return False
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)
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)
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)
示例#6
0
def get_session(server):
    '''
    Get authenticated Tintri Session for the given server

    Requires:
        ConnectionInfo object with name 'Tintri VMstore for Environment X'
        Otherwise return None

    Args:
        server (obj): CB server object

    Returns:
        tintri: Tintri object
    '''
    conn = get_ci(server)
    if not conn:
        return None
    # instantiate the Tintri server.
    tintri = Tintri(conn['ip'])
    # Login to VMstore
    tintri.login(conn['username'], conn['password'])
    return tintri
示例#7
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)
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)
示例#9
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)
示例#10
0
    print("")
    sys.exit(2)

# Get the input parameters
server = sys.argv[1]
operation = sys.argv[2]

# Assume the user name is admin for reboot or shutdown.
user_name = "admin"

# Read the password
password = getpass.getpass("Enter " + user_name + " password: "******"Tintri server needs to be VMstore, not " + product_name)

    version = version_info.preferredVersion
    print("API Version: " + version)

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

    # Validate and execute the operations.
示例#11
0
if (len(sys.argv) == 6):
    consistency_type = sys.argv[5]
else:
    consistency_type = "crash"

try:
    # Confirm the consistency type.
    if (consistency_type == "crash"):
        consistency_type = "CRASH_CONSISTENT"
    elif (consistency_type == "vm"):
        consistency_type = "VM_CONSISTENT"
    else:
        raise tintri.TintriServerError(0, cause="consistency_type is not 'crash' or 'vm': " + consistency_type)

    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Get version and product
    version_info = tintri.version
    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:
    # Create query filter to get the VM specified by the VM name.
示例#12
0
          " server_name user_name password vm_name clone_name [num_clones]\n")
    sys.exit(-1)

server_name = sys.argv[1]
user_name = sys.argv[2]
password = sys.argv[3]
vm_name = sys.argv[4]
clone_name = sys.argv[5]
if (len(sys.argv) == 7):
    num_clones = sys.argv[6]
else:
    num_clones = 1

try:
    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Get version and product
    version_info = tintri.version
    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:
    # Create query filter to get the VM specified by the VM name.
示例#13
0

# main
if len(sys.argv) < 4:
    print("\nPrints server information\n")
    print("Usage: " + sys.argv[0] + " server_name user_name password\n")
    sys.exit(-1)

server_name = sys.argv[1]
user_name = sys.argv[2]
password = sys.argv[3]

# Get the product name
try:
    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Get version and product
    version_info = tintri.version
    product_name = version_info.productName

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

except TintriServerError as tse:
    print_error(tse.__str__())
    sys.exit(2)
    
try:
    # Get appliance info
    appliance_info = tintri.get_appliance_info("default")
示例#14
0
    return


# main
if len(sys.argv) < 4:
    print("\nDelete the oldest user generated snapshot.\n")
    print("Usage: " + sys.argv[0] + " server_name user_name password\n")
    sys.exit(-1)

server_name = sys.argv[1]
user_name = sys.argv[2]
password = sys.argv[3]

try:
    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Get version and product
    version_info = tintri.version
    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:
    # Create filter to get the oldest user generated snapshot
示例#15
0
print("Fields to report:\n" + str(attributes))

# Credentials Gathering - support Python 2.X and 3.X
print("")
try:
    user_name = raw_input("Enter user name: ")
except NameError:
    user_name = input("Enter user name: ")
password = getpass.getpass("Enter password: "******"")

# Try to login into the TGC.
try:
    # instantiate the Tintri server.
    tgc = Tintri(server_name)

    # Get version and product
    version_info = tgc.version
    product = version_info.productName
    if product != "Tintri Global Center":
        raise TintriServerError(0, cause="Server needs to be a TGC")

    print_info("API Version: " + version_info.preferredVersion)

    # Login to Tintri server
    tgc.login(user_name, password)

except TintriServerError as tse:
    print_error(tse.__str__())
    sys.exit(2)
示例#16
0
    print("          password  - the password for user_name")
    print("          alert_id  - optional: only for this alert ID")
    print("")
    sys.exit(-1)

server_name = sys.argv[1]
user_name = sys.argv[2]
password = sys.argv[3]
try:
    alert_id = sys.argv[4]
except IndexError:
    alert_id = None

try:
    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Get version and product
    version_info = tintri.version
    product_name = version_info.productName
    if not tintri.is_vmstore():
        raise TintriServerError(0, -1, "Tintri server needs to be VMstore, not " + product_name)

    preferredVersion = version_info.preferredVersion
    print("API Version: " + preferredVersion)

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

except TintriServerError as tse:
    print_error(tse.__str__())
示例#17
0
    return


# main
if len(sys.argv) < 4:
    print("\nPrints server information\n")
    print("Usage: " + sys.argv[0] + " server_name user_name password\n")
    sys.exit(1)

server_name = sys.argv[1]
user_name = sys.argv[2]
password = sys.argv[3]

try:
    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Get version and product
    version_info = tintri.version
    product_name = version_info.productName

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

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

try:
    print("\nLoading transporter buffers\n")
示例#18
0
    return


# main
if len(sys.argv) < 4:
    print("\nPrints VMstore information.\n")
    print("Usage: " + sys.argv[0] + " server_name user_name password\n")
    sys.exit(1)

server_name = sys.argv[1]
user_name = sys.argv[2]
password = sys.argv[3]

try:
    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Get version and product
    version_info = tintri.version
    if (not tintri.is_tgc()):
        raise TintriServerError(
            0,
            cause="Tintri server needs to be Tintri Global Center, not a " +
            product_name)

    preferred_version = version_info.preferredVersion
    print("API Version: " + preferred_version)

except TintriServerError as tse:
    print_error(tse.__str__())
    sys.exit(2)
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)
示例#20
0
    print(
        "\nSets the first 2 VMs QoS values to the specified values, and then returns to the original values.\n"
    )
    print("Usage: " + sys.argv[0] +
          " server_name user_name password min_value, max_value\n")
    sys.exit(-1)

server_name = sys.argv[1]
user_name = sys.argv[2]
password = sys.argv[3]
new_min_value = sys.argv[4]
new_max_value = sys.argv[5]

try:
    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Get version and product
    version_info = tintri.version
    product_name = version_info.productName
    if (not tintri.is_vmstore()):
        raise TintriServerError(
            0, -1, "Tintri server needs to be VMstore, not " + product_name)

    preferredVersion = version_info.preferredVersion
    print("API Version: " + preferredVersion)

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

except TintriServerError as tse:
示例#21
0
    print("    If [VM name] is specified, it is used a filter")
    sys.exit(1)

server_name = sys.argv[1]
user_name = sys.argv[2]
password = sys.argv[3]

if len(sys.argv) == 5:
    vm_name_in = sys.argv[4]
else:
    vm_name_in = None

page_size = 50

# instantiate the Tintri server.
tintri = Tintri(server_name)

# Get version and product
version_info = tintri.version
product = version_info.productName
print("Product: " + product + " (" + version_info.preferredVersion + ")")
print ""

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

    vm_filter_spec = VirtualMachineFilterSpec()
    vm_filter_spec.limit = page_size

    # Get VMs with page size filter.
示例#22
0
# main
if len(sys.argv) < 4:
    print("\nCollect VM stats")
    print("Usage: " + sys.argv[0] + " server_name user_name password")
    sys.exit(-1)

server_name = sys.argv[1]
user_name = sys.argv[2]
password = sys.argv[3]

# Put it here so that it could be made an input parameter if desired.
page_size = 100

try:
    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Get version and product
    version_info = tintri.version
    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)
示例#23
0
    print("    server_name - name of a TGC server")
    print("    user_name   - user name used to login into the TGC server")
    print("    password    - password for the TGC and VMstore users")
    print("    min_value   - the QoS minimum value for the VM")
    print("    max_value   - the QoS maximum value for the VM")
    sys.exit(-1)

server_name = sys.argv[1]
user_name = sys.argv[2]
password = sys.argv[3]
new_min_value = sys.argv[4]
new_max_value = sys.argv[5]

try:
    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Get version and product
    version_info = tintri.version
    if (not tintri.is_tgc()):
        raise TintriServerError(
            0,
            cause="Tintri server needs to be Tintri Global Center, not a " +
            product_name)

    preferred_version = version_info.preferredVersion
    print("API Version: " + preferred_version)

    versions = preferred_version.split(".")
    major_version = versions[0]
    minor_version = int(versions[1])