Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VMs/Snapshots API CRD #13552

Merged
merged 5 commits into from
Jan 27, 2017
Merged

VMs/Snapshots API CRD #13552

merged 5 commits into from
Jan 27, 2017

Conversation

imtayadeway
Copy link
Contributor

@imtayadeway imtayadeway commented Jan 18, 2017

Here's a naive implementation of the Snapshots API, which I'm submitting for early feedback.

@abellotti I'll work on making the implementation more nuanced (i.e. error handling, etc...), but would you like to go over the high-level design together?

Adds CRD actions for snapshots of VMs

Addresses https://bugzilla.redhat.com/show_bug.cgi?id=1399526

@miq-bot add-label api, wip
@miq-bot assign @abellotti

Examples

index

GET http://localhost:3000/api/vms/1000000002002/snapshots
Authorization: Basic YWRtaW46c21hcnR2bQ==
{
  "actions": [
    {
      "href": "http://localhost:3000/api/vms/1000000002002/snapshots",
      "method": "post",
      "name": "create"
    }
  ],
  "resources": [
    {
      "href": "http://localhost:3000/api/vms/1000000002002/snapshots/1000000005471"
    }
  ],
  "subcount": 1,
  "count": 187,
  "name": "snapshots"
}

show

GET http://localhost:3000/api/vms/1000000002002/snapshots/1000000005471
Authorization: Basic YWRtaW46c21hcnR2bQ==
{
  "actions": [
    {
      "href": "http://localhost:3000/api/vms/1000000002002/snapshots/1000000005471",
      "method": "post",
      "name": "delete"
    },
    {
      "href": "http://localhost:3000/api/vms/1000000002002/snapshots/1000000005471",
      "method": "delete",
      "name": "delete"
    }
  ],
  "uid_ems": "00517423-dfb3-411d-915d-79eeaa85df9f",
  "vm_or_template_id": 1000000002002,
  "updated_on": "2014-11-24T12:14:26Z",
  "created_on": "2014-11-19T21:17:51Z",
  "disks": [],
  "create_time": "2014-11-19T21:21:31Z",
  "current": 1,
  "description": "Active VM",
  "name": "Active VM",
  "uid": "00517423-dfb3-411d-915d-79eeaa85df9f",
  "id": 1000000005471,
  "href": "http://localhost:3000/api/vms/1000000002002/snapshots/1000000005471"
}

create

happy path

POST http://localhost:3000/api/vms/1000000002158/snapshots
Authorization: Basic YWRtaW46c21hcnR2bQ==

{
  "name": "Tim's snapshot"
}

{
  "results": [
    {
      "task_href": "http://localhost:3000/api/tasks/1000000340680",
      "task_id": 1000000340680,
      "message": "Creating snapshot for ManageIQ::Providers::Vmware::InfraManager::Vm id: 1000000002158 name: test-2.demo.inec.as",
      "success": true
    }
  ]
}

GET http://localhost:3000/api/tasks/1000000340680
Authorization: Basic YWRtaW46c21hcnR2bQ==
{
  "updated_on": "2017-01-24T21:52:54Z",
  "created_on": "2017-01-24T21:52:53Z",
  "userid": "admin",
  "message": "Task completed successfully",
  "status": "Ok",
  "state": "Finished",
  "name": "summary",
  "id": 1000000340680,
  "href": "http://localhost:3000/api/tasks/1000000340680"
}

unhappy path

POST http://localhost:3000/api/vms/1000000002002/snapshots
Authorization: Basic YWRtaW46c21hcnR2bQ==

{
  "name": "Tim's snapshot"
}
{
  "results": [
    {
      "message": "Create Snapshot operation not supported for Redhat VM",
      "success": false
    }
  ]
}

destroy

happy path

unhappy path

end

def snapshots_create_resource(parent, _type, _id, data)
parent.snapshots.create!(data.merge(:create_time => Time.zone.now))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abellotti do you know if the create_time is intended to be set by the user as a required field?


expected = {
"id" => snapshot.id,
"href" => a_string_matching(snapshots_url(snapshot.id)), # uh-oh....
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abellotti bit confused by this behavior. "edit" will return /api/snapshots/:id (which does not exist), while "create" will return /api/vms/:vm_id/snapshots/:id. Any thoughts?

action_result(true, "Creating snapshot for #{parent.id}", :task_id => task_id)
else
action_result(false, validation[:message])
end
Copy link
Member

Choose a reason for hiding this comment

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

would prefer if good path is all protected by rescue:

i.e.

  def ...
    validation = parent.validate_create_snapshot
    raise validation[:message] unless validation[:available]
    ... do the queuing work
    action_result(true, ...)
  rescue => err
    action_result(false, err.to_s)
  end

Copy link
Member

Choose a reason for hiding this comment

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

also, instead of parent.id for the successful return, would be useful to have something similar to vm_ident(), maybe something like '#{ctype} id: #{parent.id} name: #{parent.name}'

action_result(true, "desc", :task_id => task_id)
else
action_result(false, validation[:message])
end
Copy link
Member

Choose a reason for hiding this comment

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

same rescue structure suggestion as above.

validation = parent.validate_remove_snapshot(id)
if validation[:available]
task_id = queue_object_action(parent, "summary", :method_name => "remove_snapshot", :args => [id])
action_result(true, "desc", :task_id => task_id)
Copy link
Member

Choose a reason for hiding this comment

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

"desc" ? maybe "Deleting snapshot #{id} for ..." same parent signature as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WIP 😄

@imtayadeway imtayadeway changed the title [WIP] Snapshots API VMs/Snapshots API CRD Jan 24, 2017
@imtayadeway
Copy link
Contributor Author

@miq-bot rm-label wip

@imtayadeway
Copy link
Contributor Author

@miq-bot add-label enhancement

@miq-bot miq-bot added enhancement and removed wip labels Jan 24, 2017
Copy link
Member

@abellotti abellotti left a comment

Choose a reason for hiding this comment

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

Looks good @imtayadeway

minor comment change and short of the rubocop changes and tests against physical vm, I'm good with this 🎵

end
end

describe "POST /api/vms/:c_id/snapshots?action=delete" do
Copy link
Member

Choose a reason for hiding this comment

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

Maybe update to "POST /api/vms/:c_id/snapshots with delete action" just to clarify that this is not a URL signature (i.e. supporting ?action=delete parameter on POSTs).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good find!

@miq-bot
Copy link
Member

miq-bot commented Jan 27, 2017

Checked commits imtayadeway/manageiq@7e47625~...522d039 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 0 offenses detected
Everything looks good. 🍪

@abellotti abellotti added this to the Sprint 53 Ending Jan 30, 2017 milestone Jan 27, 2017
@abellotti
Copy link
Member

LGTM!! 🎵

@abellotti abellotti merged commit 546e63f into ManageIQ:master Jan 27, 2017
@imtayadeway imtayadeway deleted the api/snapshots branch February 13, 2017 18:31
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.

3 participants