Exemple #1
0
def create_subnet(bot, update, user_data):
    network_addr = update.message.text
    net = networkutils.Neutron()
    if networkutils.validate_network(network_addr):
        cidr = ipaddress.ip_network(network_addr)
        if user_data["ip_version"] == cidr.version:
            cidr_list = net.list_cidr(user_data['network_id'])
            if networkutils.check_overlaps(cidr, cidr_list):
                update.message.reply_text(
                    'Overlaps with another subnet. Type again')
            else:
                user_data['cidr'] = network_addr
                user_data['enable_dhcp'] = True
                user_data['gateway_ip'] = None
                # print(user_data)
                net.create_subnet(user_data)
                update.message.reply_text('Create subnet complete')
                return ConversationHandler.END
        else:
            update.message.reply_text(
                'Network Address and IP version are inconsistent. Type again')
    else:
        update.message.reply_text(
            'Incorrect format for network address. Type again')
    return CREATE_SUBNET
Exemple #2
0
def list_network(bot, query):
    list_net = []
    net = networkutils.Neutron()
    for item in net.list_network():
        print('list_network' + '_' + item["id"])

        if item["name"] == '':
            name = item['id']
        else:
            name = item["name"]

        list_net.append([
            InlineKeyboardButton(name,
                                 callback_data='list_network' + '_' +
                                 item["id"])
        ])
    list_net.append([
        InlineKeyboardButton("<< Back to network menu",
                             callback_data='back_network_menu')
    ])
    print(list_net)
    reply_markup = InlineKeyboardMarkup(list_net)
    bot.edit_message_text(text='List networks id:',
                          chat_id=query.message.chat_id,
                          message_id=query.message.message_id,
                          reply_markup=reply_markup)
Exemple #3
0
def list_subnet(bot, query):
    list_subnet = []
    net = networkutils.Neutron()
    query_data = query.data
    network_id = query_data[12:]
    for item in net.list_subnet(network_id):
        print('list_subnet' + ': ' + item["id"])
        if item["name"] == '':
            name = item['id']
        else:
            name = item["name"]
        list_subnet.append([
            InlineKeyboardButton(name,
                                 callback_data='subnet' + '_' + item["id"])
        ])

    list_subnet.append([
        InlineKeyboardButton("<< Back to subnet menu",
                             callback_data='b_subn_menu_' + network_id)
    ])
    reply_markup = InlineKeyboardMarkup(list_subnet)
    if len(list_subnet) > 1:
        text = 'List subnets:'
    else:
        text = 'Empty!'
    bot.edit_message_text(text=text,
                          chat_id=query.message.chat_id,
                          message_id=query.message.message_id,
                          reply_markup=reply_markup)
Exemple #4
0
def delete_network(bot, query):
    net = networkutils.Neutron()
    query_data = query.data
    network_id = query_data[15:]
    net.delete_network(network_id)
    bot.edit_message_text(text="Delete complete",
                          chat_id=query.message.chat_id,
                          message_id=query.message.message_id)
Exemple #5
0
def create_network(bot, update, user_data):
    net = networkutils.Neutron()
    user_data['shared'] = update.callback_query.data
    print(user_data)

    # network_options = {'name': network_name, 'admin_state_up': True, 'shared': False}
    net.create_network(user_data)
    update.callback_query.message.reply_text("Create network complete")
    return ConversationHandler.END
Exemple #6
0
    def networks(self):
        dict_networks = {}
        net = networkutils.Neutron('192.168.100.114', 'admin', 'locdev',
                                   'admin')
        networks_row = net.list_network()
        #        print(networks_row)
        for network in networks_row:
            dict_networks[network['name']] = network['id']
#            print(dict_networks)
        return dict_networks
Exemple #7
0
def detail_network(bot, query):
    net = networkutils.Neutron()
    query_data = query.data
    network_id = query_data[15:]
    network_detail = net.show_network(network_id)
    output = "*Detail network*" + \
             "```" + "\n" + "ID: " + network_detail["id"] + "\n" + \
             "Name: " + network_detail["name"] + "\n" +  \
             "Description: " + network_detail["description"] + "\n" + \
             "Admin state up: " + str(network_detail["admin_state_up"]) + "\n" + \
             "Status: " + network_detail["status"] + "\n" + \
             "```"
    bot.edit_message_text(text=output,
                          chat_id=query.message.chat_id,
                          message_id=query.message.message_id,
                          parse_mode='Markdown')
Exemple #8
0
def detail_subnet(bot, query):
    net = networkutils.Neutron()
    query_data = query.data
    subnet_id = query_data[14:]
    subnet_detail = net.show_subnet(subnet_id)
    output = "*Detail subnet*" + \
             "```" + "\n" + "ID: " + subnet_detail["id"] + "\n" + \
             "Name: " + subnet_detail["name"] + "\n" +  \
             "Description: " + subnet_detail["description"] + "\n" + \
             "IP version: " + str(subnet_detail["ip_version"]) + "\n" + \
             "Cidr: " + subnet_detail["cidr"] + "\n" + \
             "Pool: " + str(subnet_detail["allocation_pools"]) + "\n" + \
             "DNS: " + str(subnet_detail["dns_nameservers"]) + "\n" + \
             "DHCP: " + str(subnet_detail["enable_dhcp"]) + "\n" + \
             "Gateway: " + str(subnet_detail["gateway_ip"]) + "\n" + \
             "```"
    bot.edit_message_text(text=output,
                          chat_id=query.message.chat_id,
                          message_id=query.message.message_id,
                          parse_mode='Markdown')
Exemple #9
0
def check_neutron(bot, update):
    query = update.callback_query
    query_data = query.data
    neu = networkutils.Neutron('192.168.100.114', 'admin', 'locdev', 'admin')
    dict_services = neu.list_agent()
    list_services = []
    for dict_service in dict_services:
        list_service = []
        # print(dict_service)
        list_service.extend([
            dict_service['agent_type'], dict_service['host'],
            str(dict_service['alive'])
        ])
        list_services.append(list_service)
    # print(list_services)
    msg = convert_keyboard_inline(list_services)
    # print(msg)
    # update.message.reply_text("Agent Neutron",
    #                            reply_markup=msg)
    bot.edit_message_reply_markup(chat_id=query.message.chat_id,
                                  message_id=query.message.message_id,
                                  reply_markup=msg)