Search is not available for this dataset
identifier
stringlengths 1
155
| parameters
stringlengths 2
6.09k
| docstring
stringlengths 11
63.4k
| docstring_summary
stringlengths 0
63.4k
| function
stringlengths 29
99.8k
| function_tokens
sequence | start_point
sequence | end_point
sequence | language
stringclasses 1
value | docstring_language
stringlengths 2
7
| docstring_language_predictions
stringlengths 18
23
| is_langid_reliable
stringclasses 2
values |
---|---|---|---|---|---|---|---|---|---|---|---|
VL53L1XSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self) -> str:
"""Return the name of the sensor."""
return self._name | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_name"
] | [
80,
4
] | [
82,
25
] | python | en | ['en', 'mi', 'en'] | True |
VL53L1XSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self) -> int:
"""Return the state of the sensor."""
return self._state | [
"def",
"state",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"_state"
] | [
85,
4
] | [
87,
26
] | python | en | ['en', 'en', 'en'] | True |
VL53L1XSensor.unit_of_measurement | (self) | Return the unit of measurement. | Return the unit of measurement. | def unit_of_measurement(self) -> str:
"""Return the unit of measurement."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
90,
4
] | [
92,
40
] | python | en | ['en', 'la', 'en'] | True |
VL53L1XSensor.update | (self) | Get the latest measurement and update state. | Get the latest measurement and update state. | def update(self):
"""Get the latest measurement and update state."""
if self.init:
self.vl53l1x_sensor.add_sensor(self.i2c_address, self.i2c_address)
self.init = False
self.vl53l1x_sensor.start_ranging(self.i2c_address, DEFAULT_RANGE)
self.vl53l1x_sensor.update(self.i2c_address)
self.vl53l1x_sensor.stop_ranging(self.i2c_address)
self._state = self.vl53l1x_sensor.distance | [
"def",
"update",
"(",
"self",
")",
":",
"if",
"self",
".",
"init",
":",
"self",
".",
"vl53l1x_sensor",
".",
"add_sensor",
"(",
"self",
".",
"i2c_address",
",",
"self",
".",
"i2c_address",
")",
"self",
".",
"init",
"=",
"False",
"self",
".",
"vl53l1x_sensor",
".",
"start_ranging",
"(",
"self",
".",
"i2c_address",
",",
"DEFAULT_RANGE",
")",
"self",
".",
"vl53l1x_sensor",
".",
"update",
"(",
"self",
".",
"i2c_address",
")",
"self",
".",
"vl53l1x_sensor",
".",
"stop_ranging",
"(",
"self",
".",
"i2c_address",
")",
"self",
".",
"_state",
"=",
"self",
".",
"vl53l1x_sensor",
".",
"distance"
] | [
94,
4
] | [
102,
50
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Fibaro locks. | Set up the Fibaro locks. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Fibaro locks."""
if discovery_info is None:
return
add_entities(
[FibaroLock(device) for device in hass.data[FIBARO_DEVICES]["lock"]], True
) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"discovery_info",
"is",
"None",
":",
"return",
"add_entities",
"(",
"[",
"FibaroLock",
"(",
"device",
")",
"for",
"device",
"in",
"hass",
".",
"data",
"[",
"FIBARO_DEVICES",
"]",
"[",
"\"lock\"",
"]",
"]",
",",
"True",
")"
] | [
6,
0
] | [
13,
5
] | python | en | ['en', 'et', 'en'] | True |
FibaroLock.__init__ | (self, fibaro_device) | Initialize the Fibaro device. | Initialize the Fibaro device. | def __init__(self, fibaro_device):
"""Initialize the Fibaro device."""
self._state = False
super().__init__(fibaro_device)
self.entity_id = f"{DOMAIN}.{self.ha_id}" | [
"def",
"__init__",
"(",
"self",
",",
"fibaro_device",
")",
":",
"self",
".",
"_state",
"=",
"False",
"super",
"(",
")",
".",
"__init__",
"(",
"fibaro_device",
")",
"self",
".",
"entity_id",
"=",
"f\"{DOMAIN}.{self.ha_id}\""
] | [
19,
4
] | [
23,
49
] | python | en | ['en', 'en', 'en'] | True |
FibaroLock.lock | (self, **kwargs) | Lock the device. | Lock the device. | def lock(self, **kwargs):
"""Lock the device."""
self.action("secure")
self._state = True | [
"def",
"lock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"action",
"(",
"\"secure\"",
")",
"self",
".",
"_state",
"=",
"True"
] | [
25,
4
] | [
28,
26
] | python | en | ['en', 'en', 'en'] | True |
FibaroLock.unlock | (self, **kwargs) | Unlock the device. | Unlock the device. | def unlock(self, **kwargs):
"""Unlock the device."""
self.action("unsecure")
self._state = False | [
"def",
"unlock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"action",
"(",
"\"unsecure\"",
")",
"self",
".",
"_state",
"=",
"False"
] | [
30,
4
] | [
33,
27
] | python | en | ['en', 'zh', 'en'] | True |
FibaroLock.is_locked | (self) | Return true if device is locked. | Return true if device is locked. | def is_locked(self):
"""Return true if device is locked."""
return self._state | [
"def",
"is_locked",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
36,
4
] | [
38,
26
] | python | en | ['en', 'fy', 'en'] | True |
FibaroLock.update | (self) | Update device state. | Update device state. | def update(self):
"""Update device state."""
self._state = self.current_binary_state | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"_state",
"=",
"self",
".",
"current_binary_state"
] | [
40,
4
] | [
42,
47
] | python | en | ['fr', 'en', 'en'] | True |
test_server_sends_200_response | () | test home route works | test home route works | def test_server_sends_200_response():
"""test home route works"""
response = requests.get('http://127.0.0.1:3000')
assert response.status_code == 200
assert '<title> cowsay </title>' in response.text | [
"def",
"test_server_sends_200_response",
"(",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://127.0.0.1:3000'",
")",
"assert",
"response",
".",
"status_code",
"==",
"200",
"assert",
"'<title> cowsay </title>'",
"in",
"response",
".",
"text"
] | [
3,
0
] | [
7,
53
] | python | en | ['en', 'en', 'en'] | True |
test_server_sends_200_response_header | () | test home route works | test home route works | def test_server_sends_200_response_header():
"""test home route works"""
response = requests.get('http://127.0.0.1:3000')
assert response.headers['Server'] == 'BaseHTTP/0.6 Python/3.6.4' | [
"def",
"test_server_sends_200_response_header",
"(",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://127.0.0.1:3000'",
")",
"assert",
"response",
".",
"headers",
"[",
"'Server'",
"]",
"==",
"'BaseHTTP/0.6 Python/3.6.4'"
] | [
10,
0
] | [
13,
68
] | python | en | ['en', 'en', 'en'] | True |
test_server_cowsay_sends_200_response | () | test cowsay route works | test cowsay route works | def test_server_cowsay_sends_200_response():
"""test cowsay route works"""
response = requests.get('http://127.0.0.1:3000/cowsay')
assert response.status_code == 200
assert 'address bar' in response.text | [
"def",
"test_server_cowsay_sends_200_response",
"(",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://127.0.0.1:3000/cowsay'",
")",
"assert",
"response",
".",
"status_code",
"==",
"200",
"assert",
"'address bar'",
"in",
"response",
".",
"text"
] | [
16,
0
] | [
20,
41
] | python | en | ['en', 'en', 'en'] | True |
test_server_cowsay_sends_200_response_header | () | test cowsay route works | test cowsay route works | def test_server_cowsay_sends_200_response_header():
"""test cowsay route works"""
response = requests.get('http://127.0.0.1:3000/cowsay')
assert response.headers['Server'] == 'BaseHTTP/0.6 Python/3.6.4' | [
"def",
"test_server_cowsay_sends_200_response_header",
"(",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://127.0.0.1:3000/cowsay'",
")",
"assert",
"response",
".",
"headers",
"[",
"'Server'",
"]",
"==",
"'BaseHTTP/0.6 Python/3.6.4'"
] | [
23,
0
] | [
26,
68
] | python | en | ['en', 'en', 'en'] | True |
test_server_cow_sends_200_response | () | test message route works | test message route works | def test_server_cow_sends_200_response():
"""test message route works"""
response = requests.get('http://127.0.0.1:3000/cow?msg="hello world"')
assert response.status_code == 200
assert 'hello world' in response.text | [
"def",
"test_server_cow_sends_200_response",
"(",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://127.0.0.1:3000/cow?msg=\"hello world\"'",
")",
"assert",
"response",
".",
"status_code",
"==",
"200",
"assert",
"'hello world'",
"in",
"response",
".",
"text"
] | [
29,
0
] | [
33,
41
] | python | en | ['en', 'en', 'en'] | True |
test_server_cow_sends_200_response_header | () | test message route works | test message route works | def test_server_cow_sends_200_response_header():
"""test message route works"""
response = requests.get('http://127.0.0.1:3000/cow?msg="hello world"')
assert response.headers['Server'] == 'BaseHTTP/0.6 Python/3.6.4' | [
"def",
"test_server_cow_sends_200_response_header",
"(",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://127.0.0.1:3000/cow?msg=\"hello world\"'",
")",
"assert",
"response",
".",
"headers",
"[",
"'Server'",
"]",
"==",
"'BaseHTTP/0.6 Python/3.6.4'"
] | [
36,
0
] | [
39,
68
] | python | en | ['en', 'en', 'en'] | True |
test_server_cow_sends_400_response | () | test cow route sends 400 | test cow route sends 400 | def test_server_cow_sends_400_response():
"""test cow route sends 400"""
response = requests.get('http://127.0.0.1:3000/cow?msg=hello')
assert response.status_code == 400
assert response.text == 'Incorrect format' | [
"def",
"test_server_cow_sends_400_response",
"(",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://127.0.0.1:3000/cow?msg=hello'",
")",
"assert",
"response",
".",
"status_code",
"==",
"400",
"assert",
"response",
".",
"text",
"==",
"'Incorrect format'"
] | [
42,
0
] | [
46,
46
] | python | en | ['en', 'en', 'en'] | True |
test_server_cow_sends_400_response_header | () | test cow route sends 400 | test cow route sends 400 | def test_server_cow_sends_400_response_header():
"""test cow route sends 400"""
response = requests.get('http://127.0.0.1:3000/cow?msg=hello')
assert response.headers['Server'] == 'BaseHTTP/0.6 Python/3.6.4' | [
"def",
"test_server_cow_sends_400_response_header",
"(",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://127.0.0.1:3000/cow?msg=hello'",
")",
"assert",
"response",
".",
"headers",
"[",
"'Server'",
"]",
"==",
"'BaseHTTP/0.6 Python/3.6.4'"
] | [
49,
0
] | [
52,
68
] | python | en | ['en', 'en', 'en'] | True |
test_server_sends_404_response | () | test bad route | test bad route | def test_server_sends_404_response():
"""test bad route"""
response = requests.get('http://127.0.0.1:3000/cowsa')
assert response.status_code == 404
assert response.text == 'Not Found' | [
"def",
"test_server_sends_404_response",
"(",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://127.0.0.1:3000/cowsa'",
")",
"assert",
"response",
".",
"status_code",
"==",
"404",
"assert",
"response",
".",
"text",
"==",
"'Not Found'"
] | [
55,
0
] | [
59,
39
] | python | en | ['en', 'en', 'en'] | True |
test_server_sends_404_response_header | () | test bad route | test bad route | def test_server_sends_404_response_header():
"""test bad route"""
response = requests.get('http://127.0.0.1:3000/cowsa')
assert response.headers['Server'] == 'BaseHTTP/0.6 Python/3.6.4' | [
"def",
"test_server_sends_404_response_header",
"(",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"'http://127.0.0.1:3000/cowsa'",
")",
"assert",
"response",
".",
"headers",
"[",
"'Server'",
"]",
"==",
"'BaseHTTP/0.6 Python/3.6.4'"
] | [
62,
0
] | [
65,
68
] | python | en | ['en', 'en', 'en'] | True |
test_server_cow_post_sends_201_response | () | test post route works | test post route works | def test_server_cow_post_sends_201_response():
"""test post route works"""
response = requests.post('http://127.0.0.1:3000/cow', json={'msg': 'test'})
assert response.status_code == 201
assert 'test' in response.text | [
"def",
"test_server_cow_post_sends_201_response",
"(",
")",
":",
"response",
"=",
"requests",
".",
"post",
"(",
"'http://127.0.0.1:3000/cow'",
",",
"json",
"=",
"{",
"'msg'",
":",
"'test'",
"}",
")",
"assert",
"response",
".",
"status_code",
"==",
"201",
"assert",
"'test'",
"in",
"response",
".",
"text"
] | [
68,
0
] | [
72,
34
] | python | en | ['en', 'en', 'en'] | True |
test_server_cow_post_sends_201_response_header | () | test post route works | test post route works | def test_server_cow_post_sends_201_response_header():
"""test post route works"""
response = requests.post('http://127.0.0.1:3000/cow', json={'msg': 'test'})
assert response.headers['Server'] == 'BaseHTTP/0.6 Python/3.6.4'
assert response.headers['Content-Type'] == 'application/json' | [
"def",
"test_server_cow_post_sends_201_response_header",
"(",
")",
":",
"response",
"=",
"requests",
".",
"post",
"(",
"'http://127.0.0.1:3000/cow'",
",",
"json",
"=",
"{",
"'msg'",
":",
"'test'",
"}",
")",
"assert",
"response",
".",
"headers",
"[",
"'Server'",
"]",
"==",
"'BaseHTTP/0.6 Python/3.6.4'",
"assert",
"response",
".",
"headers",
"[",
"'Content-Type'",
"]",
"==",
"'application/json'"
] | [
75,
0
] | [
79,
65
] | python | en | ['en', 'en', 'en'] | True |
test_server_cow_post_sends_400_response | () | test post route 400 works | test post route 400 works | def test_server_cow_post_sends_400_response():
"""test post route 400 works"""
response = requests.post('http://127.0.0.1:3000/cow?"ms4g=hello')
assert response.status_code == 400
assert response.text == 'Incorrect format' | [
"def",
"test_server_cow_post_sends_400_response",
"(",
")",
":",
"response",
"=",
"requests",
".",
"post",
"(",
"'http://127.0.0.1:3000/cow?\"ms4g=hello'",
")",
"assert",
"response",
".",
"status_code",
"==",
"400",
"assert",
"response",
".",
"text",
"==",
"'Incorrect format'"
] | [
82,
0
] | [
86,
46
] | python | en | ['en', 'en', 'en'] | True |
test_server_cow_post_sends_400_response_header | () | test post route 400 works | test post route 400 works | def test_server_cow_post_sends_400_response_header():
"""test post route 400 works"""
response = requests.post('http://127.0.0.1:3000/cow?"ms4g=hello')
assert response.headers['Server'] == 'BaseHTTP/0.6 Python/3.6.4' | [
"def",
"test_server_cow_post_sends_400_response_header",
"(",
")",
":",
"response",
"=",
"requests",
".",
"post",
"(",
"'http://127.0.0.1:3000/cow?\"ms4g=hello'",
")",
"assert",
"response",
".",
"headers",
"[",
"'Server'",
"]",
"==",
"'BaseHTTP/0.6 Python/3.6.4'"
] | [
89,
0
] | [
92,
68
] | python | en | ['en', 'en', 'en'] | True |
test_server_post_sends_404_response | () | test post route 404 error works | test post route 404 error works | def test_server_post_sends_404_response():
"""test post route 404 error works"""
response = requests.post('http://127.0.0.1:3000/cowsa')
assert response.status_code == 404
assert response.text == 'Not Found' | [
"def",
"test_server_post_sends_404_response",
"(",
")",
":",
"response",
"=",
"requests",
".",
"post",
"(",
"'http://127.0.0.1:3000/cowsa'",
")",
"assert",
"response",
".",
"status_code",
"==",
"404",
"assert",
"response",
".",
"text",
"==",
"'Not Found'"
] | [
95,
0
] | [
99,
39
] | python | en | ['en', 'en', 'en'] | True |
test_server_post_sends_404_response_header | () | test post route 404 error works | test post route 404 error works | def test_server_post_sends_404_response_header():
"""test post route 404 error works"""
response = requests.post('http://127.0.0.1:3000/cowsa')
assert response.headers['Server'] == 'BaseHTTP/0.6 Python/3.6.4' | [
"def",
"test_server_post_sends_404_response_header",
"(",
")",
":",
"response",
"=",
"requests",
".",
"post",
"(",
"'http://127.0.0.1:3000/cowsa'",
")",
"assert",
"response",
".",
"headers",
"[",
"'Server'",
"]",
"==",
"'BaseHTTP/0.6 Python/3.6.4'"
] | [
102,
0
] | [
105,
68
] | python | en | ['en', 'en', 'en'] | True |
MockDevice.__init__ | (self, udn) | Initialize mock device. | Initialize mock device. | def __init__(self, udn):
"""Initialize mock device."""
igd_device = object()
super().__init__(igd_device)
self._udn = udn
self.added_port_mappings = []
self.removed_port_mappings = [] | [
"def",
"__init__",
"(",
"self",
",",
"udn",
")",
":",
"igd_device",
"=",
"object",
"(",
")",
"super",
"(",
")",
".",
"__init__",
"(",
"igd_device",
")",
"self",
".",
"_udn",
"=",
"udn",
"self",
".",
"added_port_mappings",
"=",
"[",
"]",
"self",
".",
"removed_port_mappings",
"=",
"[",
"]"
] | [
18,
4
] | [
24,
39
] | python | en | ['es', 'en', 'en'] | True |
MockDevice.async_create_device | (cls, hass, ssdp_location) | Return self. | Return self. | async def async_create_device(cls, hass, ssdp_location):
"""Return self."""
return cls("UDN") | [
"async",
"def",
"async_create_device",
"(",
"cls",
",",
"hass",
",",
"ssdp_location",
")",
":",
"return",
"cls",
"(",
"\"UDN\"",
")"
] | [
27,
4
] | [
29,
25
] | python | en | ['en', 'ig', 'en'] | False |
MockDevice.udn | (self) | Get the UDN. | Get the UDN. | def udn(self) -> str:
"""Get the UDN."""
return self._udn | [
"def",
"udn",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_udn"
] | [
32,
4
] | [
34,
24
] | python | en | ['en', 'en', 'en'] | True |
MockDevice.manufacturer | (self) | Get manufacturer. | Get manufacturer. | def manufacturer(self) -> str:
"""Get manufacturer."""
return "mock-manufacturer" | [
"def",
"manufacturer",
"(",
"self",
")",
"->",
"str",
":",
"return",
"\"mock-manufacturer\""
] | [
37,
4
] | [
39,
34
] | python | en | ['en', 'da', 'en'] | False |
MockDevice.model_name | (self) | Get the model name. | Get the model name. | def model_name(self) -> str:
"""Get the model name."""
return "mock-model-name" | [
"def",
"model_name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"\"mock-model-name\""
] | [
47,
4
] | [
49,
32
] | python | en | ['en', 'en', 'en'] | True |
MockDevice.device_type | (self) | Get the device type. | Get the device type. | def device_type(self) -> str:
"""Get the device type."""
return "urn:schemas-upnp-org:device:InternetGatewayDevice:1" | [
"def",
"device_type",
"(",
"self",
")",
"->",
"str",
":",
"return",
"\"urn:schemas-upnp-org:device:InternetGatewayDevice:1\""
] | [
52,
4
] | [
54,
68
] | python | en | ['en', 'en', 'en'] | True |
MockDevice._async_add_port_mapping | (
self, external_port: int, local_ip: str, internal_port: int
) | Add a port mapping. | Add a port mapping. | async def _async_add_port_mapping(
self, external_port: int, local_ip: str, internal_port: int
) -> None:
"""Add a port mapping."""
entry = [external_port, local_ip, internal_port]
self.added_port_mappings.append(entry) | [
"async",
"def",
"_async_add_port_mapping",
"(",
"self",
",",
"external_port",
":",
"int",
",",
"local_ip",
":",
"str",
",",
"internal_port",
":",
"int",
")",
"->",
"None",
":",
"entry",
"=",
"[",
"external_port",
",",
"local_ip",
",",
"internal_port",
"]",
"self",
".",
"added_port_mappings",
".",
"append",
"(",
"entry",
")"
] | [
56,
4
] | [
61,
46
] | python | en | ['en', 'en', 'en'] | True |
MockDevice._async_delete_port_mapping | (self, external_port: int) | Remove a port mapping. | Remove a port mapping. | async def _async_delete_port_mapping(self, external_port: int) -> None:
"""Remove a port mapping."""
entry = external_port
self.removed_port_mappings.append(entry) | [
"async",
"def",
"_async_delete_port_mapping",
"(",
"self",
",",
"external_port",
":",
"int",
")",
"->",
"None",
":",
"entry",
"=",
"external_port",
"self",
".",
"removed_port_mappings",
".",
"append",
"(",
"entry",
")"
] | [
63,
4
] | [
66,
48
] | python | en | ['es', 'en', 'en'] | True |
MockDevice.async_get_traffic_data | (self) | Get traffic data. | Get traffic data. | async def async_get_traffic_data(self) -> Mapping[str, any]:
"""Get traffic data."""
return {
TIMESTAMP: dt_util.utcnow(),
BYTES_RECEIVED: 0,
BYTES_SENT: 0,
PACKETS_RECEIVED: 0,
PACKETS_SENT: 0,
} | [
"async",
"def",
"async_get_traffic_data",
"(",
"self",
")",
"->",
"Mapping",
"[",
"str",
",",
"any",
"]",
":",
"return",
"{",
"TIMESTAMP",
":",
"dt_util",
".",
"utcnow",
"(",
")",
",",
"BYTES_RECEIVED",
":",
"0",
",",
"BYTES_SENT",
":",
"0",
",",
"PACKETS_RECEIVED",
":",
"0",
",",
"PACKETS_SENT",
":",
"0",
",",
"}"
] | [
68,
4
] | [
76,
9
] | python | en | ['en', 'kk', 'en'] | True |
_format_inputs | (node: Node) |
Format the inputs of a given node
Parameters
----------
node : Node
a graph node, get and format its inputs
Returns
-------
list
the list of input names
list
the list of input values, if an input is simple type, record its value,
otherwise the value is None
|
Format the inputs of a given node | def _format_inputs(node: Node) -> Tuple[List[str], List[Any]]:
"""
Format the inputs of a given node
Parameters
----------
node : Node
a graph node, get and format its inputs
Returns
-------
list
the list of input names
list
the list of input values, if an input is simple type, record its value,
otherwise the value is None
"""
edges = _sorted_incoming_edges(node)
inputs = []
inputs_value = []
for edge in edges:
if edge.head.name == '_inputs':
assert isinstance(edge.head_slot, int)
if edge.head.operation.io_names is not None:
# when input has names, e.g., forward(self, tensor1, tensor2, another_one)
inputs.append(edge.head.operation.io_names[edge.head_slot])
else:
# when input has no name, e.g., forward(*_inputs)
inputs.append('_inputs[{}]'.format(edge.head_slot))
inputs_value.append(None)
else:
if edge.head_slot is None:
# when the input comes from a single-output operator
inputs.append('{}'.format(edge.head.name))
if edge.head.operation.type in ('prim::Constant', 'prim::GetAttr') and \
'value' in edge.head.operation.parameters:
inputs_value.append(edge.head.operation.parameters['value'])
else:
inputs_value.append(None)
else:
# when the input comes from a multi-output operator: needs to know which one it comes from
inputs.append('{}[{}]'.format(edge.head.name, edge.head_slot))
inputs_value.append(None)
return inputs, inputs_value | [
"def",
"_format_inputs",
"(",
"node",
":",
"Node",
")",
"->",
"Tuple",
"[",
"List",
"[",
"str",
"]",
",",
"List",
"[",
"Any",
"]",
"]",
":",
"edges",
"=",
"_sorted_incoming_edges",
"(",
"node",
")",
"inputs",
"=",
"[",
"]",
"inputs_value",
"=",
"[",
"]",
"for",
"edge",
"in",
"edges",
":",
"if",
"edge",
".",
"head",
".",
"name",
"==",
"'_inputs'",
":",
"assert",
"isinstance",
"(",
"edge",
".",
"head_slot",
",",
"int",
")",
"if",
"edge",
".",
"head",
".",
"operation",
".",
"io_names",
"is",
"not",
"None",
":",
"# when input has names, e.g., forward(self, tensor1, tensor2, another_one)",
"inputs",
".",
"append",
"(",
"edge",
".",
"head",
".",
"operation",
".",
"io_names",
"[",
"edge",
".",
"head_slot",
"]",
")",
"else",
":",
"# when input has no name, e.g., forward(*_inputs)",
"inputs",
".",
"append",
"(",
"'_inputs[{}]'",
".",
"format",
"(",
"edge",
".",
"head_slot",
")",
")",
"inputs_value",
".",
"append",
"(",
"None",
")",
"else",
":",
"if",
"edge",
".",
"head_slot",
"is",
"None",
":",
"# when the input comes from a single-output operator",
"inputs",
".",
"append",
"(",
"'{}'",
".",
"format",
"(",
"edge",
".",
"head",
".",
"name",
")",
")",
"if",
"edge",
".",
"head",
".",
"operation",
".",
"type",
"in",
"(",
"'prim::Constant'",
",",
"'prim::GetAttr'",
")",
"and",
"'value'",
"in",
"edge",
".",
"head",
".",
"operation",
".",
"parameters",
":",
"inputs_value",
".",
"append",
"(",
"edge",
".",
"head",
".",
"operation",
".",
"parameters",
"[",
"'value'",
"]",
")",
"else",
":",
"inputs_value",
".",
"append",
"(",
"None",
")",
"else",
":",
"# when the input comes from a multi-output operator: needs to know which one it comes from",
"inputs",
".",
"append",
"(",
"'{}[{}]'",
".",
"format",
"(",
"edge",
".",
"head",
".",
"name",
",",
"edge",
".",
"head_slot",
")",
")",
"inputs_value",
".",
"append",
"(",
"None",
")",
"return",
"inputs",
",",
"inputs_value"
] | [
37,
0
] | [
80,
31
] | python | en | ['en', 'error', 'th'] | False |
_remove_prefix | (names, graph_name) |
variables name (full name space) is too long,
shorten the name by removing the prefix ```graph_name```
|
variables name (full name space) is too long,
shorten the name by removing the prefix ```graph_name```
| def _remove_prefix(names, graph_name):
"""
variables name (full name space) is too long,
shorten the name by removing the prefix ```graph_name```
"""
if isinstance(names, list):
converted_names = []
for name in names:
if name.startswith(graph_name):
converted_names.append(name[len(graph_name):])
else:
converted_names.append(name)
return converted_names
else:
return names[len(graph_name):] if names.startswith(graph_name) else names | [
"def",
"_remove_prefix",
"(",
"names",
",",
"graph_name",
")",
":",
"if",
"isinstance",
"(",
"names",
",",
"list",
")",
":",
"converted_names",
"=",
"[",
"]",
"for",
"name",
"in",
"names",
":",
"if",
"name",
".",
"startswith",
"(",
"graph_name",
")",
":",
"converted_names",
".",
"append",
"(",
"name",
"[",
"len",
"(",
"graph_name",
")",
":",
"]",
")",
"else",
":",
"converted_names",
".",
"append",
"(",
"name",
")",
"return",
"converted_names",
"else",
":",
"return",
"names",
"[",
"len",
"(",
"graph_name",
")",
":",
"]",
"if",
"names",
".",
"startswith",
"(",
"graph_name",
")",
"else",
"names"
] | [
83,
0
] | [
97,
81
] | python | en | ['en', 'error', 'th'] | False |
UniFiClient.__init__ | (self, client, controller) | Set up client. | Set up client. | def __init__(self, client, controller) -> None:
"""Set up client."""
super().__init__(client, controller)
self._is_wired = client.mac not in controller.wireless_clients | [
"def",
"__init__",
"(",
"self",
",",
"client",
",",
"controller",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"client",
",",
"controller",
")",
"self",
".",
"_is_wired",
"=",
"client",
".",
"mac",
"not",
"in",
"controller",
".",
"wireless_clients"
] | [
9,
4
] | [
13,
70
] | python | en | ['en', 'fr', 'en'] | True |
UniFiClient.is_wired | (self) | Return if the client is wired.
Allows disabling logic to keep track of clients affected by UniFi wired bug marking wireless devices as wired. This is useful when running a network not only containing UniFi APs.
| Return if the client is wired. | def is_wired(self):
"""Return if the client is wired.
Allows disabling logic to keep track of clients affected by UniFi wired bug marking wireless devices as wired. This is useful when running a network not only containing UniFi APs.
"""
if self._is_wired and self.client.mac in self.controller.wireless_clients:
self._is_wired = False
if self.controller.option_ignore_wired_bug:
return self.client.is_wired
return self._is_wired | [
"def",
"is_wired",
"(",
"self",
")",
":",
"if",
"self",
".",
"_is_wired",
"and",
"self",
".",
"client",
".",
"mac",
"in",
"self",
".",
"controller",
".",
"wireless_clients",
":",
"self",
".",
"_is_wired",
"=",
"False",
"if",
"self",
".",
"controller",
".",
"option_ignore_wired_bug",
":",
"return",
"self",
".",
"client",
".",
"is_wired",
"return",
"self",
".",
"_is_wired"
] | [
21,
4
] | [
31,
29
] | python | en | ['en', 'en', 'en'] | True |
UniFiClient.unique_id | (self) | Return a unique identifier for this switch. | Return a unique identifier for this switch. | def unique_id(self):
"""Return a unique identifier for this switch."""
return f"{self.TYPE}-{self.client.mac}" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self.TYPE}-{self.client.mac}\""
] | [
34,
4
] | [
36,
47
] | python | en | ['en', 'en', 'en'] | True |
UniFiClient.name | (self) | Return the name of the client. | Return the name of the client. | def name(self) -> str:
"""Return the name of the client."""
return self.client.name or self.client.hostname | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"client",
".",
"name",
"or",
"self",
".",
"client",
".",
"hostname"
] | [
39,
4
] | [
41,
55
] | python | en | ['en', 'en', 'en'] | True |
UniFiClient.available | (self) | Return if controller is available. | Return if controller is available. | def available(self) -> bool:
"""Return if controller is available."""
return self.controller.available | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"controller",
".",
"available"
] | [
44,
4
] | [
46,
40
] | python | en | ['en', 'en', 'en'] | True |
UniFiClient.device_info | (self) | Return a client description for device registry. | Return a client description for device registry. | def device_info(self) -> dict:
"""Return a client description for device registry."""
return {
"connections": {(CONNECTION_NETWORK_MAC, self.client.mac)},
"default_name": self.name,
"default_manufacturer": self.client.oui,
} | [
"def",
"device_info",
"(",
"self",
")",
"->",
"dict",
":",
"return",
"{",
"\"connections\"",
":",
"{",
"(",
"CONNECTION_NETWORK_MAC",
",",
"self",
".",
"client",
".",
"mac",
")",
"}",
",",
"\"default_name\"",
":",
"self",
".",
"name",
",",
"\"default_manufacturer\"",
":",
"self",
".",
"client",
".",
"oui",
",",
"}"
] | [
49,
4
] | [
55,
9
] | python | ca | ['ca', 'fr', 'en'] | False |
test_sensors | (
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) | Test the creation and values of the IPP sensors. | Test the creation and values of the IPP sensors. | async def test_sensors(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the creation and values of the IPP sensors."""
mock_connection(aioclient_mock)
entry = await init_integration(hass, aioclient_mock, skip_setup=True)
registry = await hass.helpers.entity_registry.async_get_registry()
# Pre-create registry entries for disabled by default sensors
registry.async_get_or_create(
SENSOR_DOMAIN,
DOMAIN,
"cfe92100-67c4-11d4-a45f-f8d027761251_uptime",
suggested_object_id="epson_xp_6000_series_uptime",
disabled_by=None,
)
test_time = datetime(2019, 11, 11, 9, 10, 32, tzinfo=dt_util.UTC)
with patch("homeassistant.components.ipp.sensor.utcnow", return_value=test_time):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("sensor.epson_xp_6000_series")
assert state
assert state.attributes.get(ATTR_ICON) == "mdi:printer"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
state = hass.states.get("sensor.epson_xp_6000_series_black_ink")
assert state
assert state.attributes.get(ATTR_ICON) == "mdi:water"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is PERCENTAGE
assert state.state == "58"
state = hass.states.get("sensor.epson_xp_6000_series_photo_black_ink")
assert state
assert state.attributes.get(ATTR_ICON) == "mdi:water"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is PERCENTAGE
assert state.state == "98"
state = hass.states.get("sensor.epson_xp_6000_series_cyan_ink")
assert state
assert state.attributes.get(ATTR_ICON) == "mdi:water"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is PERCENTAGE
assert state.state == "91"
state = hass.states.get("sensor.epson_xp_6000_series_yellow_ink")
assert state
assert state.attributes.get(ATTR_ICON) == "mdi:water"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is PERCENTAGE
assert state.state == "95"
state = hass.states.get("sensor.epson_xp_6000_series_magenta_ink")
assert state
assert state.attributes.get(ATTR_ICON) == "mdi:water"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is PERCENTAGE
assert state.state == "73"
state = hass.states.get("sensor.epson_xp_6000_series_uptime")
assert state
assert state.attributes.get(ATTR_ICON) == "mdi:clock-outline"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
assert state.state == "2019-10-26T15:37:00+00:00"
entry = registry.async_get("sensor.epson_xp_6000_series_uptime")
assert entry
assert entry.unique_id == "cfe92100-67c4-11d4-a45f-f8d027761251_uptime" | [
"async",
"def",
"test_sensors",
"(",
"hass",
":",
"HomeAssistant",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"mock_connection",
"(",
"aioclient_mock",
")",
"entry",
"=",
"await",
"init_integration",
"(",
"hass",
",",
"aioclient_mock",
",",
"skip_setup",
"=",
"True",
")",
"registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"# Pre-create registry entries for disabled by default sensors",
"registry",
".",
"async_get_or_create",
"(",
"SENSOR_DOMAIN",
",",
"DOMAIN",
",",
"\"cfe92100-67c4-11d4-a45f-f8d027761251_uptime\"",
",",
"suggested_object_id",
"=",
"\"epson_xp_6000_series_uptime\"",
",",
"disabled_by",
"=",
"None",
",",
")",
"test_time",
"=",
"datetime",
"(",
"2019",
",",
"11",
",",
"11",
",",
"9",
",",
"10",
",",
"32",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"with",
"patch",
"(",
"\"homeassistant.components.ipp.sensor.utcnow\"",
",",
"return_value",
"=",
"test_time",
")",
":",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.epson_xp_6000_series\"",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_ICON",
")",
"==",
"\"mdi:printer\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_UNIT_OF_MEASUREMENT",
")",
"is",
"None",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.epson_xp_6000_series_black_ink\"",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_ICON",
")",
"==",
"\"mdi:water\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_UNIT_OF_MEASUREMENT",
")",
"is",
"PERCENTAGE",
"assert",
"state",
".",
"state",
"==",
"\"58\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.epson_xp_6000_series_photo_black_ink\"",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_ICON",
")",
"==",
"\"mdi:water\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_UNIT_OF_MEASUREMENT",
")",
"is",
"PERCENTAGE",
"assert",
"state",
".",
"state",
"==",
"\"98\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.epson_xp_6000_series_cyan_ink\"",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_ICON",
")",
"==",
"\"mdi:water\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_UNIT_OF_MEASUREMENT",
")",
"is",
"PERCENTAGE",
"assert",
"state",
".",
"state",
"==",
"\"91\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.epson_xp_6000_series_yellow_ink\"",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_ICON",
")",
"==",
"\"mdi:water\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_UNIT_OF_MEASUREMENT",
")",
"is",
"PERCENTAGE",
"assert",
"state",
".",
"state",
"==",
"\"95\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.epson_xp_6000_series_magenta_ink\"",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_ICON",
")",
"==",
"\"mdi:water\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_UNIT_OF_MEASUREMENT",
")",
"is",
"PERCENTAGE",
"assert",
"state",
".",
"state",
"==",
"\"73\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.epson_xp_6000_series_uptime\"",
")",
"assert",
"state",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_ICON",
")",
"==",
"\"mdi:clock-outline\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_UNIT_OF_MEASUREMENT",
")",
"is",
"None",
"assert",
"state",
".",
"state",
"==",
"\"2019-10-26T15:37:00+00:00\"",
"entry",
"=",
"registry",
".",
"async_get",
"(",
"\"sensor.epson_xp_6000_series_uptime\"",
")",
"assert",
"entry",
"assert",
"entry",
".",
"unique_id",
"==",
"\"cfe92100-67c4-11d4-a45f-f8d027761251_uptime\""
] | [
14,
0
] | [
80,
75
] | python | en | ['en', 'en', 'en'] | True |
test_disabled_by_default_sensors | (
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) | Test the disabled by default IPP sensors. | Test the disabled by default IPP sensors. | async def test_disabled_by_default_sensors(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the disabled by default IPP sensors."""
await init_integration(hass, aioclient_mock)
registry = await hass.helpers.entity_registry.async_get_registry()
state = hass.states.get("sensor.epson_xp_6000_series_uptime")
assert state is None
entry = registry.async_get("sensor.epson_xp_6000_series_uptime")
assert entry
assert entry.disabled
assert entry.disabled_by == "integration" | [
"async",
"def",
"test_disabled_by_default_sensors",
"(",
"hass",
":",
"HomeAssistant",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"await",
"init_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.epson_xp_6000_series_uptime\"",
")",
"assert",
"state",
"is",
"None",
"entry",
"=",
"registry",
".",
"async_get",
"(",
"\"sensor.epson_xp_6000_series_uptime\"",
")",
"assert",
"entry",
"assert",
"entry",
".",
"disabled",
"assert",
"entry",
".",
"disabled_by",
"==",
"\"integration\""
] | [
83,
0
] | [
96,
45
] | python | en | ['en', 'en', 'en'] | True |
test_missing_entry_unique_id | (
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) | Test the unique_id of IPP sensor when printer is missing identifiers. | Test the unique_id of IPP sensor when printer is missing identifiers. | async def test_missing_entry_unique_id(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the unique_id of IPP sensor when printer is missing identifiers."""
entry = await init_integration(hass, aioclient_mock, uuid=None, unique_id=None)
registry = await hass.helpers.entity_registry.async_get_registry()
entity = registry.async_get("sensor.epson_xp_6000_series")
assert entity
assert entity.unique_id == f"{entry.entry_id}_printer" | [
"async",
"def",
"test_missing_entry_unique_id",
"(",
"hass",
":",
"HomeAssistant",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"entry",
"=",
"await",
"init_integration",
"(",
"hass",
",",
"aioclient_mock",
",",
"uuid",
"=",
"None",
",",
"unique_id",
"=",
"None",
")",
"registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"entity",
"=",
"registry",
".",
"async_get",
"(",
"\"sensor.epson_xp_6000_series\"",
")",
"assert",
"entity",
"assert",
"entity",
".",
"unique_id",
"==",
"f\"{entry.entry_id}_printer\""
] | [
99,
0
] | [
108,
58
] | python | en | ['en', 'en', 'en'] | True |
discover_sensors | (topic, payload) | Given a topic, dynamically create the right sensor type.
Async friendly.
| Given a topic, dynamically create the right sensor type. | def discover_sensors(topic, payload):
"""Given a topic, dynamically create the right sensor type.
Async friendly.
"""
parts = topic.split("/")
unit = payload.get("units", "")
domain = parts[1]
if domain == "temperature":
name = parts[2]
if unit == "F":
unit = TEMP_FAHRENHEIT
else:
unit = TEMP_CELSIUS
return ArwnSensor(topic, name, "temp", unit)
if domain == "moisture":
name = f"{parts[2]} Moisture"
return ArwnSensor(topic, name, "moisture", unit, "mdi:water-percent")
if domain == "rain":
if len(parts) >= 3 and parts[2] == "today":
return ArwnSensor(
topic, "Rain Since Midnight", "since_midnight", "in", "mdi:water"
)
return (
ArwnSensor(topic + "/total", "Total Rainfall", "total", unit, "mdi:water"),
ArwnSensor(topic + "/rate", "Rainfall Rate", "rate", unit, "mdi:water"),
)
if domain == "barometer":
return ArwnSensor(topic, "Barometer", "pressure", unit, "mdi:thermometer-lines")
if domain == "wind":
return (
ArwnSensor(
topic + "/speed", "Wind Speed", "speed", unit, "mdi:speedometer"
),
ArwnSensor(topic + "/gust", "Wind Gust", "gust", unit, "mdi:speedometer"),
ArwnSensor(
topic + "/dir", "Wind Direction", "direction", DEGREE, "mdi:compass"
),
) | [
"def",
"discover_sensors",
"(",
"topic",
",",
"payload",
")",
":",
"parts",
"=",
"topic",
".",
"split",
"(",
"\"/\"",
")",
"unit",
"=",
"payload",
".",
"get",
"(",
"\"units\"",
",",
"\"\"",
")",
"domain",
"=",
"parts",
"[",
"1",
"]",
"if",
"domain",
"==",
"\"temperature\"",
":",
"name",
"=",
"parts",
"[",
"2",
"]",
"if",
"unit",
"==",
"\"F\"",
":",
"unit",
"=",
"TEMP_FAHRENHEIT",
"else",
":",
"unit",
"=",
"TEMP_CELSIUS",
"return",
"ArwnSensor",
"(",
"topic",
",",
"name",
",",
"\"temp\"",
",",
"unit",
")",
"if",
"domain",
"==",
"\"moisture\"",
":",
"name",
"=",
"f\"{parts[2]} Moisture\"",
"return",
"ArwnSensor",
"(",
"topic",
",",
"name",
",",
"\"moisture\"",
",",
"unit",
",",
"\"mdi:water-percent\"",
")",
"if",
"domain",
"==",
"\"rain\"",
":",
"if",
"len",
"(",
"parts",
")",
">=",
"3",
"and",
"parts",
"[",
"2",
"]",
"==",
"\"today\"",
":",
"return",
"ArwnSensor",
"(",
"topic",
",",
"\"Rain Since Midnight\"",
",",
"\"since_midnight\"",
",",
"\"in\"",
",",
"\"mdi:water\"",
")",
"return",
"(",
"ArwnSensor",
"(",
"topic",
"+",
"\"/total\"",
",",
"\"Total Rainfall\"",
",",
"\"total\"",
",",
"unit",
",",
"\"mdi:water\"",
")",
",",
"ArwnSensor",
"(",
"topic",
"+",
"\"/rate\"",
",",
"\"Rainfall Rate\"",
",",
"\"rate\"",
",",
"unit",
",",
"\"mdi:water\"",
")",
",",
")",
"if",
"domain",
"==",
"\"barometer\"",
":",
"return",
"ArwnSensor",
"(",
"topic",
",",
"\"Barometer\"",
",",
"\"pressure\"",
",",
"unit",
",",
"\"mdi:thermometer-lines\"",
")",
"if",
"domain",
"==",
"\"wind\"",
":",
"return",
"(",
"ArwnSensor",
"(",
"topic",
"+",
"\"/speed\"",
",",
"\"Wind Speed\"",
",",
"\"speed\"",
",",
"unit",
",",
"\"mdi:speedometer\"",
")",
",",
"ArwnSensor",
"(",
"topic",
"+",
"\"/gust\"",
",",
"\"Wind Gust\"",
",",
"\"gust\"",
",",
"unit",
",",
"\"mdi:speedometer\"",
")",
",",
"ArwnSensor",
"(",
"topic",
"+",
"\"/dir\"",
",",
"\"Wind Direction\"",
",",
"\"direction\"",
",",
"DEGREE",
",",
"\"mdi:compass\"",
")",
",",
")"
] | [
18,
0
] | [
56,
9
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the ARWN platform. | Set up the ARWN platform. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the ARWN platform."""
@callback
def async_sensor_event_received(msg):
"""Process events as sensors.
When a new event on our topic (arwn/#) is received we map it
into a known kind of sensor based on topic name. If we've
never seen this before, we keep this sensor around in a global
cache. If we have seen it before, we update the values of the
existing sensor. Either way, we push an ha state update at the
end for the new event we've seen.
This lets us dynamically incorporate sensors without any
configuration on our side.
"""
event = json.loads(msg.payload)
sensors = discover_sensors(msg.topic, event)
if not sensors:
return
store = hass.data.get(DATA_ARWN)
if store is None:
store = hass.data[DATA_ARWN] = {}
if isinstance(sensors, ArwnSensor):
sensors = (sensors,)
if "timestamp" in event:
del event["timestamp"]
for sensor in sensors:
if sensor.name not in store:
sensor.hass = hass
sensor.set_event(event)
store[sensor.name] = sensor
_LOGGER.debug(
"Registering sensor %(name)s => %(event)s",
{"name": sensor.name, "event": event},
)
async_add_entities((sensor,), True)
else:
_LOGGER.debug(
"Recording sensor %(name)s => %(event)s",
{"name": sensor.name, "event": event},
)
store[sensor.name].set_event(event)
await mqtt.async_subscribe(hass, TOPIC, async_sensor_event_received, 0)
return True | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"@",
"callback",
"def",
"async_sensor_event_received",
"(",
"msg",
")",
":",
"\"\"\"Process events as sensors.\n\n When a new event on our topic (arwn/#) is received we map it\n into a known kind of sensor based on topic name. If we've\n never seen this before, we keep this sensor around in a global\n cache. If we have seen it before, we update the values of the\n existing sensor. Either way, we push an ha state update at the\n end for the new event we've seen.\n\n This lets us dynamically incorporate sensors without any\n configuration on our side.\n \"\"\"",
"event",
"=",
"json",
".",
"loads",
"(",
"msg",
".",
"payload",
")",
"sensors",
"=",
"discover_sensors",
"(",
"msg",
".",
"topic",
",",
"event",
")",
"if",
"not",
"sensors",
":",
"return",
"store",
"=",
"hass",
".",
"data",
".",
"get",
"(",
"DATA_ARWN",
")",
"if",
"store",
"is",
"None",
":",
"store",
"=",
"hass",
".",
"data",
"[",
"DATA_ARWN",
"]",
"=",
"{",
"}",
"if",
"isinstance",
"(",
"sensors",
",",
"ArwnSensor",
")",
":",
"sensors",
"=",
"(",
"sensors",
",",
")",
"if",
"\"timestamp\"",
"in",
"event",
":",
"del",
"event",
"[",
"\"timestamp\"",
"]",
"for",
"sensor",
"in",
"sensors",
":",
"if",
"sensor",
".",
"name",
"not",
"in",
"store",
":",
"sensor",
".",
"hass",
"=",
"hass",
"sensor",
".",
"set_event",
"(",
"event",
")",
"store",
"[",
"sensor",
".",
"name",
"]",
"=",
"sensor",
"_LOGGER",
".",
"debug",
"(",
"\"Registering sensor %(name)s => %(event)s\"",
",",
"{",
"\"name\"",
":",
"sensor",
".",
"name",
",",
"\"event\"",
":",
"event",
"}",
",",
")",
"async_add_entities",
"(",
"(",
"sensor",
",",
")",
",",
"True",
")",
"else",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Recording sensor %(name)s => %(event)s\"",
",",
"{",
"\"name\"",
":",
"sensor",
".",
"name",
",",
"\"event\"",
":",
"event",
"}",
",",
")",
"store",
"[",
"sensor",
".",
"name",
"]",
".",
"set_event",
"(",
"event",
")",
"await",
"mqtt",
".",
"async_subscribe",
"(",
"hass",
",",
"TOPIC",
",",
"async_sensor_event_received",
",",
"0",
")",
"return",
"True"
] | [
63,
0
] | [
113,
15
] | python | en | ['en', 'da', 'en'] | True |
ArwnSensor.__init__ | (self, topic, name, state_key, units, icon=None) | Initialize the sensor. | Initialize the sensor. | def __init__(self, topic, name, state_key, units, icon=None):
"""Initialize the sensor."""
self.hass = None
self.entity_id = _slug(name)
self._name = name
# This mqtt topic for the sensor which is its uid
self._uid = topic
self._state_key = state_key
self.event = {}
self._unit_of_measurement = units
self._icon = icon | [
"def",
"__init__",
"(",
"self",
",",
"topic",
",",
"name",
",",
"state_key",
",",
"units",
",",
"icon",
"=",
"None",
")",
":",
"self",
".",
"hass",
"=",
"None",
"self",
".",
"entity_id",
"=",
"_slug",
"(",
"name",
")",
"self",
".",
"_name",
"=",
"name",
"# This mqtt topic for the sensor which is its uid",
"self",
".",
"_uid",
"=",
"topic",
"self",
".",
"_state_key",
"=",
"state_key",
"self",
".",
"event",
"=",
"{",
"}",
"self",
".",
"_unit_of_measurement",
"=",
"units",
"self",
".",
"_icon",
"=",
"icon"
] | [
119,
4
] | [
129,
25
] | python | en | ['en', 'en', 'en'] | True |
ArwnSensor.set_event | (self, event) | Update the sensor with the most recent event. | Update the sensor with the most recent event. | def set_event(self, event):
"""Update the sensor with the most recent event."""
self.event = {}
self.event.update(event)
self.async_write_ha_state() | [
"def",
"set_event",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"event",
"=",
"{",
"}",
"self",
".",
"event",
".",
"update",
"(",
"event",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
131,
4
] | [
135,
35
] | python | en | ['en', 'en', 'en'] | True |
ArwnSensor.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return self.event.get(self._state_key, None) | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"event",
".",
"get",
"(",
"self",
".",
"_state_key",
",",
"None",
")"
] | [
138,
4
] | [
140,
52
] | python | en | ['en', 'en', 'en'] | True |
ArwnSensor.name | (self) | Get the name of the sensor. | Get the name of the sensor. | def name(self):
"""Get the name of the sensor."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
143,
4
] | [
145,
25
] | python | en | ['en', 'en', 'en'] | True |
ArwnSensor.unique_id | (self) | Return a unique ID.
This is based on the topic that comes from mqtt
| Return a unique ID. | def unique_id(self):
"""Return a unique ID.
This is based on the topic that comes from mqtt
"""
return self._uid | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_uid"
] | [
148,
4
] | [
153,
24
] | python | ca | ['fr', 'ca', 'en'] | False |
ArwnSensor.state_attributes | (self) | Return all the state attributes. | Return all the state attributes. | def state_attributes(self):
"""Return all the state attributes."""
return self.event | [
"def",
"state_attributes",
"(",
"self",
")",
":",
"return",
"self",
".",
"event"
] | [
156,
4
] | [
158,
25
] | python | en | ['en', 'en', 'en'] | True |
ArwnSensor.unit_of_measurement | (self) | Return the unit of measurement the state is expressed in. | Return the unit of measurement the state is expressed in. | def unit_of_measurement(self):
"""Return the unit of measurement the state is expressed in."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
161,
4
] | [
163,
40
] | python | en | ['en', 'en', 'en'] | True |
ArwnSensor.should_poll | (self) | Return the polling state. | Return the polling state. | def should_poll(self):
"""Return the polling state."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
166,
4
] | [
168,
20
] | python | en | ['en', 'en', 'en'] | True |
ArwnSensor.icon | (self) | Return the icon of device based on its type. | Return the icon of device based on its type. | def icon(self):
"""Return the icon of device based on its type."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
171,
4
] | [
173,
25
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor.create | (create_deployment: dict) | Create MARO Cluster with create_deployment.
Args:
create_deployment (dict): create_deployment of k8s/aks. See lib/deployments/internal for reference.
Returns:
None.
| Create MARO Cluster with create_deployment. | def create(create_deployment: dict) -> None:
"""Create MARO Cluster with create_deployment.
Args:
create_deployment (dict): create_deployment of k8s/aks. See lib/deployments/internal for reference.
Returns:
None.
"""
logger.info("Creating cluster")
# Get standardized cluster_details
cluster_details = K8sAksExecutor._standardize_cluster_details(create_deployment=create_deployment)
cluster_name = cluster_details["name"]
if os.path.isdir(f"{GlobalPaths.ABS_MARO_CLUSTERS}/{cluster_name}"):
raise BadRequestError(f"Cluster '{cluster_name}' is exist")
# Start creating
try:
K8sAksExecutor._create_resource_group(cluster_details=cluster_details)
K8sAksExecutor._create_k8s_cluster(cluster_details=cluster_details)
K8sAksExecutor._load_k8s_context(
cluster_id=cluster_details["id"],
resource_group=cluster_details["cloud"]["resource_group"]
)
K8sAksExecutor._init_redis()
K8sAksExecutor._init_nvidia_plugin()
K8sAksExecutor._create_storage_account_secret(cluster_details=cluster_details)
DetailsWriter.save_cluster_details(cluster_name=cluster_name, cluster_details=cluster_details)
except Exception as e:
# If failed, remove details folder, then raise
shutil.rmtree(f"{GlobalPaths.ABS_MARO_CLUSTERS}/{cluster_name}")
logger.error_red(f"Failed to create cluster '{cluster_name}'")
raise e
logger.info_green(f"Cluster '{cluster_name}' is created") | [
"def",
"create",
"(",
"create_deployment",
":",
"dict",
")",
"->",
"None",
":",
"logger",
".",
"info",
"(",
"\"Creating cluster\"",
")",
"# Get standardized cluster_details",
"cluster_details",
"=",
"K8sAksExecutor",
".",
"_standardize_cluster_details",
"(",
"create_deployment",
"=",
"create_deployment",
")",
"cluster_name",
"=",
"cluster_details",
"[",
"\"name\"",
"]",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"f\"{GlobalPaths.ABS_MARO_CLUSTERS}/{cluster_name}\"",
")",
":",
"raise",
"BadRequestError",
"(",
"f\"Cluster '{cluster_name}' is exist\"",
")",
"# Start creating",
"try",
":",
"K8sAksExecutor",
".",
"_create_resource_group",
"(",
"cluster_details",
"=",
"cluster_details",
")",
"K8sAksExecutor",
".",
"_create_k8s_cluster",
"(",
"cluster_details",
"=",
"cluster_details",
")",
"K8sAksExecutor",
".",
"_load_k8s_context",
"(",
"cluster_id",
"=",
"cluster_details",
"[",
"\"id\"",
"]",
",",
"resource_group",
"=",
"cluster_details",
"[",
"\"cloud\"",
"]",
"[",
"\"resource_group\"",
"]",
")",
"K8sAksExecutor",
".",
"_init_redis",
"(",
")",
"K8sAksExecutor",
".",
"_init_nvidia_plugin",
"(",
")",
"K8sAksExecutor",
".",
"_create_storage_account_secret",
"(",
"cluster_details",
"=",
"cluster_details",
")",
"DetailsWriter",
".",
"save_cluster_details",
"(",
"cluster_name",
"=",
"cluster_name",
",",
"cluster_details",
"=",
"cluster_details",
")",
"except",
"Exception",
"as",
"e",
":",
"# If failed, remove details folder, then raise",
"shutil",
".",
"rmtree",
"(",
"f\"{GlobalPaths.ABS_MARO_CLUSTERS}/{cluster_name}\"",
")",
"logger",
".",
"error_red",
"(",
"f\"Failed to create cluster '{cluster_name}'\"",
")",
"raise",
"e",
"logger",
".",
"info_green",
"(",
"f\"Cluster '{cluster_name}' is created\"",
")"
] | [
48,
4
] | [
83,
65
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._standardize_cluster_details | (create_deployment: dict) | Standardize cluster_details from create_deployment.
We use create_deployment to build cluster_details (they share the same keys structure).
Args:
create_deployment (dict): create_deployment of k8s/aks. See lib/deployments/internal for reference.
Returns:
dict: standardized cluster_details.
| Standardize cluster_details from create_deployment. | def _standardize_cluster_details(create_deployment: dict) -> dict:
"""Standardize cluster_details from create_deployment.
We use create_deployment to build cluster_details (they share the same keys structure).
Args:
create_deployment (dict): create_deployment of k8s/aks. See lib/deployments/internal for reference.
Returns:
dict: standardized cluster_details.
"""
optional_key_to_value = {
"root['master']['redis']": {
"port": GlobalParams.DEFAULT_REDIS_PORT
},
"root['master']['redis']['port']": GlobalParams.DEFAULT_REDIS_PORT
}
with open(f"{K8sPaths.ABS_MARO_K8S_LIB}/deployments/internal/k8s_aks_create.yml") as fr:
create_deployment_template = yaml.safe_load(fr)
DeploymentValidator.validate_and_fill_dict(
template_dict=create_deployment_template,
actual_dict=create_deployment,
optional_key_to_value=optional_key_to_value
)
# Init runtime fields
create_deployment["id"] = NameCreator.create_cluster_id()
return create_deployment | [
"def",
"_standardize_cluster_details",
"(",
"create_deployment",
":",
"dict",
")",
"->",
"dict",
":",
"optional_key_to_value",
"=",
"{",
"\"root['master']['redis']\"",
":",
"{",
"\"port\"",
":",
"GlobalParams",
".",
"DEFAULT_REDIS_PORT",
"}",
",",
"\"root['master']['redis']['port']\"",
":",
"GlobalParams",
".",
"DEFAULT_REDIS_PORT",
"}",
"with",
"open",
"(",
"f\"{K8sPaths.ABS_MARO_K8S_LIB}/deployments/internal/k8s_aks_create.yml\"",
")",
"as",
"fr",
":",
"create_deployment_template",
"=",
"yaml",
".",
"safe_load",
"(",
"fr",
")",
"DeploymentValidator",
".",
"validate_and_fill_dict",
"(",
"template_dict",
"=",
"create_deployment_template",
",",
"actual_dict",
"=",
"create_deployment",
",",
"optional_key_to_value",
"=",
"optional_key_to_value",
")",
"# Init runtime fields",
"create_deployment",
"[",
"\"id\"",
"]",
"=",
"NameCreator",
".",
"create_cluster_id",
"(",
")",
"return",
"create_deployment"
] | [
86,
4
] | [
114,
32
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._create_resource_group | (cluster_details: dict) | Create the resource group if it does not exist.
Args:
cluster_details (dict): details of the cluster.
Returns:
None.
| Create the resource group if it does not exist. | def _create_resource_group(cluster_details: dict) -> None:
"""Create the resource group if it does not exist.
Args:
cluster_details (dict): details of the cluster.
Returns:
None.
"""
# Get params
subscription = cluster_details["cloud"]["subscription"]
resource_group = cluster_details["cloud"]["resource_group"]
# Check if Azure CLI is installed, and print version
azure_version = AzureController.get_version()
logger.info_green(f"Your Azure CLI version: {azure_version['azure-cli']}")
# Set subscription id
AzureController.set_subscription(subscription=subscription)
logger.info_green(f"Set subscription to '{subscription}'")
# Check and create resource group
resource_group_info = AzureController.get_resource_group(resource_group=resource_group)
if resource_group_info:
logger.warning_yellow(f"Azure resource group '{resource_group}' already exists")
else:
AzureController.create_resource_group(
resource_group=resource_group,
location=cluster_details["cloud"]["location"]
)
logger.info_green(f"Resource group '{resource_group}' is created") | [
"def",
"_create_resource_group",
"(",
"cluster_details",
":",
"dict",
")",
"->",
"None",
":",
"# Get params",
"subscription",
"=",
"cluster_details",
"[",
"\"cloud\"",
"]",
"[",
"\"subscription\"",
"]",
"resource_group",
"=",
"cluster_details",
"[",
"\"cloud\"",
"]",
"[",
"\"resource_group\"",
"]",
"# Check if Azure CLI is installed, and print version",
"azure_version",
"=",
"AzureController",
".",
"get_version",
"(",
")",
"logger",
".",
"info_green",
"(",
"f\"Your Azure CLI version: {azure_version['azure-cli']}\"",
")",
"# Set subscription id",
"AzureController",
".",
"set_subscription",
"(",
"subscription",
"=",
"subscription",
")",
"logger",
".",
"info_green",
"(",
"f\"Set subscription to '{subscription}'\"",
")",
"# Check and create resource group",
"resource_group_info",
"=",
"AzureController",
".",
"get_resource_group",
"(",
"resource_group",
"=",
"resource_group",
")",
"if",
"resource_group_info",
":",
"logger",
".",
"warning_yellow",
"(",
"f\"Azure resource group '{resource_group}' already exists\"",
")",
"else",
":",
"AzureController",
".",
"create_resource_group",
"(",
"resource_group",
"=",
"resource_group",
",",
"location",
"=",
"cluster_details",
"[",
"\"cloud\"",
"]",
"[",
"\"location\"",
"]",
")",
"logger",
".",
"info_green",
"(",
"f\"Resource group '{resource_group}' is created\"",
")"
] | [
117,
4
] | [
148,
78
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._create_k8s_cluster | (cluster_details: dict) | Create k8s cluster for the MARO Cluster.
Args:
cluster_details (dict): details of the MARO Cluster.
Returns:
None.
| Create k8s cluster for the MARO Cluster. | def _create_k8s_cluster(cluster_details: dict) -> None:
"""Create k8s cluster for the MARO Cluster.
Args:
cluster_details (dict): details of the MARO Cluster.
Returns:
None.
"""
logger.info("Creating k8s cluster")
# Create ARM parameters and start deployment
template_file_path = f"{K8sPaths.ABS_MARO_K8S_LIB}/modes/aks/create_aks_cluster/template.json"
parameters_file_path = (
f"{GlobalPaths.ABS_MARO_CLUSTERS}/{cluster_details['name']}/parameters/create_aks_cluster.json"
)
ArmTemplateParameterBuilder.create_aks_cluster(
cluster_details=cluster_details,
export_path=parameters_file_path
)
AzureController.start_deployment(
resource_group=cluster_details["cloud"]["resource_group"],
deployment_name="aks_cluster",
template_file_path=template_file_path,
parameters_file_path=parameters_file_path
)
# Attach ACR
AzureController.attach_acr(
resource_group=cluster_details["cloud"]["resource_group"],
aks_name=f"{cluster_details['id']}-aks",
acr_name=f"{cluster_details['id']}acr"
)
logger.info_green("K8s cluster is created") | [
"def",
"_create_k8s_cluster",
"(",
"cluster_details",
":",
"dict",
")",
"->",
"None",
":",
"logger",
".",
"info",
"(",
"\"Creating k8s cluster\"",
")",
"# Create ARM parameters and start deployment",
"template_file_path",
"=",
"f\"{K8sPaths.ABS_MARO_K8S_LIB}/modes/aks/create_aks_cluster/template.json\"",
"parameters_file_path",
"=",
"(",
"f\"{GlobalPaths.ABS_MARO_CLUSTERS}/{cluster_details['name']}/parameters/create_aks_cluster.json\"",
")",
"ArmTemplateParameterBuilder",
".",
"create_aks_cluster",
"(",
"cluster_details",
"=",
"cluster_details",
",",
"export_path",
"=",
"parameters_file_path",
")",
"AzureController",
".",
"start_deployment",
"(",
"resource_group",
"=",
"cluster_details",
"[",
"\"cloud\"",
"]",
"[",
"\"resource_group\"",
"]",
",",
"deployment_name",
"=",
"\"aks_cluster\"",
",",
"template_file_path",
"=",
"template_file_path",
",",
"parameters_file_path",
"=",
"parameters_file_path",
")",
"# Attach ACR",
"AzureController",
".",
"attach_acr",
"(",
"resource_group",
"=",
"cluster_details",
"[",
"\"cloud\"",
"]",
"[",
"\"resource_group\"",
"]",
",",
"aks_name",
"=",
"f\"{cluster_details['id']}-aks\"",
",",
"acr_name",
"=",
"f\"{cluster_details['id']}acr\"",
")",
"logger",
".",
"info_green",
"(",
"\"K8s cluster is created\"",
")"
] | [
151,
4
] | [
185,
51
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._init_nvidia_plugin | () | Setup nvidia plugin for the MARO Cluster.
Returns:
None.
| Setup nvidia plugin for the MARO Cluster. | def _init_nvidia_plugin() -> None:
"""Setup nvidia plugin for the MARO Cluster.
Returns:
None.
"""
client.CoreV1Api().create_namespace(body=client.V1Namespace(metadata=client.V1ObjectMeta(name="gpu-resources")))
with open(
f"{K8sPaths.ABS_MARO_K8S_LIB}/modes/aks/create_nvidia_plugin/nvidia-device-plugin.yml", "r"
) as fr:
redis_deployment = yaml.safe_load(fr)
client.AppsV1Api().create_namespaced_daemon_set(body=redis_deployment, namespace="gpu-resources") | [
"def",
"_init_nvidia_plugin",
"(",
")",
"->",
"None",
":",
"client",
".",
"CoreV1Api",
"(",
")",
".",
"create_namespace",
"(",
"body",
"=",
"client",
".",
"V1Namespace",
"(",
"metadata",
"=",
"client",
".",
"V1ObjectMeta",
"(",
"name",
"=",
"\"gpu-resources\"",
")",
")",
")",
"with",
"open",
"(",
"f\"{K8sPaths.ABS_MARO_K8S_LIB}/modes/aks/create_nvidia_plugin/nvidia-device-plugin.yml\"",
",",
"\"r\"",
")",
"as",
"fr",
":",
"redis_deployment",
"=",
"yaml",
".",
"safe_load",
"(",
"fr",
")",
"client",
".",
"AppsV1Api",
"(",
")",
".",
"create_namespaced_daemon_set",
"(",
"body",
"=",
"redis_deployment",
",",
"namespace",
"=",
"\"gpu-resources\"",
")"
] | [
188,
4
] | [
200,
105
] | python | en | ['en', 'sm', 'en'] | True |
K8sAksExecutor._create_storage_account_secret | (cluster_details: dict) | Setup storage_account_secret for the MARO Cluster.
The secret is used in Azure File Service.
Returns:
None.
| Setup storage_account_secret for the MARO Cluster. | def _create_storage_account_secret(cluster_details: dict) -> None:
"""Setup storage_account_secret for the MARO Cluster.
The secret is used in Azure File Service.
Returns:
None.
"""
# Build params
storage_account_name = f"{cluster_details['id']}st"
# Get storage account key
storage_account_keys = AzureController.get_storage_account_keys(
resource_group=cluster_details["cloud"]["resource_group"],
storage_account_name=storage_account_name
)
storage_key = storage_account_keys[0]["value"]
# Create k8s secret
client.CoreV1Api().create_namespaced_secret(
body=client.V1Secret(
metadata=client.V1ObjectMeta(name="azure-storage-account-secret"),
data={
"azurestorageaccountname": base64.b64encode(storage_account_name.encode()).decode(),
"azurestorageaccountkey": base64.b64encode(bytes(storage_key.encode())).decode()
}
),
namespace="default"
) | [
"def",
"_create_storage_account_secret",
"(",
"cluster_details",
":",
"dict",
")",
"->",
"None",
":",
"# Build params",
"storage_account_name",
"=",
"f\"{cluster_details['id']}st\"",
"# Get storage account key",
"storage_account_keys",
"=",
"AzureController",
".",
"get_storage_account_keys",
"(",
"resource_group",
"=",
"cluster_details",
"[",
"\"cloud\"",
"]",
"[",
"\"resource_group\"",
"]",
",",
"storage_account_name",
"=",
"storage_account_name",
")",
"storage_key",
"=",
"storage_account_keys",
"[",
"0",
"]",
"[",
"\"value\"",
"]",
"# Create k8s secret",
"client",
".",
"CoreV1Api",
"(",
")",
".",
"create_namespaced_secret",
"(",
"body",
"=",
"client",
".",
"V1Secret",
"(",
"metadata",
"=",
"client",
".",
"V1ObjectMeta",
"(",
"name",
"=",
"\"azure-storage-account-secret\"",
")",
",",
"data",
"=",
"{",
"\"azurestorageaccountname\"",
":",
"base64",
".",
"b64encode",
"(",
"storage_account_name",
".",
"encode",
"(",
")",
")",
".",
"decode",
"(",
")",
",",
"\"azurestorageaccountkey\"",
":",
"base64",
".",
"b64encode",
"(",
"bytes",
"(",
"storage_key",
".",
"encode",
"(",
")",
")",
")",
".",
"decode",
"(",
")",
"}",
")",
",",
"namespace",
"=",
"\"default\"",
")"
] | [
203,
4
] | [
231,
9
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor.delete | (self) | Delete the MARO Cluster.
Returns:
None.
| Delete the MARO Cluster. | def delete(self) -> None:
"""Delete the MARO Cluster.
Returns:
None.
"""
logger.info(f"Deleting cluster '{self.cluster_name}'")
# Get resource list
resource_list = AzureController.list_resources(resource_group=self.resource_group)
# Filter resources
deletable_ids = []
for resource in resource_list:
if resource["name"].startswith(self.cluster_id):
deletable_ids.append(resource["id"])
# Delete resources
if deletable_ids:
AzureController.delete_resources(resource_ids=deletable_ids)
# Delete cluster folder
shutil.rmtree(f"{GlobalPaths.ABS_MARO_CLUSTERS}/{self.cluster_name}")
logger.info_green(f"Cluster '{self.cluster_name}' is deleted") | [
"def",
"delete",
"(",
"self",
")",
"->",
"None",
":",
"logger",
".",
"info",
"(",
"f\"Deleting cluster '{self.cluster_name}'\"",
")",
"# Get resource list",
"resource_list",
"=",
"AzureController",
".",
"list_resources",
"(",
"resource_group",
"=",
"self",
".",
"resource_group",
")",
"# Filter resources",
"deletable_ids",
"=",
"[",
"]",
"for",
"resource",
"in",
"resource_list",
":",
"if",
"resource",
"[",
"\"name\"",
"]",
".",
"startswith",
"(",
"self",
".",
"cluster_id",
")",
":",
"deletable_ids",
".",
"append",
"(",
"resource",
"[",
"\"id\"",
"]",
")",
"# Delete resources",
"if",
"deletable_ids",
":",
"AzureController",
".",
"delete_resources",
"(",
"resource_ids",
"=",
"deletable_ids",
")",
"# Delete cluster folder",
"shutil",
".",
"rmtree",
"(",
"f\"{GlobalPaths.ABS_MARO_CLUSTERS}/{self.cluster_name}\"",
")",
"logger",
".",
"info_green",
"(",
"f\"Cluster '{self.cluster_name}' is deleted\"",
")"
] | [
235,
4
] | [
259,
70
] | python | en | ['en', 'it', 'en'] | True |
K8sAksExecutor.scale_node | (self, replicas: int, node_size: str) | Scale up/down MARO Node.
Args:
replicas (int): desired number of MARO Node in specific node_size.
node_size (str): size of the MARO Node VM, see https://docs.microsoft.com/en-us/azure/virtual-machines/sizes
for reference.
Returns:
None.
| Scale up/down MARO Node. | def scale_node(self, replicas: int, node_size: str) -> None:
"""Scale up/down MARO Node.
Args:
replicas (int): desired number of MARO Node in specific node_size.
node_size (str): size of the MARO Node VM, see https://docs.microsoft.com/en-us/azure/virtual-machines/sizes
for reference.
Returns:
None.
"""
# Get node_size_to_info
node_size_to_info = self._get_node_size_to_info()
# Get node_size_to_spec, and check if node_size is valid
node_size_to_spec = self._get_node_size_to_spec()
if node_size not in node_size_to_spec:
raise BadRequestError(f"Invalid node_size '{node_size}'")
# Scale node
if node_size not in node_size_to_info:
self._build_node_pool(
replicas=replicas,
node_size=node_size
)
elif node_size_to_info[node_size]["count"] != replicas:
self._scale_node_pool(
replicas=replicas,
node_size=node_size,
node_size_to_info=node_size_to_info
)
else:
logger.warning_yellow("Replica is match, no create or delete") | [
"def",
"scale_node",
"(",
"self",
",",
"replicas",
":",
"int",
",",
"node_size",
":",
"str",
")",
"->",
"None",
":",
"# Get node_size_to_info",
"node_size_to_info",
"=",
"self",
".",
"_get_node_size_to_info",
"(",
")",
"# Get node_size_to_spec, and check if node_size is valid",
"node_size_to_spec",
"=",
"self",
".",
"_get_node_size_to_spec",
"(",
")",
"if",
"node_size",
"not",
"in",
"node_size_to_spec",
":",
"raise",
"BadRequestError",
"(",
"f\"Invalid node_size '{node_size}'\"",
")",
"# Scale node",
"if",
"node_size",
"not",
"in",
"node_size_to_info",
":",
"self",
".",
"_build_node_pool",
"(",
"replicas",
"=",
"replicas",
",",
"node_size",
"=",
"node_size",
")",
"elif",
"node_size_to_info",
"[",
"node_size",
"]",
"[",
"\"count\"",
"]",
"!=",
"replicas",
":",
"self",
".",
"_scale_node_pool",
"(",
"replicas",
"=",
"replicas",
",",
"node_size",
"=",
"node_size",
",",
"node_size_to_info",
"=",
"node_size_to_info",
")",
"else",
":",
"logger",
".",
"warning_yellow",
"(",
"\"Replica is match, no create or delete\"",
")"
] | [
263,
4
] | [
295,
74
] | python | en | ['en', 'en', 'pt'] | True |
K8sAksExecutor._get_node_size_to_info | (self) | Get node_size to info mapping of the K8s Cluster.
Returns:
dict: node_size to info mapping.
| Get node_size to info mapping of the K8s Cluster. | def _get_node_size_to_info(self) -> dict:
"""Get node_size to info mapping of the K8s Cluster.
Returns:
dict: node_size to info mapping.
"""
# List nodepool
nodepools = AzureController.list_nodepool(
resource_group=self.resource_group,
aks_name=f"{self.cluster_id}-aks"
)
# Build node_size_to_count
node_size_to_count = {}
for nodepool in nodepools:
node_size_to_count[nodepool["vmSize"]] = nodepool
return node_size_to_count | [
"def",
"_get_node_size_to_info",
"(",
"self",
")",
"->",
"dict",
":",
"# List nodepool",
"nodepools",
"=",
"AzureController",
".",
"list_nodepool",
"(",
"resource_group",
"=",
"self",
".",
"resource_group",
",",
"aks_name",
"=",
"f\"{self.cluster_id}-aks\"",
")",
"# Build node_size_to_count",
"node_size_to_count",
"=",
"{",
"}",
"for",
"nodepool",
"in",
"nodepools",
":",
"node_size_to_count",
"[",
"nodepool",
"[",
"\"vmSize\"",
"]",
"]",
"=",
"nodepool",
"return",
"node_size_to_count"
] | [
297,
4
] | [
314,
33
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._get_node_size_to_spec | (self) | Get node_size to spec mapping of Azure VM.
Returns:
dict: node_size to spec mapping.
| Get node_size to spec mapping of Azure VM. | def _get_node_size_to_spec(self) -> dict:
"""Get node_size to spec mapping of Azure VM.
Returns:
dict: node_size to spec mapping.
"""
# List available sizes for VM
specs = AzureController.list_vm_sizes(location=self.location)
# Build node_size_to_spec
node_size_to_spec = {}
for spec in specs:
node_size_to_spec[spec["name"]] = spec
return node_size_to_spec | [
"def",
"_get_node_size_to_spec",
"(",
"self",
")",
"->",
"dict",
":",
"# List available sizes for VM",
"specs",
"=",
"AzureController",
".",
"list_vm_sizes",
"(",
"location",
"=",
"self",
".",
"location",
")",
"# Build node_size_to_spec",
"node_size_to_spec",
"=",
"{",
"}",
"for",
"spec",
"in",
"specs",
":",
"node_size_to_spec",
"[",
"spec",
"[",
"\"name\"",
"]",
"]",
"=",
"spec",
"return",
"node_size_to_spec"
] | [
316,
4
] | [
330,
32
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._build_node_pool | (self, replicas: int, node_size: str) | Build node pool for the specific node_size.
Args:
replicas (int): number of MARO Node in specific node_size to stop.
node_size (str): size of the MARO Node VM,
see https://docs.microsoft.com/en-us/azure/virtual-machines/sizes for reference.
Returns:
None.
| Build node pool for the specific node_size. | def _build_node_pool(self, replicas: int, node_size: str) -> None:
"""Build node pool for the specific node_size.
Args:
replicas (int): number of MARO Node in specific node_size to stop.
node_size (str): size of the MARO Node VM,
see https://docs.microsoft.com/en-us/azure/virtual-machines/sizes for reference.
Returns:
None.
"""
logger.info(f"Building '{node_size}' nodepool")
# Build nodepool
AzureController.add_nodepool(
resource_group=self.resource_group,
aks_name=f"{self.cluster_id}-aks",
nodepool_name=K8sAksExecutor._generate_nodepool_name(node_size=node_size),
node_count=replicas,
node_size=node_size
)
logger.info_green(f"'{node_size}' nodepool is built") | [
"def",
"_build_node_pool",
"(",
"self",
",",
"replicas",
":",
"int",
",",
"node_size",
":",
"str",
")",
"->",
"None",
":",
"logger",
".",
"info",
"(",
"f\"Building '{node_size}' nodepool\"",
")",
"# Build nodepool",
"AzureController",
".",
"add_nodepool",
"(",
"resource_group",
"=",
"self",
".",
"resource_group",
",",
"aks_name",
"=",
"f\"{self.cluster_id}-aks\"",
",",
"nodepool_name",
"=",
"K8sAksExecutor",
".",
"_generate_nodepool_name",
"(",
"node_size",
"=",
"node_size",
")",
",",
"node_count",
"=",
"replicas",
",",
"node_size",
"=",
"node_size",
")",
"logger",
".",
"info_green",
"(",
"f\"'{node_size}' nodepool is built\"",
")"
] | [
332,
4
] | [
354,
61
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._scale_node_pool | (self, replicas: int, node_size: str, node_size_to_info: dict) | Scale node pool of the specific node_size.
Args:
replicas (int): number of MARO Node in specific node_size to stop.
node_size (str): size of the MARO Node VM,
see https://docs.microsoft.com/en-us/azure/virtual-machines/sizes for reference.
node_size_to_info (dict): node_size to info mapping.
Returns:
None.
| Scale node pool of the specific node_size. | def _scale_node_pool(self, replicas: int, node_size: str, node_size_to_info: dict):
"""Scale node pool of the specific node_size.
Args:
replicas (int): number of MARO Node in specific node_size to stop.
node_size (str): size of the MARO Node VM,
see https://docs.microsoft.com/en-us/azure/virtual-machines/sizes for reference.
node_size_to_info (dict): node_size to info mapping.
Returns:
None.
"""
logger.info(f"Scaling '{node_size}' nodepool")
# Scale node pool
AzureController.scale_nodepool(
resource_group=self.resource_group,
aks_name=f"{self.cluster_id}-aks",
nodepool_name=node_size_to_info[node_size]["name"],
node_count=replicas
)
logger.info_green(f"'{node_size}' nodepool is scaled") | [
"def",
"_scale_node_pool",
"(",
"self",
",",
"replicas",
":",
"int",
",",
"node_size",
":",
"str",
",",
"node_size_to_info",
":",
"dict",
")",
":",
"logger",
".",
"info",
"(",
"f\"Scaling '{node_size}' nodepool\"",
")",
"# Scale node pool",
"AzureController",
".",
"scale_nodepool",
"(",
"resource_group",
"=",
"self",
".",
"resource_group",
",",
"aks_name",
"=",
"f\"{self.cluster_id}-aks\"",
",",
"nodepool_name",
"=",
"node_size_to_info",
"[",
"node_size",
"]",
"[",
"\"name\"",
"]",
",",
"node_count",
"=",
"replicas",
")",
"logger",
".",
"info_green",
"(",
"f\"'{node_size}' nodepool is scaled\"",
")"
] | [
356,
4
] | [
378,
62
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._generate_nodepool_name | (node_size: str) | Generate name of the nodepool.
Args:
node_size (str): size of the MARO Node VM.
Returns:
None.
| Generate name of the nodepool. | def _generate_nodepool_name(node_size: str) -> str:
"""Generate name of the nodepool.
Args:
node_size (str): size of the MARO Node VM.
Returns:
None.
"""
return NameCreator.create_name_with_md5(prefix="pool", key=node_size, md5_len=8) | [
"def",
"_generate_nodepool_name",
"(",
"node_size",
":",
"str",
")",
"->",
"str",
":",
"return",
"NameCreator",
".",
"create_name_with_md5",
"(",
"prefix",
"=",
"\"pool\"",
",",
"key",
"=",
"node_size",
",",
"md5_len",
"=",
"8",
")"
] | [
381,
4
] | [
390,
88
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor.list_node | (self) | Print node details to the command line.
Returns:
None.
| Print node details to the command line. | def list_node(self) -> None:
"""Print node details to the command line.
Returns:
None.
"""
# Get aks details
aks_details = AzureController.get_aks(
resource_group=self.resource_group,
aks_name=f"{self.cluster_id}-aks"
)
agent_pools_details = aks_details["agentPoolProfiles"]
# Filter and print
node_details = {}
for agent_pool_details in agent_pools_details:
node_details[agent_pool_details["vmSize"]] = agent_pool_details["count"]
logger.info(
json.dumps(
node_details,
indent=4, sort_keys=True
)
) | [
"def",
"list_node",
"(",
"self",
")",
"->",
"None",
":",
"# Get aks details",
"aks_details",
"=",
"AzureController",
".",
"get_aks",
"(",
"resource_group",
"=",
"self",
".",
"resource_group",
",",
"aks_name",
"=",
"f\"{self.cluster_id}-aks\"",
")",
"agent_pools_details",
"=",
"aks_details",
"[",
"\"agentPoolProfiles\"",
"]",
"# Filter and print",
"node_details",
"=",
"{",
"}",
"for",
"agent_pool_details",
"in",
"agent_pools_details",
":",
"node_details",
"[",
"agent_pool_details",
"[",
"\"vmSize\"",
"]",
"]",
"=",
"agent_pool_details",
"[",
"\"count\"",
"]",
"logger",
".",
"info",
"(",
"json",
".",
"dumps",
"(",
"node_details",
",",
"indent",
"=",
"4",
",",
"sort_keys",
"=",
"True",
")",
")"
] | [
392,
4
] | [
414,
9
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor.push_image | (self, image_name: str) | Push local image to the MARO Cluster.
Args:
image_name (str): name of the local image that loaded in the docker.
Returns:
None.
| Push local image to the MARO Cluster. | def push_image(self, image_name: str) -> None:
"""Push local image to the MARO Cluster.
Args:
image_name (str): name of the local image that loaded in the docker.
Returns:
None.
"""
remote_image_name = f"{self.cluster_id}acr.azurecr.io/{image_name}"
# ACR login
AzureController.login_acr(acr_name=f"{self.cluster_id}acr")
# Tag image
command = f"docker tag {image_name} {remote_image_name}"
_ = Subprocess.run(command=command)
# Push image to ACR
command = f"docker push {remote_image_name}"
_ = Subprocess.run(command=command) | [
"def",
"push_image",
"(",
"self",
",",
"image_name",
":",
"str",
")",
"->",
"None",
":",
"remote_image_name",
"=",
"f\"{self.cluster_id}acr.azurecr.io/{image_name}\"",
"# ACR login",
"AzureController",
".",
"login_acr",
"(",
"acr_name",
"=",
"f\"{self.cluster_id}acr\"",
")",
"# Tag image",
"command",
"=",
"f\"docker tag {image_name} {remote_image_name}\"",
"_",
"=",
"Subprocess",
".",
"run",
"(",
"command",
"=",
"command",
")",
"# Push image to ACR",
"command",
"=",
"f\"docker push {remote_image_name}\"",
"_",
"=",
"Subprocess",
".",
"run",
"(",
"command",
"=",
"command",
")"
] | [
418,
4
] | [
438,
43
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor.list_image | (self) | Print image details to the command line.
Returns:
None.
| Print image details to the command line. | def list_image(self):
"""Print image details to the command line.
Returns:
None.
"""
# List acr repository
acr_repositories = AzureController.list_acr_repositories(acr_name=f"{self.cluster_id}acr")
logger.info(acr_repositories) | [
"def",
"list_image",
"(",
"self",
")",
":",
"# List acr repository",
"acr_repositories",
"=",
"AzureController",
".",
"list_acr_repositories",
"(",
"acr_name",
"=",
"f\"{self.cluster_id}acr\"",
")",
"logger",
".",
"info",
"(",
"acr_repositories",
")"
] | [
440,
4
] | [
448,
37
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor.push_data | (self, local_path: str, remote_dir: str) | Push local data to the remote AFS service via azcopy.
Args:
local_path (str): path of the local data.
remote_dir (str): path of the remote folder.
Returns:
None.
| Push local data to the remote AFS service via azcopy. | def push_data(self, local_path: str, remote_dir: str) -> None:
"""Push local data to the remote AFS service via azcopy.
Args:
local_path (str): path of the local data.
remote_dir (str): path of the remote folder.
Returns:
None.
"""
# Get sas
sas = self._check_and_get_account_sas()
# Push data
abs_local_path = os.path.expanduser(local_path)
abs_source_path = PathConvertor.build_path_without_trailing_slash(abs_local_path)
target_dir = PathConvertor.build_path_with_trailing_slash(remote_dir)
if not target_dir.startswith("/"):
raise FileOperationError(f"Invalid remote path: {target_dir}\nShould be started with '/'")
copy_command = (
"azcopy copy "
f"'{abs_source_path}' "
f"'https://{self.cluster_id}st.file.core.windows.net/{self.cluster_id}-fs{target_dir}?{sas}' "
"--recursive=True"
)
_ = Subprocess.run(command=copy_command) | [
"def",
"push_data",
"(",
"self",
",",
"local_path",
":",
"str",
",",
"remote_dir",
":",
"str",
")",
"->",
"None",
":",
"# Get sas",
"sas",
"=",
"self",
".",
"_check_and_get_account_sas",
"(",
")",
"# Push data",
"abs_local_path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"local_path",
")",
"abs_source_path",
"=",
"PathConvertor",
".",
"build_path_without_trailing_slash",
"(",
"abs_local_path",
")",
"target_dir",
"=",
"PathConvertor",
".",
"build_path_with_trailing_slash",
"(",
"remote_dir",
")",
"if",
"not",
"target_dir",
".",
"startswith",
"(",
"\"/\"",
")",
":",
"raise",
"FileOperationError",
"(",
"f\"Invalid remote path: {target_dir}\\nShould be started with '/'\"",
")",
"copy_command",
"=",
"(",
"\"azcopy copy \"",
"f\"'{abs_source_path}' \"",
"f\"'https://{self.cluster_id}st.file.core.windows.net/{self.cluster_id}-fs{target_dir}?{sas}' \"",
"\"--recursive=True\"",
")",
"_",
"=",
"Subprocess",
".",
"run",
"(",
"command",
"=",
"copy_command",
")"
] | [
452,
4
] | [
477,
48
] | python | en | ['en', 'it', 'en'] | True |
K8sAksExecutor.pull_data | (self, local_dir: str, remote_path: str) | Pull remote AFS service data to local folder via azcopy.
Args:
local_dir (str): path of the local folder.
remote_path (str): path of the remote data.
Returns:
None.
| Pull remote AFS service data to local folder via azcopy. | def pull_data(self, local_dir: str, remote_path: str) -> None:
"""Pull remote AFS service data to local folder via azcopy.
Args:
local_dir (str): path of the local folder.
remote_path (str): path of the remote data.
Returns:
None.
"""
# Get sas
sas = self._check_and_get_account_sas()
# Push data
abs_local_dir = os.path.expanduser(local_dir)
source_path = PathConvertor.build_path_without_trailing_slash(remote_path)
abs_target_dir = PathConvertor.build_path_with_trailing_slash(abs_local_dir)
os.makedirs(abs_target_dir, exist_ok=True)
if not source_path.startswith("/"):
raise FileOperationError(f"Invalid remote path: {source_path}\nShould be started with '/'")
copy_command = (
"azcopy copy "
f"'https://{self.cluster_id}st.file.core.windows.net/{self.cluster_id}-fs{source_path}?{sas}' "
f"'{abs_target_dir}' "
"--recursive=True"
)
_ = Subprocess.run(command=copy_command) | [
"def",
"pull_data",
"(",
"self",
",",
"local_dir",
":",
"str",
",",
"remote_path",
":",
"str",
")",
"->",
"None",
":",
"# Get sas",
"sas",
"=",
"self",
".",
"_check_and_get_account_sas",
"(",
")",
"# Push data",
"abs_local_dir",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"local_dir",
")",
"source_path",
"=",
"PathConvertor",
".",
"build_path_without_trailing_slash",
"(",
"remote_path",
")",
"abs_target_dir",
"=",
"PathConvertor",
".",
"build_path_with_trailing_slash",
"(",
"abs_local_dir",
")",
"os",
".",
"makedirs",
"(",
"abs_target_dir",
",",
"exist_ok",
"=",
"True",
")",
"if",
"not",
"source_path",
".",
"startswith",
"(",
"\"/\"",
")",
":",
"raise",
"FileOperationError",
"(",
"f\"Invalid remote path: {source_path}\\nShould be started with '/'\"",
")",
"copy_command",
"=",
"(",
"\"azcopy copy \"",
"f\"'https://{self.cluster_id}st.file.core.windows.net/{self.cluster_id}-fs{source_path}?{sas}' \"",
"f\"'{abs_target_dir}' \"",
"\"--recursive=True\"",
")",
"_",
"=",
"Subprocess",
".",
"run",
"(",
"command",
"=",
"copy_command",
")"
] | [
479,
4
] | [
505,
48
] | python | en | ['en', 'it', 'en'] | True |
K8sAksExecutor.remove_data | (self, remote_path: str) | Remote data at the remote AFS service.
Args:
remote_path (str): path of the remote data.
Returns:
None.
| Remote data at the remote AFS service. | def remove_data(self, remote_path: str) -> None:
"""Remote data at the remote AFS service.
Args:
remote_path (str): path of the remote data.
Returns:
None.
"""
# FIXME: Remove failed, The specified resource may be in use by an SMB client
# Get sas
sas = self._check_and_get_account_sas()
# Remove data
copy_command = (
"azcopy remove "
f"'https://{self.cluster_id}st.file.core.windows.net/{self.cluster_id}-fs{remote_path}?{sas}' "
"--recursive=True"
)
_ = Subprocess.run(command=copy_command) | [
"def",
"remove_data",
"(",
"self",
",",
"remote_path",
":",
"str",
")",
"->",
"None",
":",
"# FIXME: Remove failed, The specified resource may be in use by an SMB client",
"# Get sas",
"sas",
"=",
"self",
".",
"_check_and_get_account_sas",
"(",
")",
"# Remove data",
"copy_command",
"=",
"(",
"\"azcopy remove \"",
"f\"'https://{self.cluster_id}st.file.core.windows.net/{self.cluster_id}-fs{remote_path}?{sas}' \"",
"\"--recursive=True\"",
")",
"_",
"=",
"Subprocess",
".",
"run",
"(",
"command",
"=",
"copy_command",
")"
] | [
507,
4
] | [
527,
48
] | python | en | ['en', 'it', 'en'] | True |
K8sAksExecutor._check_and_get_account_sas | (self) | Check and get account sas token, also update it to the cluster_details.
Ref: https://msdn.microsoft.com/library/azure/mt584140.aspx
Returns:
str: account sas token.
| Check and get account sas token, also update it to the cluster_details. | def _check_and_get_account_sas(self) -> str:
"""Check and get account sas token, also update it to the cluster_details.
Ref: https://msdn.microsoft.com/library/azure/mt584140.aspx
Returns:
str: account sas token.
"""
# Load details
cloud_details = self.cluster_details["cloud"]
# Regenerate sas if the key is None or expired TODO:
if "account_sas" not in cloud_details:
account_sas = AzureController.get_storage_account_sas(account_name=f"{self.cluster_id}st")
cloud_details["account_sas"] = account_sas
DetailsWriter.save_cluster_details(
cluster_name=self.cluster_name,
cluster_details=self.cluster_details
)
return cloud_details["account_sas"] | [
"def",
"_check_and_get_account_sas",
"(",
"self",
")",
"->",
"str",
":",
"# Load details",
"cloud_details",
"=",
"self",
".",
"cluster_details",
"[",
"\"cloud\"",
"]",
"# Regenerate sas if the key is None or expired TODO:",
"if",
"\"account_sas\"",
"not",
"in",
"cloud_details",
":",
"account_sas",
"=",
"AzureController",
".",
"get_storage_account_sas",
"(",
"account_name",
"=",
"f\"{self.cluster_id}st\"",
")",
"cloud_details",
"[",
"\"account_sas\"",
"]",
"=",
"account_sas",
"DetailsWriter",
".",
"save_cluster_details",
"(",
"cluster_name",
"=",
"self",
".",
"cluster_name",
",",
"cluster_details",
"=",
"self",
".",
"cluster_details",
")",
"return",
"cloud_details",
"[",
"\"account_sas\"",
"]"
] | [
529,
4
] | [
550,
43
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._create_k8s_job | (self, job_details: dict) | Create k8s job object with job_details.
Args:
job_details (dict): details of the MARO Job.
Returns:
dict: k8s job object.
| Create k8s job object with job_details. | def _create_k8s_job(self, job_details: dict) -> dict:
"""Create k8s job object with job_details.
Args:
job_details (dict): details of the MARO Job.
Returns:
dict: k8s job object.
"""
# Get config template
with open(f"{K8sPaths.ABS_MARO_K8S_LIB}/modes/aks/create_job/job.yml") as fr:
k8s_job_config = yaml.safe_load(fr)
with open(f"{K8sPaths.ABS_MARO_K8S_LIB}/modes/aks/create_job/container.yml") as fr:
k8s_container_config = yaml.safe_load(fr)
# Fill configs
k8s_job_config["metadata"]["name"] = job_details["id"]
k8s_job_config["metadata"]["labels"]["jobName"] = job_details["name"]
azure_file_config = k8s_job_config["spec"]["template"]["spec"]["volumes"][0]["azureFile"]
azure_file_config["secretName"] = "azure-storage-account-secret"
azure_file_config["shareName"] = f"{self.cluster_id}-fs"
# Create and fill container config
for component_type, component_details in job_details["components"].items():
for component_index in range(component_details["num"]):
container_config = self._create_k8s_container_config(
job_details=job_details,
k8s_container_config_template=k8s_container_config,
component_type=component_type,
component_index=component_index
)
k8s_job_config["spec"]["template"]["spec"]["containers"].append(container_config)
return k8s_job_config | [
"def",
"_create_k8s_job",
"(",
"self",
",",
"job_details",
":",
"dict",
")",
"->",
"dict",
":",
"# Get config template",
"with",
"open",
"(",
"f\"{K8sPaths.ABS_MARO_K8S_LIB}/modes/aks/create_job/job.yml\"",
")",
"as",
"fr",
":",
"k8s_job_config",
"=",
"yaml",
".",
"safe_load",
"(",
"fr",
")",
"with",
"open",
"(",
"f\"{K8sPaths.ABS_MARO_K8S_LIB}/modes/aks/create_job/container.yml\"",
")",
"as",
"fr",
":",
"k8s_container_config",
"=",
"yaml",
".",
"safe_load",
"(",
"fr",
")",
"# Fill configs",
"k8s_job_config",
"[",
"\"metadata\"",
"]",
"[",
"\"name\"",
"]",
"=",
"job_details",
"[",
"\"id\"",
"]",
"k8s_job_config",
"[",
"\"metadata\"",
"]",
"[",
"\"labels\"",
"]",
"[",
"\"jobName\"",
"]",
"=",
"job_details",
"[",
"\"name\"",
"]",
"azure_file_config",
"=",
"k8s_job_config",
"[",
"\"spec\"",
"]",
"[",
"\"template\"",
"]",
"[",
"\"spec\"",
"]",
"[",
"\"volumes\"",
"]",
"[",
"0",
"]",
"[",
"\"azureFile\"",
"]",
"azure_file_config",
"[",
"\"secretName\"",
"]",
"=",
"\"azure-storage-account-secret\"",
"azure_file_config",
"[",
"\"shareName\"",
"]",
"=",
"f\"{self.cluster_id}-fs\"",
"# Create and fill container config",
"for",
"component_type",
",",
"component_details",
"in",
"job_details",
"[",
"\"components\"",
"]",
".",
"items",
"(",
")",
":",
"for",
"component_index",
"in",
"range",
"(",
"component_details",
"[",
"\"num\"",
"]",
")",
":",
"container_config",
"=",
"self",
".",
"_create_k8s_container_config",
"(",
"job_details",
"=",
"job_details",
",",
"k8s_container_config_template",
"=",
"k8s_container_config",
",",
"component_type",
"=",
"component_type",
",",
"component_index",
"=",
"component_index",
")",
"k8s_job_config",
"[",
"\"spec\"",
"]",
"[",
"\"template\"",
"]",
"[",
"\"spec\"",
"]",
"[",
"\"containers\"",
"]",
".",
"append",
"(",
"container_config",
")",
"return",
"k8s_job_config"
] | [
554,
4
] | [
587,
29
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._create_k8s_container_config | (
self, job_details: dict, k8s_container_config_template: dict,
component_type: str, component_index: int
) | Create the container config in the k8s job object.
Args:
job_details (dict): details of the MARO Job.
k8s_container_config_template (dict): template of the k8s_container_config.
component_type (str): type of the component.
component_index (int): index of the component.
Returns:
dict: the container config.
| Create the container config in the k8s job object. | def _create_k8s_container_config(
self, job_details: dict, k8s_container_config_template: dict,
component_type: str, component_index: int
) -> dict:
"""Create the container config in the k8s job object.
Args:
job_details (dict): details of the MARO Job.
k8s_container_config_template (dict): template of the k8s_container_config.
component_type (str): type of the component.
component_index (int): index of the component.
Returns:
dict: the container config.
"""
# Copy config.
k8s_container_config = copy.deepcopy(k8s_container_config_template)
# Load details
component_details = job_details["components"][component_type]
job_id = job_details["id"]
component_id = job_details["components"][component_type]["id"]
container_name = f"{job_id}-{component_id}-{component_index}"
# Fill configs.
k8s_container_config["name"] = container_name
k8s_container_config["image"] = self._build_image_address(image_name=component_details["image"])
k8s_container_config["resources"]["requests"] = {
"cpu": component_details["resources"]["cpu"],
"memory": component_details["resources"]["memory"],
"nvidia.com/gpu": component_details["resources"]["gpu"]
}
k8s_container_config["resources"]["limits"] = {
"cpu": component_details["resources"]["cpu"],
"memory": component_details["resources"]["memory"],
"nvidia.com/gpu": component_details["resources"]["gpu"]
}
k8s_container_config["env"] = [
{
"name": "CLUSTER_ID",
"value": f"{self.cluster_id}"
},
{
"name": "CLUSTER_NAME",
"value": f"{self.cluster_name}"
},
{
"name": "JOB_ID",
"value": job_id
},
{
"name": "JOB_NAME",
"value": job_details["name"]
},
{
"name": "COMPONENT_ID",
"value": component_id
},
{
"name": "COMPONENT_TYPE",
"value": f"{component_type}"
},
{
"name": "COMPONENT_INDEX",
"value": f"{component_index}"
},
{
"name": "PYTHONUNBUFFERED",
"value": "0"
}
]
k8s_container_config["command"] = component_details["command"]
k8s_container_config["volumeMounts"][0]["mountPath"] = component_details["mount"]["target"]
return k8s_container_config | [
"def",
"_create_k8s_container_config",
"(",
"self",
",",
"job_details",
":",
"dict",
",",
"k8s_container_config_template",
":",
"dict",
",",
"component_type",
":",
"str",
",",
"component_index",
":",
"int",
")",
"->",
"dict",
":",
"# Copy config.",
"k8s_container_config",
"=",
"copy",
".",
"deepcopy",
"(",
"k8s_container_config_template",
")",
"# Load details",
"component_details",
"=",
"job_details",
"[",
"\"components\"",
"]",
"[",
"component_type",
"]",
"job_id",
"=",
"job_details",
"[",
"\"id\"",
"]",
"component_id",
"=",
"job_details",
"[",
"\"components\"",
"]",
"[",
"component_type",
"]",
"[",
"\"id\"",
"]",
"container_name",
"=",
"f\"{job_id}-{component_id}-{component_index}\"",
"# Fill configs.",
"k8s_container_config",
"[",
"\"name\"",
"]",
"=",
"container_name",
"k8s_container_config",
"[",
"\"image\"",
"]",
"=",
"self",
".",
"_build_image_address",
"(",
"image_name",
"=",
"component_details",
"[",
"\"image\"",
"]",
")",
"k8s_container_config",
"[",
"\"resources\"",
"]",
"[",
"\"requests\"",
"]",
"=",
"{",
"\"cpu\"",
":",
"component_details",
"[",
"\"resources\"",
"]",
"[",
"\"cpu\"",
"]",
",",
"\"memory\"",
":",
"component_details",
"[",
"\"resources\"",
"]",
"[",
"\"memory\"",
"]",
",",
"\"nvidia.com/gpu\"",
":",
"component_details",
"[",
"\"resources\"",
"]",
"[",
"\"gpu\"",
"]",
"}",
"k8s_container_config",
"[",
"\"resources\"",
"]",
"[",
"\"limits\"",
"]",
"=",
"{",
"\"cpu\"",
":",
"component_details",
"[",
"\"resources\"",
"]",
"[",
"\"cpu\"",
"]",
",",
"\"memory\"",
":",
"component_details",
"[",
"\"resources\"",
"]",
"[",
"\"memory\"",
"]",
",",
"\"nvidia.com/gpu\"",
":",
"component_details",
"[",
"\"resources\"",
"]",
"[",
"\"gpu\"",
"]",
"}",
"k8s_container_config",
"[",
"\"env\"",
"]",
"=",
"[",
"{",
"\"name\"",
":",
"\"CLUSTER_ID\"",
",",
"\"value\"",
":",
"f\"{self.cluster_id}\"",
"}",
",",
"{",
"\"name\"",
":",
"\"CLUSTER_NAME\"",
",",
"\"value\"",
":",
"f\"{self.cluster_name}\"",
"}",
",",
"{",
"\"name\"",
":",
"\"JOB_ID\"",
",",
"\"value\"",
":",
"job_id",
"}",
",",
"{",
"\"name\"",
":",
"\"JOB_NAME\"",
",",
"\"value\"",
":",
"job_details",
"[",
"\"name\"",
"]",
"}",
",",
"{",
"\"name\"",
":",
"\"COMPONENT_ID\"",
",",
"\"value\"",
":",
"component_id",
"}",
",",
"{",
"\"name\"",
":",
"\"COMPONENT_TYPE\"",
",",
"\"value\"",
":",
"f\"{component_type}\"",
"}",
",",
"{",
"\"name\"",
":",
"\"COMPONENT_INDEX\"",
",",
"\"value\"",
":",
"f\"{component_index}\"",
"}",
",",
"{",
"\"name\"",
":",
"\"PYTHONUNBUFFERED\"",
",",
"\"value\"",
":",
"\"0\"",
"}",
"]",
"k8s_container_config",
"[",
"\"command\"",
"]",
"=",
"component_details",
"[",
"\"command\"",
"]",
"k8s_container_config",
"[",
"\"volumeMounts\"",
"]",
"[",
"0",
"]",
"[",
"\"mountPath\"",
"]",
"=",
"component_details",
"[",
"\"mount\"",
"]",
"[",
"\"target\"",
"]",
"return",
"k8s_container_config"
] | [
589,
4
] | [
663,
35
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._build_image_address | (self, image_name: str) | Build image address name for image that stored at Azure Container Registry.
Args:
image_name (str): name of the image.
Returns:
str: image address name.
| Build image address name for image that stored at Azure Container Registry. | def _build_image_address(self, image_name: str) -> str:
"""Build image address name for image that stored at Azure Container Registry.
Args:
image_name (str): name of the image.
Returns:
str: image address name.
"""
# Get repositories
acr_repositories = AzureController.list_acr_repositories(acr_name=f"{self.cluster_id}acr")
# Build address
if image_name in acr_repositories:
return f"{self.cluster_id}acr.azurecr.io/{image_name}"
else:
return image_name | [
"def",
"_build_image_address",
"(",
"self",
",",
"image_name",
":",
"str",
")",
"->",
"str",
":",
"# Get repositories",
"acr_repositories",
"=",
"AzureController",
".",
"list_acr_repositories",
"(",
"acr_name",
"=",
"f\"{self.cluster_id}acr\"",
")",
"# Build address",
"if",
"image_name",
"in",
"acr_repositories",
":",
"return",
"f\"{self.cluster_id}acr.azurecr.io/{image_name}\"",
"else",
":",
"return",
"image_name"
] | [
665,
4
] | [
681,
29
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor._export_log | (pod_id: str, container_name: str, export_dir: str) | Export k8s job logs to the specific folder.
Args:
pod_id (str): id of the k8s pod.
container_name (str): name of the container.
export_dir (str): path of the exported folder.
Returns:
None.
| Export k8s job logs to the specific folder. | def _export_log(pod_id: str, container_name: str, export_dir: str) -> None:
"""Export k8s job logs to the specific folder.
Args:
pod_id (str): id of the k8s pod.
container_name (str): name of the container.
export_dir (str): path of the exported folder.
Returns:
None.
"""
os.makedirs(os.path.expanduser(export_dir + f"/{pod_id}"), exist_ok=True)
with open(os.path.expanduser(export_dir + f"/{pod_id}/{container_name}.log"), "w") as fw:
return_str = client.CoreV1Api().read_namespaced_pod_log(name=pod_id, namespace="default")
fw.write(return_str) | [
"def",
"_export_log",
"(",
"pod_id",
":",
"str",
",",
"container_name",
":",
"str",
",",
"export_dir",
":",
"str",
")",
"->",
"None",
":",
"os",
".",
"makedirs",
"(",
"os",
".",
"path",
".",
"expanduser",
"(",
"export_dir",
"+",
"f\"/{pod_id}\"",
")",
",",
"exist_ok",
"=",
"True",
")",
"with",
"open",
"(",
"os",
".",
"path",
".",
"expanduser",
"(",
"export_dir",
"+",
"f\"/{pod_id}/{container_name}.log\"",
")",
",",
"\"w\"",
")",
"as",
"fw",
":",
"return_str",
"=",
"client",
".",
"CoreV1Api",
"(",
")",
".",
"read_namespaced_pod_log",
"(",
"name",
"=",
"pod_id",
",",
"namespace",
"=",
"\"default\"",
")",
"fw",
".",
"write",
"(",
"return_str",
")"
] | [
684,
4
] | [
698,
32
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor.status | (self) | Print details of specific MARO Resources (redis only at this time).
Returns:
None.
| Print details of specific MARO Resources (redis only at this time). | def status(self) -> None:
"""Print details of specific MARO Resources (redis only at this time).
Returns:
None.
"""
return_status = {}
# Get pods details
pod_list = client.CoreV1Api().list_pod_for_all_namespaces(watch=False).to_dict()["items"]
for pod in pod_list:
if "app" in pod["metadata"]["labels"] and pod["metadata"]["labels"]["app"] == "maro-redis":
return_status["redis"] = {
"private_ip_address": pod["status"]["pod_ip"]
}
break
# Print status
logger.info(
json.dumps(
return_status,
indent=4, sort_keys=True
)
) | [
"def",
"status",
"(",
"self",
")",
"->",
"None",
":",
"return_status",
"=",
"{",
"}",
"# Get pods details",
"pod_list",
"=",
"client",
".",
"CoreV1Api",
"(",
")",
".",
"list_pod_for_all_namespaces",
"(",
"watch",
"=",
"False",
")",
".",
"to_dict",
"(",
")",
"[",
"\"items\"",
"]",
"for",
"pod",
"in",
"pod_list",
":",
"if",
"\"app\"",
"in",
"pod",
"[",
"\"metadata\"",
"]",
"[",
"\"labels\"",
"]",
"and",
"pod",
"[",
"\"metadata\"",
"]",
"[",
"\"labels\"",
"]",
"[",
"\"app\"",
"]",
"==",
"\"maro-redis\"",
":",
"return_status",
"[",
"\"redis\"",
"]",
"=",
"{",
"\"private_ip_address\"",
":",
"pod",
"[",
"\"status\"",
"]",
"[",
"\"pod_ip\"",
"]",
"}",
"break",
"# Print status",
"logger",
".",
"info",
"(",
"json",
".",
"dumps",
"(",
"return_status",
",",
"indent",
"=",
"4",
",",
"sort_keys",
"=",
"True",
")",
")"
] | [
702,
4
] | [
726,
9
] | python | en | ['en', 'en', 'en'] | True |
K8sAksExecutor.load_k8s_context | (self) | Activate load k8s context operation.
Returns:
None.
| Activate load k8s context operation. | def load_k8s_context(self) -> None:
"""Activate load k8s context operation.
Returns:
None.
"""
self._load_k8s_context(
cluster_id=self.cluster_id,
resource_group=self.resource_group
) | [
"def",
"load_k8s_context",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"_load_k8s_context",
"(",
"cluster_id",
"=",
"self",
".",
"cluster_id",
",",
"resource_group",
"=",
"self",
".",
"resource_group",
")"
] | [
730,
4
] | [
739,
9
] | python | en | ['nl', 'en', 'en'] | True |
K8sAksExecutor._load_k8s_context | (cluster_id: int, resource_group: str) | Load the k8s context.
Set current k8s context (only in the CLI runtime) to the k8s cluster that related to the MARO Cluster.
Args:
cluster_id (str): id of the MARO Cluster.
resource_group (str): name of the resource group.
Returns:
None.
| Load the k8s context. | def _load_k8s_context(cluster_id: int, resource_group: str) -> None:
"""Load the k8s context.
Set current k8s context (only in the CLI runtime) to the k8s cluster that related to the MARO Cluster.
Args:
cluster_id (str): id of the MARO Cluster.
resource_group (str): name of the resource group.
Returns:
None.
"""
AzureController.load_aks_context(
resource_group=resource_group,
aks_name=f"{cluster_id}-aks"
)
config.load_kube_config(context=f"{cluster_id}-aks") | [
"def",
"_load_k8s_context",
"(",
"cluster_id",
":",
"int",
",",
"resource_group",
":",
"str",
")",
"->",
"None",
":",
"AzureController",
".",
"load_aks_context",
"(",
"resource_group",
"=",
"resource_group",
",",
"aks_name",
"=",
"f\"{cluster_id}-aks\"",
")",
"config",
".",
"load_kube_config",
"(",
"context",
"=",
"f\"{cluster_id}-aks\"",
")"
] | [
742,
4
] | [
758,
60
] | python | en | ['en', 'en', 'en'] | True |
ArmTemplateParameterBuilder.create_aks_cluster | (cluster_details: dict, export_path: str) | Create parameters file for AKS cluster.
Args:
cluster_details (dict): details of the MARO Cluster.
export_path (str): path to export the parameter file.
Returns:
dict: parameter dict, should be exported to json.
| Create parameters file for AKS cluster. | def create_aks_cluster(cluster_details: dict, export_path: str) -> dict:
"""Create parameters file for AKS cluster.
Args:
cluster_details (dict): details of the MARO Cluster.
export_path (str): path to export the parameter file.
Returns:
dict: parameter dict, should be exported to json.
"""
# Get params
cluster_id = cluster_details['id']
with open(f"{K8sPaths.ABS_MARO_K8S_LIB}/modes/aks/create_aks_cluster/parameters.json", "r") as f:
base_parameters = json.load(f)
parameters = base_parameters["parameters"]
parameters["acrName"]["value"] = f"{cluster_id}acr"
parameters["acrSku"]["value"] = "Basic"
parameters["adminPublicKey"]["value"] = cluster_details["cloud"]["default_public_key"]
parameters["adminUsername"]["value"] = cluster_details["cloud"]["default_username"]
parameters["agentCount"]["value"] = 1
parameters["agentVMSize"]["value"] = cluster_details["master"]["node_size"]
parameters["clusterName"]["value"] = f"{cluster_id}-aks"
parameters["fileShareName"]["value"] = f"{cluster_id}-fs"
parameters["location"]["value"] = cluster_details["cloud"]["location"]
parameters["storageAccountName"]["value"] = f"{cluster_id}st"
parameters["virtualNetworkName"]["value"] = f"{cluster_id}-vnet"
# Export parameters if the path is set
if export_path:
os.makedirs(os.path.dirname(export_path), exist_ok=True)
with open(export_path, "w") as fw:
json.dump(base_parameters, fw, indent=4)
return parameters | [
"def",
"create_aks_cluster",
"(",
"cluster_details",
":",
"dict",
",",
"export_path",
":",
"str",
")",
"->",
"dict",
":",
"# Get params",
"cluster_id",
"=",
"cluster_details",
"[",
"'id'",
"]",
"with",
"open",
"(",
"f\"{K8sPaths.ABS_MARO_K8S_LIB}/modes/aks/create_aks_cluster/parameters.json\"",
",",
"\"r\"",
")",
"as",
"f",
":",
"base_parameters",
"=",
"json",
".",
"load",
"(",
"f",
")",
"parameters",
"=",
"base_parameters",
"[",
"\"parameters\"",
"]",
"parameters",
"[",
"\"acrName\"",
"]",
"[",
"\"value\"",
"]",
"=",
"f\"{cluster_id}acr\"",
"parameters",
"[",
"\"acrSku\"",
"]",
"[",
"\"value\"",
"]",
"=",
"\"Basic\"",
"parameters",
"[",
"\"adminPublicKey\"",
"]",
"[",
"\"value\"",
"]",
"=",
"cluster_details",
"[",
"\"cloud\"",
"]",
"[",
"\"default_public_key\"",
"]",
"parameters",
"[",
"\"adminUsername\"",
"]",
"[",
"\"value\"",
"]",
"=",
"cluster_details",
"[",
"\"cloud\"",
"]",
"[",
"\"default_username\"",
"]",
"parameters",
"[",
"\"agentCount\"",
"]",
"[",
"\"value\"",
"]",
"=",
"1",
"parameters",
"[",
"\"agentVMSize\"",
"]",
"[",
"\"value\"",
"]",
"=",
"cluster_details",
"[",
"\"master\"",
"]",
"[",
"\"node_size\"",
"]",
"parameters",
"[",
"\"clusterName\"",
"]",
"[",
"\"value\"",
"]",
"=",
"f\"{cluster_id}-aks\"",
"parameters",
"[",
"\"fileShareName\"",
"]",
"[",
"\"value\"",
"]",
"=",
"f\"{cluster_id}-fs\"",
"parameters",
"[",
"\"location\"",
"]",
"[",
"\"value\"",
"]",
"=",
"cluster_details",
"[",
"\"cloud\"",
"]",
"[",
"\"location\"",
"]",
"parameters",
"[",
"\"storageAccountName\"",
"]",
"[",
"\"value\"",
"]",
"=",
"f\"{cluster_id}st\"",
"parameters",
"[",
"\"virtualNetworkName\"",
"]",
"[",
"\"value\"",
"]",
"=",
"f\"{cluster_id}-vnet\"",
"# Export parameters if the path is set",
"if",
"export_path",
":",
"os",
".",
"makedirs",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"export_path",
")",
",",
"exist_ok",
"=",
"True",
")",
"with",
"open",
"(",
"export_path",
",",
"\"w\"",
")",
"as",
"fw",
":",
"json",
".",
"dump",
"(",
"base_parameters",
",",
"fw",
",",
"indent",
"=",
"4",
")",
"return",
"parameters"
] | [
763,
4
] | [
798,
25
] | python | en | ['en', 'en', 'en'] | True |
setup | (hass, config) | Use config values to set up a function enabling status retrieval. | Use config values to set up a function enabling status retrieval. | def setup(hass, config):
"""Use config values to set up a function enabling status retrieval."""
conf = config[DOMAIN]
host = conf[CONF_HOST]
port = conf[CONF_PORT]
apcups_data = APCUPSdData(host, port)
hass.data[DOMAIN] = apcups_data
# It doesn't really matter why we're not able to get the status, just that
# we can't.
try:
apcups_data.update(no_throttle=True)
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Failure while testing APCUPSd status retrieval")
return False
return True | [
"def",
"setup",
"(",
"hass",
",",
"config",
")",
":",
"conf",
"=",
"config",
"[",
"DOMAIN",
"]",
"host",
"=",
"conf",
"[",
"CONF_HOST",
"]",
"port",
"=",
"conf",
"[",
"CONF_PORT",
"]",
"apcups_data",
"=",
"APCUPSdData",
"(",
"host",
",",
"port",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"apcups_data",
"# It doesn't really matter why we're not able to get the status, just that",
"# we can't.",
"try",
":",
"apcups_data",
".",
"update",
"(",
"no_throttle",
"=",
"True",
")",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"_LOGGER",
".",
"exception",
"(",
"\"Failure while testing APCUPSd status retrieval\"",
")",
"return",
"False",
"return",
"True"
] | [
36,
0
] | [
52,
15
] | python | en | ['en', 'en', 'en'] | True |
APCUPSdData.__init__ | (self, host, port) | Initialize the data object. | Initialize the data object. | def __init__(self, host, port):
"""Initialize the data object."""
self._host = host
self._port = port
self._status = None
self._get = status.get
self._parse = status.parse | [
"def",
"__init__",
"(",
"self",
",",
"host",
",",
"port",
")",
":",
"self",
".",
"_host",
"=",
"host",
"self",
".",
"_port",
"=",
"port",
"self",
".",
"_status",
"=",
"None",
"self",
".",
"_get",
"=",
"status",
".",
"get",
"self",
".",
"_parse",
"=",
"status",
".",
"parse"
] | [
62,
4
] | [
69,
34
] | python | en | ['en', 'en', 'en'] | True |
APCUPSdData.status | (self) | Get latest update if throttle allows. Return status. | Get latest update if throttle allows. Return status. | def status(self):
"""Get latest update if throttle allows. Return status."""
self.update()
return self._status | [
"def",
"status",
"(",
"self",
")",
":",
"self",
".",
"update",
"(",
")",
"return",
"self",
".",
"_status"
] | [
72,
4
] | [
75,
27
] | python | en | ['en', 'en', 'en'] | True |
APCUPSdData._get_status | (self) | Get the status from APCUPSd and parse it into a dict. | Get the status from APCUPSd and parse it into a dict. | def _get_status(self):
"""Get the status from APCUPSd and parse it into a dict."""
return self._parse(self._get(host=self._host, port=self._port)) | [
"def",
"_get_status",
"(",
"self",
")",
":",
"return",
"self",
".",
"_parse",
"(",
"self",
".",
"_get",
"(",
"host",
"=",
"self",
".",
"_host",
",",
"port",
"=",
"self",
".",
"_port",
")",
")"
] | [
77,
4
] | [
79,
71
] | python | en | ['en', 'en', 'en'] | True |
APCUPSdData.update | (self, **kwargs) | Fetch the latest status from APCUPSd. | Fetch the latest status from APCUPSd. | def update(self, **kwargs):
"""Fetch the latest status from APCUPSd."""
self._status = self._get_status() | [
"def",
"update",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_status",
"=",
"self",
".",
"_get_status",
"(",
")"
] | [
82,
4
] | [
84,
41
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass, config, retry_delay=FIRST_RETRY_TIME) | Set up the asuswrt component. | Set up the asuswrt component. | async def async_setup(hass, config, retry_delay=FIRST_RETRY_TIME):
"""Set up the asuswrt component."""
conf = config[DOMAIN]
api = AsusWrt(
conf[CONF_HOST],
conf[CONF_PORT],
conf[CONF_PROTOCOL] == "telnet",
conf[CONF_USERNAME],
conf.get(CONF_PASSWORD, ""),
conf.get("ssh_key", conf.get("pub_key", "")),
conf[CONF_MODE],
conf[CONF_REQUIRE_IP],
interface=conf[CONF_INTERFACE],
dnsmasq=conf[CONF_DNSMASQ],
)
try:
await api.connection.async_connect()
except OSError as ex:
_LOGGER.warning(
"Error [%s] connecting %s to %s. Will retry in %s seconds...",
str(ex),
DOMAIN,
conf[CONF_HOST],
retry_delay,
)
async def retry_setup(now):
"""Retry setup if a error happens on asuswrt API."""
await async_setup(
hass, config, retry_delay=min(2 * retry_delay, MAX_RETRY_TIME)
)
async_call_later(hass, retry_delay, retry_setup)
return True
if not api.is_connected:
_LOGGER.error("Error connecting %s to %s", DOMAIN, conf[CONF_HOST])
return False
hass.data[DATA_ASUSWRT] = api
hass.async_create_task(
async_load_platform(
hass, "sensor", DOMAIN, config[DOMAIN].get(CONF_SENSORS), config
)
)
hass.async_create_task(
async_load_platform(hass, "device_tracker", DOMAIN, {}, config)
)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
",",
"retry_delay",
"=",
"FIRST_RETRY_TIME",
")",
":",
"conf",
"=",
"config",
"[",
"DOMAIN",
"]",
"api",
"=",
"AsusWrt",
"(",
"conf",
"[",
"CONF_HOST",
"]",
",",
"conf",
"[",
"CONF_PORT",
"]",
",",
"conf",
"[",
"CONF_PROTOCOL",
"]",
"==",
"\"telnet\"",
",",
"conf",
"[",
"CONF_USERNAME",
"]",
",",
"conf",
".",
"get",
"(",
"CONF_PASSWORD",
",",
"\"\"",
")",
",",
"conf",
".",
"get",
"(",
"\"ssh_key\"",
",",
"conf",
".",
"get",
"(",
"\"pub_key\"",
",",
"\"\"",
")",
")",
",",
"conf",
"[",
"CONF_MODE",
"]",
",",
"conf",
"[",
"CONF_REQUIRE_IP",
"]",
",",
"interface",
"=",
"conf",
"[",
"CONF_INTERFACE",
"]",
",",
"dnsmasq",
"=",
"conf",
"[",
"CONF_DNSMASQ",
"]",
",",
")",
"try",
":",
"await",
"api",
".",
"connection",
".",
"async_connect",
"(",
")",
"except",
"OSError",
"as",
"ex",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Error [%s] connecting %s to %s. Will retry in %s seconds...\"",
",",
"str",
"(",
"ex",
")",
",",
"DOMAIN",
",",
"conf",
"[",
"CONF_HOST",
"]",
",",
"retry_delay",
",",
")",
"async",
"def",
"retry_setup",
"(",
"now",
")",
":",
"\"\"\"Retry setup if a error happens on asuswrt API.\"\"\"",
"await",
"async_setup",
"(",
"hass",
",",
"config",
",",
"retry_delay",
"=",
"min",
"(",
"2",
"*",
"retry_delay",
",",
"MAX_RETRY_TIME",
")",
")",
"async_call_later",
"(",
"hass",
",",
"retry_delay",
",",
"retry_setup",
")",
"return",
"True",
"if",
"not",
"api",
".",
"is_connected",
":",
"_LOGGER",
".",
"error",
"(",
"\"Error connecting %s to %s\"",
",",
"DOMAIN",
",",
"conf",
"[",
"CONF_HOST",
"]",
")",
"return",
"False",
"hass",
".",
"data",
"[",
"DATA_ASUSWRT",
"]",
"=",
"api",
"hass",
".",
"async_create_task",
"(",
"async_load_platform",
"(",
"hass",
",",
"\"sensor\"",
",",
"DOMAIN",
",",
"config",
"[",
"DOMAIN",
"]",
".",
"get",
"(",
"CONF_SENSORS",
")",
",",
"config",
")",
")",
"hass",
".",
"async_create_task",
"(",
"async_load_platform",
"(",
"hass",
",",
"\"device_tracker\"",
",",
"DOMAIN",
",",
"{",
"}",
",",
"config",
")",
")",
"return",
"True"
] | [
65,
0
] | [
119,
15
] | python | en | ['en', 'en', 'en'] | True |
mock_config_flow_login | () | Mock a successful login. | Mock a successful login. | def mock_config_flow_login():
"""Mock a successful login."""
with patch("homeassistant.components.neato.config_flow.Account", return_value=True):
yield | [
"def",
"mock_config_flow_login",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.neato.config_flow.Account\"",
",",
"return_value",
"=",
"True",
")",
":",
"yield"
] | [
37,
0
] | [
40,
13
] | python | en | ['en', 'co', 'en'] | True |
mock_controller_login | () | Mock a successful login. | Mock a successful login. | def mock_controller_login():
"""Mock a successful login."""
with patch("homeassistant.components.neato.Account", return_value=True):
yield | [
"def",
"mock_controller_login",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.neato.Account\"",
",",
"return_value",
"=",
"True",
")",
":",
"yield"
] | [
44,
0
] | [
47,
13
] | python | en | ['en', 'co', 'en'] | True |
test_no_config_entry | (hass) | There is nothing in configuration.yaml. | There is nothing in configuration.yaml. | async def test_no_config_entry(hass):
"""There is nothing in configuration.yaml."""
res = await async_setup_component(hass, NEATO_DOMAIN, {})
assert res is True | [
"async",
"def",
"test_no_config_entry",
"(",
"hass",
")",
":",
"res",
"=",
"await",
"async_setup_component",
"(",
"hass",
",",
"NEATO_DOMAIN",
",",
"{",
"}",
")",
"assert",
"res",
"is",
"True"
] | [
50,
0
] | [
53,
22
] | python | en | ['en', 'en', 'en'] | True |
test_create_valid_config_entry | (hass, config_flow, hub) | There is something in configuration.yaml. | There is something in configuration.yaml. | async def test_create_valid_config_entry(hass, config_flow, hub):
"""There is something in configuration.yaml."""
assert hass.config_entries.async_entries(NEATO_DOMAIN) == []
assert await async_setup_component(hass, NEATO_DOMAIN, {NEATO_DOMAIN: VALID_CONFIG})
await hass.async_block_till_done()
entries = hass.config_entries.async_entries(NEATO_DOMAIN)
assert entries
assert entries[0].data[CONF_USERNAME] == USERNAME
assert entries[0].data[CONF_PASSWORD] == PASSWORD
assert entries[0].data[CONF_VENDOR] == VENDOR_NEATO | [
"async",
"def",
"test_create_valid_config_entry",
"(",
"hass",
",",
"config_flow",
",",
"hub",
")",
":",
"assert",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"NEATO_DOMAIN",
")",
"==",
"[",
"]",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"NEATO_DOMAIN",
",",
"{",
"NEATO_DOMAIN",
":",
"VALID_CONFIG",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entries",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"NEATO_DOMAIN",
")",
"assert",
"entries",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_USERNAME",
"]",
"==",
"USERNAME",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_PASSWORD",
"]",
"==",
"PASSWORD",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_VENDOR",
"]",
"==",
"VENDOR_NEATO"
] | [
56,
0
] | [
66,
55
] | python | en | ['en', 'en', 'en'] | True |
test_config_entries_in_sync | (hass, hub) | The config entry and configuration.yaml are in sync. | The config entry and configuration.yaml are in sync. | async def test_config_entries_in_sync(hass, hub):
"""The config entry and configuration.yaml are in sync."""
MockConfigEntry(domain=NEATO_DOMAIN, data=VALID_CONFIG).add_to_hass(hass)
assert hass.config_entries.async_entries(NEATO_DOMAIN)
assert await async_setup_component(hass, NEATO_DOMAIN, {NEATO_DOMAIN: VALID_CONFIG})
await hass.async_block_till_done()
entries = hass.config_entries.async_entries(NEATO_DOMAIN)
assert entries
assert entries[0].data[CONF_USERNAME] == USERNAME
assert entries[0].data[CONF_PASSWORD] == PASSWORD
assert entries[0].data[CONF_VENDOR] == VENDOR_NEATO | [
"async",
"def",
"test_config_entries_in_sync",
"(",
"hass",
",",
"hub",
")",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"NEATO_DOMAIN",
",",
"data",
"=",
"VALID_CONFIG",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"assert",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"NEATO_DOMAIN",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"NEATO_DOMAIN",
",",
"{",
"NEATO_DOMAIN",
":",
"VALID_CONFIG",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entries",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"NEATO_DOMAIN",
")",
"assert",
"entries",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_USERNAME",
"]",
"==",
"USERNAME",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_PASSWORD",
"]",
"==",
"PASSWORD",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_VENDOR",
"]",
"==",
"VENDOR_NEATO"
] | [
69,
0
] | [
81,
55
] | python | en | ['en', 'en', 'en'] | True |
test_config_entries_not_in_sync | (hass, config_flow, hub) | The config entry and configuration.yaml are not in sync. | The config entry and configuration.yaml are not in sync. | async def test_config_entries_not_in_sync(hass, config_flow, hub):
"""The config entry and configuration.yaml are not in sync."""
MockConfigEntry(domain=NEATO_DOMAIN, data=DIFFERENT_CONFIG).add_to_hass(hass)
assert hass.config_entries.async_entries(NEATO_DOMAIN)
assert await async_setup_component(hass, NEATO_DOMAIN, {NEATO_DOMAIN: VALID_CONFIG})
await hass.async_block_till_done()
entries = hass.config_entries.async_entries(NEATO_DOMAIN)
assert entries
assert entries[0].data[CONF_USERNAME] == USERNAME
assert entries[0].data[CONF_PASSWORD] == PASSWORD
assert entries[0].data[CONF_VENDOR] == VENDOR_NEATO | [
"async",
"def",
"test_config_entries_not_in_sync",
"(",
"hass",
",",
"config_flow",
",",
"hub",
")",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"NEATO_DOMAIN",
",",
"data",
"=",
"DIFFERENT_CONFIG",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"assert",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"NEATO_DOMAIN",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"NEATO_DOMAIN",
",",
"{",
"NEATO_DOMAIN",
":",
"VALID_CONFIG",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entries",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"NEATO_DOMAIN",
")",
"assert",
"entries",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_USERNAME",
"]",
"==",
"USERNAME",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_PASSWORD",
"]",
"==",
"PASSWORD",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_VENDOR",
"]",
"==",
"VENDOR_NEATO"
] | [
84,
0
] | [
96,
55
] | python | en | ['en', 'en', 'en'] | True |
test_config_entries_not_in_sync_error | (hass) | The config entry and configuration.yaml are not in sync, the new configuration is wrong. | The config entry and configuration.yaml are not in sync, the new configuration is wrong. | async def test_config_entries_not_in_sync_error(hass):
"""The config entry and configuration.yaml are not in sync, the new configuration is wrong."""
MockConfigEntry(domain=NEATO_DOMAIN, data=VALID_CONFIG).add_to_hass(hass)
assert hass.config_entries.async_entries(NEATO_DOMAIN)
with patch(
"homeassistant.components.neato.config_flow.Account",
side_effect=NeatoLoginException(),
):
assert not await async_setup_component(
hass, NEATO_DOMAIN, {NEATO_DOMAIN: DIFFERENT_CONFIG}
)
await hass.async_block_till_done()
entries = hass.config_entries.async_entries(NEATO_DOMAIN)
assert entries
assert entries[0].data[CONF_USERNAME] == USERNAME
assert entries[0].data[CONF_PASSWORD] == PASSWORD
assert entries[0].data[CONF_VENDOR] == VENDOR_NEATO | [
"async",
"def",
"test_config_entries_not_in_sync_error",
"(",
"hass",
")",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"NEATO_DOMAIN",
",",
"data",
"=",
"VALID_CONFIG",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"assert",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"NEATO_DOMAIN",
")",
"with",
"patch",
"(",
"\"homeassistant.components.neato.config_flow.Account\"",
",",
"side_effect",
"=",
"NeatoLoginException",
"(",
")",
",",
")",
":",
"assert",
"not",
"await",
"async_setup_component",
"(",
"hass",
",",
"NEATO_DOMAIN",
",",
"{",
"NEATO_DOMAIN",
":",
"DIFFERENT_CONFIG",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entries",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"NEATO_DOMAIN",
")",
"assert",
"entries",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_USERNAME",
"]",
"==",
"USERNAME",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_PASSWORD",
"]",
"==",
"PASSWORD",
"assert",
"entries",
"[",
"0",
"]",
".",
"data",
"[",
"CONF_VENDOR",
"]",
"==",
"VENDOR_NEATO"
] | [
99,
0
] | [
117,
55
] | python | en | ['en', 'en', 'en'] | True |
find_box | (segment: io.BytesIO, target_type: bytes, box_start: int = 0) | Find location of first box (or sub_box if box_start provided) of given type. | Find location of first box (or sub_box if box_start provided) of given type. | def find_box(segment: io.BytesIO, target_type: bytes, box_start: int = 0) -> int:
"""Find location of first box (or sub_box if box_start provided) of given type."""
if box_start == 0:
box_end = segment.seek(0, io.SEEK_END)
segment.seek(0)
index = 0
else:
segment.seek(box_start)
box_end = box_start + int.from_bytes(segment.read(4), byteorder="big")
index = box_start + 8
while 1:
if index > box_end - 8: # End of box, not found
break
segment.seek(index)
box_header = segment.read(8)
if box_header[4:8] == target_type:
yield index
segment.seek(index)
index += int.from_bytes(box_header[0:4], byteorder="big") | [
"def",
"find_box",
"(",
"segment",
":",
"io",
".",
"BytesIO",
",",
"target_type",
":",
"bytes",
",",
"box_start",
":",
"int",
"=",
"0",
")",
"->",
"int",
":",
"if",
"box_start",
"==",
"0",
":",
"box_end",
"=",
"segment",
".",
"seek",
"(",
"0",
",",
"io",
".",
"SEEK_END",
")",
"segment",
".",
"seek",
"(",
"0",
")",
"index",
"=",
"0",
"else",
":",
"segment",
".",
"seek",
"(",
"box_start",
")",
"box_end",
"=",
"box_start",
"+",
"int",
".",
"from_bytes",
"(",
"segment",
".",
"read",
"(",
"4",
")",
",",
"byteorder",
"=",
"\"big\"",
")",
"index",
"=",
"box_start",
"+",
"8",
"while",
"1",
":",
"if",
"index",
">",
"box_end",
"-",
"8",
":",
"# End of box, not found",
"break",
"segment",
".",
"seek",
"(",
"index",
")",
"box_header",
"=",
"segment",
".",
"read",
"(",
"8",
")",
"if",
"box_header",
"[",
"4",
":",
"8",
"]",
"==",
"target_type",
":",
"yield",
"index",
"segment",
".",
"seek",
"(",
"index",
")",
"index",
"+=",
"int",
".",
"from_bytes",
"(",
"box_header",
"[",
"0",
":",
"4",
"]",
",",
"byteorder",
"=",
"\"big\"",
")"
] | [
4,
0
] | [
22,
65
] | python | en | ['en', 'en', 'en'] | True |
get_init | (segment: io.BytesIO) | Get init section from fragmented mp4. | Get init section from fragmented mp4. | def get_init(segment: io.BytesIO) -> bytes:
"""Get init section from fragmented mp4."""
moof_location = next(find_box(segment, b"moof"))
segment.seek(0)
return segment.read(moof_location) | [
"def",
"get_init",
"(",
"segment",
":",
"io",
".",
"BytesIO",
")",
"->",
"bytes",
":",
"moof_location",
"=",
"next",
"(",
"find_box",
"(",
"segment",
",",
"b\"moof\"",
")",
")",
"segment",
".",
"seek",
"(",
"0",
")",
"return",
"segment",
".",
"read",
"(",
"moof_location",
")"
] | [
25,
0
] | [
29,
38
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.