Esempio n. 1
0
def add_instance(request, group_name):
    params = request.POST
    num = int(params["instanceCnt"])
    subnet = None
    asg_status = params['asgStatus']
    launch_in_asg = True
    if 'subnet' in params:
        subnet = params['subnet']
        if asg_status == 'UNKNOWN':
            launch_in_asg = False
        elif 'customSubnet' in params:
            launch_in_asg = False
    try:
        if not launch_in_asg:
            host_ids = groups_helper.launch_instance_in_group(request, group_name, num, subnet)
            if len(host_ids) > 0:
                content = '{} hosts have been launched to group {} (host ids: {})'.format(num, group_name, host_ids)
                messages.add_message(request, messages.SUCCESS, content)
            else:
                content = 'Failed to launch hosts to group {}. Please make sure the' \
                          ' <a href="https://deploy.pinadmin.com/groups/{}/config/">group config</a>' \
                          ' is correct. If you have any question, please contact your friendly Teletraan owners' \
                          ' for immediate assistance!'.format(group_name, group_name)
                messages.add_message(request, messages.ERROR, content)
        else:
            groups_helper.launch_instance_in_group(request, group_name, num, None)
            content = 'Capacity increased by {} for Auto Scaling Group {}. Please go to ' \
                      '<a href="https://deploy.pinadmin.com/groups/{}/">group page</a> ' \
                      'to check new hosts information.'.format(num, group_name, group_name)
            messages.add_message(request, messages.SUCCESS, content)
    except:
        log.error(traceback.format_exc())
        raise
    return redirect('/groups/{}'.format(group_name))
Esempio n. 2
0
def add_instance(request, group_name):
    params = request.POST
    asgStatus = params["asgStatus"]
    instanceCnt = int(params["instanceCnt"])
    subnet = ""
    try:
        if asgStatus == "ENABLED":
            groups_helper.launch_instance_in_group(request, group_name, instanceCnt, subnet)
            content = (
                "Capacity increased by {} for Auto Scaling Group {}. Please go to "
                '<a href="https://deploy.pinadmin.com/groups/{}/">group page</a> '
                "to check new hosts information.".format(instanceCnt, group_name, group_name)
            )
            messages.add_message(request, messages.SUCCESS, content)
        elif asgStatus == "DISABLED":
            content = (
                "This Auto Scaling Group {} is disabled."
                ' Please go to <a href="https://deploy.pinadmin.com/groups/{}/config/">group config</a>'
                " to enable it.".format(group_name, group_name)
            )
            messages.add_message(request, messages.ERROR, content)
        else:
            if "subnet" in params:
                subnet = params["subnet"]
            instanceIds = groups_helper.launch_instance_in_group(request, group_name, instanceCnt, subnet)
            if len(instanceIds) > 0:
                content = "{} instances have been launched to group {} (instance ids: {})".format(
                    instanceCnt, group_name, instanceIds
                )
                messages.add_message(request, messages.SUCCESS, content)
            else:
                content = (
                    "Failed to launch instances to group {}. Please make sure the"
                    ' <a href="https://deploy.pinadmin.com/groups/{}/config/">group config</a>'
                    " is correct. If you have any question, please contact your friendly Teletraan owners"
                    " for immediate assistance!".format(group_name, group_name)
                )
                messages.add_message(request, messages.ERROR, content)
    except:
        log.error(traceback.format_exc())
        raise
    return redirect("/groups/{}".format(group_name))
Esempio n. 3
0
def add_instance(request, name, stage):
    params = request.POST
    groupName = params["groupName"]
    asgStatus = params["asgStatus"]
    instanceCnt = int(params["instanceCnt"])
    subnet = ""
    try:
        if asgStatus == 'ENABLED':
            groups_helper.launch_instance_in_group(request, groupName,
                                                   instanceCnt, subnet)
            content = 'Capacity increased by {} for Auto Scaling Group {}. Please go to ' \
                      '<a href="https://deploy.pinadmin.com/groups/{}/">group page</a> ' \
                      'to check new hosts information.'.format(instanceCnt, groupName, groupName)
            messages.add_message(request, messages.SUCCESS, content)
        elif asgStatus == 'DISABLED':
            content = 'This Auto Scaling Group {} is disabled.' \
                      ' Please go to <a href="https://deploy.pinadmin.com/groups/{}/config/">group config</a>' \
                      ' to enable it.'.format(groupName, groupName)
            messages.add_message(request, messages.ERROR, content)
        else:
            if "subnet" in params:
                subnet = params["subnet"]
            instanceIds = groups_helper.launch_instance_in_group(
                request, groupName, instanceCnt, subnet)
            if len(instanceIds) > 0:
                content = '{} instances have been launched to group {} (instance ids: {})' \
                    .format(instanceCnt, groupName, instanceIds)
                messages.add_message(request, messages.SUCCESS, content)
            else:
                content = 'Failed to launch instances to group {}. Please make sure the' \
                          ' <a href="https://deploy.pinadmin.com/groups/{}/config/">group config</a>' \
                          ' is correct. If you have any question, please contact your friendly Teletraan owners' \
                          ' for immediate assistance!'.format(groupName, groupName)
                messages.add_message(request, messages.ERROR, content)
    except:
        log.error(traceback.format_exc())
        raise
    return redirect('/env/{}/{}/deploy'.format(name, stage))
Esempio n. 4
0
def add_instance(request, group_name):
    params = request.POST
    num = int(params["instanceCnt"])
    subnet = None
    asg_status = params['asgStatus']
    launch_in_asg = True
    if 'subnet' in params:
        subnet = params['subnet']
        if asg_status == 'UNKNOWN':
            launch_in_asg = False
        elif 'customSubnet' in params:
            launch_in_asg = False
    try:
        if not launch_in_asg:
            host_ids = groups_helper.launch_instance_in_group(
                request, group_name, num, subnet)
            if len(host_ids) > 0:
                content = '{} hosts have been launched to group {} (host ids: {})'.format(
                    num, group_name, host_ids)
                messages.add_message(request, messages.SUCCESS, content)
            else:
                content = 'Failed to launch hosts to group {}. Please make sure the' \
                          ' <a href="https://deploy.pinadmin.com/groups/{}/config/">group config</a>' \
                          ' is correct. If you have any question, please contact your friendly Teletraan owners' \
                          ' for immediate assistance!'.format(group_name, group_name)
                messages.add_message(request, messages.ERROR, content)
        else:
            groups_helper.launch_instance_in_group(request, group_name, num,
                                                   None)
            content = 'Capacity increased by {} for Auto Scaling Group {}. Please go to ' \
                      '<a href="https://deploy.pinadmin.com/groups/{}/">group page</a> ' \
                      'to check new hosts information.'.format(num, group_name, group_name)
            messages.add_message(request, messages.SUCCESS, content)
    except:
        log.error(traceback.format_exc())
        raise
    return redirect('/groups/{}'.format(group_name))