HewlettPackard / oneview-ansible

This project is no longer being developed and has limited support. Please use the newer Ansible Collection project: https://github.com/HewlettPackard/oneview-ansible-collection
Apache License 2.0
104 stars 65 forks source link

Issue with filter on oneview_server_profile_facts #290

Closed njordr closed 7 years ago

njordr commented 7 years ago

Scenario/Intent

I want to filter a server profile list using uri instead of macType as in documentation

Environment Details

Steps to Reproduce

- name: "Get server profile"
      oneview_server_profile_facts:
        hostname: "{{ hpo_host }}"
        username: "{{ hpo_usename }}"
        password: "{{ hpo_password }}"
        api_version: "{{ hpo_api_version }}"
        params:
          filter: uri="{{ server_profile_uri }}"
      delegate_to: localhost

Expected Result

A server profile

Actual Result

"msg": "The specified filter is not valid ([uri=\"/rest/server-profiles/086f072a-e9f4-4a9b-add8-b534f45339e8\"

What am I doing wrong?

Thanks

njordr commented 7 years ago

This is the server profile retrieved using its name:

{
            "affinity": null,
            "associatedServer": null,
            "bios": {
                "manageBios": true,
                "overriddenSettings": [
                    {
                        "id": "IntelProcVtd",
                        "value": "Enabled"
                    },
                    {
                        "id": "ProcHyperthreading",
                        "value": "Enabled"
                    },
                    {
                        "id": "ProcVirtualization",
                        "value": "Enabled"
                    },
                    {
                        "id": "Sriov",
                        "value": "Disabled"
                    }
                ]
            },
            "boot": {
                "manageBoot": false,
                "order": []
            },
            "bootMode": {
                "manageMode": true,
                "mode": "UEFI",
                "pxeBootPolicy": "Auto"
            },
            "category": "server-profiles",
            "connections": [],
            "created": "20170928T091040.189Z",
            "description": "",
            "eTag": "1506590044030/16",
            "enclosureBay": null,
            "enclosureGroupUri": null,
            "enclosureUri": null,
            "firmware": {
                "firmwareBaselineUri": "/rest/firmware-drivers/871790_001_spp-2016_10_0-SPP2016100_2016_1015_191",
                "firmwareInstallType": "FirmwareOnlyOfflineMode",
                "forceInstallFirmware": false,
                "manageFirmware": true
            },
            "hideUnusedFlexNics": null,
            "inProgress": false,
            "iscsiInitiatorName": "iqn.2015-02.com.hpe:oneview-086f072a-e9f4-4a9b-add8-b534f45339e8",
            "iscsiInitiatorNameType": "AutoGenerated",
            "localStorage": {
                "controllers": [
                    {
                        "deviceSlot": "Embedded",
                        "importConfiguration": false,
                        "initialize": false,
                        "logicalDrives": [
                            {
                                "bootable": false,
                                "driveNumber": 1,
                                "driveTechnology": "SasHdd",
                                "name": "logical_drive_01",
                                "numPhysicalDrives": 8,
                                "raidLevel": "RAID6",
                                "sasLogicalJBODId": null
                            }
                        ],
                        "mode": "RAID"
                    }
                ],
                "sasLogicalJBODs": []
            },
            "macType": "Physical",
            "modified": "20170928T100218.580Z",
            "name": "XXXXXXXXXXX",
            "osDeploymentSettings": null,
            "sanStorage": {
                "manageSanStorage": false,
                "volumeAttachments": []
            },
            "serialNumber": "XXXXXXXXXXX",
            "serialNumberType": "Physical",
            "serverHardwareTypeUri": "/rest/server-hardware-types/3DDB47B3-2146-4833-955C-AB04B7DE405C",
            "serverHardwareUri": "/rest/server-hardware/32353537-3835-5A43-3336-34315739394B",
            "serverProfileTemplateUri": "/rest/server-profile-templates/be6a3e0f-f36d-482a-b8b8-5cee256539cd",
            "state": "Normal",
            "status": "OK",
            "taskUri": "/rest/tasks/2491DDDD-0338-4A59-82F2-60901625F8FB",
            "templateCompliance": "Compliant",
            "type": "ServerProfileV6",
            "uri": "/rest/server-profiles/086f072a-e9f4-4a9b-add8-b534f45339e8",
            "uuid": "32353537-3835-5A43-3336-34315739394B",
            "wwnType": "Physical"
        }
fgbulsoni commented 7 years ago

I'm not entirely sure why it does not work, but I did try it directly in the OV REST API and also got no results.

I did get results when using filter: uuid="32353537-3835-5A43-3336-34315739394B", which is basically the last part of the URI, but running 'uri=' always returned empty.

It might be that uri can't be used as a parameter for filter in OV, or that we have to convert special character such as '/', but I wasn't able to find that out easily.

Since I've seen this specific request for URI for SPs before, I've implemented an easy way to query it, like what we do with name, see PR #291 for details, but I do think the filter is meant to work, we're just probably missing something.

njordr commented 7 years ago

Also uuid doesn't work for me:

fatal: [xxxxxxxxx -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "The specified filter is not valid ([uuid=\"32353537-3835-5A43-3336-34315739394B\"]).; {u'errorSource': None, u'recommendedActions': [u'Verify parameters and try again.'], u'data': {}, u'errorCode': u'INVALID_FILTER', u'details': u'', u'message': u'The specified filter is not valid ([uuid=\"32353537-3835-5A43-3336-34315739394B\"]).', u'nestedErrors': []}"}

Working fine with your patch.

Thanks

njordr commented 7 years ago

Similar issue with server profile templates module. Attached the patched module

oneview_server_profile_template_facts.py.txt

fgbulsoni commented 7 years ago

Also uuid doesn't work for me:

How are you using the filter? I've just tried the following and it worked:

    - name: SP filtered by UUID
      oneview_server_profile_facts:
        config: "{{ config }}"
        params:
          filter: uuid='e23d9fa4-f926-4447-b971-90116ca3e61e'
      delegate_to: localhost

Output:

TASK [SP filtered by UUID] ***************************************************************************************************************************************************************************************
task path: /home/vagrant/dev/oneview-ansible/examples/oneview_server_profile_facts.yml:38
Using module file /home/vagrant/dev/oneview-ansible/library/oneview_server_profile_facts.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/vagrant/.ansible/tmp/ansible-tmp-1507123597.39-134068858394549 `" && echo ansible-tmp-1507123597.39-134068858394549="` echo /home/vagrant/.ansible/tmp/ansible-tmp-1507123597.39-134068858394549 `" ) && sleep 0'
<localhost> PUT /tmp/tmpzBLKAt TO /home/vagrant/.ansible/tmp/ansible-tmp-1507123597.39-134068858394549/oneview_server_profile_facts.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1507123597.39-134068858394549/ /home/vagrant/.ansible/tmp/ansible-tmp-1507123597.39-134068858394549/oneview_server_profile_facts.py && sleep 0'
<localhost> EXEC /bin/sh -c 'python2 /home/vagrant/.ansible/tmp/ansible-tmp-1507123597.39-134068858394549/oneview_server_profile_facts.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1507123597.39-134068858394549/" > /dev/null 2>&1 && sleep 0'
 [WARNING]: Module did not set no_log for password

ok: [localhost -> localhost] => {
    "ansible_facts": {
        "server_profiles": [
            {
                "affinity": "Bay",
                "associatedServer": null,
                "bios": {
                    "manageBios": false,
                    "overriddenSettings": []
                },
                "boot": {
                    "manageBoot": true,
                    "order": [
                        "CD",
                        "USB",
                        "HardDisk",
                        "PXE"
                    ]
                },
                "bootMode": {
                    "manageMode": true,
                    "mode": "BIOS",
                    "pxeBootPolicy": null
                },
                "category": "server-profiles",
                "connections": [],
                "created": "20170921T191931.609Z",
                "description": "",
                "eTag": "1506021573205/6",
                "enclosureBay": 5,
                "enclosureGroupUri": "/rest/enclosure-groups/b4347fac-1ba2-4110-887e-059f70dd5c19",
                "enclosureUri": "/rest/enclosures/0000000000A66102",
                "firmware": {
                    "firmwareActivationType": null,
                    "firmwareBaselineUri": null,
                    "firmwareInstallType": null,
                    "firmwareScheduleDateTime": null,
                    "forceInstallFirmware": false,
                    "manageFirmware": false
                },
                "hideUnusedFlexNics": true,
                "inProgress": false,
                "iscsiInitiatorName": "iqn.2015-02.com.hpe:oneview-vcgem5f00w",
                "iscsiInitiatorNameType": "AutoGenerated",
                "localStorage": {
                    "controllers": [],
                    "sasLogicalJBODs": []
                },
                "macType": "Virtual",
                "modified": "20170921T192003.175Z",
                "name": "SP2",
                "osDeploymentSettings": null,
                "refreshState": "NotRefreshing",
                "sanStorage": {
                    "manageSanStorage": false,
                    "sanSystemCredentials": [],
                    "volumeAttachments": []
                },
                "serialNumber": "VCGEM5F00W",
                "serialNumberType": "Virtual",
                "serverHardwareTypeUri": "/rest/server-hardware-types/DC1A8042-B5CA-4496-93D3-D4AAEF2EC4A1",
                "serverHardwareUri": "/rest/server-hardware/30303437-3034-4D32-3230-313132344752",
                "serverProfileTemplateUri": "/rest/server-profile-templates/c0868397-eff6-49ed-8151-4338702792d3",
                "state": "Normal",
                "status": "OK",
                "taskUri": "/rest/tasks/E2BC435B-ED34-4B4B-B51D-8B46D2F84B64",
                "templateCompliance": "Compliant",
                "type": "ServerProfileV7",
                "uri": "/rest/server-profiles/e23d9fa4-f926-4447-b971-90116ca3e61e",
                "uuid": "e23d9fa4-f926-4447-b971-90116ca3e61e",
                "wwnType": "Virtual"
            }
        ]
    },
    "changed": false,
    "failed": false,
    "invocation": {
        "module_args": {
            "api_version": null,
            "config": "/home/vagrant/dev/oneview-ansible/examples/oneview_config.json",
            "hostname": null,
            "image_streamer_hostname": null,
            "name": null,
            "options": null,
            "params": {
                "filter": "uuid='e23d9fa4-f926-4447-b971-90116ca3e61e'"
            },
            "password": null,
            "uri": null,
            "username": null
        }
    }
}
njordr commented 7 years ago

Yes, I used it in the filter, no luck for me

fgbulsoni commented 7 years ago

Are you using double quotes or single quotes on your string?

Double quotes will fail, since the API expects the 'value' to be wrapped in single quotes:

filter: uuid="e23d9fa4-f926-4447-b971-90116ca3e61e"

fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "The specified filter is not valid ([uuid=\"e23d9fa4-f926-4447-b971-90116ca3e61e\"]).; {u'errorSource': None, u'recommendedActions': [u'Verify parameters and try again.'], u'data': {}, u'errorCode': u'INVALID_FILTER', u'details': u'', u'message': u'The specified filter is not valid ([uuid=\"e23d9fa4-f926-4447-b971-90116ca3e61e\"]).', u'nestedErrors': []}"}

This succeeds:

filter: uuid='e23d9fa4-f926-4447-b971-90116ca3e61e'

ok: [localhost -> localhost]
njordr commented 7 years ago

double quotes :(

now it works also for me

fgbulsoni commented 7 years ago

double quotes :(

now it works also for me

Awesome :octocat:

Similar issue with server profile templates module. Attached the patched module

oneview_server_profile_template_facts.py.txt

May I ask that you create a PR for that?

By the way, might I ask what is the use case here for using URIs instead of name or other attributes on these queries? Do you have those URIs saved up somewhere?

njordr commented 7 years ago

I have the URI from a set of queries in ansible playbook. What we need is to know which server profile template is applied to a server, so I do the following:

I'll create the PR, probably tomorrow :)

Thanks for your help

fgbulsoni commented 7 years ago

query server_hardware_facts and get the server profile uri query server_profile_facts and get the server profile template uri query the server_profile_template and get the name compare the name with another variable and act accordingly

Awesome, thanks for clarifying.

I'll create the PR, probably tomorrow :)

No need, I've added a couple extra changes into the open PR together with the SPT acceptance of the uri field, that will be available in master once that PR is merged.

Let me know if you run into other issues :octocat:

njordr commented 7 years ago

Cool, thanks