def get_monthly_create_options(username, package_id): mgr = get_hardware_manager() results = mgr.get_dedicated_server_create_options(package_id) package = get_client()["Product_Package"].getObject(id=package_id, mask="mask[id,name]") results["package_id"] = package_id results["package_name"] = package["name"] # Sort locations by their long name results["locations"] = sorted(results["locations"], key=lambda x: x["long_name"]) groups = {} # Sort items within each category by the sort key, then the capacity key for k, v in results["categories"].items(): group = v["group"] or "Miscellaneous" if group not in groups: groups[group] = {} items = multikeysort(v["items"], ["sort", "capacity", "recurring_fee"]) v["items"] = items groups[group][k] = v # results['categories'][k]['items'] = items results["groups"] = groups 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 get_monthly_create_options(username, package_id): mgr = get_hardware_manager() results = mgr.get_dedicated_server_create_options(package_id) package = get_client()['Product_Package'].getObject(id=package_id, mask="mask[id,name]") results['package_id'] = package_id results['package_name'] = package['name'] # Sort locations by their long name results['locations'] = sorted(results['locations'], key=lambda x: x['long_name']) groups = {} # Sort items within each category by the sort key, then the capacity key for k, v in results['categories'].items(): group = v['group'] or 'Miscellaneous' if group not in groups: groups[group] = {} items = multikeysort(v['items'], ['sort', 'capacity', 'recurring_fee']) v['items'] = items groups[group][k] = v #results['categories'][k]['items'] = items results['groups'] = groups return results
def get_record(record_id): api = get_client()['Dns_Domain_ResourceRecord'] try: record = api.getObject(id=record_id, mask='domain') except SoftLayerAPIError: record = None return record
def global_search(search): client = get_client() match_string = '<span class="text-primary">%s</span>' % search term = re.compile(search, re.IGNORECASE) results = [] if 'vm' in app.config['installed_blueprints']: cci = CCIManager(client) # if hostname_regex.match(term): for vm in cci.list_instances(): if term.match(vm['hostname']) or \ term.match(vm.get('primaryIpAddress', '')): text = '%s (%s)' % (vm['fullyQualifiedDomainName'], vm.get('primaryIpAddress', 'No Public IP')) text = term.sub(match_string, text) results.append({ 'label': '<strong>VM:</strong> ' + text, 'value': url_for('vm_module.view', vm_id=vm['id']) }) if 'servers' in app.config['installed_blueprints']: hw = HardwareManager(client) for svr in hw.list_hardware(): if term.match(svr['hostname']) or \ term.match(svr.get('primaryIpAddress', '')): text = '%s (%s)' % (svr['fullyQualifiedDomainName'], svr.get('primaryIpAddress', 'No Public IP')) text = term.sub(match_string, text) results.append({ 'label': '<strong>Server:</strong> ' + text, 'value': url_for('server_module.view', server_id=svr['id']) }) if 'sshkeys' in app.config['installed_blueprints']: ssh = SshKeyManager(client) for key in ssh.list_keys(): if term.match(key['label']) or term.match(key['fingerprint']): text = '%s (%s)' % (key['label'], key['fingerprint']) text = term.sub(match_string, text) results.append({ 'label': '<strong>SSH Key:</strong> ' + text, 'value': url_for('ssh_module.view', key_id=key['id']) }) return results
def queue_list(account_id): manager = MessagingManager(get_client()) mq_client = manager.get_connection(account_id) queues = mq_client.get_queues()['items'] print queues return ''
def _perform_login(username, remember): client = get_client() if not client['Account'].getObject(): flash('Invalid credentials, please try again.', 'error') return logout() user = models.User.query.filter_by(username=username).first() if user is None: user = models.User(username=username) db.session.add(user) db.session.commit() login_user(user, remember=remember) return user
def index(): account = get_client()['Account'] mask = set([ 'openTickets[id, modifyDate, title, createDate, status[name], ' 'group[name]]', ]) tickets = account.getObject(mask='mask[%s]' % ','.join(mask)) payload = {} payload['title'] = 'List Tickets' payload['tickets'] = tickets['openTickets'] payload['parse_date'] = parse_date return render_template("ticket_index.html", **payload)
def global_search(search): client = get_client() match_string = '<span class="text-primary">%s</span>' % search term = re.compile(search, re.IGNORECASE) results = [] if 'vm' in app.config['installed_blueprints']: cci = CCIManager(client) # if hostname_regex.match(term): for vm in cci.list_instances(): if term.match(vm['hostname']) or \ term.match(vm.get('primaryIpAddress', '')): text = '%s (%s)' % (vm['fullyQualifiedDomainName'], vm.get('primaryIpAddress', 'No Public IP')) text = term.sub(match_string, text) results.append({'label': '<strong>VM:</strong> ' + text, 'value': url_for('vm_module.view', vm_id=vm['id'])}) if 'servers' in app.config['installed_blueprints']: hw = HardwareManager(client) for svr in hw.list_hardware(): if term.match(svr['hostname']) or \ term.match(svr.get('primaryIpAddress', '')): text = '%s (%s)' % (svr['fullyQualifiedDomainName'], svr.get('primaryIpAddress', 'No Public IP')) text = term.sub(match_string, text) results.append({'label': '<strong>Server:</strong> ' + text, 'value': url_for('server_module.view', server_id=svr['id'])}) if 'sshkeys' in app.config['installed_blueprints']: ssh = SshKeyManager(client) for key in ssh.list_keys(): if term.match(key['label']) or term.match(key['fingerprint']): text = '%s (%s)' % (key['label'], key['fingerprint']) text = term.sub(match_string, text) results.append({'label': '<strong>SSH Key:</strong> ' + text, 'value': url_for('ssh_module.view', key_id=key['id'])}) return results
def stop_vm(instance_id): """ Stops a running virtual machine. :param int instance_id: The ID of the virtual machine to stop. """ vg_client = get_client()['Virtual_Guest'] try: vg_client.powerOff(id=instance_id) success = True message = 'Instance is being stopped.' except SoftLayerAPIError as exception: success = False message = str(exception.message) return (success, message)
def get_widget_data(self): if not self.data: mask = set([ 'hardware(SoftLayer_Hardware_Server)[id, datacenter[id, name],' 'hardwareStatus, hostname, outboundPublicBandwidthUsage, ' 'projectedPublicBandwidthUsage, ' 'operatingSystem[softwareLicense[softwareDescription[name]]]]', 'virtualGuests[id, datacenter[id, name], hostname, status,' 'outboundPublicBandwidthUsage, projectedPublicBandwidthUsage,' 'operatingSystem[softwareLicense[softwareDescription[name]]],' 'activeTransaction]', ]) account = get_client()['Account'] self.data = account.getObject(mask='mask[%s]' % ','.join(mask)) return self.data
def reboot_instance(instance_id, soft=True): """ Provides a single interface function for rebooting a VM. :param int instance_id: The ID of the CloudCompute instance to reboot. :param bool soft: Flag to determine if this should be a soft or hard reboot. [Default: true (soft)] """ try: vg = get_client()['Virtual_Guest'] if soft: vg.rebootSoft(id=instance_id) else: vg.rebootHard(id=instance_id) success = True message = 'Reboot request sent to instance.' except SoftLayerAPIError as exception: success = False message = str(exception.message) return (success, message)
def reboot_server(server_id, soft=True): """ Provides a single interface function for rebooting a server. :param int server_id: The ID of the server to reboot. :param bool soft: Flag to determine if this should be a soft or hard reboot. [Default: true (soft)] """ try: vg = get_client()['Hardware_Server'] if soft: vg.rebootSoft(id=server_id) else: vg.rebootHard(id=server_id) success = True message = 'Reboot request sent to instance.' except SoftLayerAPIError as exception: success = False message = str(exception) return (success, message)
def reboot_server(server_id, soft=True): """ Provides a single interface function for rebooting a server. :param int server_id: The ID of the server to reboot. :param bool soft: Flag to determine if this should be a soft or hard reboot. [Default: true (soft)] """ try: vg = get_client()["Hardware_Server"] if soft: vg.rebootSoft(id=server_id) else: vg.rebootHard(id=server_id) success = True message = "Reboot request sent to instance." except SoftLayerAPIError as exception: success = False message = str(exception) return (success, message)
def get_sshkey_manager(): return SshKeyManager(get_client())
def get_vm_manager(): return CCIManager(get_client())
def get_network_manager(): return NetworkManager(get_client())
def get_questions(): return get_client()['User_Security_Question'].getAllObjects()
def get_dns_manager(): return DNSManager(get_client())
def get_hardware_manager(): return HardwareManager(get_client())
def get_ssl_manager(): return SSLManager(get_client())
def render(self): mgr = MessagingManager(get_client()) return render_template('mq_widget_summary.html', accounts=mgr.list_accounts())
def render(self): mgr = NetworkManager(get_client()) return render_template('network_widget_summary.html', stats=mgr.summary_by_datacenter())