manageiq-api icon indicating copy to clipboard operation
manageiq-api copied to clipboard

[WIP] API for VM Infra Reconfigure field form

Open jaisejose1123 opened this issue 3 months ago • 13 comments

Related PR https://github.com/ManageIQ/manageiq/pull/22980

API for VM Infra Reconfigure field form

Before - /vm_infra/reconfigure_form_fields/new,2983,4671 image

After Get request for multiple ids GET /api/vm_infras/4671,2983

{
    "objectIds": [
        4671,
        4672
    ],
    "memory": "8",
    "memory_type": "GB",
    "socket_count": "2",
    "cores_per_socket_count": "1",
    "disks": [
        {
            "hdFilename": "7a0eaa34-df13-401f-b01a-1d19bb82329f",
            "hdType": "thin",
            "hdMode": "persistent",
            "hdSize": "40",
            "hdUnit": "GB",
            "add_remove": "",
            "cb_bootable": true,
            "vm": [
                {
                    "href": "http://localhost:3000/api/vm_infras/4671",
                    "id": "4671",
                    "vendor": "redhat",
                    "format": null,
                    "version": null,
                    "name": "2_vcr_liberty_keystone_v3",
                    "description": null,
                    "location": "20a02fe8-9586-4b01-b153-175b0257d1de.ovf",
                    "config_xml": null,
                    "autostart": null,
                    "host_id": null,
                    "last_sync_on": null,
                    "created_on": "2019-04-30T14:07:45Z",
                    "updated_on": "2020-01-14T15:11:22Z",
                    "storage_id": "29",
                    "guid": "8796fa1e-67bd-474c-b730-884f1cf7069a",
                    "ems_id": "56",
                    "last_scan_on": null,
                    "last_scan_attempt_on": null,
                    "uid_ems": "20a02fe8-9586-4b01-b153-175b0257d1de",
                    "retires_on": null,
                    "retired": null,
                    "boot_time": "2018-10-05T12:39:57Z",
                    "tools_status": null,
                    "standby_action": null,
                    "power_state": "off",
                    "state_changed_on": "2020-01-14T15:11:22Z",
                    "previous_state": "up",
                    "connection_state": "connected",
                    "last_perf_capture_on": null,
                    "registered": null,
                    "busy": null,
                    "smart": null,
                    "memory_reserve": 8192,
                    "memory_reserve_expand": null,
                    "memory_limit": 32768,
                    "memory_shares": null,
                    "memory_shares_level": null,
                    "cpu_reserve": null,
                    "cpu_reserve_expand": null,
                    "cpu_limit": null,
                    "cpu_shares": null,
                    "cpu_shares_level": null,
                    "cpu_affinity": null,
                    "ems_created_on": null,
                    "template": false,
                    "evm_owner_id": null,
                    "miq_group_id": "1",
                    "linked_clone": null,
                    "fault_tolerance": null,
                    "type": "ManageIQ::Providers::Redhat::InfraManager::Vm",
                    "ems_ref": "/api/vms/20a02fe8-9586-4b01-b153-175b0257d1de",
                    "ems_cluster_id": "10",
                    "retirement_warn": null,
                    "retirement_last_warn": null,
                    "vnc_port": null,
                    "flavor_id": null,
                    "availability_zone_id": null,
                    "cloud": false,
                    "retirement_state": null,
                    "cloud_network_id": null,
                    "cloud_subnet_id": null,
                    "cloud_tenant_id": null,
                    "raw_power_state": "down",
                    "publicly_available": null,
                    "orchestration_stack_id": null,
                    "retirement_requester": null,
                    "tenant_id": "1",
                    "resource_group_id": null,
                    "deprecated": null,
                    "storage_profile_id": null,
                    "cpu_hot_add_enabled": null,
                    "cpu_hot_remove_enabled": null,
                    "memory_hot_add_enabled": null,
                    "memory_hot_add_limit": null,
                    "memory_hot_add_increment": null,
                    "hostname": null,
                    "ems_ref_type": null,
                    "restart_needed": false,
                    "ancestry": "4678/4672",
                    "placement_group_id": null
                },
                {
                    "href": "http://localhost:3000/api/vm_infras/4672",
                    "id": "4672",
                    "vendor": "redhat",
                    "format": null,
                    "version": null,
                    "name": "3_vcr_kilo",
                    "description": null,
                    "location": "7404871d-ef18-4aee-86a4-6c9e1807867b.ovf",
                    "config_xml": null,
                    "autostart": null,
                    "host_id": null,
                    "last_sync_on": null,
                    "created_on": "2019-04-30T14:07:45Z",
                    "updated_on": "2020-01-14T15:11:22Z",
                    "storage_id": "29",
                    "guid": "8dfe73ad-8e67-4292-aeb1-840a4cb8a521",
                    "ems_id": "56",
                    "last_scan_on": null,
                    "last_scan_attempt_on": null,
                    "uid_ems": "7404871d-ef18-4aee-86a4-6c9e1807867b",
                    "retires_on": null,
                    "retired": null,
                    "boot_time": "2018-10-05T12:39:54Z",
                    "tools_status": null,
                    "standby_action": null,
                    "power_state": "off",
                    "state_changed_on": "2020-01-14T15:11:22Z",
                    "previous_state": "up",
                    "connection_state": "connected",
                    "last_perf_capture_on": null,
                    "registered": null,
                    "busy": null,
                    "smart": null,
                    "memory_reserve": 8192,
                    "memory_reserve_expand": null,
                    "memory_limit": 32768,
                    "memory_shares": null,
                    "memory_shares_level": null,
                    "cpu_reserve": null,
                    "cpu_reserve_expand": null,
                    "cpu_limit": null,
                    "cpu_shares": null,
                    "cpu_shares_level": null,
                    "cpu_affinity": null,
                    "ems_created_on": null,
                    "template": false,
                    "evm_owner_id": null,
                    "miq_group_id": "1",
                    "linked_clone": null,
                    "fault_tolerance": null,
                    "type": "ManageIQ::Providers::Redhat::InfraManager::Vm",
                    "ems_ref": "/api/vms/7404871d-ef18-4aee-86a4-6c9e1807867b",
                    "ems_cluster_id": "10",
                    "retirement_warn": null,
                    "retirement_last_warn": null,
                    "vnc_port": null,
                    "flavor_id": null,
                    "availability_zone_id": null,
                    "cloud": false,
                    "retirement_state": null,
                    "cloud_network_id": null,
                    "cloud_subnet_id": null,
                    "cloud_tenant_id": null,
                    "raw_power_state": "down",
                    "publicly_available": null,
                    "orchestration_stack_id": null,
                    "retirement_requester": null,
                    "tenant_id": "1",
                    "resource_group_id": null,
                    "deprecated": null,
                    "storage_profile_id": null,
                    "cpu_hot_add_enabled": null,
                    "cpu_hot_remove_enabled": null,
                    "memory_hot_add_enabled": null,
                    "memory_hot_add_limit": null,
                    "memory_hot_add_increment": null,
                    "hostname": null,
                    "ems_ref_type": null,
                    "restart_needed": false,
                    "ancestry": "4678",
                    "placement_group_id": null
                }
            ]
        }
    ],
    "network_adapters": [],
    "cdroms": [],
    "vm_vendor": "redhat",
    "vm_type": "ManageIQ::Providers::Redhat::InfraManager::Vm",
    "orchestration_stack_id": null,
    "disk_default_type": "thin",
    "cb_memory": false,
    "cb_cpu": false
}

Get request for single id GET /api/vm_infras/4671

{
    "objectIds": [
        4671
    ],
    "memory": "8",
    "memory_type": "GB",
    "socket_count": "2",
    "cores_per_socket_count": "1",
    "disks": [
        {
            "hdFilename": "7a0eaa34-df13-401f-b01a-1d19bb82329f",
            "hdType": "thin",
            "hdMode": "persistent",
            "hdSize": "40",
            "hdUnit": "GB",
            "add_remove": "",
            "cb_bootable": true,
            "vm": [
                {
                    "href": "http://localhost:3000/api/vm_infras/4671",
                    "id": "4671",
                    "vendor": "redhat",
                    "format": null,
                    "version": null,
                    "name": "2_vcr_liberty_keystone_v3",
                    "description": null,
                    "location": "20a02fe8-9586-4b01-b153-175b0257d1de.ovf",
                    "config_xml": null,
                    "autostart": null,
                    "host_id": null,
                    "last_sync_on": null,
                    "created_on": "2019-04-30T14:07:45Z",
                    "updated_on": "2020-01-14T15:11:22Z",
                    "storage_id": "29",
                    "guid": "8796fa1e-67bd-474c-b730-884f1cf7069a",
                    "ems_id": "56",
                    "last_scan_on": null,
                    "last_scan_attempt_on": null,
                    "uid_ems": "20a02fe8-9586-4b01-b153-175b0257d1de",
                    "retires_on": null,
                    "retired": null,
                    "boot_time": "2018-10-05T12:39:57Z",
                    "tools_status": null,
                    "standby_action": null,
                    "power_state": "off",
                    "state_changed_on": "2020-01-14T15:11:22Z",
                    "previous_state": "up",
                    "connection_state": "connected",
                    "last_perf_capture_on": null,
                    "registered": null,
                    "busy": null,
                    "smart": null,
                    "memory_reserve": 8192,
                    "memory_reserve_expand": null,
                    "memory_limit": 32768,
                    "memory_shares": null,
                    "memory_shares_level": null,
                    "cpu_reserve": null,
                    "cpu_reserve_expand": null,
                    "cpu_limit": null,
                    "cpu_shares": null,
                    "cpu_shares_level": null,
                    "cpu_affinity": null,
                    "ems_created_on": null,
                    "template": false,
                    "evm_owner_id": null,
                    "miq_group_id": "1",
                    "linked_clone": null,
                    "fault_tolerance": null,
                    "type": "ManageIQ::Providers::Redhat::InfraManager::Vm",
                    "ems_ref": "/api/vms/20a02fe8-9586-4b01-b153-175b0257d1de",
                    "ems_cluster_id": "10",
                    "retirement_warn": null,
                    "retirement_last_warn": null,
                    "vnc_port": null,
                    "flavor_id": null,
                    "availability_zone_id": null,
                    "cloud": false,
                    "retirement_state": null,
                    "cloud_network_id": null,
                    "cloud_subnet_id": null,
                    "cloud_tenant_id": null,
                    "raw_power_state": "down",
                    "publicly_available": null,
                    "orchestration_stack_id": null,
                    "retirement_requester": null,
                    "tenant_id": "1",
                    "resource_group_id": null,
                    "deprecated": null,
                    "storage_profile_id": null,
                    "cpu_hot_add_enabled": null,
                    "cpu_hot_remove_enabled": null,
                    "memory_hot_add_enabled": null,
                    "memory_hot_add_limit": null,
                    "memory_hot_add_increment": null,
                    "hostname": null,
                    "ems_ref_type": null,
                    "restart_needed": false,
                    "ancestry": "4678/4672",
                    "placement_group_id": null
                }
            ]
        }
    ],
    "network_adapters": [
        {
            "name": "nic1",
            "vlan": "ovirtmgmt",
            "mac": "00:1a:4a:fc:68:0e",
            "add_remove": ""
        }
    ],
    "cdroms": [],
    "vm_vendor": "redhat",
    "vm_type": "ManageIQ::Providers::Redhat::InfraManager::Vm",
    "orchestration_stack_id": null,
    "disk_default_type": "thin",
    "cb_memory": false,
    "cb_cpu": false
}

Todo: API response

jaisejose1123 avatar Mar 25 '24 11:03 jaisejose1123

(out of band) update:

Going to move these to vms_controller.rb#reconfigure

kbrock avatar Mar 26 '24 21:03 kbrock

suggestion: (was out of band)

putting here so it doesn't get lost

    # @param type Vm
    def reconfigure_resource(type, id, data = nil)
      api_resource(type, id, "Reconfigure") do |vm|
        options = {}
        if data[:disk_add]
          ensure_supports(type, vm, :reconfigure_disk)

        end

        request = VmReconfigureRequest.make_request(@request_id, options, current_user)
        {}
      end
    end

kbrock avatar Mar 26 '24 21:03 kbrock

@jaisejose1123 could you push a more recent version of this? I'm curious where it currently stands

I marked as wip. please remove the WIP when you are ready for review. (or ping me and I can remove the WIP)

kbrock avatar Apr 18 '24 19:04 kbrock

Implemented VM infrastructures inside the VM controller.

jaisejose1123 avatar Apr 19 '24 10:04 jaisejose1123

Implemented VM infrastructures inside the VM controller.

Api screen short for multiple id's image Backend result while calling this above api image

Api screen short for multiple id's image Backend result while calling this above api image

jaisejose1123 avatar Apr 19 '24 10:04 jaisejose1123

When calling a single ID instead of multiple IDs, it should provide additional data. Consequently, we implemented APIs with different actions.

The below image will show the result while calling single id in manager-ui-classic image

but while calling multiple id's it shows only limited data image

jaisejose1123 avatar Apr 19 '24 10:04 jaisejose1123

Checked commit https://github.com/jaisejose1123/manageiq-api/commit/7cb123bc9fb3529b4bd7e760c32a555a1cc389a2 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint 3 files checked, 40 offenses detected

app/controllers/api/base_controller/generic.rb

app/controllers/api/vms_controller.rb

spec/requests/authentications_spec.rb

miq-bot avatar Apr 19 '24 11:04 miq-bot

I assume at some point this will create a VmReconfigureRequest right?

agrare avatar Apr 22 '24 14:04 agrare

Hey @jaisejose1123 ,

I had a short discussion with @kbrock and below is the outcome.

  • Explained the conversion of http.get and use API.get
  • Discussed about the method in reconfigure.rb/def get_reconfig_info
  • talked about attibutes=supports_reconfigure_cdrome/network_Adapters
  • @kbrock to talk with @Fryguy about the supports column.
  • @jeffibm to checkout this branch and get the new response, reformat the response similar to the output from get_reconfig_info method.

@jaisejose1123 , could you please update the PR.

jeffibm avatar Apr 23 '24 15:04 jeffibm

By utilizing the following GET API, we can gather the VM resources for the reconfigure field form for single id Api http://localhost:3000/api/vms/4671?attributes=name,num_cpu,cpu_cores_per_socket,mem_cpu,vendor,type,host.name,hardware.guest_devices,lans,hardware.disks,hardware.cdroms

Response image

by this we can collect all the related information like lans,disks,network_adapters,hardware etc...

jaisejose1123 avatar Apr 24 '24 08:04 jaisejose1123

For multiple IDs, we can retrieve the data using bulk querying

post Apihttp://localhost:3000/api/vms?attributes=name,num_cpu,cpu_cores_per_socket,mem_cpu,vendor,type,host.name,hardware.guest_devices,lans,hardware.disks,hardware.cdroms

by passing json { "action" : "query", "resources" : [ { "id" : 2983 }, { "id" : 4671 } ] }

image

Response includes all the related information like lans,disks,network_adapters,hardware etc... image

jaisejose1123 avatar Apr 24 '24 11:04 jaisejose1123

Most of this data should be retrieved using the standard GET api. Much of the data has a little manipulation but is pretty standard https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/controllers/mixins/actions/vm_actions/reconfigure.rb#L233

We do run into problems when accessing vm.supports?(:reconfigure_network_adapters). It looks like some of this has been

kbrock avatar Apr 24 '24 14:04 kbrock

http://localhost:3000/api/vms?expand=resources&attributes=name,num_cpu,cpu_cores_per_socket,mem_cpu,vendor,type,host.name,hardware.guest_devices,lans,hardware.disks,hardware.cdroms&filter[]=id=[2983,4671]

Updated the multiple id's api to Get request

Resopnse image

jaisejose1123 avatar Apr 24 '24 14:04 jaisejose1123