Example #1
0
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
Example #2
0
    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)
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
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
Example #7
0
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 ''
Example #8
0
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
Example #9
0
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)
Example #10
0
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
Example #11
0
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)
Example #12
0
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)
Example #13
0
    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
Example #14
0
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)
Example #15
0
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)
Example #16
0
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)
Example #17
0
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)
Example #18
0
def get_sshkey_manager():
    return SshKeyManager(get_client())
Example #19
0
def get_vm_manager():
    return CCIManager(get_client())
Example #20
0
def get_network_manager():
    return NetworkManager(get_client())
Example #21
0
def get_questions():
    return get_client()['User_Security_Question'].getAllObjects()
Example #22
0
def get_vm_manager():
    return CCIManager(get_client())
Example #23
0
def get_dns_manager():
    return DNSManager(get_client())
Example #24
0
def get_questions():
    return get_client()['User_Security_Question'].getAllObjects()
Example #25
0
def get_hardware_manager():
    return HardwareManager(get_client())
Example #26
0
def get_hardware_manager():
    return HardwareManager(get_client())
Example #27
0
def get_ssl_manager():
    return SSLManager(get_client())
Example #28
0
 def render(self):
     mgr = MessagingManager(get_client())
     return render_template('mq_widget_summary.html',
                            accounts=mgr.list_accounts())
Example #29
0
 def render(self):
     mgr = NetworkManager(get_client())
     return render_template('network_widget_summary.html',
                            stats=mgr.summary_by_datacenter())
Example #30
0
def get_dns_manager():
    return DNSManager(get_client())