def code_checker(self):
        try:
            if self.code == '0': # if 3.0
                volume_list = CinderClient().volumelist()
                #volume_list = ['<:volume_list>']
                if len(volume_list) == 0:
                    return self.createJSONResponse("", None, "No Volumes")
                return self.createJSONResponse("", volume_list, self.response)
        except Exception as e:
            SESSION.clear()
            response = "Oops! It failed with - " + str(e)
            if "\n" in response:
                response = response.replace("\n", "")
            return self.createJSONResponse("", None, response)

        "Add other 3.* related stuff."
 def code_checker(self):
     try:
         if self.code == '0':
             if self.is_session_empty('type_of_deployment', SESSION):
                 deploy_list = ['<:all_in_one>']
                 return self.createJSONResponse("type_of_deployment",
                                                deploy_list, self.response,
                                                True)
             elif self.is_session_empty('ipaddress_confirm', SESSION):
                 # ip_list = ['<:192.168.0.46>']
                 return self.createJSONResponse("ipaddress_confirm", None,
                                                self.response, False, True)
             elif self.is_session_empty("deploy_confirm", SESSION):
                 choice_list = ['<:yes>', '<:no>']
                 res = self.response + " Deployment IP: " + SESSION[
                     "ipaddress_confirm"]
                 return self.createJSONResponse("deploy_confirm",
                                                choice_list, res, True)
             else:
                 if SESSION['deploy_confirm'] == 'yes':
                     print SESSION['ipaddress_confirm']
                     DeployOpenStackCloud().deploy(
                         SESSION['ipaddress_confirm'])
                     return self.createJSONResponse(
                         "", None, "We are deploying openstack for you "
                         "please check status <a target='_blank' "
                         "href='/consoleScreen?ip=" +
                         SESSION['ipaddress_confirm'] + "'>Here </a>")
                     SESSION.clear()
                 else:
                     SESSION.clear()
                     res = str(bot.get_response(
                         'deploy_not_confirm')).split(':')[1]
                     return self.createJSONResponse("", None, res)
     except Exception as e:
         response = "Oops! It failed with - " + str(e)
         if "\n" in response:
             response = response.replace("\n", "")
         return self.createJSONResponse("", None, response)
 def code_checker(self):
     try:
         if self.code == '0':
             if self.is_session_empty('cloud_clean_up', SESSION):
                 instance_list = NovaClient().nova_vm_list()
                 network_list = NeutronClient().netlist()
                 # TODO(ndahiwade): Add to the if condition as the cloud
                 # components get added in the future.
                 if len(network_list) == 0 and len(instance_list) == 0:
                     return self.createJSONResponse("", None,
                                                    "No VMs and Networks")
                 res = \
                     str(bot.get_response('Cloud_Clean_up')).split(':')[
                         1]
                 lst = ['<:yes>', '<:no>']
                 return self.createJSONResponse("cloud_clean_up", lst, res,
                                                True)
             else:
                 if SESSION['cloud_clean_up'] == 'yes':
                     # TODO(ndahiwade): Add to the bulk deletion with future
                     # enhancements ( Eg. Storage)
                     NovaClient().nova_vm_delete_all()
                     NeutronClient().net_delete_all()
                     SESSION.clear()
                     res = str(bot.get_response(
                         'Cloud_Clean_Up_Done')).split(':')[1]
                     return self.createJSONResponse("", None, res)
                 elif SESSION['cloud_clean_up'] == 'no':
                     SESSION.clear()
                     res = str(
                         bot.get_response(
                             'Cloud_Clean_Up_Not_Confirm')).split(':')[1]
                     return self.createJSONResponse("", None, res)
     except Exception as e:
         response = "Oops! It failed with - " + str(e)
         if "\n" in response:
             response = response.replace("\n", "")
         return self.createJSONResponse("", None, response)
    def code_checker(self):
        try:
            if self.code == '0':  # if 2.0
                if self.is_session_empty('network_name', SESSION):
                    return self.createJSONResponse("network_name", None,
                                                   self.response, False, True)
                if self.is_session_empty('subnet_name', SESSION):
                    return self.createJSONResponse("subnet_name", None,
                                                   self.response, False, True)
                elif self.is_session_empty('cidr', SESSION):
                    return self.createJSONResponse("cidr", None, self.response,
                                                   False, True)
                elif 'network_name' in SESSION and 'cidr' in SESSION and \
                                'subnet_name' in SESSION:
                    if self.is_session_empty('network_create_confirm',
                                             SESSION):
                        res = '{} Network_Name: {} Subnet_Name: {} CIDR: {}' \
                            .format(
                            str(bot.get_response('Network_Create_Confirm')).
                            split(':')[1], SESSION['network_name'],
                            SESSION['subnet_name'], SESSION['cidr'])
                        lst = ['<:yes>', '<:no>']
                        return self.createJSONResponse(
                            "network_create_confirm", lst, res, True)
                    else:
                        if SESSION['network_create_confirm'] == 'yes':
                            NeutronClient().networkcreate()
                            SESSION.clear()
                            res = str(bot.get_response(
                                'Network_Create_Done')).split(':')[1]
                            return self.createJSONResponse("", None, res)
                        elif SESSION['network_create_confirm'] == 'no':
                            SESSION.clear()
                            res = str(
                                bot.get_response('Network_Create_Not_Confirm')
                            ).split(':')[1]
                            return self.createJSONResponse("", None, res)
        except Exception as e:
            response = "Oops! It failed with - " + str(e)
            if "\n" in response:
                response = response.replace("\n", "")
            return self.createJSONResponse("", None, response)

        try:
            if self.code == '1':  # if 2.1
                network_list = NeutronClient().netlist()
                #network_list = ['<:network>']
                if len(network_list) == 0:
                    return self.createJSONResponse("", None, "No Networks")
                return self.createJSONResponse("", network_list, self.response)
        except Exception as e:
            response = "Oops! It failed with - " + str(e)
            if "\n" in response:
                response = response.replace("\n", "")
            return self.createJSONResponse("", None, response)

        try:
            if self.code == 'd':  # if 2.2
                if self.is_session_empty('network_delete', SESSION):
                    network_list = NeutronClient().netlist()
                    if len(network_list) == 0:
                        return self.createJSONResponse("", None, "No Networks")
                    #network_list = ['<:network>']
                    return self.createJSONResponse("network_delete",
                                                   network_list, self.response,
                                                   True)
                elif 'network_delete' in SESSION:
                    if self.is_session_empty('network_delete_confirm',
                                             SESSION):
                        res = str(bot.get_response(
                            'network_Delete_Confirm')).split(':')[1]
                        lst = ['<:yes>', '<:no>']
                        return self.createJSONResponse(
                            "network_delete_confirm", lst, res, True)
                    else:
                        if SESSION['network_delete_confirm'] == 'yes':
                            NeutronClient().netdelete()
                            SESSION.clear()
                            res = str(bot.get_response(
                                'Network_Delete_Done')).split(':')[1]
                            return self.createJSONResponse("", None, res)
                        elif SESSION['network_delete_confirm'] == 'no':
                            SESSION.clear()
                            res = str(
                                bot.get_response('Network_Delete_Not_Confirm')
                            ).split(':')[1]
                            return self.createJSONResponse("", None, res)
        except Exception as e:
            response = "Oops! It failed with - " + str(e)
            if "\n" in response:
                response = response.replace("\n", "")
            return self.createJSONResponse("", None, response)

        try:
            if self.code == 'D':
                if self.is_session_empty('network_delete_all', SESSION):
                    network_list = NeutronClient().netlist()
                    if len(network_list) == 0:
                        return self.createJSONResponse("", None,
                                                       "No Networks ")
                    res = \
                    str(bot.get_response('network_Delete_all')).split(':')[1]
                    lst = ['<:yes>', '<:no>']
                    return self.createJSONResponse("network_delete_all", lst,
                                                   res, True)
                else:
                    if SESSION['network_delete_all'] == 'yes':
                        NeutronClient().net_delete_all()
                        SESSION.clear()
                        res = str(bot.get_response(
                            'Network_Delete_All_Done')).split(':')[1]
                        return self.createJSONResponse("", None, res)
                    elif SESSION['network_delete_all'] == 'no':
                        SESSION.clear()
                        res = str(
                            bot.get_response('Network_Delete_All_Not_Confirm')
                        ).split(':')[1]
                        return self.createJSONResponse("", None, res)
        except Exception as e:
            response = "Oops! It failed with - " + str(e)
            if "\n" in response:
                response = response.replace("\n", "")
            return self.createJSONResponse("", None, response)

        "Add other 2.* related stuff."
    def code_checker(self):
        try:
            if self.code == '0':  # if 1.0
                if self.is_session_empty('flavor', SESSION):
                    # flavor_list = ['<:m1.tiny>']
                    flavor_list = NovaClient().novaflavorlist()
                    return self.createJSONResponse("flavor", flavor_list,
                                                   self.response, True)
                elif self.is_session_empty('image', SESSION):
                    # image_list = ['<:ubuntu>']
                    image_list = NovaClient().novaimagelist()
                    return self.createJSONResponse("image", image_list,
                                                   self.response, True)
                elif self.is_session_empty('vm_name', SESSION):
                    return self.createJSONResponse("vm_name", None,
                                                   self.response, False, True)
                elif self.is_session_empty('net_name', SESSION):
                    network_list = NeutronClient().netlist()
                    return self.createJSONResponse('net_name', network_list,
                                                   self.response, True)
                elif 'flavor' in SESSION and 'image' in SESSION and 'vm_name'\
                    in SESSION and 'net_name' in SESSION:
                    if self.is_session_empty('vm_create_confirm', SESSION):
                        res = '{} Flavor: {} Image: {} Name: {} Network_Name: {}'\
                            .format(str(bot.get_response('VM_Create_Confirm')).
                                    split(':')[1],SESSION['flavor'],
                                    SESSION['image'],SESSION['vm_name'],
                                    SESSION['net_name'])
                        lst = ['<:yes>', '<:no>']
                        return self.createJSONResponse("vm_create_confirm",
                                                       lst, res, True)
                    else:
                        if SESSION['vm_create_confirm'] == 'yes':
                            NovaClient().novaboot()
                            SESSION.clear()
                            res = \
                            str(bot.get_response('VM_Create_Done')).split(':')[1]
                            return self.createJSONResponse("", None, res)
                        elif SESSION['vm_create_confirm'] == 'no':
                            SESSION.clear()
                            res = \
                            str(bot.get_response('VM_Create_Not_Confirm')).split(
                                ':')[1]
                            return self.createJSONResponse("", None, res)
        except Exception as e:
            response = "Oops! It failed with - " + str(e)
            if "\n" in response:
                response = response.replace("\n", "")
            return self.createJSONResponse("", None, response)

        try:
            if self.code == '1':  # if 1.1
                nova_list = NovaClient().nova_vm_list()
                if len(nova_list) == 0:
                    return self.createJSONResponse("", None, "No VMs")
                return self.createJSONResponse("", nova_list, self.response)
        except Exception as e:
            response = "Oops! It failed with - " + str(e)
            if "\n" in response:
                response = response.replace("\n", "")
            return self.createJSONResponse("", None, response)

        try:
            if self.code == 'd':  # if 1.d
                if self.is_session_empty('vm_delete', SESSION):
                    nova_list = NovaClient().nova_vm_list()
                    if len(nova_list) == 0:
                        return self.createJSONResponse("", None, "No VMs")
                    return self.createJSONResponse("vm_delete", nova_list,
                                                   self.response, True)
                elif 'vm_delete' in SESSION:
                    if self.is_session_empty('vm_delete_confirm', SESSION):
                        res = str(bot.get_response('VM_Delete_Confirm')).split(
                            ':')[1]
                        lst = ['<:yes>', '<:no>']
                        return self.createJSONResponse("vm_delete_confirm",
                                                       lst, res, True)
                    else:
                        if SESSION['vm_delete_confirm'] == 'yes':
                            NovaClient().nova_vm_delete()
                            SESSION.clear()
                            res = \
                            str(bot.get_response('VM_Delete_Done')).split(':')[1]
                            return self.createJSONResponse("", None, res)
                        elif SESSION['vm_delete_confirm'] == 'no':
                            SESSION.clear()
                            res = str(
                                bot.get_response(
                                    'VM_Delete_Not_Confirm').split(':')[1])
                            return self.createJSONResponse("", None, res)
        except Exception as e:
            response = "Oops! It failed with - " + str(e)
            if "\n" in response:
                response = response.replace("\n", "")
            return self.createJSONResponse("", None, response)

        try:
            if self.code == 'D':
                if self.is_session_empty('vm_delete_all', SESSION):
                    nova_list = NovaClient().nova_vm_list()
                    if len(nova_list) == 0:
                        return self.createJSONResponse("", None, "No VMs ")
                    res = \
                    str(bot.get_response('vm_Delete_all')).split(':')[1]
                    lst = ['<:yes>', '<:no>']
                    return self.createJSONResponse("vm_delete_all", lst, res,
                                                   True)
                else:
                    if SESSION['vm_delete_all'] == 'yes':
                        NovaClient().nova_vm_delete_all()
                        SESSION.clear()
                        res = str(bot.get_response(
                            'VM_Delete_All_Done')).split(':')[1]
                        return self.createJSONResponse("", None, res)
                    elif SESSION['vm_delete_all'] == 'no':
                        SESSION.clear()
                        res = str(bot.get_response(
                            'VM_Delete_All_Not_Confirm')).split(':')[1]
                        return self.createJSONResponse("", None, res)
        except Exception as e:
            response = "Oops! It failed with - " + str(e)
            if "\n" in response:
                response = response.replace("\n", "")
            return self.createJSONResponse("", None, response)

        try:
            if self.code == '3':
                avail_zone = NovaClient().avail_zone_session()
                #avail_zone = ['<:az>']
                return self.createJSONResponse("", avail_zone, self.response)
        except Exception as e:
            response = "Oops! It failed with - " + str(e)
            if "\n" in response:
                response = response.replace("\n", "")
            return self.createJSONResponse("", None, response)

        "Add other 1.* related stuff."