Beispiel #1
0
def test_payload():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleModule(resources["vcenter_vm"], definitions)
    assert module.payload() == {}
    module = rm.AnsibleInfoModule(resources["vcenter_vm"], definitions)
    assert module.payload() == {
        "get": {
            "body": {},
            "path": {
                "vm": "vm"
            },
            "query": {}
        },
        "list": {
            "body": {},
            "path": {},
            "query": {
                "filter.vms": "filter.vms"
            }
        },
    }
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data_with_param_in_path)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleInfoModule(
        resources["vcenter_vmtemplate_libraryitems_checkouts"], definitions)
    assert module.payload() == {}
Beispiel #2
0
def test_AnsibleInfoModule_parameters():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleInfoModule(resources["vcenter_vm"], definitions)
    assert module.name == "vcenter_vm_info"
    assert module.parameters() == [
        {
            "_loc_in_payload": "filter.vms",
            "_required_with_operations": [],
            "description": "desc of multi",
            "elements": "string",
            "in": "query",
            "name": "filter.vms",
            "operationIds": ["list"],
            "required": None,
            "type": "array",
        },
        {
            "_loc_in_payload": "vm",
            "_required_with_operations": ["get"],
            "description": "Id of the VM Required with I(state=['get'])",
            "in": "path",
            "name": "vm",
            "operationIds": ["get"],
            "type": "string",
        },
    ]
Beispiel #3
0
def test_filter_out_trusted_module():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleModuleBase(resources["vcenter_vm"], definitions)
    assert module.is_trusted()
    module.name = "something_we_dont_trust"
    assert not module.is_trusted()
Beispiel #4
0
def test_AnsibleModule_parameters():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleModule(resources["vcenter_vm"], definitions)
    assert module.name == "vcenter_vm"
    assert module.parameters() == [{
        "enum": [],
        "name": "state",
        "type": "str"
    }]
Beispiel #5
0
def test_AnsibleModule_parameters_complex():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data_with_param_in_path)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleModule(
        resources["vcenter_vmtemplate_libraryitems_checkouts"], definitions)
    assert module.name == "vcenter_vmtemplate_libraryitems_checkouts"
    assert module.parameters() == [
        {
            "_loc_in_payload": "action",
            "_required_with_operations": ["check_in", "check_out"],
            "description": "action=check-out This parameter is mandatory.",
            "enum": ["check-in", "check-out"],
            "in": "query",
            "name": "action",
            "operationIds": ["check_in", "check_out"],
            "required": True,
            "type": "string",
        },
        {
            "_loc_in_payload":
            "spec/message",
            "_required_with_operations": ["check_in"],
            "description":
            "Message describing the changes made to the virtual machine. "
            "Required with I(state=['check_in'])",
            "in":
            None,
            "name":
            "message",
            "operationIds": ["check_in"],
            "type":
            "string",
        },
        {
            "_loc_in_payload":
            "spec/name",
            "_required_with_operations": [],
            "description":
            "Name of the virtual machine to check out of the library "
            "item.",
            "in":
            None,
            "name":
            "name",
            "operationIds": ["check_out"],
            "required":
            False,
            "type":
            "string",
        },
        {
            "_loc_in_payload": "spec/placement",
            "_required_with_operations": [],
            "description":
            "Information used to place the checked out virtual machine.",
            "elements": "dict",
            "in": None,
            "name": "placement",
            "operationIds": ["check_out"],
            "required": False,
            "subkeys": {
                "cluster": {
                    "_operationIds": ["check_out", "check_out"],
                    "_required_with_operations": [],
                    "description":
                    "Cluster onto which the virtual machine should "
                    "be placed. If {@name #cluster} and {@name "
                    "#resourcePool} are both specified, {@name "
                    "#resourcePool} must belong to {@name #cluster}. "
                    "If {@name #cluster} and {@name #host} are both "
                    "specified, {@name #host} must be a member of "
                    "{@name #cluster}.",
                    "name":
                    "cluster",
                    "type":
                    "string",
                },
                "folder": {
                    "_operationIds": ["check_out", "check_out"],
                    "_required_with_operations": [],
                    "description":
                    "Virtual machine folder into which the virtual "
                    "machine should be placed.",
                    "name":
                    "folder",
                    "type":
                    "string",
                },
                "host": {
                    "_operationIds": ["check_out", "check_out"],
                    "_required_with_operations": [],
                    "description":
                    "Host onto which the virtual machine should be "
                    "placed. If {@name #host} and {@name "
                    "#resourcePool} are both specified, {@name "
                    "#resourcePool} must belong to {@name #host}. If "
                    "{@name #host} and {@name #cluster} are both "
                    "specified, {@name #host} must be a member of "
                    "{@name #cluster}.",
                    "name":
                    "host",
                    "type":
                    "string",
                },
                "resource_pool": {
                    "_operationIds": ["check_out", "check_out"],
                    "_required_with_operations": [],
                    "description":
                    "Resource pool into which the virtual machine "
                    "should be placed.",
                    "name": "resource_pool",
                    "type": "string",
                },
            },
            "type": "object",
        },
        {
            "_loc_in_payload":
            "spec/powered_on",
            "_required_with_operations": [],
            "description":
            "Specifies whether the virtual machine should be powered on "
            "after check out.",
            "in":
            None,
            "name":
            "powered_on",
            "operationIds": ["check_out"],
            "required":
            False,
            "type":
            "boolean",
        },
        {
            "enum": ["check_in", "check_out"],
            "name": "state",
            "type": "str",
            "required": True,
        },
        {
            "_loc_in_payload":
            "template_library_item",
            "_required_with_operations": ["check_in", "check_out"],
            "description":
            "Identifier of the content library item containing the source "
            "virtual machine template to be checked out. This parameter is mandatory.",
            "in":
            "path",
            "name":
            "template_library_item",
            "operationIds": ["check_in", "check_out"],
            "required":
            True,
            "type":
            "string",
        },
        {
            "_loc_in_payload":
            "vm",
            "_required_with_operations": ["check_in"],
            "description":
            "Identifier of the virtual machine to check into the library "
            "item. Required with I(state=['check_in'])",
            "in":
            "path",
            "name":
            "vm",
            "operationIds": ["check_in"],
            "type":
            "string",
        },
    ]
Beispiel #6
0
def test_AnsibleModuleBase():
    paths = rm.SwaggerFile.load_paths(my_raw_paths_data)
    resources = rm.SwaggerFile.init_resources(paths.values())
    definitions = rm.Definitions(my_definitions)
    module = rm.AnsibleModuleBase(resources["vcenter_vm"], definitions)
    assert module.name == "vcenter_vm"