-
Notifications
You must be signed in to change notification settings - Fork 15
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 physical server profile template #81
Merged
agrare
merged 20 commits into
ManageIQ:master
from
Autosde:add_physical_server_profile_template
Nov 30, 2022
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6dd1444
add physical server profile template
eilam20 b581d60
add physical server profile template
eilam20 8186a7e
add physical server profile template
eilam20 116b226
add deploy_server_from_template_queue to run deploy_server_from_template
eilam20 b69b318
add bulk_api
eilam20 f22ddac
add EmsRefreshWorkflow to check the status of the job in intersight c…
eilam20 5622c90
fix
eilam20 1c9d9b1
call connect func with the ems
eilam20 aa04aa6
call connect functions with the ems
eilam20 d1a5754
fix
eilam20 406a740
add require 'intersight_client'
eilam20 478e7d1
add require_nested :PhysicalServerProfileTemplate
eilam20 8404b3d
fix
eilam20 b614ae0
fix
eilam20 2ba1816
add get ProfileTemplates to vcr
eilam20 9eacc00
add get ProfileTemplates to vcr
eilam20 3f00570
add get ProfileTemplates to vcr
eilam20 d513094
add get ProfileTemplates to vcr
eilam20 f8b6305
fix yml
eilam20 324e40e
fix yml
eilam20 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...models/manageiq/providers/cisco_intersight/physical_infra_manager/ems_refresh_workflow.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class ManageIQ::Providers::CiscoIntersight::PhysicalInfraManager::EmsRefreshWorkflow < ManageIQ::Providers::EmsRefreshWorkflow | ||
def run_native_op | ||
queue_signal(:poll_native_task) | ||
end | ||
alias start run_native_op | ||
|
||
def poll_native_task | ||
wf_api = ext_management_system.connect(:service=>'WorkflowApi') | ||
native_object_response = wf_api.get_workflow_workflow_info_list({:filter => "Input.workflowContext.WorkflowType eq 'serverconfig' and Input.workflowContext.WorkflowSubtype eq 'Deploy' and Input.workflowContext.InitiatorCtx.InitiatorMoid eq '#{options[:native_task_id]}'", :select => "Status"}) | ||
native_object = native_object_response.results[0] | ||
|
||
case native_object.status | ||
when "FAILED" | ||
signal(:abort, "Task failed") | ||
when "TIME_OUT" | ||
signal(:abort, "Task time out") | ||
when "COMPLETED" | ||
queue_signal(:refresh) | ||
else | ||
queue_signal(:poll_native_task, :deliver_on => Time.now.utc + options[:interval]) | ||
end | ||
rescue => err | ||
_log.log_backtrace(err) | ||
signal(:abort, err.message, "error") | ||
end | ||
|
||
def refresh | ||
task_ids = EmsRefresh.queue_refresh_task(ext_management_system) | ||
if task_ids.blank? | ||
process_error("Failed to queue refresh", "error") | ||
queue_signal(:error) | ||
else | ||
context[:refresh_task_ids] = task_ids | ||
update!(:context => context) | ||
|
||
queue_signal(:poll_refresh) | ||
end | ||
end | ||
|
||
def ext_management_system | ||
@ext_management_system ||= ExtManagementSystem.find(options[:ems_id]) | ||
end | ||
end |
64 changes: 64 additions & 0 deletions
64
...eiq/providers/cisco_intersight/physical_infra_manager/physical_server_profile_template.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module ManageIQ::Providers::CiscoIntersight | ||
class PhysicalInfraManager::PhysicalServerProfileTemplate < ::PhysicalServerProfileTemplate | ||
def self.display_name(number = 1) | ||
n_('Physical Server Profile Template (CiscoIntersight)', 'Physical Server Profile Template (CiscoIntersight)', number) | ||
end | ||
|
||
def provider_object(connection) | ||
connection.find!(ems_ref) | ||
end | ||
|
||
def deploy_server_from_template(server_id, profile_name) | ||
# Load the gem | ||
require 'intersight_client' | ||
|
||
bulk = ext_management_system.connect(:service=>'BulkApi') | ||
cloner = IntersightClient::BulkMoCloner.new({:sources => [{"Moid" => ems_ref, "ObjectType" => 'server.ProfileTemplate'}], :targets => [{"Name" => profile_name, :ObjectType => 'server.Profile'}]}) | ||
|
||
# create a new server profile from server profile template | ||
|
||
result = bulk.create_bulk_mo_cloner(cloner) | ||
new_profile_moid = result.responses[0].body.moid | ||
|
||
server_profile_updated = IntersightClient::ServerProfile.new( | ||
{ | ||
:assigned_server => {"Moid" => server_id, "ObjectType" => "compute.Blade"}, | ||
:server_assignment_mode => "Static", | ||
:target_platform => nil, | ||
:uuid_address_type => nil | ||
} | ||
) | ||
# assign the profile server to the selected server | ||
server_api = ext_management_system.connect(:service=>'ServerApi') | ||
begin | ||
result = server_api.patch_server_profile(new_profile_moid, server_profile_updated, {}) | ||
_log.info("Server profile successfully assigned with server #{server_id} (ems_ref #{result.assigned_server.moid})") | ||
rescue IntersightClient::ApiError => e | ||
_log.error("Assign server failed for server profile (ems_ref #{new_profile_moid}) server (ems_ref #{server_id})") | ||
raise MiqException::Error, "Assign server failed: #{e.response_body}" | ||
end | ||
|
||
server_profile_updated = {'Action' => "Deploy"} | ||
# deploy the server | ||
begin | ||
result = server_api.patch_server_profile(new_profile_moid, server_profile_updated, {}) | ||
_log.info("Server profile #{result.config_context.control_action} initiated successfully") | ||
rescue IntersightClient::ApiError => e | ||
_log.error("#{action} server failed for server profile (ems_ref #{new_profile_moid})") | ||
raise MiqException::Error, "#Deploy server failed: #{e.response_body}" | ||
end | ||
|
||
# create a job to refresh the cisco intersight provider after the deployment finished | ||
options = { | ||
:target_class => self.class.name, | ||
:target_id => id, | ||
:ems_id => ext_management_system.id, | ||
:native_task_id => new_profile_moid, | ||
:interval => 30.seconds, | ||
:target_option => "deploy" | ||
} | ||
|
||
ManageIQ::Providers::CiscoIntersight::PhysicalInfraManager::EmsRefreshWorkflow.create_job(options).tap(&:signal_start) | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
NOTE this looks identical to the method in core except for the target_entity/ext_management_system bit. It would be nice to add a
refresh_target
method in core that defaults totarget_entity
if targeted_refresh is supported andext_management_system
otherwise which would allow you to override it and simply returnext_management_system
if you just want to do a full.Would be a good follow-up PR if you want to implement that in core.
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.
ManageIQ/manageiq#22254