def _extract_datacenter_options(all_options): """ This method extracts all available datacenters from the all_options dict. :param dict all_options: The all_options dictionary produced by the get_create_options() API call. """ # Reference for data center codes to give them a prettier name. datacenters = { 'ams01': 'Amsterdam', 'dal01': 'Dallas (1)', 'dal05': 'Dallas (5)', 'sea01': 'Seattle', 'sjc01': 'San Jose', 'sng01': 'Singapore', 'wdc01': 'Washington, D.C.' } results = [] # Load and sort all data centers for option in all_options['datacenters']: name = lookup(option, 'template', 'datacenter', 'name') if name and name in datacenters: name = datacenters[name] results.append((lookup(option, 'template', 'datacenter', 'name'), name)) results = sorted(results) return results
def _extract_memory_options(all_options): """ This method extracts all memory options from the all_options dict. :param dict all_options: The all_options dictionary produced by the get_create_options() API call. """ results = [] # Load and sort memory options for option in all_options['memory']: results.append((str(lookup(option, 'template', 'maxMemory')), lookup(option, 'itemPrice', 'item', 'description'))) return results
def render(self): mask = set([ 'openTickets[id, status[name], group[name]]', 'ticketsClosedTodayCount', 'ticketsClosedInTheLastThreeDaysCount', ]) stats = get_client()['Account'].getObject(mask='mask[%s]' % ','.join(mask)) tickets = { 'closed_today': stats['ticketsClosedTodayCount'], 'closed_3days': stats['ticketsClosedInTheLastThreeDaysCount'], 'open': { 'total': len(stats['openTickets']), }, } for ticket in stats['openTickets']: category = lookup(ticket, 'group', 'name') if not category: category = 'Other' if category not in tickets['open']: tickets['open'][category] = 0 tickets['open'][category] += 1 return render_template('ticket_widget_stats.html', tickets=tickets)
def _extract_processor_options(all_options): """ This method extracts all processor options from the all_options dict. :param dict all_options: The all_options dictionary produced by the get_create_options() API call. """ results = [] # Load all processor options except for those tied to # dedicated account hosts for option in all_options['processors']: if 'dedicatedAccountHostOnlyFlag' not in option['template'] \ or not lookup(option, 'template', 'dedicatedAccountHostOnlyFlag'): results.append((str(lookup(option, 'template', 'startCpus')), lookup(option, 'itemPrice', 'item', 'description') )) return results
def _extract_processor_options(all_options): """ This method extracts all processor options from the all_options dict. :param dict all_options: The all_options dictionary produced by the get_create_options() API call. """ results = [] # Load all processor options except for those tied to # dedicated account hosts for option in all_options['processors']: if 'dedicatedAccountHostOnlyFlag' not in option['template'] \ or not lookup(option, 'template', 'dedicatedAccountHostOnlyFlag'): results.append((str(lookup(option, 'template', 'startCpus')), lookup(option, 'itemPrice', 'item', 'description'))) return results
def _extract_os_options(all_options): """ This method extracts all O/S options from the all_options dict. :param dict all_options: The all_options dictionary produced by the get_create_options() API call. """ results = [] # Load and sort available operating systems # TODO - Turn this into relational fields for option in all_options['operatingSystems']: # Remove premium operating systems from the list recurring_fee = int(lookup(option, 'itemPrice', 'recurringFee')) if not recurring_fee: results.append( (lookup(option, 'template', 'operatingSystemReferenceCode'), lookup(option, 'itemPrice', 'item', 'description'))) return sorted(results)
def _extract_os_options(all_options): """ This method extracts all O/S options from the all_options dict. :param dict all_options: The all_options dictionary produced by the get_create_options() API call. """ results = [] # Load and sort available operating systems # TODO - Turn this into relational fields for option in all_options['operatingSystems']: # Remove premium operating systems from the list recurring_fee = int(lookup(option, 'itemPrice', 'recurringFee')) if not recurring_fee: results.append((lookup(option, 'template', 'operatingSystemReferenceCode'), lookup(option, 'itemPrice', 'item', 'description'))) return sorted(results)
def get_password(object_id, username): """ This function is called via AJAX to retrieve the root/admin password for the specified machine and account. :param int object_id: The server ID to retrieve the password for. :param string username: The specific admin account that owns the password. """ server = manager.get_server(object_id, True) if not server: return 'Invalid account' password = '******' for account in lookup(server, 'operatingSystem', 'passwords'): if username == account['username']: password = account['password'] return password
def _extract_hw_data(hw): return_data = { "id": hw.get("id", None), "hostname": hw.get("hostname"), "domain": hw.get("domain"), "fqdn": hw.get("fullyQualifiedDomainName", None), "datacenter": hw.get("datacenter", {}).get("name", None), "public": hw.get("primaryIpAddress", None), "private": hw.get("primaryBackendIpAddress", None), "cpu": hw.get("processorCoreAmount", None), "memory": hw.get("memoryCapacity", None), } if hw.get("activeTransaction"): active = False # print hw['activeTransaction'] status = lookup(hw, "activeTransaction", "transactionStatus", "friendlyName") if not status: status = "Unknown status" else: active = True status = "Running" return_data["active"] = active return_data["status"] = status # status_id = hw.get('hardwareStatusId') # if status_id == 5: # return_data['active'] = True # else: # return_data['active'] = False os_block = lookup(hw, "operatingSystem", "softwareLicense", "softwareDescription") if os_block: return_data["os"] = os_block["name"] + " " + os_block["version"] if lookup(hw, "operatingSystem", "passwords"): usernames = [] for username in lookup(hw, "operatingSystem", "passwords"): usernames.append(username["username"]) return_data["usernames"] = usernames if hw.get("networkComponents"): network = [] for comp in hw.get("networkComponents"): net = { "status": comp["status"], "speed": comp["speed"], "maxSpeed": comp["maxSpeed"], "name": comp["name"], "port": comp.get("port"), } if comp.get("macAddress"): net["mac"] = comp.get("macAddress") elif comp.get("ipmiMacAddress"): net["mac"] = comp.get("ipmiMacAddress") if comp.get("primaryIpAddress"): net["ip"] = comp.get("primaryIpAddress") elif comp.get("ipmiIpAddress"): net["ip"] = comp.get("ipmiIpAddress") if comp.get("primarySubnet"): subnet = { "netmask": lookup(comp, "primarySubnet", "netmask"), "broadcast": lookup(comp, "primarySubnet", "broadcastAddress"), "gateway": lookup(comp, "primarySubnet", "gateway"), "network_identifier": lookup(comp, "primarySubnet", "networkIdentifier"), } net["subnet"] = subnet network.append(net) return_data["network"] = network return return_data
def _extract_instance_data(instance): """ This option takes an instance record from the API and extracts its useful data into a flattened dictionary. :param dict instance: The instance dictionary from the API. """ if instance.get('activeTransaction'): active = False status = lookup(instance, 'activeTransaction', 'transactionStatus', 'friendlyName') if not status: status = 'Unknown status' elif instance['powerState'].get('keyName') == 'HALTED': active = False status = 'Stopped' else: active = True status = 'Running' tagReferencesList = instance.get('tagReferences', None) if not tagReferencesList: tag = 'None' else: tags = [] for tagReference in tagReferencesList: tags.append(tagReference['tag']['name']) tag = ", ".join(tags) return_data = { 'id': instance.get('id', None), 'hostname': instance.get('hostname'), 'domain': instance.get('domain'), 'fqdn': instance.get('fullyQualifiedDomainName', None), 'datacenter': instance.get('datacenter', {}).get('name', None), 'public': instance.get('primaryIpAddress', None), 'private': instance.get('primaryBackendIpAddress', None), 'cpu': instance.get('maxCpu', None), 'memory': instance.get('maxMemory', None), 'active': active, 'status': status, 'notes': instance.get('notes'), 'userdata': instance.get('userdata'), 'tags': tag } os_block = lookup(instance, 'operatingSystem', 'softwareLicense', 'softwareDescription') if os_block: return_data['os'] = os_block['name'] + ' ' + os_block['version'] return_data['os_code'] = os_block['referenceCode'] if lookup(instance, 'operatingSystem', 'passwords'): usernames = [] for username in lookup(instance, 'operatingSystem', 'passwords'): usernames.append(username['username']) return_data['usernames'] = usernames if instance.get('networkComponents'): network = [] for comp in instance.get('networkComponents'): net = {'status': comp['status'], 'speed': comp['speed'], 'maxSpeed': comp['maxSpeed'], 'name': comp['name'], 'port': comp.get('port'), 'id': comp['id'], } if comp.get('macAddress'): net['mac'] = comp.get('macAddress') if comp.get('primaryIpAddress'): net['ip'] = comp.get('primaryIpAddress') if comp.get('primarySubnet'): subnet = {'netmask': lookup(comp, 'primarySubnet', 'netmask'), 'broadcast': lookup(comp, 'primarySubnet', 'broadcastAddress'), 'gateway': lookup(comp, 'primarySubnet', 'gateway'), 'network_identifier': lookup(comp, 'primarySubnet', 'networkIdentifier'), } net['subnet'] = subnet network.append(net) return_data['network'] = network return return_data
def _extract_instance_data(instance): """ This option takes an instance record from the API and extracts its useful data into a flattened dictionary. :param dict instance: The instance dictionary from the API. """ if instance.get('activeTransaction'): active = False status = lookup(instance, 'activeTransaction', 'transactionStatus', 'friendlyName') if not status: status = 'Unknown status' elif instance['powerState'].get('keyName') == 'HALTED': active = False status = 'Stopped' else: active = True status = 'Running' tagReferencesList = instance.get('tagReferences', None) if not tagReferencesList: tag = 'None' else: tags = [] for tagReference in tagReferencesList: tags.append(tagReference['tag']['name']) tag = ", ".join(tags) return_data = { 'id': instance.get('id', None), 'hostname': instance.get('hostname'), 'domain': instance.get('domain'), 'fqdn': instance.get('fullyQualifiedDomainName', None), 'datacenter': instance.get('datacenter', {}).get('name', None), 'public': instance.get('primaryIpAddress', None), 'private': instance.get('primaryBackendIpAddress', None), 'cpu': instance.get('maxCpu', None), 'memory': instance.get('maxMemory', None), 'active': active, 'status': status, 'notes': instance.get('notes'), 'userdata': instance.get('userdata'), 'tags': tag } os_block = lookup(instance, 'operatingSystem', 'softwareLicense', 'softwareDescription') if os_block: return_data['os'] = os_block['name'] + ' ' + os_block['version'] return_data['os_code'] = os_block['referenceCode'] if lookup(instance, 'operatingSystem', 'passwords'): usernames = [] for username in lookup(instance, 'operatingSystem', 'passwords'): usernames.append(username['username']) return_data['usernames'] = usernames if instance.get('networkComponents'): network = [] for comp in instance.get('networkComponents'): net = { 'status': comp['status'], 'speed': comp['speed'], 'maxSpeed': comp['maxSpeed'], 'name': comp['name'], 'port': comp.get('port'), 'id': comp['id'], } if comp.get('macAddress'): net['mac'] = comp.get('macAddress') if comp.get('primaryIpAddress'): net['ip'] = comp.get('primaryIpAddress') if comp.get('primarySubnet'): subnet = { 'netmask': lookup(comp, 'primarySubnet', 'netmask'), 'broadcast': lookup(comp, 'primarySubnet', 'broadcastAddress'), 'gateway': lookup(comp, 'primarySubnet', 'gateway'), 'network_identifier': lookup(comp, 'primarySubnet', 'networkIdentifier'), } net['subnet'] = subnet network.append(net) return_data['network'] = network return return_data
def _extract_hw_data(hw): return_data = { 'id': hw.get('id', None), 'hostname': hw.get('hostname'), 'domain': hw.get('domain'), 'fqdn': hw.get('fullyQualifiedDomainName', None), 'datacenter': hw.get('datacenter', {}).get('name', None), 'public': hw.get('primaryIpAddress', None), 'private': hw.get('primaryBackendIpAddress', None), 'cpu': hw.get('processorCoreAmount', None), 'memory': hw.get('memoryCapacity', None), } if hw.get('activeTransaction'): active = False # print hw['activeTransaction'] status = lookup(hw, 'activeTransaction', 'transactionStatus', 'friendlyName') if not status: status = 'Unknown status' else: active = True status = 'Running' return_data['active'] = active return_data['status'] = status # status_id = hw.get('hardwareStatusId') # if status_id == 5: # return_data['active'] = True # else: # return_data['active'] = False os_block = lookup(hw, 'operatingSystem', 'softwareLicense', 'softwareDescription') if os_block: return_data['os'] = os_block['name'] + ' ' + os_block['version'] if lookup(hw, 'operatingSystem', 'passwords'): usernames = [] for username in lookup(hw, 'operatingSystem', 'passwords'): usernames.append(username['username']) return_data['usernames'] = usernames if hw.get('networkComponents'): network = [] for comp in hw.get('networkComponents'): net = { 'status': comp['status'], 'speed': comp['speed'], 'maxSpeed': comp['maxSpeed'], 'name': comp['name'], 'port': comp.get('port'), } if comp.get('macAddress'): net['mac'] = comp.get('macAddress') elif comp.get('ipmiMacAddress'): net['mac'] = comp.get('ipmiMacAddress') if comp.get('primaryIpAddress'): net['ip'] = comp.get('primaryIpAddress') elif comp.get('ipmiIpAddress'): net['ip'] = comp.get('ipmiIpAddress') if comp.get('primarySubnet'): subnet = { 'netmask': lookup(comp, 'primarySubnet', 'netmask'), 'broadcast': lookup(comp, 'primarySubnet', 'broadcastAddress'), 'gateway': lookup(comp, 'primarySubnet', 'gateway'), 'network_identifier': lookup(comp, 'primarySubnet', 'networkIdentifier'), } net['subnet'] = subnet network.append(net) return_data['network'] = network return return_data