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

Use device_name for cdrom reconfiguration request #4548

Merged
merged 2 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,29 +231,6 @@ ManageIQ.angular.app.controller('reconfigureFormController', ['$http', '$scope',
vm.reconfigureModel.vmRemoveNetworkAdapters.length > 0;
};

vm.updateCDRomsConnectDisconnect = function() {
vm.reconfigureModel.vmConnectCDRoms = [];
vm.reconfigureModel.vmDisconnectCDRoms = [];

angular.forEach(vm.reconfigureModel.vmCDRoms, function(cdRom) {
if (cdRom.connect_disconnect === 'disconnect') {
vm.reconfigureModel.vmDisconnectCDRoms.push({
name: cdRom.hdFilename,
});
}
if (cdRom.connect_disconnect === 'connect') {
vm.reconfigureModel.vmConnectCDRoms.push({
name: cdRom.name,
filename: cdRom.filename,
storage_id: cdRom.storage_id,
});
}
});
vm.cb_cdRoms = vm.reconfigureModel.vmConnectCDRoms.length > 0 ||
vm.reconfigureModel.vmDisconnectCDRoms.length > 0;
};


vm.resetAddValues = function() {
vm.reconfigureModel.hdType = vm.disk_default_type;
vm.reconfigureModel.hdMode = 'persistent';
Expand Down Expand Up @@ -441,8 +418,13 @@ ManageIQ.angular.app.controller('reconfigureFormController', ['$http', '$scope',
vm.cancelAddRemoveDisk(disk);
});

angular.forEach(vm.reconfigureModel.vmCDRoms, function(cd) {
vm.cancelCDRomConnectDisconnect(cd);
});

$scope.angularForm.$setPristine(true);
vm.updateDisksAddRemove();
vm.updateCDRomsConnectDisconnect();

miqService.miqFlash('warn', __('All changes have been reset'));
};
Expand Down Expand Up @@ -527,15 +509,15 @@ ManageIQ.angular.app.controller('reconfigureFormController', ['$http', '$scope',
angular.forEach(vm.reconfigureModel.vmCDRoms, function(cdRom) {
if (cdRom.connect_disconnect === 'connect') {
vm.reconfigureModel.vmConnectCDRoms.push(
{ name: cdRom.name,
{ device_name: cdRom.device_name,
filename: cdRom.filename,
storage_id: cdRom.storage_id,
}
);
}
if (cdRom.connect_disconnect === 'disconnect') {
vm.reconfigureModel.vmDisconnectCDRoms.push(
{ name: cdRom.name });
{ device_name: cdRom.device_name });
}
});
vm.cb_cdRoms = vm.reconfigureModel.vmConnectCDRoms.length > 0 ||
Expand Down Expand Up @@ -568,12 +550,9 @@ ManageIQ.angular.app.controller('reconfigureFormController', ['$http', '$scope',

vm.cancelCDRomConnectDisconnect = function(vmCDRom) {
var index = vm.reconfigureModel.vmCDRoms.indexOf(vmCDRom);
if (vmCDRom.connect_disconnect === "disconnect") {
vmCDRom.filename = vmCDRom.orgFilename;
}
vmCDRom.filename = vmCDRom.orgFilename;
vmCDRom.connect_disconnect = '';
vm.reconfigureModel.vmCDRoms[index].connect_disconnect = '';
vm.updateCDRomsConnectDisconnect();
};

init();
Expand Down
21 changes: 13 additions & 8 deletions app/controllers/mixins/actions/vm_actions/reconfigure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,20 @@ def build_request_cdroms_list(cdroms)
connect_disconnect = ''
cdroms.map do |cd|
id = cd.id
name = cd.device_name
device_name = cd.device_name
type = cd.device_type
filename = cd.filename
storage_id = cd.storage_id
if cd.filename && @req.options[:cdrom_disconnect]&.find { |d_cd| d_cd[:name] == cd.device_name }
if cd.filename && @req.options[:cdrom_disconnect]&.find { |d_cd| d_cd[:device_name] == cd.device_name }
filename = ''
connect_disconnect = 'disconnect'
end
conn_cd = @req.options[:cdrom_connect]&.find { |c_cd| c_cd[:name] == cd.device_name }
conn_cd = @req.options[:cdrom_connect]&.find { |c_cd| c_cd[:device_name] == cd.device_name }
if cd.filename && conn_cd
filename = conn_cd[:filename]
connect_disconnect = 'connect'
end
vmcdroms << {:id => id, :name => name, :filename => filename, :type => type, :storage_id => storage_id, :connect_disconnect => connect_disconnect}
vmcdroms << {:id => id, :device_name => device_name, :filename => filename, :type => type, :storage_id => storage_id, :connect_disconnect => connect_disconnect}
end
vmcdroms
end
Expand Down Expand Up @@ -322,17 +322,22 @@ def build_network_adapters_list(vm)
network_adapters
end

def filename_string(name)
# an empty cdrom filename can be in the form of a string containing a pair of square brackets
name.blank? || name == '[]' ? '' : name.to_s
end

def build_vmcdrom_list(vm)
vmcdroms = []
cdroms = vm.hardware.cdroms
if cdroms.present?
cdroms.map do |cd|
id = cd.id
name = cd.device_name
device_name = cd.device_name
type = cd.device_type
filename = cd.filename
storage_id = cd.storage_id
vmcdroms << {:id => id, :name => name, :filename => filename, :type => type, :storage_id => storage_id}
filename = filename_string(cd.filename)
storage_id = cd.storage_id || ''
vmcdroms << {:id => id, :device_name => device_name, :filename => filename, :type => type, :storage_id => storage_id}
end
vmcdroms
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/vm_common/_reconfigure.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@
%tr{"ng-repeat" => "cdRom in vm.reconfigureModel.vmCDRoms",
"ng-class" => "{'danger': cdRom.connected_status == 'disconnected', 'active': cdRom.connected_status == 'connected'}"}
%td
{{cdRom.name}}
{{cdRom.device_name}}
%td{"ng-if" => "cdRom.connect_disconnect != 'connecting'"}
{{cdRom.filename}}
%td{"ng-if" => "cdRom.connect_disconnect == 'connecting'"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('reconfigureFormController', function() {
cores_per_socket_count: '3',
disks: [{hdFilename: "test_disk.vmdk", hdType: "thick", hdMode: "persistent", new_controller_type: "VirtualLsiLogicController", hdSize: "0", hdUnit: "MB", add_remove: ""}],
network_adapters: [{name: "Network adapter 1", vlan: "test_network", mac: "00:00:00:00:00:00", add_remove: ""}],
cdroms: [{name: "CDROM 1", filename: "test_filename.iso", storage_id: '5', connect_disconnect: ""}],
cdroms: [{device_name: "CDROM 1", filename: "test_filename.iso", storage_id: '5', connect_disconnect: ""}],
vm_vendor: 'vm-vendor',
vm_type: 'vm-type',
disk_default_type: 'disk-default-type'};
Expand Down