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

Automate method to list ansible credentials #53

Merged
merged 5 commits into from
Feb 16, 2017

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented Feb 14, 2017

https://www.pivotaltracker.com/story/show/137304515

Automate method to list machine, network and other ansible credentials.
The method accepts a type and yields a
{id => name} hash
e.g.
{id1 => "test1", id2 => "test2"}

Depends on PR ManageIQ/manageiq#13912

@mkanoor
Copy link
Contributor Author

mkanoor commented Feb 14, 2017

@bzwei @tinaafitz
Please review

@tinaafitz
Copy link
Member

@mkanoor Looks good.

dialog_hash = {
'sort_by' => "value",
'data_type' => "string",
'required' => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

credential is optional since it is already predefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bzwei
I dont understand what the required means in the context of dialogs. I will ask @eclarizio

'required' => true,
'sort_order' => "ascending",
'values' => list,
'default_value' => list.length == 1 ? list.keys.first : nil
Copy link
Contributor

Choose a reason for hiding this comment

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

The list should be like

nil => '<Default>'
id => 'credential name'

default will be always nil => <Default>, which means to use the one already defined in the job template.


def credentials
result = provider.try(:credentials) || []
result.select { |c| c.type == @handle.inputs['credential_type'] }
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use provider.credentials.find_by(:type => type). How does inputs['credential_type'] get set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bzwei
The credential_type is set as an input parameter into the method. So the 2 instances available_network_credential will set
credential_type =
ManageIQ::Providers::AnsibleTower::AutomationManager::NetworkCredential
available_machine_credentials will set
credential_type =
ManageIQ::Providers::AnsibleTower::AutomationManager::MachineCredential

The method itself has a default credential_type set to
ManageIQ::Providers::AnsibleTower::AutomationManager::MachineCredential

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bzwei
The find_by works on associations, by the time we get the credentials on the Automate method side it has been converted into an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bzwei

@handle.vmdb('Authentication').where("resource_id = ? AND type = ?",provider.id, @handle.inputs['credential_type'])

This would work do you prefer this

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation. From performance point of view, this is better.

# for provisioning we use service_template
# for reconfig and retire use service
service = @handle.root['service_template'] || @handle.root['service']
service.try(:job_template, 'Provision').try(:manager)
Copy link
Member

Choose a reason for hiding this comment

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

@mkanoor It is possible that the different actions could run JobTemplates on different providers. We would need to determine the service_action here and not just hardcode Provision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gmcculloug I discussed this with @bzwei and this is where we came up with the the restriction that all job templates in a service have to point to the same manager. Since credentials are connected to a manager for the entire job template we will have a single manager. So all service_actions (Provision, Reconfigure, Retire) will point to the same manager and hence the same set of credentials.


def fetch_list_data
credential_list = Hash[*credentials.pluck(:id, :name).flatten]
@handle.log(:info, "Number of credentials found #{credential_list.keys.count}")
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why credential_list.keys.count and not just credential_list.count?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gmcculloug didn't realize Hash has a count method

Copy link
Contributor

Choose a reason for hiding this comment

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

Good for debugging, but I am not convinced we want to log the count here in final release.

'required' => false,
'sort_order' => "ascending",
'values' => list,
'default_value' => nil
Copy link
Member

Choose a reason for hiding this comment

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

sort_by should be "description" and since the value is an ID data_type should be "integer".

datatype:
priority: 1
owner:
default_value: ManageIQ::Providers::AnsibleTower::AutomationManager::MachineCredential
Copy link
Member

Choose a reason for hiding this comment

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

Can default_value be blank since the instance is always passing this parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gmcculloug
One reason I decided to do that was to preserve the expected format of the value when the method gets copied around to a different class/domain without instances.


def fetch_list_data
credential_list = Hash[*credentials.pluck(:id, :name).flatten]
@handle.log(:info, "Number of credentials found #{credential_list.keys.count}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Good for debugging, but I am not convinced we want to log the count here in final release.

def fetch_list_data
credential_list = Hash[*credentials.pluck(:id, :name).flatten]
@handle.log(:info, "Number of credentials found #{credential_list.keys.count}")
return nil => "<none>" if credential_list.blank?
Copy link
Contributor

@bzwei bzwei Feb 16, 2017

Choose a reason for hiding this comment

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

I would simply do

def fetch_list_data
  credential_list = Hash[*credentials.pluck(:id, :name).flatten]
  {nil => '<Default>'}.merge(credential_list)
end

@mkanoor
Copy link
Contributor Author

mkanoor commented Feb 16, 2017

@bzwei @gmcculloug
Please review

@miq-bot
Copy link
Member

miq-bot commented Feb 16, 2017

Checked commits mkanoor/manageiq-content@607e6f7~...6693372 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks good. 🏆

@gmcculloug gmcculloug self-assigned this Feb 16, 2017
@gmcculloug gmcculloug merged commit 35d3b7e into ManageIQ:master Feb 16, 2017
@gmcculloug gmcculloug added this to the Sprint 55 Ending Feb 27, 2017 milestone Feb 27, 2017
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.

5 participants