22import json
33import logging
44
5- from six .moves .urllib .request import urlopen
5+ from six .moves .urllib .request import urlopen , Request
66from six .moves .urllib .parse import urlencode
77
88logger = logging .getLogger ()
@@ -20,12 +20,12 @@ def __init__(self, server, mon_port, hive_id=DEFAULT_HIVE_ID):
2020 hive_id = self .__hive_id
2121 )
2222
23- def __get (self , url , timeout ):
24- u = urlopen (url , timeout = TIMEOUT )
23+ def __post (self , url , timeout ):
24+ u = urlopen (Request ( url , method = 'POST' ) , timeout = TIMEOUT )
2525 u .read ()
2626
2727 def rebalance_all_tablets (self ):
28- self .__get (
28+ self .__post (
2929 self .__url + '&page=Rebalance' ,
3030 timeout = TIMEOUT
3131 )
@@ -39,7 +39,7 @@ def change_tablet_group(self, tablet_id, channels=()):
3939 if channels :
4040 url_lst .append ('channel=' + ',' .join (map (str , channels )))
4141
42- self .__get ('&' .join (url_lst ), timeout = TIMEOUT )
42+ self .__post ('&' .join (url_lst ), timeout = TIMEOUT )
4343
4444 def change_tablet_group_by_tablet_type (self , tablet_type , percent = None , channels = ()):
4545 url_lst = [
@@ -53,17 +53,17 @@ def change_tablet_group_by_tablet_type(self, tablet_type, percent=None, channels
5353 )
5454 if channels :
5555 url_lst .append ('channel=' + ',' .join (map (str , channels )))
56- self .__get ('&' .join (url_lst ), timeout = TIMEOUT )
56+ self .__post ('&' .join (url_lst ), timeout = TIMEOUT )
5757
5858 def kick_tablets_from_node (self , node_id ):
59- self .__get (
59+ self .__post (
6060 self .__url + "&page=KickNode&node={node}" .format (node = node_id ),
6161 timeout = TIMEOUT
6262 )
6363
6464 def block_node (self , node_id , block = True ):
6565 block = '1' if block else '0'
66- self .__get (
66+ self .__post (
6767 self .__url + "&page=SetDown&node={node}&down={down}" .format (node = node_id , down = block ),
6868 timeout = TIMEOUT
6969 )
@@ -72,7 +72,7 @@ def unblock_node(self, node_id):
7272 self .block_node (node_id , block = False )
7373
7474 def change_tablet_weight (self , tablet_id , tablet_weight ):
75- self .__get (
75+ self .__post (
7676 self .__url + "&page=UpdateResources&tablet={tablet}&kv={size}" .format (
7777 tablet = tablet_id ,
7878 size = tablet_weight
@@ -81,7 +81,7 @@ def change_tablet_weight(self, tablet_id, tablet_weight):
8181 )
8282
8383 def change_tablet_cpu_usage (self , tablet_id , cpu_usage ):
84- self .__get (
84+ self .__post (
8585 self .__url + "&page=UpdateResources&tablet={tablet}&cpu={size}" .format (
8686 tablet = tablet_id ,
8787 size = cpu_usage
@@ -93,21 +93,21 @@ def set_min_scatter_to_balance(self, min_scatter_to_balance=101):
9393 """
9494 min_scatter_to_balance=101 -- effectively disables auto rebalancing
9595 """
96- self .__get (
96+ self .__post (
9797 self .__url + "&page=Settings&minScatterToBalance={min_scatter_to_balance}" .format (
9898 min_scatter_to_balance = min_scatter_to_balance ), timeout = TIMEOUT
9999 )
100100
101101 def set_max_scheduled_tablets (self , max_scheduled_tablets = 10 ):
102- self .__get (
102+ self .__post (
103103 self .__url + "&page=Settings&maxScheduledTablets={max_scheduled_tablets}" .format (
104104 max_scheduled_tablets = max_scheduled_tablets
105105 ),
106106 timeout = TIMEOUT
107107 )
108108
109109 def set_max_boot_batch_size (self , max_boot_batch_size = 10 ):
110- self .__get (
110+ self .__post (
111111 self .__url + "&page=Settings&maxBootBatchSize={max_boot_batch_size}" .format (
112112 max_boot_batch_size = max_boot_batch_size
113113 ),
0 commit comments