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

Add get_by_id and get_subservice_by_id #225

Merged
merged 2 commits into from
Oct 28, 2016
Merged

Conversation

djberg96
Copy link
Collaborator

This adds two methods to the ResourceGroupBasedService that will allow users to get objects based on an ID string without having to parse that information out themselves.

For example, a VM contains an ID for its NIC like this:

"id": "/subscriptions/xyz/resourceGroups/some_group/providers/Microsoft.Network/networkInterfaces/some_nic"

With that information we can then get a model object like so:

nic_id = vm.properties.network_profile.network_interfaces[0].id
vms.get_by_id(nic_id)

This will also make deleting associated resources easier.

@djberg96
Copy link
Collaborator Author

@bzwei @bronaghs Please review.

# nic_id = vm.properties.network_profile.network_interfaces[0].id
# nic = vm.get_by_id(nic_id)
#
def get_by_id(id_string)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest method name get_associate_resource

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm, ok, but I've kept the originals as aliases because I like short method names. :)


url = File.join(Azure::Armrest::RESOURCE, id_string) + "?api-version=#{api_version}"

model_class = case info[:service_name].downcase
Copy link
Contributor

Choose a reason for hiding this comment

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

let's follow the indent style required by rubocop

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the indent style that rubocop wants is terrible.

@djberg96 djberg96 force-pushed the get_by_id branch 2 times, most recently from 939e93b to b36b178 Compare October 17, 2016 19:24
@djberg96 djberg96 force-pushed the get_by_id branch 5 times, most recently from 13429c3 to 877ae60 Compare October 26, 2016 18:50
@djberg96
Copy link
Collaborator Author

@bzwei Ok, I modified the code so that it's a single method that works with either a service or subservice.

@@ -187,6 +238,37 @@ def list_in_all_groups

array
end

def get_model_class(service_name)
case service_name.downcase
Copy link
Contributor

Choose a reason for hiding this comment

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

We can simply maintain a hash table for the lookup instead of long list of case/when

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bzwei ok, done.

@bzwei
Copy link
Contributor

bzwei commented Oct 28, 2016

@djberg96 looks good. Can you address the warnings from rubocop?

Merge get_by_id and get_subservice_by_id into a single method and update specs accordingly.

Use nicer regex syntax, and make regex less greedy.
@miq-bot
Copy link
Member

miq-bot commented Oct 28, 2016

Checked commits djberg96/azure-armrest@a413205~...d7255ab with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
2 files checked, 1 offense detected

lib/azure/armrest/resource_group_based_service.rb

  • ❕ - Line 102, Col 7 - Metrics/AbcSize - Assignment Branch Condition size for get_associated_resource is too high. [30.15/20]

@djberg96
Copy link
Collaborator Author

@bzwei ok, fixed the rubocop warnings that I could.

@bronaghs
Copy link

👍

@bzwei bzwei merged commit 3387435 into ManageIQ:master Oct 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants