From b9d4fc2bb9ac42928edea6ab5958fe3c7127036c Mon Sep 17 00:00:00 2001 From: Ben Thomasson Date: Thu, 8 Mar 2018 22:32:35 -0500 Subject: [PATCH] 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 --- awx/ui/client/src/network-ui/fsm.js | 2 +- awx/ui/client/src/network-ui/mode.fsm.js | 13 -- awx/ui/client/src/network-ui/models.js | 25 +-- awx/ui/client/src/network-ui/move.fsm.js | 58 +++++++ .../src/network-ui/network.ui.controller.js | 164 +++++++++++++----- awx/ui/client/src/network-ui/time.fsm.js | 2 +- 6 files changed, 181 insertions(+), 83 deletions(-) diff --git a/awx/ui/client/src/network-ui/fsm.js b/awx/ui/client/src/network-ui/fsm.js index e66e865a57..ffd833623d 100644 --- a/awx/ui/client/src/network-ui/fsm.js +++ b/awx/ui/client/src/network-ui/fsm.js @@ -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) { diff --git a/awx/ui/client/src/network-ui/mode.fsm.js b/awx/ui/client/src/network-ui/mode.fsm.js index 2ef48e177f..22cfeec656 100644 --- a/awx/ui/client/src/network-ui/mode.fsm.js +++ b/awx/ui/client/src/network-ui/mode.fsm.js @@ -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); -}; - diff --git a/awx/ui/client/src/network-ui/models.js b/awx/ui/client/src/network-ui/models.js index b2b9f16204..2a25033ed5 100644 --- a/awx/ui/client/src/network-ui/models.js +++ b/awx/ui/client/src/network-ui/models.js @@ -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) { diff --git a/awx/ui/client/src/network-ui/move.fsm.js b/awx/ui/client/src/network-ui/move.fsm.js index 0a99d2b235..66444ae68a 100644 --- a/awx/ui/client/src/network-ui/move.fsm.js +++ b/awx/ui/client/src/network-ui/move.fsm.js @@ -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); }; diff --git a/awx/ui/client/src/network-ui/network.ui.controller.js b/awx/ui/client/src/network-ui/network.ui.controller.js index 433f4ed807..f80ee71c27 100644 --- a/awx/ui/client/src/network-ui/network.ui.controller.js +++ b/awx/ui/client/src/network-ui/network.ui.controller.js @@ -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