-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conversation
# nic_id = vm.properties.network_profile.network_interfaces[0].id | ||
# nic = vm.get_by_id(nic_id) | ||
# | ||
def get_by_id(id_string) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
939e93b
to
b36b178
Compare
13429c3
to
877ae60
Compare
@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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzwei ok, done.
@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.
Checked commits djberg96/azure-armrest@a413205~...d7255ab with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1 lib/azure/armrest/resource_group_based_service.rb
|
@bzwei ok, fixed the rubocop warnings that I could. |
👍 |
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:
With that information we can then get a model object like so:
This will also make deleting associated resources easier.