mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 16:51:11 +03:00
Adds creating links from host vars from inventory
* Adds creating links from host vars * Returns devices to the toolbox after they are removed from the canvas
This commit is contained in:
parent
66c351c60c
commit
b9d4fc2bb9
@ -19,7 +19,7 @@ function NullChannel(from_controller, tracer) {
|
||||
this.trace = false;
|
||||
}
|
||||
|
||||
NullChannel.prototype.send = function(msg_type) {
|
||||
NullChannel.prototype.send = function() {
|
||||
};
|
||||
|
||||
function FSMController (scope, name, initial_state, tracer) {
|
||||
|
@ -23,15 +23,9 @@ var Rack = new _Rack();
|
||||
exports.Rack = Rack;
|
||||
|
||||
|
||||
_State.prototype.start = function (controller) {
|
||||
controller.scope.current_mode = controller.state.name;
|
||||
};
|
||||
|
||||
|
||||
_Start.prototype.start = function (controller) {
|
||||
|
||||
controller.scope.inventory_toolbox_controller.handle_message('Disable', {});
|
||||
|
||||
controller.changeState(Rack);
|
||||
};
|
||||
_Start.prototype.start.transitions = ['MultiSite'];
|
||||
@ -42,10 +36,3 @@ _Rack.prototype.start = function (controller) {
|
||||
controller.scope.inventory_toolbox_controller.handle_message('Enable', {});
|
||||
controller.scope.move_controller.changeState(move.Ready);
|
||||
};
|
||||
|
||||
_Rack.prototype.end = function (controller) {
|
||||
|
||||
controller.scope.inventory_toolbox_controller.handle_message('Disable', {});
|
||||
controller.scope.move_controller.changeState(move.Disable);
|
||||
};
|
||||
|
||||
|
@ -16,19 +16,13 @@ function Device(id, name, x, y, type, host_id) {
|
||||
this.type = type;
|
||||
this.selected = false;
|
||||
this.remote_selected = false;
|
||||
this.edit_label = false;
|
||||
this.status = null;
|
||||
this.working = false;
|
||||
this.moving = false;
|
||||
this.icon = false;
|
||||
this.tasks = [];
|
||||
this.shape = type === "router" ? "circular" : "rectangular";
|
||||
this.interface_seq = util.natural_numbers(0);
|
||||
this.interfaces = [];
|
||||
this.process_id_seq = util.natural_numbers(0);
|
||||
this.processes = [];
|
||||
this.in_group = false;
|
||||
this.template = false;
|
||||
this.interfaces_by_name = {};
|
||||
this.variables = {};
|
||||
}
|
||||
exports.Device = Device;
|
||||
@ -42,9 +36,8 @@ Device.prototype.toJSON = function () {
|
||||
interfaces: this.interfaces.map(function (x) {
|
||||
return x.toJSON();
|
||||
}),
|
||||
processes: this.processes.map(function (x) {
|
||||
return x.toJSON();
|
||||
})};
|
||||
variables: this.variables
|
||||
};
|
||||
};
|
||||
|
||||
Device.prototype.is_selected = function (x, y) {
|
||||
@ -76,18 +69,6 @@ Interface.prototype.toJSON = function () {
|
||||
name: this.name};
|
||||
};
|
||||
|
||||
Interface.prototype.remote_interface = function () {
|
||||
|
||||
if (this.link === null) {
|
||||
return null;
|
||||
}
|
||||
if (this.link.to_interface === this) {
|
||||
return this.link.from_interface;
|
||||
} else {
|
||||
return this.link.to_interface;
|
||||
}
|
||||
};
|
||||
|
||||
Interface.prototype.is_selected = function (x, y) {
|
||||
|
||||
if (this.link === null || this.device === null) {
|
||||
|
@ -84,7 +84,10 @@ _Ready.prototype.onPasteDevice = function (controller, msg_type, message) {
|
||||
|
||||
var scope = controller.scope;
|
||||
var device = null;
|
||||
var remote_device = null;
|
||||
var intf = null;
|
||||
var link = null;
|
||||
var new_link = null;
|
||||
var i = 0;
|
||||
var c_messages = [];
|
||||
|
||||
@ -99,7 +102,10 @@ _Ready.prototype.onPasteDevice = function (controller, msg_type, message) {
|
||||
scope.scaledY,
|
||||
message.device.type,
|
||||
message.device.host_id);
|
||||
device.variables = message.device.variables;
|
||||
scope.update_links_in_vars_by_device(device.name, device.variables);
|
||||
scope.devices.push(device);
|
||||
scope.devices_by_name[message.device.name] = device;
|
||||
c_messages.push(new messages.DeviceCreate(scope.client_id,
|
||||
device.id,
|
||||
device.x,
|
||||
@ -110,13 +116,65 @@ _Ready.prototype.onPasteDevice = function (controller, msg_type, message) {
|
||||
for (i=0; i < message.device.interfaces.length; i++) {
|
||||
intf = new models.Interface(message.device.interfaces[i].id, message.device.interfaces[i].name);
|
||||
device.interfaces.push(intf);
|
||||
device.interfaces_by_name[message.device.interfaces[i].name] = intf;
|
||||
intf.device = device;
|
||||
c_messages.push(new messages.InterfaceCreate(controller.scope.client_id,
|
||||
device.id,
|
||||
intf.id,
|
||||
intf.name));
|
||||
}
|
||||
if (scope.links_in_vars_by_device[device.name] !== undefined) {
|
||||
for (i=0; i < scope.links_in_vars_by_device[device.name].length; i++) {
|
||||
link = scope.links_in_vars_by_device[device.name][i];
|
||||
if (device.interfaces_by_name[link.from_interface] === undefined) {
|
||||
intf = new models.Interface(device.interface_seq(), link.from_interface);
|
||||
device.interfaces.push(intf);
|
||||
device.interfaces_by_name[link.from_interface] = intf;
|
||||
intf.device = device;
|
||||
c_messages.push(new messages.InterfaceCreate(controller.scope.client_id,
|
||||
device.id,
|
||||
intf.id,
|
||||
intf.name));
|
||||
}
|
||||
if (scope.devices_by_name[link.to_device] !== undefined) {
|
||||
remote_device = scope.devices_by_name[link.to_device];
|
||||
if (remote_device.interfaces_by_name[link.to_interface] === undefined) {
|
||||
intf = new models.Interface(remote_device.interface_seq(), link.to_interface);
|
||||
remote_device.interfaces.push(intf);
|
||||
remote_device.interfaces_by_name[link.to_interface] = intf;
|
||||
intf.device = remote_device;
|
||||
c_messages.push(new messages.InterfaceCreate(controller.scope.client_id,
|
||||
remote_device.id,
|
||||
intf.id,
|
||||
intf.name));
|
||||
}
|
||||
}
|
||||
if (scope.devices_by_name[link.to_device] === undefined) {
|
||||
continue;
|
||||
}
|
||||
if (scope.devices_by_name[link.to_device].interfaces_by_name[link.to_interface] === undefined) {
|
||||
continue;
|
||||
}
|
||||
new_link = new models.Link(scope.link_id_seq(),
|
||||
device,
|
||||
scope.devices_by_name[link.to_device],
|
||||
device.interfaces_by_name[link.from_interface],
|
||||
scope.devices_by_name[link.to_device].interfaces_by_name[link.to_interface]);
|
||||
c_messages.push(new messages.LinkCreate(controller.scope.client_id,
|
||||
new_link.id,
|
||||
new_link.from_device.id,
|
||||
new_link.to_device.id,
|
||||
new_link.from_interface.id,
|
||||
new_link.to_interface.id));
|
||||
device.interfaces_by_name[link.from_interface].link = new_link;
|
||||
scope.devices_by_name[link.to_device].interfaces_by_name[link.to_interface].link = new_link;
|
||||
scope.links.push(new_link);
|
||||
scope.updateInterfaceDots();
|
||||
}
|
||||
}
|
||||
scope.selected_devices.push(device);
|
||||
device.selected = true;
|
||||
console.log(c_messages);
|
||||
scope.send_control_message(new messages.MultipleMessage(controller.scope.client_id, c_messages));
|
||||
controller.changeState(Selected2);
|
||||
};
|
||||
|
@ -117,7 +117,9 @@ var NetworkUIController = function($scope,
|
||||
$scope.recording = false;
|
||||
$scope.replay = false;
|
||||
$scope.devices = [];
|
||||
$scope.devices_by_name = {};
|
||||
$scope.links = [];
|
||||
$scope.links_in_vars_by_device = {};
|
||||
$scope.tests = [];
|
||||
$scope.current_tests = [];
|
||||
$scope.current_test = null;
|
||||
@ -195,6 +197,42 @@ var NetworkUIController = function($scope,
|
||||
var toolboxTitleMargin = toolboxTopMargin + 35;
|
||||
var toolboxHeight = $scope.graph.height - $('.Networking-top').height();
|
||||
|
||||
$scope.update_links_in_vars_by_device = function (device_name, variables) {
|
||||
|
||||
var j = 0;
|
||||
var link = null;
|
||||
|
||||
if (variables.ansible_topology !== undefined) {
|
||||
if (variables.ansible_topology.links !== undefined) {
|
||||
for (j=0; j < variables.ansible_topology.links.length; j++) {
|
||||
link = variables.ansible_topology.links[j];
|
||||
if (link.remote_device_name !== undefined &&
|
||||
link.remote_interface_name !== undefined &&
|
||||
link.name !== undefined) {
|
||||
if ($scope.links_in_vars_by_device[device_name] === undefined) {
|
||||
$scope.links_in_vars_by_device[device_name] = [];
|
||||
}
|
||||
if ($scope.links_in_vars_by_device[link.remote_device_name] === undefined) {
|
||||
$scope.links_in_vars_by_device[link.remote_device_name] = [];
|
||||
}
|
||||
$scope.links_in_vars_by_device[device_name].push({
|
||||
from_interface: link.name,
|
||||
to_interface: link.remote_interface_name,
|
||||
from_device: device_name,
|
||||
to_device: link.remote_device_name
|
||||
});
|
||||
$scope.links_in_vars_by_device[link.remote_device_name].push({
|
||||
from_interface: link.remote_interface_name,
|
||||
to_interface: link.name,
|
||||
from_device: link.remote_device_name,
|
||||
to_device: device_name
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Inventory Toolbox Setup
|
||||
$scope.inventory_toolbox = new models.ToolBox(0, 'Inventory', 'device', 0, toolboxTopMargin, 200, toolboxHeight);
|
||||
if (!$scope.disconnected) {
|
||||
@ -206,36 +244,38 @@ var NetworkUIController = function($scope,
|
||||
devices_by_name[$scope.devices[i].name] = $scope.devices[i];
|
||||
}
|
||||
let hosts = response.data.results;
|
||||
console.log(hosts.length);
|
||||
for(i = 0; i<hosts.length; i++) {
|
||||
console.log(i);
|
||||
try {
|
||||
var device_type = null;
|
||||
var device_name = null;
|
||||
var device = null;
|
||||
let device_type = null;
|
||||
let device_name = null;
|
||||
let device = null;
|
||||
let host = hosts[i];
|
||||
device_name = host.name;
|
||||
console.log(device_name);
|
||||
if (host.variables !== "") {
|
||||
host.data = jsyaml.safeLoad(host.variables);
|
||||
console.log(host.data);
|
||||
} else {
|
||||
host.data = {};
|
||||
}
|
||||
if (host.data.awx === undefined) {
|
||||
if (host.data.ansible_topology === undefined) {
|
||||
device_type = 'unknown';
|
||||
device_name = host.name;
|
||||
} else {
|
||||
if (host.data.awx.type === undefined) {
|
||||
if (host.data.ansible_topology.type === undefined) {
|
||||
device_type = 'unknown';
|
||||
} else {
|
||||
device_type = host.data.awx.type;
|
||||
}
|
||||
if (host.data.awx.name === undefined) {
|
||||
device_name = host.name;
|
||||
} else {
|
||||
device_name = host.data.awx.name;
|
||||
device_type = host.data.ansible_topology.type;
|
||||
}
|
||||
|
||||
$scope.update_links_in_vars_by_device(device_name, host.data);
|
||||
}
|
||||
if (devices_by_name[device_name] === undefined) {
|
||||
console.log(['adding', device_name]);
|
||||
device = new models.Device(0, device_name, 0, 0, device_type, host.id);
|
||||
device.icon = true;
|
||||
device.variables = JSON.stringify(host.data);
|
||||
device.variables = host.data;
|
||||
$scope.inventory_toolbox.items.push(device);
|
||||
}
|
||||
} catch (error) {
|
||||
@ -346,6 +386,7 @@ var NetworkUIController = function($scope,
|
||||
$scope.clear_selections = function () {
|
||||
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var devices = $scope.devices;
|
||||
var links = $scope.links;
|
||||
$scope.selected_items = [];
|
||||
@ -359,6 +400,9 @@ var NetworkUIController = function($scope,
|
||||
links[i].selected = false;
|
||||
}
|
||||
for (i = 0; i < devices.length; i++) {
|
||||
for (j = 0; j < devices[i].interfaces.length; j++) {
|
||||
devices[i].interfaces[j].selected = false;
|
||||
}
|
||||
if (devices[i].selected) {
|
||||
$scope.send_control_message(new messages.DeviceUnSelected($scope.client_id, devices[i].id));
|
||||
}
|
||||
@ -613,6 +657,39 @@ var NetworkUIController = function($scope,
|
||||
|
||||
};
|
||||
|
||||
$scope.onDeviceDestroy = function(data) {
|
||||
$scope.destroy_device(data);
|
||||
};
|
||||
|
||||
$scope.destroy_device = function(data) {
|
||||
|
||||
// Delete the device and any links connecting to the device.
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var dindex = -1;
|
||||
var lindex = -1;
|
||||
var devices = $scope.devices.slice();
|
||||
var all_links = $scope.links.slice();
|
||||
for (i = 0; i < devices.length; i++) {
|
||||
if (devices[i].id === data.id) {
|
||||
dindex = $scope.devices.indexOf(devices[i]);
|
||||
if (dindex !== -1) {
|
||||
$scope.devices.splice(dindex, 1);
|
||||
}
|
||||
lindex = -1;
|
||||
for (j = 0; j < all_links.length; j++) {
|
||||
if (all_links[j].to_device === devices[i] ||
|
||||
all_links[j].from_device === devices[i]) {
|
||||
lindex = $scope.links.indexOf(all_links[j]);
|
||||
if (lindex !== -1) {
|
||||
$scope.links.splice(lindex, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.deleteDevice = function(){
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
@ -626,7 +703,15 @@ var NetworkUIController = function($scope,
|
||||
index = $scope.devices.indexOf(devices[i]);
|
||||
if (index !== -1) {
|
||||
$scope.devices.splice(index, 1);
|
||||
$scope.devices_by_name[devices[i].name] = undefined;
|
||||
$scope.$emit('awxNet-removeSearchOption', devices[i]);
|
||||
devices[i].x = 0;
|
||||
devices[i].y = 0;
|
||||
devices[i].selected = false;
|
||||
devices[i].remote_selected = false;
|
||||
devices[i].interfaces = [];
|
||||
devices[i].interfaces_by_name = [];
|
||||
$scope.inventory_toolbox.items.push(devices[i]);
|
||||
$scope.send_control_message(new messages.DeviceDestroy($scope.client_id,
|
||||
devices[i].id,
|
||||
devices[i].x,
|
||||
@ -641,6 +726,14 @@ var NetworkUIController = function($scope,
|
||||
index = $scope.links.indexOf(all_links[j]);
|
||||
if (index !== -1) {
|
||||
$scope.links.splice(index, 1);
|
||||
$scope.send_control_message(new messages.LinkDestroy($scope.client_id,
|
||||
all_links[j].id,
|
||||
all_links[j].from_device.id,
|
||||
all_links[j].to_device.id,
|
||||
all_links[j].from_interface.id,
|
||||
all_links[j].to_interface.id,
|
||||
all_links[j].name));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -824,6 +917,7 @@ var NetworkUIController = function($scope,
|
||||
data.host_id);
|
||||
$scope.device_id_seq = util.natural_numbers(data.id);
|
||||
$scope.devices.push(device);
|
||||
$scope.devices_by_name[device.name] = device;
|
||||
};
|
||||
|
||||
$scope.onInterfaceCreate = function(data) {
|
||||
@ -843,6 +937,7 @@ var NetworkUIController = function($scope,
|
||||
};
|
||||
|
||||
$scope.onLinkCreate = function(data) {
|
||||
console.log(data);
|
||||
$scope.create_link(data);
|
||||
};
|
||||
|
||||
@ -874,6 +969,7 @@ var NetworkUIController = function($scope,
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(new_link);
|
||||
if (new_link.from_interface !== null && new_link.to_interface !== null) {
|
||||
new_link.from_interface.dot();
|
||||
new_link.to_interface.dot();
|
||||
@ -929,39 +1025,6 @@ var NetworkUIController = function($scope,
|
||||
}
|
||||
};
|
||||
|
||||
$scope.onDeviceDestroy = function(data) {
|
||||
$scope.destroy_device(data);
|
||||
};
|
||||
|
||||
$scope.destroy_device = function(data) {
|
||||
|
||||
// Delete the device and any links connecting to the device.
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var dindex = -1;
|
||||
var lindex = -1;
|
||||
var devices = $scope.devices.slice();
|
||||
var all_links = $scope.links.slice();
|
||||
for (i = 0; i < devices.length; i++) {
|
||||
if (devices[i].id === data.id) {
|
||||
dindex = $scope.devices.indexOf(devices[i]);
|
||||
if (dindex !== -1) {
|
||||
$scope.devices.splice(dindex, 1);
|
||||
}
|
||||
lindex = -1;
|
||||
for (j = 0; j < all_links.length; j++) {
|
||||
if (all_links[j].to_device === devices[i] ||
|
||||
all_links[j].from_device === devices[i]) {
|
||||
lindex = $scope.links.indexOf(all_links[j]);
|
||||
if (lindex !== -1) {
|
||||
$scope.links.splice(lindex, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.onClientId = function(data) {
|
||||
$scope.client_id = data;
|
||||
};
|
||||
@ -999,6 +1062,7 @@ var NetworkUIController = function($scope,
|
||||
//Erase the existing state
|
||||
$scope.devices = [];
|
||||
$scope.links = [];
|
||||
$scope.devices_by_name = {};
|
||||
|
||||
var device_map = {};
|
||||
var device_interface_map = {};
|
||||
@ -1043,6 +1107,9 @@ var NetworkUIController = function($scope,
|
||||
device.y,
|
||||
device.device_type,
|
||||
device.host_id);
|
||||
if (device.variables !== undefined) {
|
||||
new_device.variables = device.variables;
|
||||
}
|
||||
|
||||
for (j=0; j < $scope.inventory_toolbox.items.length; j++) {
|
||||
if($scope.inventory_toolbox.items[j].name === device.name) {
|
||||
@ -1053,6 +1120,7 @@ var NetworkUIController = function($scope,
|
||||
new_device.interface_seq = util.natural_numbers(device.interface_id_seq);
|
||||
new_device.process_id_seq = util.natural_numbers(device.process_id_seq);
|
||||
$scope.devices.push(new_device);
|
||||
$scope.devices_by_name[new_device.name] = new_device;
|
||||
device_map[device.id] = new_device;
|
||||
device_interface_map[device.id] = {};
|
||||
for (j = 0; j < device.interfaces.length; j++) {
|
||||
@ -1062,6 +1130,7 @@ var NetworkUIController = function($scope,
|
||||
new_intf.device = new_device;
|
||||
device_interface_map[device.id][intf.id] = new_intf;
|
||||
new_device.interfaces.push(new_intf);
|
||||
new_device.interfaces_by_name[new_intf.name] = new_intf;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1131,6 +1200,9 @@ var NetworkUIController = function($scope,
|
||||
device.y,
|
||||
device.device_type,
|
||||
device.host_id);
|
||||
if (device.variables !== undefined) {
|
||||
new_device.variables = device.variables;
|
||||
}
|
||||
$scope.inventory_toolbox.items.push(new_device);
|
||||
}
|
||||
console.log($scope.inventory_toolbox.items);
|
||||
|
@ -180,7 +180,7 @@ _Present.prototype.onDownloadRecordingButton = function(controller) {
|
||||
controller.scope.onDownloadRecordingButton();
|
||||
};
|
||||
|
||||
_Present.prototype.onNoop = function(controller, msg_type, message) {
|
||||
_Present.prototype.onNoop = function() {
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user