Skip to content

Conversation

@skateman
Copy link
Member

@skateman skateman commented Oct 8, 2020

Similarly to the provider forms, the CloudVolume forms also have provider-specific fields that we're moving to params_for_create methods under the provider-specific subclasses. This change exposes these schemas through the OPTIONS endpoint. The only necessary param is the id of a StorageManager that will be selected from a dropdown defined in the common schema.

The current name of the param is ems_id but I'm open for better ideas. Also I'm not sure if all the storage manager subclasses follow the "#{provider.class}::CloudVolume" convention on which this PR heavily relies.

// OPTIONS /api/cloud_volumes?ems_id=XY
{
  // ...
  "form_schema": {
    fields: [
      // ...
    ]
  }  
}

Parent issue: ManageIQ/manageiq-ui-classic#7334

@miq-bot add_reviewer @agrare
@miq-bot add_label enhancement

@skateman
Copy link
Member Author

@agrare I have a feeling that this will only work for Amazon, because the OpenStack cloud volumes are subclassed differently. The goal here is to have an endpoint that is able to tell me the CloudVolume subclass for the given storage manager and call its params_for_create.

@miq-bot add_label question

@agrare
Copy link
Member

agrare commented Oct 14, 2020

@skateman we could do ems.cloud_volumes_klass

@skateman
Copy link
Member Author

@skateman we could do ems.cloud_volumes_klass

Perfect!

@skateman skateman changed the title Expose the DDF schema for CloudVolume subclasses via OPTIONS [WIP] Expose the DDF schema for CloudVolume subclasses via OPTIONS Oct 30, 2020
@miq-bot miq-bot added the wip label Oct 30, 2020
@skateman skateman changed the title [WIP] Expose the DDF schema for CloudVolume subclasses via OPTIONS Expose the DDF schema for CloudVolume subclasses via OPTIONS Dec 2, 2020
@miq-bot miq-bot removed the wip label Dec 2, 2020
@skateman
Copy link
Member Author

skateman commented Dec 4, 2020

@agrare are you okay with these changes? Can we get this merged?

@skateman skateman mentioned this pull request Dec 9, 2020
10 tasks
end

def options
return super unless params[:ems_id]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this imply the user has to pass in the ems_id? (Or do we know the ems_id based on the incoming endpoint?

That is, if a user does OPTIONS /api/cloud_volumes/123 I would expect under the covers we would look up the ems_id and not force the user to enter it into the query.

Copy link
Member Author

@skateman skateman Dec 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't really do OPTIONS /api/cloud_volumes/123 if you want to create the very first cloud volume 😕 this is for getting you the right DDF schema from the right provider...

klass = CloudVolume.class_by_ems(ext_management_system)

validate = klass.validate_create_volume(ext_management_system)
raise validate[:message] unless validate[:available]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agrare Is this specific to CloudVolume? Asking because if we have this pattern for checking things, then should be apply that to the other PRs, like this one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fryguy this is the older "AvailabilityMixin" style versus SupportsFeature

@abellotti
Copy link
Member

If possible, my preference here is to specify the type of the CloudVolume instead of the id of the hosting provider. This is for consistency with what we do with the OPTIONS on providers, i.e. do something like this:

OPTIONS /api/cloud_volumes?type=ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume

Also, with this PR, I'm getting a 500 when the provider specified does not have a ::CloudVolume. Getting the following:

{
  "error":  {
     "kind":"internal_server_error",
     "message":"uninitialized constant ManageIQ::Providers::Vmware::InfraManager::CloudVolume","klass":"NameError"
    }
}

Probably need to check the klass exists before using it.

      ems = ExtManagementSystem.find(params[:ems_id])
      klass = ems.class::CloudVolume

      raise BadRequestError, "No DDF specified for - #{klass}" unless klass.respond_to?(:params_for_create)

@chessbyte
Copy link
Member

@abellotti do we really want to expose type=ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume in our API? /cc @Fryguy @gtanzillo @agrare

@Fryguy
Copy link
Member

Fryguy commented Jan 13, 2021

Unfortunately, we've already exposed those types. It's not uncommon to query an endpoint for a particular type or sub-type.

@skateman
Copy link
Member Author

@abellotti we're asking with an ems_id and not a class because we don't really have access to it. The dropdown is being feeded with name and emd_id using loadOptions and an onChange picks up any change and fires the OPTIONS request. Theoretically we can cache the result of the loadOptions but it would be super hacky and definitely not The React Way™ of doing things. Also we're submitting the same ems_id with the form, so the dropdown can't just be altered to have both the class and the ems_id as its value...

@miq-bot
Copy link
Member

miq-bot commented Jan 14, 2021

Checked commits skateman/manageiq-api@8f64421~...9eb555e with ruby 2.6.3, rubocop 0.82.0, haml-lint 0.35.0, and yamllint
2 files checked, 1 offense detected

app/controllers/api/cloud_volumes_controller.rb

@abellotti
Copy link
Member

Thanks @skateman for looking into it and adding the check for the class existence. LGTM!! 👍

@gtanzillo gtanzillo merged commit 204cbb0 into ManageIQ:master Jan 14, 2021
@skateman skateman deleted the ddf-cloud-volume branch January 15, 2021 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants