def _rebuild_instances(self, instances): # TODO: Add a keys_dir to projectSettings ca_dir = os.path.join( self._main_window.projectSettings()["project_files_dir"], "keys") for instance in instances: log.debug('CloudInspectorView._rebuild_instances {}'.format( instance.name)) builder = CloudBuilder(self, self._provider, ca_dir) cloud_instance = CloudInstances.instance().get_instance( instance.id) public_key = cloud_instance.public_key private_key = cloud_instance.private_key # Fake a KeyPair object because we don't store it. keypair = namedtuple('KeyPair', ['private_key', 'public_key'])(private_key, public_key) builder.startAtSetup(instance, keypair) builder.instanceCreated.connect( self._main_window.add_instance_to_project) builder.instanceCreated.connect( CloudInstances.instance().add_instance) builder.instanceIdExists.connect( self._associateBuilderWithInstance) builder.instanceHasIP.connect( CloudInstances.instance().update_host_for_instance) builder.buildComplete.connect(self._instanceBuilt) builder.start() return builder
def createInstance(self, instance_name, flavor_id, image_id): if not instance_name.endswith("-gns3"): instance_name += "-gns3" # TODO: Add a keys_dir to projectSettings ca_dir = os.path.join(self._main_window.projectSettings()["project_files_dir"], "keys") builder = CloudBuilder(self, self._provider, ca_dir) builder.startAtCreate(instance_name, flavor_id, image_id) builder.instanceCreated.connect(self._main_window.add_instance_to_project) builder.instanceCreated.connect(CloudInstances.instance().add_instance) builder.instanceIdExists.connect(self._associateBuilderWithInstance) builder.instanceHasIP.connect(CloudInstances.instance().update_host_for_instance) builder.buildComplete.connect(self._instanceBuilt) builder.start() return builder
def _update_model(self, instances): if not instances: return # Filter instances to only those in the current project project_instances = [i for i in instances if i.id in self._project_instances_id] # populate underlying model if this is the first call if self._model.rowCount() == 0 and len(project_instances) > 0: self._populate_model(project_instances) self._rebuild_instances(project_instances) instance_manager = CloudInstances.instance() instance_manager.update_instances(instances) # Clean up removed instances real = set(i.id for i in project_instances) current = set(self._model.instanceIds) for i in current.difference(real): self._model.removeInstanceById(i) self.uiInstancesTableView.resizeColumnsToContents() # Update instance status for i in project_instances: # get the customized instance state from self._model model_instance = self._model.getInstanceById(i.id) # update model instance state if needed if i.state != RunningInstanceState.RUNNING: self._model.updateInstanceFields(i, ['state'])
def _update_model(self, instances): if not instances: return # Filter instances to only those in the current project project_instances = [ i for i in instances if i.id in self._project_instances_id ] # populate underlying model if this is the first call if self._model.rowCount() == 0 and len(project_instances) > 0: self._populate_model(project_instances) self._rebuild_instances(project_instances) instance_manager = CloudInstances.instance() instance_manager.update_instances(instances) # Clean up removed instances real = set(i.id for i in project_instances) current = set(self._model.instanceIds) for i in current.difference(real): self._model.removeInstanceById(i) self.uiInstancesTableView.resizeColumnsToContents() # Update instance status for i in project_instances: # get the customized instance state from self._model model_instance = self._model.getInstanceById(i.id) # update model instance state if needed if i.state != RunningInstanceState.RUNNING: self._model.updateInstanceFields(i, ['state'])
def createInstance(self, instance_name, flavor_id, image_id): if not instance_name.endswith("-gns3"): instance_name += "-gns3" # TODO: Add a keys_dir to projectSettings ca_dir = os.path.join( self._main_window.projectSettings()["project_files_dir"], "keys") builder = CloudBuilder(self, self._provider, ca_dir) builder.startAtCreate(instance_name, flavor_id, image_id) builder.instanceCreated.connect( self._main_window.add_instance_to_project) builder.instanceCreated.connect(CloudInstances.instance().add_instance) builder.instanceIdExists.connect(self._associateBuilderWithInstance) builder.instanceHasIP.connect( CloudInstances.instance().update_host_for_instance) builder.buildComplete.connect(self._instanceBuilt) builder.start() return builder
def _rebuild_instances(self, instances): # TODO: Add a keys_dir to projectSettings ca_dir = os.path.join(self._main_window.projectSettings()["project_files_dir"], "keys") for instance in instances: log.debug('CloudInspectorView._rebuild_instances {}'.format(instance.name)) builder = CloudBuilder(self, self._provider, ca_dir) cloud_instance = CloudInstances.instance().get_instance(instance.id) public_key = cloud_instance.public_key private_key = cloud_instance.private_key # Fake a KeyPair object because we don't store it. keypair = namedtuple('KeyPair', ['private_key', 'public_key'])(private_key, public_key) builder.startAtSetup(instance, keypair) builder.instanceCreated.connect(self._main_window.add_instance_to_project) builder.instanceCreated.connect(CloudInstances.instance().add_instance) builder.instanceIdExists.connect(self._associateBuilderWithInstance) builder.instanceHasIP.connect(CloudInstances.instance().update_host_for_instance) builder.buildComplete.connect(self._instanceBuilt) builder.start() return builder
def _create_new_instance(self): idx = self.uiCreateInstanceComboBox.currentIndex() flavor_id = self.flavor_index_id[idx] image_id = self._settings['default_image'] name, ok = QInputDialog.getText(self, "New instance", "Choose a name for the instance and press Ok,\n" "then wait for the instance to appear in the inspector.") if ok: create_thread = CreateInstanceThread(self, self._provider, name, flavor_id, image_id) create_thread.instanceCreated.connect(self._main_window.add_instance_to_project) create_thread.instanceCreated.connect(CloudInstances.instance().add_instance) create_thread.start()
def _update_model(self, instances): if not instances: return # populate underlying model if this is the first call if self._model.rowCount() == 0 and len(instances) > 0: self._populate_model(instances) instance_manager = CloudInstances.instance() instance_manager.update_instances(instances) # filter instances to only those in the current project project_instances = [i for i in instances if i.id in self._project_instances_id] for i in project_instances: if i.state != RunningInstanceState.RUNNING: self._model.updateInstanceFields(i, ['state']) # cleanup removed instances real = set(i.id for i in project_instances) current = set(self._model.instanceIds) for i in current.difference(real): self._model.removeInstanceById(i) self.uiInstancesTableView.resizeColumnsToContents() # start gns3server if needed for i in project_instances: # get the real instance state from self._model model_instance = self._model.getInstanceById(i.id) if model_instance.state == RunningInstanceState.RUNNING: # instance state transition: RUNNING --> GNS3SERVER_STARTING model_instance.state = RunningInstanceState.GNS3SERVER_STARTING self._model.updateInstanceFields(model_instance, ['state']) # start GNS3 server and deadman switch public_ip = self._get_public_ip(i.public_ips) instance_manager.update_host_for_instance(i.id, public_ip) topology_instance = instance_manager.get_instance(i.id) ssh_thread = StartGNS3ServerThread( self, public_ip, topology_instance.private_key, i.id, self._provider.username, self._provider.api_key, self._provider.region, 1800) ssh_thread.gns3server_started.connect(self._gns3server_started_slot) ssh_thread.start()