def install(alsi=None): from assemblyline.al.common import forge ds = forge.get_datastore() ip = net.get_hostip() mac = net.get_mac_for_ip(ip) existing_reg = ds.get_node(mac) if existing_reg: alsi.info("Registration already exist. Skipping...") return reg = DEFAULT_CORE_REGISTRATION.copy() reg['hostname'] = net.get_hostname() reg['ip'] = ip reg['mac_address'] = mac reg['machine_info'] = sysinfo.get_machine_info() reg['platform'] = sysinfo.get_platform() if 'roles' not in reg: reg['roles'] = [] if "dispatcher" not in reg["roles"]: reg['roles'].append("dispatcher") if "middleman" not in reg["roles"]: reg['roles'].append("middleman") ds.save_node(mac, reg) alsi.info("Core server registered!")
def __init__(self, vmcfg=None): self.disk_root = config.workers.virtualmachines.disk_root if not os.path.exists(self.disk_root): os.makedirs(self.disk_root) self.vmm = None self.cfg = vmcfg if vmcfg is None: self.cfg = get_vmcfg_for_localhost() self.vmrevert_scheduler = None self.host_ip = net.get_hostip() self.host_mac = net.get_mac_for_ip(self.host_ip) self.log = logging.getLogger('assemblyline.vmm') self.vm_profiles = {} self.vmm_lock = threading.Lock() self._state = State.INIT self._hostagent_client = ServiceAgentClient(async=True) self.store = forge.get_datastore() self.vm_configs = {}
def __init__(self): self.ip = net.get_hostip() self.mac = net.get_mac_for_ip(self.ip) self.store = forge.get_datastore() self.log = logging.getLogger('assemblyline.agent') self.log.info('Starting HostAgent: MAC[%s] STORE[%s]' % (self.mac, self.store)) # This hosts registration from riak (Hosts tab in UI). self.registration = None self.service_manager = None self.vm_manager = None self.flex_manager = None self.lock = None self.consumer_thread = None self._should_run = False self.host_profile = {} self.executor_thread = None # Chores are actions that we run periodically and which we coallesce # when the same chore is requested multiple times in the same tick. # Jobs are executed as they are received. self.jobs = LocalQueue() self.last_heartbeat = 0 self.rpc_handlers = { AgentRequest.PING: self.ping, AgentRequest.DRAIN: self.drain, AgentRequest.UNDRAIN: self.undrain, AgentRequest.SHUTDOWN: self.shutdown, AgentRequest.VM_LIST: self.list_vms, AgentRequest.VM_START: self.start_vm, AgentRequest.VM_STOP: self.stop_vm, AgentRequest.VM_STOP_ALL: self.stop_all_vms, AgentRequest.VM_RESTART: self.restart_vm, AgentRequest.VM_REFRESH_ALL: self.refresh_vm_all, AgentRequest.VM_REFRESH_FLEET: self.refresh_vm_fleet, AgentRequest.VM_GET_REVERT_TIMES: self.vm_get_revert_times, AgentRequest.START_SERVICES: self.start_services, AgentRequest.STOP_SERVICES: self.stop_services, } self._should_run = True
def __init__(self): # Delay these imports so most nodes don't import them. global Scheduler from apscheduler.scheduler import Scheduler self.bottleneck_queue_sizes = {} self.cores = None self.datastore = forge.get_datastore() self.flex_profile = None self.flex_scheduler = None self.log = logging.getLogger('assemblyline.flex') self.mac = net.get_mac_for_ip(net.get_hostip()) self.main_bottleneck = '' self.needs_cleanup = True self.previous_queue_sizes = {} self.safe_start_dict = {} self.safeq = NamedQueue('safe-start-%s' % self.mac) self.service_manager = None self.ram_mb = None self.tick_count = 0 self.vm_manager = None
def get_vmcfg_for_localhost(): ip = net.get_hostip() mac = net.get_mac_for_ip(ip) store = forge.get_datastore() host_registration = store.get_node(mac) if not host_registration: raise ConfigException('Could not find host registration fr %s' % mac) profile_name = host_registration.get('profile', None) if not profile_name: raise ConfigException('Could not find profile for host: %s' % mac) host_profile = store.get_profile(profile_name) if not host_profile: raise ConfigException('Could not fetch host profile %s' % profile_name) vm_config = host_profile.get('virtual_machines', None) if not vm_config: raise ConfigException('Could not find virtual machine section in %s' % profile_name) store.client.close() return vm_config
self.stop() except RemoteShutdownInterrupt as ri: msg = 'Shutting down due to remote command: %s' % ri self.log.info(msg) self.stop() except Exception as ex: msg = 'Shutting down due to unhandled exception: %s' % get_stacktrace_info(ex) self.log.error(msg) self.stop() class AgentClient(object): def __init__(self, async=False, sender=None): """ If sender is not specified the local MAC is used """ self.sender = sender or net.get_mac_for_ip(net.get_hostip()) self.async = async def _send_agent_rpc(self, mac, command, args=None): result = send_rpc_comms_queue(ControllerRequest( to=mac, mtype=command, body=args, sender=self.sender), async=self.async) if not self.async: if result: return result.body return 'timeout' else: return result