repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ev3dev/ev3dev-lang-python | ev3dev2/control/GyroBalancer.py | GyroBalancer._fast_write | def _fast_write(self, outfile, value):
"""Function for fast writing to motor files."""
outfile.truncate(0)
outfile.write(str(int(value)))
outfile.flush() | python | def _fast_write(self, outfile, value):
"""Function for fast writing to motor files."""
outfile.truncate(0)
outfile.write(str(int(value)))
outfile.flush() | [
"def",
"_fast_write",
"(",
"self",
",",
"outfile",
",",
"value",
")",
":",
"outfile",
".",
"truncate",
"(",
"0",
")",
"outfile",
".",
"write",
"(",
"str",
"(",
"int",
"(",
"value",
")",
")",
")",
"outfile",
".",
"flush",
"(",
")"
] | Function for fast writing to motor files. | [
"Function",
"for",
"fast",
"writing",
"to",
"motor",
"files",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/control/GyroBalancer.py#L179-L183 | train |
ev3dev/ev3dev-lang-python | ev3dev2/control/GyroBalancer.py | GyroBalancer._set_duty | def _set_duty(self, motor_duty_file, duty, friction_offset,
voltage_comp):
"""Function to set the duty cycle of the motors."""
# Compensate for nominal voltage and round the input
duty_int = int(round(duty*voltage_comp))
# Add or subtract offset and clamp the value bet... | python | def _set_duty(self, motor_duty_file, duty, friction_offset,
voltage_comp):
"""Function to set the duty cycle of the motors."""
# Compensate for nominal voltage and round the input
duty_int = int(round(duty*voltage_comp))
# Add or subtract offset and clamp the value bet... | [
"def",
"_set_duty",
"(",
"self",
",",
"motor_duty_file",
",",
"duty",
",",
"friction_offset",
",",
"voltage_comp",
")",
":",
"duty_int",
"=",
"int",
"(",
"round",
"(",
"duty",
"*",
"voltage_comp",
")",
")",
"if",
"duty_int",
">",
"0",
":",
"duty_int",
"=... | Function to set the duty cycle of the motors. | [
"Function",
"to",
"set",
"the",
"duty",
"cycle",
"of",
"the",
"motors",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/control/GyroBalancer.py#L185-L198 | train |
ev3dev/ev3dev-lang-python | ev3dev2/control/GyroBalancer.py | GyroBalancer.balance | def balance(self):
"""Run the _balance method as a thread."""
balance_thread = threading.Thread(target=self._balance)
balance_thread.start() | python | def balance(self):
"""Run the _balance method as a thread."""
balance_thread = threading.Thread(target=self._balance)
balance_thread.start() | [
"def",
"balance",
"(",
"self",
")",
":",
"balance_thread",
"=",
"threading",
".",
"Thread",
"(",
"target",
"=",
"self",
".",
"_balance",
")",
"balance_thread",
".",
"start",
"(",
")"
] | Run the _balance method as a thread. | [
"Run",
"the",
"_balance",
"method",
"as",
"a",
"thread",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/control/GyroBalancer.py#L212-L215 | train |
ev3dev/ev3dev-lang-python | ev3dev2/control/GyroBalancer.py | GyroBalancer._move | def _move(self, speed=0, steering=0, seconds=None):
"""Move robot."""
self.drive_queue.put((speed, steering))
if seconds is not None:
time.sleep(seconds)
self.drive_queue.put((0, 0))
self.drive_queue.join() | python | def _move(self, speed=0, steering=0, seconds=None):
"""Move robot."""
self.drive_queue.put((speed, steering))
if seconds is not None:
time.sleep(seconds)
self.drive_queue.put((0, 0))
self.drive_queue.join() | [
"def",
"_move",
"(",
"self",
",",
"speed",
"=",
"0",
",",
"steering",
"=",
"0",
",",
"seconds",
"=",
"None",
")",
":",
"self",
".",
"drive_queue",
".",
"put",
"(",
"(",
"speed",
",",
"steering",
")",
")",
"if",
"seconds",
"is",
"not",
"None",
":"... | Move robot. | [
"Move",
"robot",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/control/GyroBalancer.py#L475-L481 | train |
ev3dev/ev3dev-lang-python | ev3dev2/control/GyroBalancer.py | GyroBalancer.move_forward | def move_forward(self, seconds=None):
"""Move robot forward."""
self._move(speed=SPEED_MAX, steering=0, seconds=seconds) | python | def move_forward(self, seconds=None):
"""Move robot forward."""
self._move(speed=SPEED_MAX, steering=0, seconds=seconds) | [
"def",
"move_forward",
"(",
"self",
",",
"seconds",
"=",
"None",
")",
":",
"self",
".",
"_move",
"(",
"speed",
"=",
"SPEED_MAX",
",",
"steering",
"=",
"0",
",",
"seconds",
"=",
"seconds",
")"
] | Move robot forward. | [
"Move",
"robot",
"forward",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/control/GyroBalancer.py#L483-L485 | train |
ev3dev/ev3dev-lang-python | ev3dev2/control/GyroBalancer.py | GyroBalancer.move_backward | def move_backward(self, seconds=None):
"""Move robot backward."""
self._move(speed=-SPEED_MAX, steering=0, seconds=seconds) | python | def move_backward(self, seconds=None):
"""Move robot backward."""
self._move(speed=-SPEED_MAX, steering=0, seconds=seconds) | [
"def",
"move_backward",
"(",
"self",
",",
"seconds",
"=",
"None",
")",
":",
"self",
".",
"_move",
"(",
"speed",
"=",
"-",
"SPEED_MAX",
",",
"steering",
"=",
"0",
",",
"seconds",
"=",
"seconds",
")"
] | Move robot backward. | [
"Move",
"robot",
"backward",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/control/GyroBalancer.py#L487-L489 | train |
ev3dev/ev3dev-lang-python | ev3dev2/control/GyroBalancer.py | GyroBalancer.rotate_left | def rotate_left(self, seconds=None):
"""Rotate robot left."""
self._move(speed=0, steering=STEER_MAX, seconds=seconds) | python | def rotate_left(self, seconds=None):
"""Rotate robot left."""
self._move(speed=0, steering=STEER_MAX, seconds=seconds) | [
"def",
"rotate_left",
"(",
"self",
",",
"seconds",
"=",
"None",
")",
":",
"self",
".",
"_move",
"(",
"speed",
"=",
"0",
",",
"steering",
"=",
"STEER_MAX",
",",
"seconds",
"=",
"seconds",
")"
] | Rotate robot left. | [
"Rotate",
"robot",
"left",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/control/GyroBalancer.py#L491-L493 | train |
ev3dev/ev3dev-lang-python | ev3dev2/control/GyroBalancer.py | GyroBalancer.rotate_right | def rotate_right(self, seconds=None):
"""Rotate robot right."""
self._move(speed=0, steering=-STEER_MAX, seconds=seconds) | python | def rotate_right(self, seconds=None):
"""Rotate robot right."""
self._move(speed=0, steering=-STEER_MAX, seconds=seconds) | [
"def",
"rotate_right",
"(",
"self",
",",
"seconds",
"=",
"None",
")",
":",
"self",
".",
"_move",
"(",
"speed",
"=",
"0",
",",
"steering",
"=",
"-",
"STEER_MAX",
",",
"seconds",
"=",
"seconds",
")"
] | Rotate robot right. | [
"Rotate",
"robot",
"right",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/control/GyroBalancer.py#L495-L497 | train |
ev3dev/ev3dev-lang-python | ev3dev2/button.py | ButtonBase.evdev_device | def evdev_device(self):
"""
Return our corresponding evdev device object
"""
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for device in devices:
if device.name == self.evdev_device_name:
return device
raise Exception("%s: ... | python | def evdev_device(self):
"""
Return our corresponding evdev device object
"""
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for device in devices:
if device.name == self.evdev_device_name:
return device
raise Exception("%s: ... | [
"def",
"evdev_device",
"(",
"self",
")",
":",
"devices",
"=",
"[",
"evdev",
".",
"InputDevice",
"(",
"fn",
")",
"for",
"fn",
"in",
"evdev",
".",
"list_devices",
"(",
")",
"]",
"for",
"device",
"in",
"devices",
":",
"if",
"device",
".",
"name",
"==",
... | Return our corresponding evdev device object | [
"Return",
"our",
"corresponding",
"evdev",
"device",
"object"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/button.py#L115-L125 | train |
ev3dev/ev3dev-lang-python | ev3dev2/button.py | ButtonBase.wait_for_bump | def wait_for_bump(self, buttons, timeout_ms=None):
"""
Wait for the button to be pressed down and then released.
Both actions must happen within timeout_ms.
"""
start_time = time.time()
if self.wait_for_pressed(buttons, timeout_ms):
if timeout_ms is not None:... | python | def wait_for_bump(self, buttons, timeout_ms=None):
"""
Wait for the button to be pressed down and then released.
Both actions must happen within timeout_ms.
"""
start_time = time.time()
if self.wait_for_pressed(buttons, timeout_ms):
if timeout_ms is not None:... | [
"def",
"wait_for_bump",
"(",
"self",
",",
"buttons",
",",
"timeout_ms",
"=",
"None",
")",
":",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"if",
"self",
".",
"wait_for_pressed",
"(",
"buttons",
",",
"timeout_ms",
")",
":",
"if",
"timeout_ms",
"is",... | Wait for the button to be pressed down and then released.
Both actions must happen within timeout_ms. | [
"Wait",
"for",
"the",
"button",
"to",
"be",
"pressed",
"down",
"and",
"then",
"released",
".",
"Both",
"actions",
"must",
"happen",
"within",
"timeout_ms",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/button.py#L202-L214 | train |
ev3dev/ev3dev-lang-python | ev3dev2/button.py | ButtonEVIO.buttons_pressed | def buttons_pressed(self):
"""
Returns list of names of pressed buttons.
"""
for b in self._buffer_cache:
fcntl.ioctl(self._button_file(b), self.EVIOCGKEY, self._buffer_cache[b])
pressed = []
for k, v in self._buttons.items():
buf = self._buffer_c... | python | def buttons_pressed(self):
"""
Returns list of names of pressed buttons.
"""
for b in self._buffer_cache:
fcntl.ioctl(self._button_file(b), self.EVIOCGKEY, self._buffer_cache[b])
pressed = []
for k, v in self._buttons.items():
buf = self._buffer_c... | [
"def",
"buttons_pressed",
"(",
"self",
")",
":",
"for",
"b",
"in",
"self",
".",
"_buffer_cache",
":",
"fcntl",
".",
"ioctl",
"(",
"self",
".",
"_button_file",
"(",
"b",
")",
",",
"self",
".",
"EVIOCGKEY",
",",
"self",
".",
"_buffer_cache",
"[",
"b",
... | Returns list of names of pressed buttons. | [
"Returns",
"list",
"of",
"names",
"of",
"pressed",
"buttons",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/button.py#L255-L270 | train |
aws/sagemaker-containers | src/sagemaker_containers/_mpi.py | _orted_process | def _orted_process():
"""Waits maximum of 5 minutes for orted process to start"""
for i in range(5 * 60):
procs = [p for p in psutil.process_iter(attrs=['name']) if p.info['name'] == 'orted']
if procs:
return procs
time.sleep(1) | python | def _orted_process():
"""Waits maximum of 5 minutes for orted process to start"""
for i in range(5 * 60):
procs = [p for p in psutil.process_iter(attrs=['name']) if p.info['name'] == 'orted']
if procs:
return procs
time.sleep(1) | [
"def",
"_orted_process",
"(",
")",
":",
"for",
"i",
"in",
"range",
"(",
"5",
"*",
"60",
")",
":",
"procs",
"=",
"[",
"p",
"for",
"p",
"in",
"psutil",
".",
"process_iter",
"(",
"attrs",
"=",
"[",
"'name'",
"]",
")",
"if",
"p",
".",
"info",
"[",
... | Waits maximum of 5 minutes for orted process to start | [
"Waits",
"maximum",
"of",
"5",
"minutes",
"for",
"orted",
"process",
"to",
"start"
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_mpi.py#L75-L82 | train |
aws/sagemaker-containers | src/sagemaker_containers/_mpi.py | _parse_custom_mpi_options | def _parse_custom_mpi_options(custom_mpi_options):
# type: (str) -> Tuple[argparse.Namespace, List[str]]
"""Parse custom MPI options provided by user. Known options default value will be overridden
and unknown options would be identified separately."""
parser = argparse.ArgumentParser()
parser.add_... | python | def _parse_custom_mpi_options(custom_mpi_options):
# type: (str) -> Tuple[argparse.Namespace, List[str]]
"""Parse custom MPI options provided by user. Known options default value will be overridden
and unknown options would be identified separately."""
parser = argparse.ArgumentParser()
parser.add_... | [
"def",
"_parse_custom_mpi_options",
"(",
"custom_mpi_options",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"'--NCCL_DEBUG'",
",",
"default",
"=",
"\"INFO\"",
",",
"type",
"=",
"str",
")",
"return",
... | Parse custom MPI options provided by user. Known options default value will be overridden
and unknown options would be identified separately. | [
"Parse",
"custom",
"MPI",
"options",
"provided",
"by",
"user",
".",
"Known",
"options",
"default",
"value",
"will",
"be",
"overridden",
"and",
"unknown",
"options",
"would",
"be",
"identified",
"separately",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_mpi.py#L230-L238 | train |
aws/sagemaker-containers | src/sagemaker_containers/_modules.py | download_and_install | def download_and_install(uri, name=DEFAULT_MODULE_NAME, cache=True):
# type: (str, str, bool) -> None
"""Download, prepare and install a compressed tar file from S3 or local directory as a module.
The SageMaker Python SDK saves the user provided scripts as compressed tar files in S3.
This function down... | python | def download_and_install(uri, name=DEFAULT_MODULE_NAME, cache=True):
# type: (str, str, bool) -> None
"""Download, prepare and install a compressed tar file from S3 or local directory as a module.
The SageMaker Python SDK saves the user provided scripts as compressed tar files in S3.
This function down... | [
"def",
"download_and_install",
"(",
"uri",
",",
"name",
"=",
"DEFAULT_MODULE_NAME",
",",
"cache",
"=",
"True",
")",
":",
"should_use_cache",
"=",
"cache",
"and",
"exists",
"(",
"name",
")",
"if",
"not",
"should_use_cache",
":",
"with",
"_files",
".",
"tmpdir... | Download, prepare and install a compressed tar file from S3 or local directory as a module.
The SageMaker Python SDK saves the user provided scripts as compressed tar files in S3.
This function downloads this compressed file and, if provided, transforms it
into a module before installing it.
This meth... | [
"Download",
"prepare",
"and",
"install",
"a",
"compressed",
"tar",
"file",
"from",
"S3",
"or",
"local",
"directory",
"as",
"a",
"module",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_modules.py#L126-L159 | train |
aws/sagemaker-containers | src/sagemaker_containers/_modules.py | run | def run(module_name, args=None, env_vars=None, wait=True, capture_error=False):
# type: (str, list, dict, bool, bool) -> subprocess.Popen
"""Run Python module as a script.
Search sys.path for the named module and execute its contents as the __main__ module.
Since the argument is a module name, you mus... | python | def run(module_name, args=None, env_vars=None, wait=True, capture_error=False):
# type: (str, list, dict, bool, bool) -> subprocess.Popen
"""Run Python module as a script.
Search sys.path for the named module and execute its contents as the __main__ module.
Since the argument is a module name, you mus... | [
"def",
"run",
"(",
"module_name",
",",
"args",
"=",
"None",
",",
"env_vars",
"=",
"None",
",",
"wait",
"=",
"True",
",",
"capture_error",
"=",
"False",
")",
":",
"args",
"=",
"args",
"or",
"[",
"]",
"env_vars",
"=",
"env_vars",
"or",
"{",
"}",
"cmd... | Run Python module as a script.
Search sys.path for the named module and execute its contents as the __main__ module.
Since the argument is a module name, you must not give a file extension (.py). The module name should be a valid
absolute Python module name, but the implementation may not always enforce t... | [
"Run",
"Python",
"module",
"as",
"a",
"script",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_modules.py#L162-L225 | train |
aws/sagemaker-containers | src/sagemaker_containers/_modules.py | run_module | def run_module(uri, args, env_vars=None, name=DEFAULT_MODULE_NAME, cache=None, wait=True, capture_error=False):
# type: (str, list, dict, str, bool, bool, bool) -> subprocess.Popen
"""Download, prepare and executes a compressed tar file from S3 or provided directory as a module.
SageMaker Python SDK saves ... | python | def run_module(uri, args, env_vars=None, name=DEFAULT_MODULE_NAME, cache=None, wait=True, capture_error=False):
# type: (str, list, dict, str, bool, bool, bool) -> subprocess.Popen
"""Download, prepare and executes a compressed tar file from S3 or provided directory as a module.
SageMaker Python SDK saves ... | [
"def",
"run_module",
"(",
"uri",
",",
"args",
",",
"env_vars",
"=",
"None",
",",
"name",
"=",
"DEFAULT_MODULE_NAME",
",",
"cache",
"=",
"None",
",",
"wait",
"=",
"True",
",",
"capture_error",
"=",
"False",
")",
":",
"_warning_cache_deprecation",
"(",
"cach... | Download, prepare and executes a compressed tar file from S3 or provided directory as a module.
SageMaker Python SDK saves the user provided scripts as compressed tar files in S3
https://github.com/aws/sagemaker-python-sdk.
This function downloads this compressed file, transforms it as a module, and execut... | [
"Download",
"prepare",
"and",
"executes",
"a",
"compressed",
"tar",
"file",
"from",
"S3",
"or",
"provided",
"directory",
"as",
"a",
"module",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_modules.py#L254-L281 | train |
aws/sagemaker-containers | src/sagemaker_containers/_worker.py | Request.content_type | def content_type(self): # type: () -> str
"""The request's content-type.
Returns:
(str): The value, if any, of the header 'ContentType' (used by some AWS services) and 'Content-Type'.
Otherwise, returns 'application/json' as default.
"""
# todo(mvsusp): ... | python | def content_type(self): # type: () -> str
"""The request's content-type.
Returns:
(str): The value, if any, of the header 'ContentType' (used by some AWS services) and 'Content-Type'.
Otherwise, returns 'application/json' as default.
"""
# todo(mvsusp): ... | [
"def",
"content_type",
"(",
"self",
")",
":",
"return",
"self",
".",
"headers",
".",
"get",
"(",
"'ContentType'",
")",
"or",
"self",
".",
"headers",
".",
"get",
"(",
"'Content-Type'",
")",
"or",
"_content_types",
".",
"JSON"
] | The request's content-type.
Returns:
(str): The value, if any, of the header 'ContentType' (used by some AWS services) and 'Content-Type'.
Otherwise, returns 'application/json' as default. | [
"The",
"request",
"s",
"content",
"-",
"type",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_worker.py#L135-L144 | train |
aws/sagemaker-containers | src/sagemaker_containers/_worker.py | Request.accept | def accept(self): # type: () -> str
"""The content-type for the response to the client.
Returns:
(str): The value of the header 'Accept' or the user-supplied SAGEMAKER_DEFAULT_INVOCATIONS_ACCEPT
environment variable.
"""
accept = self.headers.get('Accept... | python | def accept(self): # type: () -> str
"""The content-type for the response to the client.
Returns:
(str): The value of the header 'Accept' or the user-supplied SAGEMAKER_DEFAULT_INVOCATIONS_ACCEPT
environment variable.
"""
accept = self.headers.get('Accept... | [
"def",
"accept",
"(",
"self",
")",
":",
"accept",
"=",
"self",
".",
"headers",
".",
"get",
"(",
"'Accept'",
")",
"if",
"not",
"accept",
"or",
"accept",
"==",
"_content_types",
".",
"ANY",
":",
"return",
"self",
".",
"_default_accept",
"else",
":",
"ret... | The content-type for the response to the client.
Returns:
(str): The value of the header 'Accept' or the user-supplied SAGEMAKER_DEFAULT_INVOCATIONS_ACCEPT
environment variable. | [
"The",
"content",
"-",
"type",
"for",
"the",
"response",
"to",
"the",
"client",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_worker.py#L147-L159 | train |
aws/sagemaker-containers | src/sagemaker_containers/_worker.py | Request.content | def content(self): # type: () -> object
"""The request incoming data.
It automatic decodes from utf-8
Returns:
(obj): incoming data
"""
as_text = self.content_type in _content_types.UTF8_TYPES
return self.get_data(as_text=as_text) | python | def content(self): # type: () -> object
"""The request incoming data.
It automatic decodes from utf-8
Returns:
(obj): incoming data
"""
as_text = self.content_type in _content_types.UTF8_TYPES
return self.get_data(as_text=as_text) | [
"def",
"content",
"(",
"self",
")",
":",
"as_text",
"=",
"self",
".",
"content_type",
"in",
"_content_types",
".",
"UTF8_TYPES",
"return",
"self",
".",
"get_data",
"(",
"as_text",
"=",
"as_text",
")"
] | The request incoming data.
It automatic decodes from utf-8
Returns:
(obj): incoming data | [
"The",
"request",
"incoming",
"data",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_worker.py#L162-L172 | train |
aws/sagemaker-containers | src/sagemaker_containers/entry_point.py | run | def run(uri,
user_entry_point,
args,
env_vars=None,
wait=True,
capture_error=False,
runner=_runner.ProcessRunnerType,
extra_opts=None):
# type: (str, str, List[str], Dict[str, str], bool, bool, _runner.RunnerType, Dict[str, str]) -> None
"""Download, prepa... | python | def run(uri,
user_entry_point,
args,
env_vars=None,
wait=True,
capture_error=False,
runner=_runner.ProcessRunnerType,
extra_opts=None):
# type: (str, str, List[str], Dict[str, str], bool, bool, _runner.RunnerType, Dict[str, str]) -> None
"""Download, prepa... | [
"def",
"run",
"(",
"uri",
",",
"user_entry_point",
",",
"args",
",",
"env_vars",
"=",
"None",
",",
"wait",
"=",
"True",
",",
"capture_error",
"=",
"False",
",",
"runner",
"=",
"_runner",
".",
"ProcessRunnerType",
",",
"extra_opts",
"=",
"None",
")",
":",... | Download, prepare and executes a compressed tar file from S3 or provided directory as an user
entrypoint. Runs the user entry point, passing env_vars as environment variables and args as command
arguments.
If the entry point is:
- A Python package: executes the packages as >>> env_vars python -m mo... | [
"Download",
"prepare",
"and",
"executes",
"a",
"compressed",
"tar",
"file",
"from",
"S3",
"or",
"provided",
"directory",
"as",
"an",
"user",
"entrypoint",
".",
"Runs",
"the",
"user",
"entry",
"point",
"passing",
"env_vars",
"as",
"environment",
"variables",
"a... | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/entry_point.py#L22-L89 | train |
aws/sagemaker-containers | src/sagemaker_containers/_logging.py | configure_logger | def configure_logger(level, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s'):
# type: (int, str) -> None
"""Set logger configuration.
Args:
level (int): Logger level
format (str): Logger format
"""
logging.basicConfig(format=format, level=level)
if level >= logging... | python | def configure_logger(level, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s'):
# type: (int, str) -> None
"""Set logger configuration.
Args:
level (int): Logger level
format (str): Logger format
"""
logging.basicConfig(format=format, level=level)
if level >= logging... | [
"def",
"configure_logger",
"(",
"level",
",",
"format",
"=",
"'%(asctime)s %(name)-12s %(levelname)-8s %(message)s'",
")",
":",
"logging",
".",
"basicConfig",
"(",
"format",
"=",
"format",
",",
"level",
"=",
"level",
")",
"if",
"level",
">=",
"logging",
".",
"IN... | Set logger configuration.
Args:
level (int): Logger level
format (str): Logger format | [
"Set",
"logger",
"configuration",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_logging.py#L25-L38 | train |
aws/sagemaker-containers | src/sagemaker_containers/_intermediate_output.py | _timestamp | def _timestamp():
"""Return a timestamp with microsecond precision."""
moment = time.time()
moment_us = repr(moment).split('.')[1]
return time.strftime("%Y-%m-%d-%H-%M-%S-{}".format(moment_us), time.gmtime(moment)) | python | def _timestamp():
"""Return a timestamp with microsecond precision."""
moment = time.time()
moment_us = repr(moment).split('.')[1]
return time.strftime("%Y-%m-%d-%H-%M-%S-{}".format(moment_us), time.gmtime(moment)) | [
"def",
"_timestamp",
"(",
")",
":",
"moment",
"=",
"time",
".",
"time",
"(",
")",
"moment_us",
"=",
"repr",
"(",
"moment",
")",
".",
"split",
"(",
"'.'",
")",
"[",
"1",
"]",
"return",
"time",
".",
"strftime",
"(",
"\"%Y-%m-%d-%H-%M-%S-{}\"",
".",
"fo... | Return a timestamp with microsecond precision. | [
"Return",
"a",
"timestamp",
"with",
"microsecond",
"precision",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_intermediate_output.py#L36-L40 | train |
aws/sagemaker-containers | src/sagemaker_containers/_mapping.py | split_by_criteria | def split_by_criteria(dictionary, keys=None, prefix=None): # type: (dict, set or list or tuple) -> SplitResultSpec
"""Split a dictionary in two by the provided keys.
Args:
dictionary (dict[str, object]): A Python dictionary
keys (sequence [str]): A sequence of keys which will be added the spli... | python | def split_by_criteria(dictionary, keys=None, prefix=None): # type: (dict, set or list or tuple) -> SplitResultSpec
"""Split a dictionary in two by the provided keys.
Args:
dictionary (dict[str, object]): A Python dictionary
keys (sequence [str]): A sequence of keys which will be added the spli... | [
"def",
"split_by_criteria",
"(",
"dictionary",
",",
"keys",
"=",
"None",
",",
"prefix",
"=",
"None",
")",
":",
"keys",
"=",
"keys",
"or",
"[",
"]",
"keys",
"=",
"set",
"(",
"keys",
")",
"included_items",
"=",
"{",
"k",
":",
"dictionary",
"[",
"k",
... | Split a dictionary in two by the provided keys.
Args:
dictionary (dict[str, object]): A Python dictionary
keys (sequence [str]): A sequence of keys which will be added the split criteria
prefix (str): A prefix which will be added the split criteria
Returns:
`SplitResultSpec` : ... | [
"Split",
"a",
"dictionary",
"in",
"two",
"by",
"the",
"provided",
"keys",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_mapping.py#L119-L140 | train |
aws/sagemaker-containers | src/sagemaker_containers/_transformer.py | default_output_fn | def default_output_fn(prediction, accept):
"""Function responsible to serialize the prediction for the response.
Args:
prediction (obj): prediction returned by predict_fn .
accept (str): accept content-type expected by the client.
Returns:
(worker.Response): a Flask response object... | python | def default_output_fn(prediction, accept):
"""Function responsible to serialize the prediction for the response.
Args:
prediction (obj): prediction returned by predict_fn .
accept (str): accept content-type expected by the client.
Returns:
(worker.Response): a Flask response object... | [
"def",
"default_output_fn",
"(",
"prediction",
",",
"accept",
")",
":",
"return",
"_worker",
".",
"Response",
"(",
"response",
"=",
"_encoders",
".",
"encode",
"(",
"prediction",
",",
"accept",
")",
",",
"mimetype",
"=",
"accept",
")"
] | Function responsible to serialize the prediction for the response.
Args:
prediction (obj): prediction returned by predict_fn .
accept (str): accept content-type expected by the client.
Returns:
(worker.Response): a Flask response object with the following args:
* Args:
... | [
"Function",
"responsible",
"to",
"serialize",
"the",
"prediction",
"for",
"the",
"response",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_transformer.py#L77-L91 | train |
aws/sagemaker-containers | src/sagemaker_containers/_transformer.py | Transformer.transform | def transform(self): # type: () -> _worker.Response
"""Take a request with input data, deserialize it, make a prediction, and return a
serialized response.
Returns:
sagemaker_containers.beta.framework.worker.Response: a Flask response object with
the following args:... | python | def transform(self): # type: () -> _worker.Response
"""Take a request with input data, deserialize it, make a prediction, and return a
serialized response.
Returns:
sagemaker_containers.beta.framework.worker.Response: a Flask response object with
the following args:... | [
"def",
"transform",
"(",
"self",
")",
":",
"request",
"=",
"_worker",
".",
"Request",
"(",
")",
"result",
"=",
"self",
".",
"_transform_fn",
"(",
"self",
".",
"_model",
",",
"request",
".",
"content",
",",
"request",
".",
"content_type",
",",
"request",
... | Take a request with input data, deserialize it, make a prediction, and return a
serialized response.
Returns:
sagemaker_containers.beta.framework.worker.Response: a Flask response object with
the following args:
* response: the serialized data to return
... | [
"Take",
"a",
"request",
"with",
"input",
"data",
"deserialize",
"it",
"make",
"a",
"prediction",
"and",
"return",
"a",
"serialized",
"response",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_transformer.py#L159-L177 | train |
aws/sagemaker-containers | src/sagemaker_containers/_transformer.py | Transformer._default_transform_fn | def _default_transform_fn(self, model, content, content_type, accept):
"""Make predictions against the model and return a serialized response.
This serves as the default implementation of transform_fn, used when the user has not
implemented one themselves.
Args:
model (obj)... | python | def _default_transform_fn(self, model, content, content_type, accept):
"""Make predictions against the model and return a serialized response.
This serves as the default implementation of transform_fn, used when the user has not
implemented one themselves.
Args:
model (obj)... | [
"def",
"_default_transform_fn",
"(",
"self",
",",
"model",
",",
"content",
",",
"content_type",
",",
"accept",
")",
":",
"try",
":",
"data",
"=",
"self",
".",
"_input_fn",
"(",
"content",
",",
"content_type",
")",
"except",
"_errors",
".",
"UnsupportedFormat... | Make predictions against the model and return a serialized response.
This serves as the default implementation of transform_fn, used when the user has not
implemented one themselves.
Args:
model (obj): model loaded by model_fn.
content: request content.
cont... | [
"Make",
"predictions",
"against",
"the",
"model",
"and",
"return",
"a",
"serialized",
"response",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_transformer.py#L179-L208 | train |
aws/sagemaker-containers | src/sagemaker_containers/__init__.py | training_env | def training_env(): # type: () -> _env.TrainingEnv
"""Create a TrainingEnv.
Returns:
TrainingEnv: an instance of TrainingEnv
"""
from sagemaker_containers import _env
return _env.TrainingEnv(
resource_config=_env.read_resource_config(),
input_data_config=_env.read_input_d... | python | def training_env(): # type: () -> _env.TrainingEnv
"""Create a TrainingEnv.
Returns:
TrainingEnv: an instance of TrainingEnv
"""
from sagemaker_containers import _env
return _env.TrainingEnv(
resource_config=_env.read_resource_config(),
input_data_config=_env.read_input_d... | [
"def",
"training_env",
"(",
")",
":",
"from",
"sagemaker_containers",
"import",
"_env",
"return",
"_env",
".",
"TrainingEnv",
"(",
"resource_config",
"=",
"_env",
".",
"read_resource_config",
"(",
")",
",",
"input_data_config",
"=",
"_env",
".",
"read_input_data_c... | Create a TrainingEnv.
Returns:
TrainingEnv: an instance of TrainingEnv | [
"Create",
"a",
"TrainingEnv",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/__init__.py#L16-L28 | train |
aws/sagemaker-containers | src/sagemaker_containers/_env.py | _write_json | def _write_json(obj, path): # type: (object, str) -> None
"""Writes a serializeable object as a JSON file"""
with open(path, 'w') as f:
json.dump(obj, f) | python | def _write_json(obj, path): # type: (object, str) -> None
"""Writes a serializeable object as a JSON file"""
with open(path, 'w') as f:
json.dump(obj, f) | [
"def",
"_write_json",
"(",
"obj",
",",
"path",
")",
":",
"with",
"open",
"(",
"path",
",",
"'w'",
")",
"as",
"f",
":",
"json",
".",
"dump",
"(",
"obj",
",",
"f",
")"
] | Writes a serializeable object as a JSON file | [
"Writes",
"a",
"serializeable",
"object",
"as",
"a",
"JSON",
"file"
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_env.py#L36-L39 | train |
aws/sagemaker-containers | src/sagemaker_containers/_env.py | _create_training_directories | def _create_training_directories():
"""Creates the directory structure and files necessary for training under the base path
"""
logger.info('Creating a new training folder under %s .' % base_dir)
os.makedirs(model_dir)
os.makedirs(input_config_dir)
os.makedirs(output_data_dir)
_write_json(... | python | def _create_training_directories():
"""Creates the directory structure and files necessary for training under the base path
"""
logger.info('Creating a new training folder under %s .' % base_dir)
os.makedirs(model_dir)
os.makedirs(input_config_dir)
os.makedirs(output_data_dir)
_write_json(... | [
"def",
"_create_training_directories",
"(",
")",
":",
"logger",
".",
"info",
"(",
"'Creating a new training folder under %s .'",
"%",
"base_dir",
")",
"os",
".",
"makedirs",
"(",
"model_dir",
")",
"os",
".",
"makedirs",
"(",
"input_config_dir",
")",
"os",
".",
"... | Creates the directory structure and files necessary for training under the base path | [
"Creates",
"the",
"directory",
"structure",
"and",
"files",
"necessary",
"for",
"training",
"under",
"the",
"base",
"path"
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_env.py#L150-L168 | train |
aws/sagemaker-containers | src/sagemaker_containers/_env.py | num_gpus | def num_gpus(): # type: () -> int
"""The number of gpus available in the current container.
Returns:
int: number of gpus available in the current container.
"""
try:
cmd = shlex.split('nvidia-smi --list-gpus')
output = subprocess.check_output(cmd).decode('utf-8')
return... | python | def num_gpus(): # type: () -> int
"""The number of gpus available in the current container.
Returns:
int: number of gpus available in the current container.
"""
try:
cmd = shlex.split('nvidia-smi --list-gpus')
output = subprocess.check_output(cmd).decode('utf-8')
return... | [
"def",
"num_gpus",
"(",
")",
":",
"try",
":",
"cmd",
"=",
"shlex",
".",
"split",
"(",
"'nvidia-smi --list-gpus'",
")",
"output",
"=",
"subprocess",
".",
"check_output",
"(",
"cmd",
")",
".",
"decode",
"(",
"'utf-8'",
")",
"return",
"sum",
"(",
"[",
"1"... | The number of gpus available in the current container.
Returns:
int: number of gpus available in the current container. | [
"The",
"number",
"of",
"gpus",
"available",
"in",
"the",
"current",
"container",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_env.py#L285-L297 | train |
aws/sagemaker-containers | src/sagemaker_containers/_env.py | write_env_vars | def write_env_vars(env_vars=None): # type: (dict) -> None
"""Write the dictionary env_vars in the system, as environment variables.
Args:
env_vars ():
Returns:
"""
env_vars = env_vars or {}
env_vars['PYTHONPATH'] = ':'.join(sys.path)
for name, value in env_vars.items():
... | python | def write_env_vars(env_vars=None): # type: (dict) -> None
"""Write the dictionary env_vars in the system, as environment variables.
Args:
env_vars ():
Returns:
"""
env_vars = env_vars or {}
env_vars['PYTHONPATH'] = ':'.join(sys.path)
for name, value in env_vars.items():
... | [
"def",
"write_env_vars",
"(",
"env_vars",
"=",
"None",
")",
":",
"env_vars",
"=",
"env_vars",
"or",
"{",
"}",
"env_vars",
"[",
"'PYTHONPATH'",
"]",
"=",
"':'",
".",
"join",
"(",
"sys",
".",
"path",
")",
"for",
"name",
",",
"value",
"in",
"env_vars",
... | Write the dictionary env_vars in the system, as environment variables.
Args:
env_vars ():
Returns: | [
"Write",
"the",
"dictionary",
"env_vars",
"in",
"the",
"system",
"as",
"environment",
"variables",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_env.py#L925-L938 | train |
aws/sagemaker-containers | src/sagemaker_containers/_env.py | TrainingEnv.to_env_vars | def to_env_vars(self):
"""Environment variable representation of the training environment
Returns:
dict: an instance of dictionary
"""
env = {
'hosts': self.hosts, 'network_interface_name': self.network_interface_name,
'hps': self.hyperparameters, 'u... | python | def to_env_vars(self):
"""Environment variable representation of the training environment
Returns:
dict: an instance of dictionary
"""
env = {
'hosts': self.hosts, 'network_interface_name': self.network_interface_name,
'hps': self.hyperparameters, 'u... | [
"def",
"to_env_vars",
"(",
"self",
")",
":",
"env",
"=",
"{",
"'hosts'",
":",
"self",
".",
"hosts",
",",
"'network_interface_name'",
":",
"self",
".",
"network_interface_name",
",",
"'hps'",
":",
"self",
".",
"hyperparameters",
",",
"'user_entry_point'",
":",
... | Environment variable representation of the training environment
Returns:
dict: an instance of dictionary | [
"Environment",
"variable",
"representation",
"of",
"the",
"training",
"environment"
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_env.py#L641-L671 | train |
aws/sagemaker-containers | src/sagemaker_containers/_encoders.py | array_to_npy | def array_to_npy(array_like): # type: (np.array or Iterable or int or float) -> object
"""Convert an array like object to the NPY format.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
... | python | def array_to_npy(array_like): # type: (np.array or Iterable or int or float) -> object
"""Convert an array like object to the NPY format.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
... | [
"def",
"array_to_npy",
"(",
"array_like",
")",
":",
"buffer",
"=",
"BytesIO",
"(",
")",
"np",
".",
"save",
"(",
"buffer",
",",
"array_like",
")",
"return",
"buffer",
".",
"getvalue",
"(",
")"
] | Convert an array like object to the NPY format.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
Args:
array_like (np.array or Iterable or int or float): array like object to be co... | [
"Convert",
"an",
"array",
"like",
"object",
"to",
"the",
"NPY",
"format",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_encoders.py#L24-L38 | train |
aws/sagemaker-containers | src/sagemaker_containers/_encoders.py | npy_to_numpy | def npy_to_numpy(npy_array): # type: (object) -> np.array
"""Convert an NPY array into numpy.
Args:
npy_array (npy array): to be converted to numpy array
Returns:
(np.array): converted numpy array.
"""
stream = BytesIO(npy_array)
return np.load(stream, allow_pickle=True) | python | def npy_to_numpy(npy_array): # type: (object) -> np.array
"""Convert an NPY array into numpy.
Args:
npy_array (npy array): to be converted to numpy array
Returns:
(np.array): converted numpy array.
"""
stream = BytesIO(npy_array)
return np.load(stream, allow_pickle=True) | [
"def",
"npy_to_numpy",
"(",
"npy_array",
")",
":",
"stream",
"=",
"BytesIO",
"(",
"npy_array",
")",
"return",
"np",
".",
"load",
"(",
"stream",
",",
"allow_pickle",
"=",
"True",
")"
] | Convert an NPY array into numpy.
Args:
npy_array (npy array): to be converted to numpy array
Returns:
(np.array): converted numpy array. | [
"Convert",
"an",
"NPY",
"array",
"into",
"numpy",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_encoders.py#L41-L50 | train |
aws/sagemaker-containers | src/sagemaker_containers/_encoders.py | array_to_json | def array_to_json(array_like): # type: (np.array or Iterable or int or float) -> str
"""Convert an array like object to JSON.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
Args:
... | python | def array_to_json(array_like): # type: (np.array or Iterable or int or float) -> str
"""Convert an array like object to JSON.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
Args:
... | [
"def",
"array_to_json",
"(",
"array_like",
")",
":",
"def",
"default",
"(",
"_array_like",
")",
":",
"if",
"hasattr",
"(",
"_array_like",
",",
"'tolist'",
")",
":",
"return",
"_array_like",
".",
"tolist",
"(",
")",
"return",
"json",
".",
"JSONEncoder",
"("... | Convert an array like object to JSON.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
Args:
array_like (np.array or Iterable or int or float): array like object to be converted to... | [
"Convert",
"an",
"array",
"like",
"object",
"to",
"JSON",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_encoders.py#L53-L71 | train |
aws/sagemaker-containers | src/sagemaker_containers/_encoders.py | json_to_numpy | def json_to_numpy(string_like, dtype=None): # type: (str) -> np.array
"""Convert a JSON object to a numpy array.
Args:
string_like (str): JSON string.
dtype (dtype, optional): Data type of the resulting array. If None, the dtypes will be determined by the
... | python | def json_to_numpy(string_like, dtype=None): # type: (str) -> np.array
"""Convert a JSON object to a numpy array.
Args:
string_like (str): JSON string.
dtype (dtype, optional): Data type of the resulting array. If None, the dtypes will be determined by the
... | [
"def",
"json_to_numpy",
"(",
"string_like",
",",
"dtype",
"=",
"None",
")",
":",
"data",
"=",
"json",
".",
"loads",
"(",
"string_like",
")",
"return",
"np",
".",
"array",
"(",
"data",
",",
"dtype",
"=",
"dtype",
")"
] | Convert a JSON object to a numpy array.
Args:
string_like (str): JSON string.
dtype (dtype, optional): Data type of the resulting array. If None, the dtypes will be determined by the
contents of each column, individually. This argument can only b... | [
"Convert",
"a",
"JSON",
"object",
"to",
"a",
"numpy",
"array",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_encoders.py#L74-L86 | train |
aws/sagemaker-containers | src/sagemaker_containers/_encoders.py | csv_to_numpy | def csv_to_numpy(string_like, dtype=None): # type: (str) -> np.array
"""Convert a CSV object to a numpy array.
Args:
string_like (str): CSV string.
dtype (dtype, optional): Data type of the resulting array. If None, the dtypes will be determined by the
... | python | def csv_to_numpy(string_like, dtype=None): # type: (str) -> np.array
"""Convert a CSV object to a numpy array.
Args:
string_like (str): CSV string.
dtype (dtype, optional): Data type of the resulting array. If None, the dtypes will be determined by the
... | [
"def",
"csv_to_numpy",
"(",
"string_like",
",",
"dtype",
"=",
"None",
")",
":",
"stream",
"=",
"StringIO",
"(",
"string_like",
")",
"return",
"np",
".",
"genfromtxt",
"(",
"stream",
",",
"dtype",
"=",
"dtype",
",",
"delimiter",
"=",
"','",
")"
] | Convert a CSV object to a numpy array.
Args:
string_like (str): CSV string.
dtype (dtype, optional): Data type of the resulting array. If None, the dtypes will be determined by the
contents of each column, individually. This argument can only be used to
... | [
"Convert",
"a",
"CSV",
"object",
"to",
"a",
"numpy",
"array",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_encoders.py#L89-L101 | train |
aws/sagemaker-containers | src/sagemaker_containers/_encoders.py | array_to_csv | def array_to_csv(array_like): # type: (np.array or Iterable or int or float) -> str
"""Convert an array like object to CSV.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
Args:
... | python | def array_to_csv(array_like): # type: (np.array or Iterable or int or float) -> str
"""Convert an array like object to CSV.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
Args:
... | [
"def",
"array_to_csv",
"(",
"array_like",
")",
":",
"stream",
"=",
"StringIO",
"(",
")",
"np",
".",
"savetxt",
"(",
"stream",
",",
"array_like",
",",
"delimiter",
"=",
"','",
",",
"fmt",
"=",
"'%s'",
")",
"return",
"stream",
".",
"getvalue",
"(",
")"
] | Convert an array like object to CSV.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
Args:
array_like (np.array or Iterable or int or float): array like object to be converted to ... | [
"Convert",
"an",
"array",
"like",
"object",
"to",
"CSV",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_encoders.py#L104-L118 | train |
aws/sagemaker-containers | src/sagemaker_containers/_encoders.py | decode | def decode(obj, content_type):
# type: (np.array or Iterable or int or float, str) -> np.array
"""Decode an object ton a one of the default content types to a numpy array.
Args:
obj (object): to be decoded.
content_type (str): content type to be used.
Returns:
np.array: decoded... | python | def decode(obj, content_type):
# type: (np.array or Iterable or int or float, str) -> np.array
"""Decode an object ton a one of the default content types to a numpy array.
Args:
obj (object): to be decoded.
content_type (str): content type to be used.
Returns:
np.array: decoded... | [
"def",
"decode",
"(",
"obj",
",",
"content_type",
")",
":",
"try",
":",
"decoder",
"=",
"_decoders_map",
"[",
"content_type",
"]",
"return",
"decoder",
"(",
"obj",
")",
"except",
"KeyError",
":",
"raise",
"_errors",
".",
"UnsupportedFormatError",
"(",
"conte... | Decode an object ton a one of the default content types to a numpy array.
Args:
obj (object): to be decoded.
content_type (str): content type to be used.
Returns:
np.array: decoded object. | [
"Decode",
"an",
"object",
"ton",
"a",
"one",
"of",
"the",
"default",
"content",
"types",
"to",
"a",
"numpy",
"array",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_encoders.py#L125-L140 | train |
aws/sagemaker-containers | src/sagemaker_containers/_encoders.py | encode | def encode(array_like, content_type):
# type: (np.array or Iterable or int or float, str) -> np.array
"""Encode an array like object in a specific content_type to a numpy array.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-... | python | def encode(array_like, content_type):
# type: (np.array or Iterable or int or float, str) -> np.array
"""Encode an array like object in a specific content_type to a numpy array.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-... | [
"def",
"encode",
"(",
"array_like",
",",
"content_type",
")",
":",
"try",
":",
"encoder",
"=",
"_encoders_map",
"[",
"content_type",
"]",
"return",
"encoder",
"(",
"array_like",
")",
"except",
"KeyError",
":",
"raise",
"_errors",
".",
"UnsupportedFormatError",
... | Encode an array like object in a specific content_type to a numpy array.
To understand better what an array like object is see:
https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
Args:
array_like (np.array or Iterable or int or float): t... | [
"Encode",
"an",
"array",
"like",
"object",
"in",
"a",
"specific",
"content_type",
"to",
"a",
"numpy",
"array",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_encoders.py#L143-L161 | train |
aws/sagemaker-containers | src/sagemaker_containers/_files.py | tmpdir | def tmpdir(suffix='', prefix='tmp', dir=None): # type: (str, str, str) -> None
"""Create a temporary directory with a context manager. The file is deleted when the context exits.
The prefix, suffix, and dir arguments are the same as for mkstemp().
Args:
suffix (str): If suffix is specified, the ... | python | def tmpdir(suffix='', prefix='tmp', dir=None): # type: (str, str, str) -> None
"""Create a temporary directory with a context manager. The file is deleted when the context exits.
The prefix, suffix, and dir arguments are the same as for mkstemp().
Args:
suffix (str): If suffix is specified, the ... | [
"def",
"tmpdir",
"(",
"suffix",
"=",
"''",
",",
"prefix",
"=",
"'tmp'",
",",
"dir",
"=",
"None",
")",
":",
"tmp",
"=",
"tempfile",
".",
"mkdtemp",
"(",
"suffix",
"=",
"suffix",
",",
"prefix",
"=",
"prefix",
",",
"dir",
"=",
"dir",
")",
"yield",
"... | Create a temporary directory with a context manager. The file is deleted when the context exits.
The prefix, suffix, and dir arguments are the same as for mkstemp().
Args:
suffix (str): If suffix is specified, the file name will end with that suffix, otherwise there will be no
... | [
"Create",
"a",
"temporary",
"directory",
"with",
"a",
"context",
"manager",
".",
"The",
"file",
"is",
"deleted",
"when",
"the",
"context",
"exits",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_files.py#L50-L67 | train |
aws/sagemaker-containers | src/sagemaker_containers/_files.py | download_and_extract | def download_and_extract(uri, name, path): # type: (str, str, str) -> None
"""Download, prepare and install a compressed tar file from S3 or local directory as an entry point.
SageMaker Python SDK saves the user provided entry points as compressed tar files in S3
Args:
name (str): name of the ent... | python | def download_and_extract(uri, name, path): # type: (str, str, str) -> None
"""Download, prepare and install a compressed tar file from S3 or local directory as an entry point.
SageMaker Python SDK saves the user provided entry points as compressed tar files in S3
Args:
name (str): name of the ent... | [
"def",
"download_and_extract",
"(",
"uri",
",",
"name",
",",
"path",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"os",
".",
"makedirs",
"(",
"path",
")",
"if",
"not",
"os",
".",
"listdir",
"(",
"path",
")",
":"... | Download, prepare and install a compressed tar file from S3 or local directory as an entry point.
SageMaker Python SDK saves the user provided entry points as compressed tar files in S3
Args:
name (str): name of the entry point.
uri (str): the location of the entry point.
path (bool): ... | [
"Download",
"prepare",
"and",
"install",
"a",
"compressed",
"tar",
"file",
"from",
"S3",
"or",
"local",
"directory",
"as",
"an",
"entry",
"point",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_files.py#L108-L137 | train |
aws/sagemaker-containers | src/sagemaker_containers/_files.py | s3_download | def s3_download(url, dst): # type: (str, str) -> None
"""Download a file from S3.
Args:
url (str): the s3 url of the file.
dst (str): the destination where the file will be saved.
"""
url = parse.urlparse(url)
if url.scheme != 's3':
raise ValueError("Expecting 's3' scheme,... | python | def s3_download(url, dst): # type: (str, str) -> None
"""Download a file from S3.
Args:
url (str): the s3 url of the file.
dst (str): the destination where the file will be saved.
"""
url = parse.urlparse(url)
if url.scheme != 's3':
raise ValueError("Expecting 's3' scheme,... | [
"def",
"s3_download",
"(",
"url",
",",
"dst",
")",
":",
"url",
"=",
"parse",
".",
"urlparse",
"(",
"url",
")",
"if",
"url",
".",
"scheme",
"!=",
"'s3'",
":",
"raise",
"ValueError",
"(",
"\"Expecting 's3' scheme, got: %s in %s\"",
"%",
"(",
"url",
".",
"s... | Download a file from S3.
Args:
url (str): the s3 url of the file.
dst (str): the destination where the file will be saved. | [
"Download",
"a",
"file",
"from",
"S3",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_files.py#L140-L157 | train |
aws/sagemaker-containers | src/sagemaker_containers/_functions.py | matching_args | def matching_args(fn, dictionary): # type: (Callable, _mapping.Mapping) -> dict
"""Given a function fn and a dict dictionary, returns the function arguments that match the dict keys.
Example:
def train(channel_dirs, model_dir): pass
dictionary = {'channel_dirs': {}, 'model_dir': '/opt/ml/mod... | python | def matching_args(fn, dictionary): # type: (Callable, _mapping.Mapping) -> dict
"""Given a function fn and a dict dictionary, returns the function arguments that match the dict keys.
Example:
def train(channel_dirs, model_dir): pass
dictionary = {'channel_dirs': {}, 'model_dir': '/opt/ml/mod... | [
"def",
"matching_args",
"(",
"fn",
",",
"dictionary",
")",
":",
"arg_spec",
"=",
"getargspec",
"(",
"fn",
")",
"if",
"arg_spec",
".",
"keywords",
":",
"return",
"dictionary",
"return",
"_mapping",
".",
"split_by_criteria",
"(",
"dictionary",
",",
"arg_spec",
... | Given a function fn and a dict dictionary, returns the function arguments that match the dict keys.
Example:
def train(channel_dirs, model_dir): pass
dictionary = {'channel_dirs': {}, 'model_dir': '/opt/ml/model', 'other_args': None}
args = functions.matching_args(train, dictionary) # {'... | [
"Given",
"a",
"function",
"fn",
"and",
"a",
"dict",
"dictionary",
"returns",
"the",
"function",
"arguments",
"that",
"match",
"the",
"dict",
"keys",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_functions.py#L24-L48 | train |
aws/sagemaker-containers | src/sagemaker_containers/_functions.py | error_wrapper | def error_wrapper(fn, error_class): # type: (Callable or None, Exception) -> ...
"""Wraps function fn in a try catch block that re-raises error_class.
Args:
fn (function): function to wrapped
error_class (Exception): Error class to be re-raised
Returns:
(object): fn wrapped in a t... | python | def error_wrapper(fn, error_class): # type: (Callable or None, Exception) -> ...
"""Wraps function fn in a try catch block that re-raises error_class.
Args:
fn (function): function to wrapped
error_class (Exception): Error class to be re-raised
Returns:
(object): fn wrapped in a t... | [
"def",
"error_wrapper",
"(",
"fn",
",",
"error_class",
")",
":",
"def",
"wrapper",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"return",
"fn",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"except",
"Exception",
"as",
"e",
":",
"six"... | Wraps function fn in a try catch block that re-raises error_class.
Args:
fn (function): function to wrapped
error_class (Exception): Error class to be re-raised
Returns:
(object): fn wrapped in a try catch. | [
"Wraps",
"function",
"fn",
"in",
"a",
"try",
"catch",
"block",
"that",
"re",
"-",
"raises",
"error_class",
"."
] | 0030f07abbaf22a55d986d97274d7a8d1aa1f10c | https://github.com/aws/sagemaker-containers/blob/0030f07abbaf22a55d986d97274d7a8d1aa1f10c/src/sagemaker_containers/_functions.py#L73-L89 | train |
ceph/ceph-deploy | ceph_deploy/util/packages.py | ceph_is_installed | def ceph_is_installed(module):
"""
A helper callback to be executed after the connection is made to ensure
that Ceph is installed.
"""
ceph_package = Ceph(module.conn)
if not ceph_package.installed:
host = module.conn.hostname
raise RuntimeError(
'ceph needs to be ins... | python | def ceph_is_installed(module):
"""
A helper callback to be executed after the connection is made to ensure
that Ceph is installed.
"""
ceph_package = Ceph(module.conn)
if not ceph_package.installed:
host = module.conn.hostname
raise RuntimeError(
'ceph needs to be ins... | [
"def",
"ceph_is_installed",
"(",
"module",
")",
":",
"ceph_package",
"=",
"Ceph",
"(",
"module",
".",
"conn",
")",
"if",
"not",
"ceph_package",
".",
"installed",
":",
"host",
"=",
"module",
".",
"conn",
".",
"hostname",
"raise",
"RuntimeError",
"(",
"'ceph... | A helper callback to be executed after the connection is made to ensure
that Ceph is installed. | [
"A",
"helper",
"callback",
"to",
"be",
"executed",
"after",
"the",
"connection",
"is",
"made",
"to",
"ensure",
"that",
"Ceph",
"is",
"installed",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/util/packages.py#L64-L74 | train |
ceph/ceph-deploy | ceph_deploy/util/log.py | color_format | def color_format():
"""
Main entry point to get a colored formatter, it will use the
BASE_FORMAT by default and fall back to no colors if the system
does not support it
"""
str_format = BASE_COLOR_FORMAT if supports_color() else BASE_FORMAT
color_format = color_message(str_format)
return... | python | def color_format():
"""
Main entry point to get a colored formatter, it will use the
BASE_FORMAT by default and fall back to no colors if the system
does not support it
"""
str_format = BASE_COLOR_FORMAT if supports_color() else BASE_FORMAT
color_format = color_message(str_format)
return... | [
"def",
"color_format",
"(",
")",
":",
"str_format",
"=",
"BASE_COLOR_FORMAT",
"if",
"supports_color",
"(",
")",
"else",
"BASE_FORMAT",
"color_format",
"=",
"color_message",
"(",
"str_format",
")",
"return",
"ColoredFormatter",
"(",
"color_format",
")"
] | Main entry point to get a colored formatter, it will use the
BASE_FORMAT by default and fall back to no colors if the system
does not support it | [
"Main",
"entry",
"point",
"to",
"get",
"a",
"colored",
"formatter",
"it",
"will",
"use",
"the",
"BASE_FORMAT",
"by",
"default",
"and",
"fall",
"back",
"to",
"no",
"colors",
"if",
"the",
"system",
"does",
"not",
"support",
"it"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/util/log.py#L59-L67 | train |
ceph/ceph-deploy | ceph_deploy/mon.py | mon_status_check | def mon_status_check(conn, logger, hostname, args):
"""
A direct check for JSON output on the monitor status.
For newer versions of Ceph (dumpling and newer) a new mon_status command
was added ( `ceph daemon mon mon_status` ) and should be revisited if the
output changes as this check depends on th... | python | def mon_status_check(conn, logger, hostname, args):
"""
A direct check for JSON output on the monitor status.
For newer versions of Ceph (dumpling and newer) a new mon_status command
was added ( `ceph daemon mon mon_status` ) and should be revisited if the
output changes as this check depends on th... | [
"def",
"mon_status_check",
"(",
"conn",
",",
"logger",
",",
"hostname",
",",
"args",
")",
":",
"asok_path",
"=",
"paths",
".",
"mon",
".",
"asok",
"(",
"args",
".",
"cluster",
",",
"hostname",
")",
"out",
",",
"err",
",",
"code",
"=",
"remoto",
".",
... | A direct check for JSON output on the monitor status.
For newer versions of Ceph (dumpling and newer) a new mon_status command
was added ( `ceph daemon mon mon_status` ) and should be revisited if the
output changes as this check depends on that availability. | [
"A",
"direct",
"check",
"for",
"JSON",
"output",
"on",
"the",
"monitor",
"status",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/mon.py#L21-L49 | train |
ceph/ceph-deploy | ceph_deploy/mon.py | catch_mon_errors | def catch_mon_errors(conn, logger, hostname, cfg, args):
"""
Make sure we are able to catch up common mishaps with monitors
and use that state of a monitor to determine what is missing
and warn apropriately about it.
"""
monmap = mon_status_check(conn, logger, hostname, args).get('monmap', {})
... | python | def catch_mon_errors(conn, logger, hostname, cfg, args):
"""
Make sure we are able to catch up common mishaps with monitors
and use that state of a monitor to determine what is missing
and warn apropriately about it.
"""
monmap = mon_status_check(conn, logger, hostname, args).get('monmap', {})
... | [
"def",
"catch_mon_errors",
"(",
"conn",
",",
"logger",
",",
"hostname",
",",
"cfg",
",",
"args",
")",
":",
"monmap",
"=",
"mon_status_check",
"(",
"conn",
",",
"logger",
",",
"hostname",
",",
"args",
")",
".",
"get",
"(",
"'monmap'",
",",
"{",
"}",
"... | Make sure we are able to catch up common mishaps with monitors
and use that state of a monitor to determine what is missing
and warn apropriately about it. | [
"Make",
"sure",
"we",
"are",
"able",
"to",
"catch",
"up",
"common",
"mishaps",
"with",
"monitors",
"and",
"use",
"that",
"state",
"of",
"a",
"monitor",
"to",
"determine",
"what",
"is",
"missing",
"and",
"warn",
"apropriately",
"about",
"it",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/mon.py#L52-L73 | train |
ceph/ceph-deploy | ceph_deploy/mon.py | mon_status | def mon_status(conn, logger, hostname, args, silent=False):
"""
run ``ceph daemon mon.`hostname` mon_status`` on the remote end and provide
not only the output, but be able to return a boolean status of what is
going on.
``False`` represents a monitor that is not doing OK even if it is up and
ru... | python | def mon_status(conn, logger, hostname, args, silent=False):
"""
run ``ceph daemon mon.`hostname` mon_status`` on the remote end and provide
not only the output, but be able to return a boolean status of what is
going on.
``False`` represents a monitor that is not doing OK even if it is up and
ru... | [
"def",
"mon_status",
"(",
"conn",
",",
"logger",
",",
"hostname",
",",
"args",
",",
"silent",
"=",
"False",
")",
":",
"mon",
"=",
"'mon.%s'",
"%",
"hostname",
"try",
":",
"out",
"=",
"mon_status_check",
"(",
"conn",
",",
"logger",
",",
"hostname",
",",... | run ``ceph daemon mon.`hostname` mon_status`` on the remote end and provide
not only the output, but be able to return a boolean status of what is
going on.
``False`` represents a monitor that is not doing OK even if it is up and
running, while ``True`` would mean the monitor is up and running correctly... | [
"run",
"ceph",
"daemon",
"mon",
".",
"hostname",
"mon_status",
"on",
"the",
"remote",
"end",
"and",
"provide",
"not",
"only",
"the",
"output",
"but",
"be",
"able",
"to",
"return",
"a",
"boolean",
"status",
"of",
"what",
"is",
"going",
"on",
".",
"False",... | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/mon.py#L76-L108 | train |
ceph/ceph-deploy | ceph_deploy/mon.py | hostname_is_compatible | def hostname_is_compatible(conn, logger, provided_hostname):
"""
Make sure that the host that we are connecting to has the same value as the
`hostname` in the remote host, otherwise mons can fail not reaching quorum.
"""
logger.debug('determining if provided host has same hostname in remote')
re... | python | def hostname_is_compatible(conn, logger, provided_hostname):
"""
Make sure that the host that we are connecting to has the same value as the
`hostname` in the remote host, otherwise mons can fail not reaching quorum.
"""
logger.debug('determining if provided host has same hostname in remote')
re... | [
"def",
"hostname_is_compatible",
"(",
"conn",
",",
"logger",
",",
"provided_hostname",
")",
":",
"logger",
".",
"debug",
"(",
"'determining if provided host has same hostname in remote'",
")",
"remote_hostname",
"=",
"conn",
".",
"remote_module",
".",
"shortname",
"(",
... | Make sure that the host that we are connecting to has the same value as the
`hostname` in the remote host, otherwise mons can fail not reaching quorum. | [
"Make",
"sure",
"that",
"the",
"host",
"that",
"we",
"are",
"connecting",
"to",
"has",
"the",
"same",
"value",
"as",
"the",
"hostname",
"in",
"the",
"remote",
"host",
"otherwise",
"mons",
"can",
"fail",
"not",
"reaching",
"quorum",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/mon.py#L290-L304 | train |
ceph/ceph-deploy | ceph_deploy/mon.py | make | def make(parser):
"""
Ceph MON Daemon management
"""
parser.formatter_class = ToggleRawTextHelpFormatter
mon_parser = parser.add_subparsers(dest='subcommand')
mon_parser.required = True
mon_add = mon_parser.add_parser(
'add',
help=('R|Add a monitor to an existing cluster:\n... | python | def make(parser):
"""
Ceph MON Daemon management
"""
parser.formatter_class = ToggleRawTextHelpFormatter
mon_parser = parser.add_subparsers(dest='subcommand')
mon_parser.required = True
mon_add = mon_parser.add_parser(
'add',
help=('R|Add a monitor to an existing cluster:\n... | [
"def",
"make",
"(",
"parser",
")",
":",
"parser",
".",
"formatter_class",
"=",
"ToggleRawTextHelpFormatter",
"mon_parser",
"=",
"parser",
".",
"add_subparsers",
"(",
"dest",
"=",
"'subcommand'",
")",
"mon_parser",
".",
"required",
"=",
"True",
"mon_add",
"=",
... | Ceph MON Daemon management | [
"Ceph",
"MON",
"Daemon",
"management"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/mon.py#L476-L545 | train |
ceph/ceph-deploy | ceph_deploy/mon.py | get_mon_initial_members | def get_mon_initial_members(args, error_on_empty=False, _cfg=None):
"""
Read the Ceph config file and return the value of mon_initial_members
Optionally, a NeedHostError can be raised if the value is None.
"""
if _cfg:
cfg = _cfg
else:
cfg = conf.ceph.load(args)
mon_initial_m... | python | def get_mon_initial_members(args, error_on_empty=False, _cfg=None):
"""
Read the Ceph config file and return the value of mon_initial_members
Optionally, a NeedHostError can be raised if the value is None.
"""
if _cfg:
cfg = _cfg
else:
cfg = conf.ceph.load(args)
mon_initial_m... | [
"def",
"get_mon_initial_members",
"(",
"args",
",",
"error_on_empty",
"=",
"False",
",",
"_cfg",
"=",
"None",
")",
":",
"if",
"_cfg",
":",
"cfg",
"=",
"_cfg",
"else",
":",
"cfg",
"=",
"conf",
".",
"ceph",
".",
"load",
"(",
"args",
")",
"mon_initial_mem... | Read the Ceph config file and return the value of mon_initial_members
Optionally, a NeedHostError can be raised if the value is None. | [
"Read",
"the",
"Ceph",
"config",
"file",
"and",
"return",
"the",
"value",
"of",
"mon_initial_members",
"Optionally",
"a",
"NeedHostError",
"can",
"be",
"raised",
"if",
"the",
"value",
"is",
"None",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/mon.py#L552-L569 | train |
ceph/ceph-deploy | ceph_deploy/mon.py | is_running | def is_running(conn, args):
"""
Run a command to check the status of a mon, return a boolean.
We heavily depend on the format of the output, if that ever changes
we need to modify this.
Check daemon status for 3 times
output of the status should be similar to::
mon.mira094: running {"v... | python | def is_running(conn, args):
"""
Run a command to check the status of a mon, return a boolean.
We heavily depend on the format of the output, if that ever changes
we need to modify this.
Check daemon status for 3 times
output of the status should be similar to::
mon.mira094: running {"v... | [
"def",
"is_running",
"(",
"conn",
",",
"args",
")",
":",
"stdout",
",",
"stderr",
",",
"_",
"=",
"remoto",
".",
"process",
".",
"check",
"(",
"conn",
",",
"args",
")",
"result_string",
"=",
"b' '",
".",
"join",
"(",
"stdout",
")",
"for",
"run_check",... | Run a command to check the status of a mon, return a boolean.
We heavily depend on the format of the output, if that ever changes
we need to modify this.
Check daemon status for 3 times
output of the status should be similar to::
mon.mira094: running {"version":"0.61.5"}
or when it fails:... | [
"Run",
"a",
"command",
"to",
"check",
"the",
"status",
"of",
"a",
"mon",
"return",
"a",
"boolean",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/mon.py#L572-L596 | train |
ceph/ceph-deploy | ceph_deploy/util/system.py | executable_path | def executable_path(conn, executable):
"""
Remote validator that accepts a connection object to ensure that a certain
executable is available returning its full path if so.
Otherwise an exception with thorough details will be raised, informing the
user that the executable was not found.
"""
... | python | def executable_path(conn, executable):
"""
Remote validator that accepts a connection object to ensure that a certain
executable is available returning its full path if so.
Otherwise an exception with thorough details will be raised, informing the
user that the executable was not found.
"""
... | [
"def",
"executable_path",
"(",
"conn",
",",
"executable",
")",
":",
"executable_path",
"=",
"conn",
".",
"remote_module",
".",
"which",
"(",
"executable",
")",
"if",
"not",
"executable_path",
":",
"raise",
"ExecutableNotFound",
"(",
"executable",
",",
"conn",
... | Remote validator that accepts a connection object to ensure that a certain
executable is available returning its full path if so.
Otherwise an exception with thorough details will be raised, informing the
user that the executable was not found. | [
"Remote",
"validator",
"that",
"accepts",
"a",
"connection",
"object",
"to",
"ensure",
"that",
"a",
"certain",
"executable",
"is",
"available",
"returning",
"its",
"full",
"path",
"if",
"so",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/util/system.py#L5-L16 | train |
ceph/ceph-deploy | ceph_deploy/util/system.py | is_systemd_service_enabled | def is_systemd_service_enabled(conn, service='ceph'):
"""
Detects if a systemd service is enabled or not.
"""
_, _, returncode = remoto.process.check(
conn,
[
'systemctl',
'is-enabled',
'--quiet',
'{service}'.format(service=service),
... | python | def is_systemd_service_enabled(conn, service='ceph'):
"""
Detects if a systemd service is enabled or not.
"""
_, _, returncode = remoto.process.check(
conn,
[
'systemctl',
'is-enabled',
'--quiet',
'{service}'.format(service=service),
... | [
"def",
"is_systemd_service_enabled",
"(",
"conn",
",",
"service",
"=",
"'ceph'",
")",
":",
"_",
",",
"_",
",",
"returncode",
"=",
"remoto",
".",
"process",
".",
"check",
"(",
"conn",
",",
"[",
"'systemctl'",
",",
"'is-enabled'",
",",
"'--quiet'",
",",
"'... | Detects if a systemd service is enabled or not. | [
"Detects",
"if",
"a",
"systemd",
"service",
"is",
"enabled",
"or",
"not",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/util/system.py#L167-L180 | train |
ceph/ceph-deploy | ceph_deploy/repo.py | make | def make(parser):
"""
Repo definition management
"""
parser.add_argument(
'repo_name',
metavar='REPO-NAME',
help='Name of repo to manage. Can match an entry in cephdeploy.conf'
)
parser.add_argument(
'--repo-url',
help='a repo URL that mirrors/contains ... | python | def make(parser):
"""
Repo definition management
"""
parser.add_argument(
'repo_name',
metavar='REPO-NAME',
help='Name of repo to manage. Can match an entry in cephdeploy.conf'
)
parser.add_argument(
'--repo-url',
help='a repo URL that mirrors/contains ... | [
"def",
"make",
"(",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'repo_name'",
",",
"metavar",
"=",
"'REPO-NAME'",
",",
"help",
"=",
"'Name of repo to manage. Can match an entry in cephdeploy.conf'",
")",
"parser",
".",
"add_argument",
"(",
"'--repo-url'"... | Repo definition management | [
"Repo",
"definition",
"management"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/repo.py#L77-L113 | train |
ceph/ceph-deploy | ceph_deploy/conf/cephdeploy.py | Conf.get_list | def get_list(self, section, key):
"""
Assumes that the value for a given key is going to be a list
separated by commas. It gets rid of trailing comments.
If just one item is present it returns a list with a single item, if no
key is found an empty list is returned.
"""
... | python | def get_list(self, section, key):
"""
Assumes that the value for a given key is going to be a list
separated by commas. It gets rid of trailing comments.
If just one item is present it returns a list with a single item, if no
key is found an empty list is returned.
"""
... | [
"def",
"get_list",
"(",
"self",
",",
"section",
",",
"key",
")",
":",
"value",
"=",
"self",
".",
"get_safe",
"(",
"section",
",",
"key",
",",
"[",
"]",
")",
"if",
"value",
"==",
"[",
"]",
":",
"return",
"value",
"value",
"=",
"re",
".",
"split",
... | Assumes that the value for a given key is going to be a list
separated by commas. It gets rid of trailing comments.
If just one item is present it returns a list with a single item, if no
key is found an empty list is returned. | [
"Assumes",
"that",
"the",
"value",
"for",
"a",
"given",
"key",
"is",
"going",
"to",
"be",
"a",
"list",
"separated",
"by",
"commas",
".",
"It",
"gets",
"rid",
"of",
"trailing",
"comments",
".",
"If",
"just",
"one",
"item",
"is",
"present",
"it",
"return... | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/conf/cephdeploy.py#L189-L207 | train |
ceph/ceph-deploy | ceph_deploy/conf/cephdeploy.py | Conf.get_default_repo | def get_default_repo(self):
"""
Go through all the repositories defined in the config file and search
for a truthy value for the ``default`` key. If there isn't any return
None.
"""
for repo in self.get_repos():
if self.get_safe(repo, 'default') and self.getbo... | python | def get_default_repo(self):
"""
Go through all the repositories defined in the config file and search
for a truthy value for the ``default`` key. If there isn't any return
None.
"""
for repo in self.get_repos():
if self.get_safe(repo, 'default') and self.getbo... | [
"def",
"get_default_repo",
"(",
"self",
")",
":",
"for",
"repo",
"in",
"self",
".",
"get_repos",
"(",
")",
":",
"if",
"self",
".",
"get_safe",
"(",
"repo",
",",
"'default'",
")",
"and",
"self",
".",
"getboolean",
"(",
"repo",
",",
"'default'",
")",
"... | Go through all the repositories defined in the config file and search
for a truthy value for the ``default`` key. If there isn't any return
None. | [
"Go",
"through",
"all",
"the",
"repositories",
"defined",
"in",
"the",
"config",
"file",
"and",
"search",
"for",
"a",
"truthy",
"value",
"for",
"the",
"default",
"key",
".",
"If",
"there",
"isn",
"t",
"any",
"return",
"None",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/conf/cephdeploy.py#L209-L218 | train |
ceph/ceph-deploy | ceph_deploy/new.py | validate_host_ip | def validate_host_ip(ips, subnets):
"""
Make sure that a given host all subnets specified will have at least one IP
in that range.
"""
# Make sure we prune ``None`` arguments
subnets = [s for s in subnets if s is not None]
validate_one_subnet = len(subnets) == 1
def ip_in_one_subnet(ips... | python | def validate_host_ip(ips, subnets):
"""
Make sure that a given host all subnets specified will have at least one IP
in that range.
"""
# Make sure we prune ``None`` arguments
subnets = [s for s in subnets if s is not None]
validate_one_subnet = len(subnets) == 1
def ip_in_one_subnet(ips... | [
"def",
"validate_host_ip",
"(",
"ips",
",",
"subnets",
")",
":",
"subnets",
"=",
"[",
"s",
"for",
"s",
"in",
"subnets",
"if",
"s",
"is",
"not",
"None",
"]",
"validate_one_subnet",
"=",
"len",
"(",
"subnets",
")",
"==",
"1",
"def",
"ip_in_one_subnet",
"... | Make sure that a given host all subnets specified will have at least one IP
in that range. | [
"Make",
"sure",
"that",
"a",
"given",
"host",
"all",
"subnets",
"specified",
"will",
"have",
"at",
"least",
"one",
"IP",
"in",
"that",
"range",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/new.py#L78-L102 | train |
ceph/ceph-deploy | ceph_deploy/new.py | get_public_network_ip | def get_public_network_ip(ips, public_subnet):
"""
Given a public subnet, chose the one IP from the remote host that exists
within the subnet range.
"""
for ip in ips:
if net.ip_in_subnet(ip, public_subnet):
return ip
msg = "IPs (%s) are not valid for any of subnet specified ... | python | def get_public_network_ip(ips, public_subnet):
"""
Given a public subnet, chose the one IP from the remote host that exists
within the subnet range.
"""
for ip in ips:
if net.ip_in_subnet(ip, public_subnet):
return ip
msg = "IPs (%s) are not valid for any of subnet specified ... | [
"def",
"get_public_network_ip",
"(",
"ips",
",",
"public_subnet",
")",
":",
"for",
"ip",
"in",
"ips",
":",
"if",
"net",
".",
"ip_in_subnet",
"(",
"ip",
",",
"public_subnet",
")",
":",
"return",
"ip",
"msg",
"=",
"\"IPs (%s) are not valid for any of subnet specif... | Given a public subnet, chose the one IP from the remote host that exists
within the subnet range. | [
"Given",
"a",
"public",
"subnet",
"chose",
"the",
"one",
"IP",
"from",
"the",
"remote",
"host",
"that",
"exists",
"within",
"the",
"subnet",
"range",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/new.py#L105-L114 | train |
ceph/ceph-deploy | ceph_deploy/new.py | make | def make(parser):
"""
Start deploying a new cluster, and write a CLUSTER.conf and keyring for it.
"""
parser.add_argument(
'mon',
metavar='MON',
nargs='+',
help='initial monitor hostname, fqdn, or hostname:fqdn pair',
type=arg_validators.Hostname(),
)
... | python | def make(parser):
"""
Start deploying a new cluster, and write a CLUSTER.conf and keyring for it.
"""
parser.add_argument(
'mon',
metavar='MON',
nargs='+',
help='initial monitor hostname, fqdn, or hostname:fqdn pair',
type=arg_validators.Hostname(),
)
... | [
"def",
"make",
"(",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'mon'",
",",
"metavar",
"=",
"'MON'",
",",
"nargs",
"=",
"'+'",
",",
"help",
"=",
"'initial monitor hostname, fqdn, or hostname:fqdn pair'",
",",
"type",
"=",
"arg_validators",
".",
"... | Start deploying a new cluster, and write a CLUSTER.conf and keyring for it. | [
"Start",
"deploying",
"a",
"new",
"cluster",
"and",
"write",
"a",
"CLUSTER",
".",
"conf",
"and",
"keyring",
"for",
"it",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/new.py#L237-L276 | train |
ceph/ceph-deploy | ceph_deploy/mds.py | make | def make(parser):
"""
Ceph MDS daemon management
"""
mds_parser = parser.add_subparsers(dest='subcommand')
mds_parser.required = True
mds_create = mds_parser.add_parser(
'create',
help='Deploy Ceph MDS on remote host(s)'
)
mds_create.add_argument(
'mds',
... | python | def make(parser):
"""
Ceph MDS daemon management
"""
mds_parser = parser.add_subparsers(dest='subcommand')
mds_parser.required = True
mds_create = mds_parser.add_parser(
'create',
help='Deploy Ceph MDS on remote host(s)'
)
mds_create.add_argument(
'mds',
... | [
"def",
"make",
"(",
"parser",
")",
":",
"mds_parser",
"=",
"parser",
".",
"add_subparsers",
"(",
"dest",
"=",
"'subcommand'",
")",
"mds_parser",
".",
"required",
"=",
"True",
"mds_create",
"=",
"mds_parser",
".",
"add_parser",
"(",
"'create'",
",",
"help",
... | Ceph MDS daemon management | [
"Ceph",
"MDS",
"daemon",
"management"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/mds.py#L206-L226 | train |
ceph/ceph-deploy | ceph_deploy/hosts/util.py | install_yum_priorities | def install_yum_priorities(distro, _yum=None):
"""
EPEL started packaging Ceph so we need to make sure that the ceph.repo we
install has a higher priority than the EPEL repo so that when installing
Ceph it will come from the repo file we create.
The name of the package changed back and forth (!) si... | python | def install_yum_priorities(distro, _yum=None):
"""
EPEL started packaging Ceph so we need to make sure that the ceph.repo we
install has a higher priority than the EPEL repo so that when installing
Ceph it will come from the repo file we create.
The name of the package changed back and forth (!) si... | [
"def",
"install_yum_priorities",
"(",
"distro",
",",
"_yum",
"=",
"None",
")",
":",
"yum",
"=",
"_yum",
"or",
"pkg_managers",
".",
"yum",
"package_name",
"=",
"'yum-plugin-priorities'",
"if",
"distro",
".",
"normalized_name",
"==",
"'centos'",
":",
"if",
"dist... | EPEL started packaging Ceph so we need to make sure that the ceph.repo we
install has a higher priority than the EPEL repo so that when installing
Ceph it will come from the repo file we create.
The name of the package changed back and forth (!) since CentOS 4:
From the CentOS wiki::
Note: Th... | [
"EPEL",
"started",
"packaging",
"Ceph",
"so",
"we",
"need",
"to",
"make",
"sure",
"that",
"the",
"ceph",
".",
"repo",
"we",
"install",
"has",
"a",
"higher",
"priority",
"than",
"the",
"EPEL",
"repo",
"so",
"that",
"when",
"installing",
"Ceph",
"it",
"wil... | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/util.py#L8-L31 | train |
ceph/ceph-deploy | ceph_deploy/util/decorators.py | make_exception_message | def make_exception_message(exc):
"""
An exception is passed in and this function
returns the proper string depending on the result
so it is readable enough.
"""
if str(exc):
return '%s: %s\n' % (exc.__class__.__name__, exc)
else:
return '%s\n' % (exc.__class__.__name__) | python | def make_exception_message(exc):
"""
An exception is passed in and this function
returns the proper string depending on the result
so it is readable enough.
"""
if str(exc):
return '%s: %s\n' % (exc.__class__.__name__, exc)
else:
return '%s\n' % (exc.__class__.__name__) | [
"def",
"make_exception_message",
"(",
"exc",
")",
":",
"if",
"str",
"(",
"exc",
")",
":",
"return",
"'%s: %s\\n'",
"%",
"(",
"exc",
".",
"__class__",
".",
"__name__",
",",
"exc",
")",
"else",
":",
"return",
"'%s\\n'",
"%",
"(",
"exc",
".",
"__class__",... | An exception is passed in and this function
returns the proper string depending on the result
so it is readable enough. | [
"An",
"exception",
"is",
"passed",
"in",
"and",
"this",
"function",
"returns",
"the",
"proper",
"string",
"depending",
"on",
"the",
"result",
"so",
"it",
"is",
"readable",
"enough",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/util/decorators.py#L102-L111 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | platform_information | def platform_information(_linux_distribution=None):
""" detect platform information from remote host """
linux_distribution = _linux_distribution or platform.linux_distribution
distro, release, codename = linux_distribution()
if not distro:
distro, release, codename = parse_os_release()
if n... | python | def platform_information(_linux_distribution=None):
""" detect platform information from remote host """
linux_distribution = _linux_distribution or platform.linux_distribution
distro, release, codename = linux_distribution()
if not distro:
distro, release, codename = parse_os_release()
if n... | [
"def",
"platform_information",
"(",
"_linux_distribution",
"=",
"None",
")",
":",
"linux_distribution",
"=",
"_linux_distribution",
"or",
"platform",
".",
"linux_distribution",
"distro",
",",
"release",
",",
"codename",
"=",
"linux_distribution",
"(",
")",
"if",
"no... | detect platform information from remote host | [
"detect",
"platform",
"information",
"from",
"remote",
"host"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L14-L50 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | write_keyring | def write_keyring(path, key, uid=-1, gid=-1):
""" create a keyring file """
# Note that we *require* to avoid deletion of the temp file
# otherwise we risk not being able to copy the contents from
# one file system to the other, hence the `delete=False`
tmp_file = tempfile.NamedTemporaryFile('wb', d... | python | def write_keyring(path, key, uid=-1, gid=-1):
""" create a keyring file """
# Note that we *require* to avoid deletion of the temp file
# otherwise we risk not being able to copy the contents from
# one file system to the other, hence the `delete=False`
tmp_file = tempfile.NamedTemporaryFile('wb', d... | [
"def",
"write_keyring",
"(",
"path",
",",
"key",
",",
"uid",
"=",
"-",
"1",
",",
"gid",
"=",
"-",
"1",
")",
":",
"tmp_file",
"=",
"tempfile",
".",
"NamedTemporaryFile",
"(",
"'wb'",
",",
"delete",
"=",
"False",
")",
"tmp_file",
".",
"write",
"(",
"... | create a keyring file | [
"create",
"a",
"keyring",
"file"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L178-L189 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | create_mon_path | def create_mon_path(path, uid=-1, gid=-1):
"""create the mon path if it does not exist"""
if not os.path.exists(path):
os.makedirs(path)
os.chown(path, uid, gid); | python | def create_mon_path(path, uid=-1, gid=-1):
"""create the mon path if it does not exist"""
if not os.path.exists(path):
os.makedirs(path)
os.chown(path, uid, gid); | [
"def",
"create_mon_path",
"(",
"path",
",",
"uid",
"=",
"-",
"1",
",",
"gid",
"=",
"-",
"1",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"os",
".",
"makedirs",
"(",
"path",
")",
"os",
".",
"chown",
"(",
"pa... | create the mon path if it does not exist | [
"create",
"the",
"mon",
"path",
"if",
"it",
"does",
"not",
"exist"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L192-L196 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | create_done_path | def create_done_path(done_path, uid=-1, gid=-1):
"""create a done file to avoid re-doing the mon deployment"""
with open(done_path, 'wb'):
pass
os.chown(done_path, uid, gid); | python | def create_done_path(done_path, uid=-1, gid=-1):
"""create a done file to avoid re-doing the mon deployment"""
with open(done_path, 'wb'):
pass
os.chown(done_path, uid, gid); | [
"def",
"create_done_path",
"(",
"done_path",
",",
"uid",
"=",
"-",
"1",
",",
"gid",
"=",
"-",
"1",
")",
":",
"with",
"open",
"(",
"done_path",
",",
"'wb'",
")",
":",
"pass",
"os",
".",
"chown",
"(",
"done_path",
",",
"uid",
",",
"gid",
")"
] | create a done file to avoid re-doing the mon deployment | [
"create",
"a",
"done",
"file",
"to",
"avoid",
"re",
"-",
"doing",
"the",
"mon",
"deployment"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L199-L203 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | create_init_path | def create_init_path(init_path, uid=-1, gid=-1):
"""create the init path if it does not exist"""
if not os.path.exists(init_path):
with open(init_path, 'wb'):
pass
os.chown(init_path, uid, gid); | python | def create_init_path(init_path, uid=-1, gid=-1):
"""create the init path if it does not exist"""
if not os.path.exists(init_path):
with open(init_path, 'wb'):
pass
os.chown(init_path, uid, gid); | [
"def",
"create_init_path",
"(",
"init_path",
",",
"uid",
"=",
"-",
"1",
",",
"gid",
"=",
"-",
"1",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"init_path",
")",
":",
"with",
"open",
"(",
"init_path",
",",
"'wb'",
")",
":",
"pass... | create the init path if it does not exist | [
"create",
"the",
"init",
"path",
"if",
"it",
"does",
"not",
"exist"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L206-L211 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | write_monitor_keyring | def write_monitor_keyring(keyring, monitor_keyring, uid=-1, gid=-1):
"""create the monitor keyring file"""
write_file(keyring, monitor_keyring, 0o600, None, uid, gid) | python | def write_monitor_keyring(keyring, monitor_keyring, uid=-1, gid=-1):
"""create the monitor keyring file"""
write_file(keyring, monitor_keyring, 0o600, None, uid, gid) | [
"def",
"write_monitor_keyring",
"(",
"keyring",
",",
"monitor_keyring",
",",
"uid",
"=",
"-",
"1",
",",
"gid",
"=",
"-",
"1",
")",
":",
"write_file",
"(",
"keyring",
",",
"monitor_keyring",
",",
"0o600",
",",
"None",
",",
"uid",
",",
"gid",
")"
] | create the monitor keyring file | [
"create",
"the",
"monitor",
"keyring",
"file"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L260-L262 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | which | def which(executable):
"""find the location of an executable"""
locations = (
'/usr/local/bin',
'/bin',
'/usr/bin',
'/usr/local/sbin',
'/usr/sbin',
'/sbin',
)
for location in locations:
executable_path = os.path.join(location, executable)
... | python | def which(executable):
"""find the location of an executable"""
locations = (
'/usr/local/bin',
'/bin',
'/usr/bin',
'/usr/local/sbin',
'/usr/sbin',
'/sbin',
)
for location in locations:
executable_path = os.path.join(location, executable)
... | [
"def",
"which",
"(",
"executable",
")",
":",
"locations",
"=",
"(",
"'/usr/local/bin'",
",",
"'/bin'",
",",
"'/usr/bin'",
",",
"'/usr/local/sbin'",
",",
"'/usr/sbin'",
",",
"'/sbin'",
",",
")",
"for",
"location",
"in",
"locations",
":",
"executable_path",
"=",... | find the location of an executable | [
"find",
"the",
"location",
"of",
"an",
"executable"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L331-L345 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | make_mon_removed_dir | def make_mon_removed_dir(path, file_name):
""" move old monitor data """
try:
os.makedirs('/var/lib/ceph/mon-removed')
except OSError as e:
if e.errno != errno.EEXIST:
raise
shutil.move(path, os.path.join('/var/lib/ceph/mon-removed/', file_name)) | python | def make_mon_removed_dir(path, file_name):
""" move old monitor data """
try:
os.makedirs('/var/lib/ceph/mon-removed')
except OSError as e:
if e.errno != errno.EEXIST:
raise
shutil.move(path, os.path.join('/var/lib/ceph/mon-removed/', file_name)) | [
"def",
"make_mon_removed_dir",
"(",
"path",
",",
"file_name",
")",
":",
"try",
":",
"os",
".",
"makedirs",
"(",
"'/var/lib/ceph/mon-removed'",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e",
".",
"errno",
"!=",
"errno",
".",
"EEXIST",
":",
"raise",
... | move old monitor data | [
"move",
"old",
"monitor",
"data"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L348-L355 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | safe_mkdir | def safe_mkdir(path, uid=-1, gid=-1):
""" create path if it doesn't exist """
try:
os.mkdir(path)
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise
else:
os.chown(path, uid, gid) | python | def safe_mkdir(path, uid=-1, gid=-1):
""" create path if it doesn't exist """
try:
os.mkdir(path)
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise
else:
os.chown(path, uid, gid) | [
"def",
"safe_mkdir",
"(",
"path",
",",
"uid",
"=",
"-",
"1",
",",
"gid",
"=",
"-",
"1",
")",
":",
"try",
":",
"os",
".",
"mkdir",
"(",
"path",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e",
".",
"errno",
"==",
"errno",
".",
"EEXIST",
":... | create path if it doesn't exist | [
"create",
"path",
"if",
"it",
"doesn",
"t",
"exist"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L358-L368 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | safe_makedirs | def safe_makedirs(path, uid=-1, gid=-1):
""" create path recursively if it doesn't exist """
try:
os.makedirs(path)
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise
else:
os.chown(path, uid, gid) | python | def safe_makedirs(path, uid=-1, gid=-1):
""" create path recursively if it doesn't exist """
try:
os.makedirs(path)
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise
else:
os.chown(path, uid, gid) | [
"def",
"safe_makedirs",
"(",
"path",
",",
"uid",
"=",
"-",
"1",
",",
"gid",
"=",
"-",
"1",
")",
":",
"try",
":",
"os",
".",
"makedirs",
"(",
"path",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e",
".",
"errno",
"==",
"errno",
".",
"EEXIST"... | create path recursively if it doesn't exist | [
"create",
"path",
"recursively",
"if",
"it",
"doesn",
"t",
"exist"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L371-L381 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | zeroing | def zeroing(dev):
""" zeroing last few blocks of device """
# this kills the crab
#
# sgdisk will wipe out the main copy of the GPT partition
# table (sorry), but it doesn't remove the backup copies, and
# subsequent commands will continue to complain and fail when
# they see those. zeroing... | python | def zeroing(dev):
""" zeroing last few blocks of device """
# this kills the crab
#
# sgdisk will wipe out the main copy of the GPT partition
# table (sorry), but it doesn't remove the backup copies, and
# subsequent commands will continue to complain and fail when
# they see those. zeroing... | [
"def",
"zeroing",
"(",
"dev",
")",
":",
"lba_size",
"=",
"4096",
"size",
"=",
"33",
"*",
"lba_size",
"return",
"True",
"with",
"open",
"(",
"dev",
",",
"'wb'",
")",
"as",
"f",
":",
"f",
".",
"seek",
"(",
"-",
"size",
",",
"os",
".",
"SEEK_END",
... | zeroing last few blocks of device | [
"zeroing",
"last",
"few",
"blocks",
"of",
"device"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L384-L398 | train |
ceph/ceph-deploy | ceph_deploy/hosts/remotes.py | enable_yum_priority_obsoletes | def enable_yum_priority_obsoletes(path="/etc/yum/pluginconf.d/priorities.conf"):
"""Configure Yum priorities to include obsoletes"""
config = configparser.ConfigParser()
config.read(path)
config.set('main', 'check_obsoletes', '1')
with open(path, 'w') as fout:
config.write(fout) | python | def enable_yum_priority_obsoletes(path="/etc/yum/pluginconf.d/priorities.conf"):
"""Configure Yum priorities to include obsoletes"""
config = configparser.ConfigParser()
config.read(path)
config.set('main', 'check_obsoletes', '1')
with open(path, 'w') as fout:
config.write(fout) | [
"def",
"enable_yum_priority_obsoletes",
"(",
"path",
"=",
"\"/etc/yum/pluginconf.d/priorities.conf\"",
")",
":",
"config",
"=",
"configparser",
".",
"ConfigParser",
"(",
")",
"config",
".",
"read",
"(",
"path",
")",
"config",
".",
"set",
"(",
"'main'",
",",
"'ch... | Configure Yum priorities to include obsoletes | [
"Configure",
"Yum",
"priorities",
"to",
"include",
"obsoletes"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/remotes.py#L401-L407 | train |
ceph/ceph-deploy | vendor.py | vendorize | def vendorize(vendor_requirements):
"""
This is the main entry point for vendorizing requirements. It expects
a list of tuples that should contain the name of the library and the
version.
For example, a library ``foo`` with version ``0.0.1`` would look like::
vendor_requirements = [
... | python | def vendorize(vendor_requirements):
"""
This is the main entry point for vendorizing requirements. It expects
a list of tuples that should contain the name of the library and the
version.
For example, a library ``foo`` with version ``0.0.1`` would look like::
vendor_requirements = [
... | [
"def",
"vendorize",
"(",
"vendor_requirements",
")",
":",
"for",
"library",
"in",
"vendor_requirements",
":",
"if",
"len",
"(",
"library",
")",
"==",
"2",
":",
"name",
",",
"version",
"=",
"library",
"cmd",
"=",
"None",
"elif",
"len",
"(",
"library",
")"... | This is the main entry point for vendorizing requirements. It expects
a list of tuples that should contain the name of the library and the
version.
For example, a library ``foo`` with version ``0.0.1`` would look like::
vendor_requirements = [
('foo', '0.0.1'),
] | [
"This",
"is",
"the",
"main",
"entry",
"point",
"for",
"vendorizing",
"requirements",
".",
"It",
"expects",
"a",
"list",
"of",
"tuples",
"that",
"should",
"contain",
"the",
"name",
"of",
"the",
"library",
"and",
"the",
"version",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/vendor.py#L93-L112 | train |
ceph/ceph-deploy | ceph_deploy/gatherkeys.py | _keyring_equivalent | def _keyring_equivalent(keyring_one, keyring_two):
"""
Check two keyrings are identical
"""
def keyring_extract_key(file_path):
"""
Cephx keyring files may or may not have white space before some lines.
They may have some values in quotes, so a safe way to compare is to
e... | python | def _keyring_equivalent(keyring_one, keyring_two):
"""
Check two keyrings are identical
"""
def keyring_extract_key(file_path):
"""
Cephx keyring files may or may not have white space before some lines.
They may have some values in quotes, so a safe way to compare is to
e... | [
"def",
"_keyring_equivalent",
"(",
"keyring_one",
",",
"keyring_two",
")",
":",
"def",
"keyring_extract_key",
"(",
"file_path",
")",
":",
"with",
"open",
"(",
"file_path",
")",
"as",
"f",
":",
"for",
"line",
"in",
"f",
":",
"content",
"=",
"line",
".",
"... | Check two keyrings are identical | [
"Check",
"two",
"keyrings",
"are",
"identical"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/gatherkeys.py#L17-L38 | train |
ceph/ceph-deploy | ceph_deploy/gatherkeys.py | keytype_path_to | def keytype_path_to(args, keytype):
"""
Get the local filename for a keyring type
"""
if keytype == "admin":
return '{cluster}.client.admin.keyring'.format(
cluster=args.cluster)
if keytype == "mon":
return '{cluster}.mon.keyring'.format(
cluster=args.cluster)... | python | def keytype_path_to(args, keytype):
"""
Get the local filename for a keyring type
"""
if keytype == "admin":
return '{cluster}.client.admin.keyring'.format(
cluster=args.cluster)
if keytype == "mon":
return '{cluster}.mon.keyring'.format(
cluster=args.cluster)... | [
"def",
"keytype_path_to",
"(",
"args",
",",
"keytype",
")",
":",
"if",
"keytype",
"==",
"\"admin\"",
":",
"return",
"'{cluster}.client.admin.keyring'",
".",
"format",
"(",
"cluster",
"=",
"args",
".",
"cluster",
")",
"if",
"keytype",
"==",
"\"mon\"",
":",
"r... | Get the local filename for a keyring type | [
"Get",
"the",
"local",
"filename",
"for",
"a",
"keyring",
"type"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/gatherkeys.py#L41-L53 | train |
ceph/ceph-deploy | ceph_deploy/gatherkeys.py | gatherkeys_missing | def gatherkeys_missing(args, distro, rlogger, keypath, keytype, dest_dir):
"""
Get or create the keyring from the mon using the mon keyring by keytype and
copy to dest_dir
"""
args_prefix = [
'/usr/bin/ceph',
'--connect-timeout=25',
'--cluster={cluster}'.format(
c... | python | def gatherkeys_missing(args, distro, rlogger, keypath, keytype, dest_dir):
"""
Get or create the keyring from the mon using the mon keyring by keytype and
copy to dest_dir
"""
args_prefix = [
'/usr/bin/ceph',
'--connect-timeout=25',
'--cluster={cluster}'.format(
c... | [
"def",
"gatherkeys_missing",
"(",
"args",
",",
"distro",
",",
"rlogger",
",",
"keypath",
",",
"keytype",
",",
"dest_dir",
")",
":",
"args_prefix",
"=",
"[",
"'/usr/bin/ceph'",
",",
"'--connect-timeout=25'",
",",
"'--cluster={cluster}'",
".",
"format",
"(",
"clus... | Get or create the keyring from the mon using the mon keyring by keytype and
copy to dest_dir | [
"Get",
"or",
"create",
"the",
"keyring",
"from",
"the",
"mon",
"using",
"the",
"mon",
"keyring",
"by",
"keytype",
"and",
"copy",
"to",
"dest_dir"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/gatherkeys.py#L100-L147 | train |
ceph/ceph-deploy | ceph_deploy/gatherkeys.py | gatherkeys_with_mon | def gatherkeys_with_mon(args, host, dest_dir):
"""
Connect to mon and gather keys if mon is in quorum.
"""
distro = hosts.get(host, username=args.username)
remote_hostname = distro.conn.remote_module.shortname()
dir_keytype_mon = ceph_deploy.util.paths.mon.path(args.cluster, remote_hostname)
... | python | def gatherkeys_with_mon(args, host, dest_dir):
"""
Connect to mon and gather keys if mon is in quorum.
"""
distro = hosts.get(host, username=args.username)
remote_hostname = distro.conn.remote_module.shortname()
dir_keytype_mon = ceph_deploy.util.paths.mon.path(args.cluster, remote_hostname)
... | [
"def",
"gatherkeys_with_mon",
"(",
"args",
",",
"host",
",",
"dest_dir",
")",
":",
"distro",
"=",
"hosts",
".",
"get",
"(",
"host",
",",
"username",
"=",
"args",
".",
"username",
")",
"remote_hostname",
"=",
"distro",
".",
"conn",
".",
"remote_module",
"... | Connect to mon and gather keys if mon is in quorum. | [
"Connect",
"to",
"mon",
"and",
"gather",
"keys",
"if",
"mon",
"is",
"in",
"quorum",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/gatherkeys.py#L150-L220 | train |
ceph/ceph-deploy | ceph_deploy/gatherkeys.py | gatherkeys | def gatherkeys(args):
"""
Gather keys from any mon and store in current working directory.
Backs up keys from previous installs and stores new keys.
"""
oldmask = os.umask(0o77)
try:
try:
tmpd = tempfile.mkdtemp()
LOG.info("Storing keys in temp directory %s", tmp... | python | def gatherkeys(args):
"""
Gather keys from any mon and store in current working directory.
Backs up keys from previous installs and stores new keys.
"""
oldmask = os.umask(0o77)
try:
try:
tmpd = tempfile.mkdtemp()
LOG.info("Storing keys in temp directory %s", tmp... | [
"def",
"gatherkeys",
"(",
"args",
")",
":",
"oldmask",
"=",
"os",
".",
"umask",
"(",
"0o77",
")",
"try",
":",
"try",
":",
"tmpd",
"=",
"tempfile",
".",
"mkdtemp",
"(",
")",
"LOG",
".",
"info",
"(",
"\"Storing keys in temp directory %s\"",
",",
"tmpd",
... | Gather keys from any mon and store in current working directory.
Backs up keys from previous installs and stores new keys. | [
"Gather",
"keys",
"from",
"any",
"mon",
"and",
"store",
"in",
"current",
"working",
"directory",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/gatherkeys.py#L223-L268 | train |
ceph/ceph-deploy | ceph_deploy/gatherkeys.py | make | def make(parser):
"""
Gather authentication keys for provisioning new nodes.
"""
parser.add_argument(
'mon',
metavar='HOST',
nargs='+',
help='monitor host to pull keys from',
)
parser.set_defaults(
func=gatherkeys,
) | python | def make(parser):
"""
Gather authentication keys for provisioning new nodes.
"""
parser.add_argument(
'mon',
metavar='HOST',
nargs='+',
help='monitor host to pull keys from',
)
parser.set_defaults(
func=gatherkeys,
) | [
"def",
"make",
"(",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'mon'",
",",
"metavar",
"=",
"'HOST'",
",",
"nargs",
"=",
"'+'",
",",
"help",
"=",
"'monitor host to pull keys from'",
",",
")",
"parser",
".",
"set_defaults",
"(",
"func",
"=",
... | Gather authentication keys for provisioning new nodes. | [
"Gather",
"authentication",
"keys",
"for",
"provisioning",
"new",
"nodes",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/gatherkeys.py#L272-L284 | train |
ceph/ceph-deploy | ceph_deploy/hosts/__init__.py | get | def get(hostname,
username=None,
fallback=None,
detect_sudo=True,
use_rhceph=False,
callbacks=None):
"""
Retrieve the module that matches the distribution of a ``hostname``. This
function will connect to that host and retrieve the distribution
information, then re... | python | def get(hostname,
username=None,
fallback=None,
detect_sudo=True,
use_rhceph=False,
callbacks=None):
"""
Retrieve the module that matches the distribution of a ``hostname``. This
function will connect to that host and retrieve the distribution
information, then re... | [
"def",
"get",
"(",
"hostname",
",",
"username",
"=",
"None",
",",
"fallback",
"=",
"None",
",",
"detect_sudo",
"=",
"True",
",",
"use_rhceph",
"=",
"False",
",",
"callbacks",
"=",
"None",
")",
":",
"conn",
"=",
"get_connection",
"(",
"hostname",
",",
"... | Retrieve the module that matches the distribution of a ``hostname``. This
function will connect to that host and retrieve the distribution
information, then return the appropriate module and slap a few attributes
to that module defining the information it found from the hostname.
For example, if host `... | [
"Retrieve",
"the",
"module",
"that",
"matches",
"the",
"distribution",
"of",
"a",
"hostname",
".",
"This",
"function",
"will",
"connect",
"to",
"that",
"host",
"and",
"retrieve",
"the",
"distribution",
"information",
"then",
"return",
"the",
"appropriate",
"modu... | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/__init__.py#L16-L84 | train |
ceph/ceph-deploy | ceph_deploy/connection.py | get_connection | def get_connection(hostname, username, logger, threads=5, use_sudo=None, detect_sudo=True):
"""
A very simple helper, meant to return a connection
that will know about the need to use sudo.
"""
if username:
hostname = "%s@%s" % (username, hostname)
try:
conn = remoto.Connection(
... | python | def get_connection(hostname, username, logger, threads=5, use_sudo=None, detect_sudo=True):
"""
A very simple helper, meant to return a connection
that will know about the need to use sudo.
"""
if username:
hostname = "%s@%s" % (username, hostname)
try:
conn = remoto.Connection(
... | [
"def",
"get_connection",
"(",
"hostname",
",",
"username",
",",
"logger",
",",
"threads",
"=",
"5",
",",
"use_sudo",
"=",
"None",
",",
"detect_sudo",
"=",
"True",
")",
":",
"if",
"username",
":",
"hostname",
"=",
"\"%s@%s\"",
"%",
"(",
"username",
",",
... | A very simple helper, meant to return a connection
that will know about the need to use sudo. | [
"A",
"very",
"simple",
"helper",
"meant",
"to",
"return",
"a",
"connection",
"that",
"will",
"know",
"about",
"the",
"need",
"to",
"use",
"sudo",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/connection.py#L5-L29 | train |
ceph/ceph-deploy | ceph_deploy/connection.py | get_local_connection | def get_local_connection(logger, use_sudo=False):
"""
Helper for local connections that are sometimes needed to operate
on local hosts
"""
return get_connection(
socket.gethostname(), # cannot rely on 'localhost' here
None,
logger=logger,
threads=1,
use_sudo=... | python | def get_local_connection(logger, use_sudo=False):
"""
Helper for local connections that are sometimes needed to operate
on local hosts
"""
return get_connection(
socket.gethostname(), # cannot rely on 'localhost' here
None,
logger=logger,
threads=1,
use_sudo=... | [
"def",
"get_local_connection",
"(",
"logger",
",",
"use_sudo",
"=",
"False",
")",
":",
"return",
"get_connection",
"(",
"socket",
".",
"gethostname",
"(",
")",
",",
"None",
",",
"logger",
"=",
"logger",
",",
"threads",
"=",
"1",
",",
"use_sudo",
"=",
"us... | Helper for local connections that are sometimes needed to operate
on local hosts | [
"Helper",
"for",
"local",
"connections",
"that",
"are",
"sometimes",
"needed",
"to",
"operate",
"on",
"local",
"hosts"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/connection.py#L32-L44 | train |
ceph/ceph-deploy | ceph_deploy/mgr.py | make | def make(parser):
"""
Ceph MGR daemon management
"""
mgr_parser = parser.add_subparsers(dest='subcommand')
mgr_parser.required = True
mgr_create = mgr_parser.add_parser(
'create',
help='Deploy Ceph MGR on remote host(s)'
)
mgr_create.add_argument(
'mgr',
... | python | def make(parser):
"""
Ceph MGR daemon management
"""
mgr_parser = parser.add_subparsers(dest='subcommand')
mgr_parser.required = True
mgr_create = mgr_parser.add_parser(
'create',
help='Deploy Ceph MGR on remote host(s)'
)
mgr_create.add_argument(
'mgr',
... | [
"def",
"make",
"(",
"parser",
")",
":",
"mgr_parser",
"=",
"parser",
".",
"add_subparsers",
"(",
"dest",
"=",
"'subcommand'",
")",
"mgr_parser",
".",
"required",
"=",
"True",
"mgr_create",
"=",
"mgr_parser",
".",
"add_parser",
"(",
"'create'",
",",
"help",
... | Ceph MGR daemon management | [
"Ceph",
"MGR",
"daemon",
"management"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/mgr.py#L206-L226 | train |
ceph/ceph-deploy | ceph_deploy/pkg.py | make | def make(parser):
"""
Manage packages on remote hosts.
"""
action = parser.add_mutually_exclusive_group()
action.add_argument(
'--install',
metavar='PKG(s)',
help='Comma-separated package(s) to install',
)
action.add_argument(
'--remove',
metavar='P... | python | def make(parser):
"""
Manage packages on remote hosts.
"""
action = parser.add_mutually_exclusive_group()
action.add_argument(
'--install',
metavar='PKG(s)',
help='Comma-separated package(s) to install',
)
action.add_argument(
'--remove',
metavar='P... | [
"def",
"make",
"(",
"parser",
")",
":",
"action",
"=",
"parser",
".",
"add_mutually_exclusive_group",
"(",
")",
"action",
".",
"add_argument",
"(",
"'--install'",
",",
"metavar",
"=",
"'PKG(s)'",
",",
"help",
"=",
"'Comma-separated package(s) to install'",
",",
... | Manage packages on remote hosts. | [
"Manage",
"packages",
"on",
"remote",
"hosts",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/pkg.py#L60-L86 | train |
ceph/ceph-deploy | ceph_deploy/osd.py | get_bootstrap_osd_key | def get_bootstrap_osd_key(cluster):
"""
Read the bootstrap-osd key for `cluster`.
"""
path = '{cluster}.bootstrap-osd.keyring'.format(cluster=cluster)
try:
with open(path, 'rb') as f:
return f.read()
except IOError:
raise RuntimeError('bootstrap-osd keyring not found;... | python | def get_bootstrap_osd_key(cluster):
"""
Read the bootstrap-osd key for `cluster`.
"""
path = '{cluster}.bootstrap-osd.keyring'.format(cluster=cluster)
try:
with open(path, 'rb') as f:
return f.read()
except IOError:
raise RuntimeError('bootstrap-osd keyring not found;... | [
"def",
"get_bootstrap_osd_key",
"(",
"cluster",
")",
":",
"path",
"=",
"'{cluster}.bootstrap-osd.keyring'",
".",
"format",
"(",
"cluster",
"=",
"cluster",
")",
"try",
":",
"with",
"open",
"(",
"path",
",",
"'rb'",
")",
"as",
"f",
":",
"return",
"f",
".",
... | Read the bootstrap-osd key for `cluster`. | [
"Read",
"the",
"bootstrap",
"-",
"osd",
"key",
"for",
"cluster",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/osd.py#L17-L26 | train |
ceph/ceph-deploy | ceph_deploy/osd.py | create_osd_keyring | def create_osd_keyring(conn, cluster, key):
"""
Run on osd node, writes the bootstrap key if not there yet.
"""
logger = conn.logger
path = '/var/lib/ceph/bootstrap-osd/{cluster}.keyring'.format(
cluster=cluster,
)
if not conn.remote_module.path_exists(path):
logger.warning('... | python | def create_osd_keyring(conn, cluster, key):
"""
Run on osd node, writes the bootstrap key if not there yet.
"""
logger = conn.logger
path = '/var/lib/ceph/bootstrap-osd/{cluster}.keyring'.format(
cluster=cluster,
)
if not conn.remote_module.path_exists(path):
logger.warning('... | [
"def",
"create_osd_keyring",
"(",
"conn",
",",
"cluster",
",",
"key",
")",
":",
"logger",
"=",
"conn",
".",
"logger",
"path",
"=",
"'/var/lib/ceph/bootstrap-osd/{cluster}.keyring'",
".",
"format",
"(",
"cluster",
"=",
"cluster",
",",
")",
"if",
"not",
"conn",
... | Run on osd node, writes the bootstrap key if not there yet. | [
"Run",
"on",
"osd",
"node",
"writes",
"the",
"bootstrap",
"key",
"if",
"not",
"there",
"yet",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/osd.py#L29-L39 | train |
ceph/ceph-deploy | ceph_deploy/osd.py | osd_tree | def osd_tree(conn, cluster):
"""
Check the status of an OSD. Make sure all are up and in
What good output would look like::
{
"epoch": 8,
"num_osds": 1,
"num_up_osds": 1,
"num_in_osds": "1",
"full": "false",
"nearfull": "false... | python | def osd_tree(conn, cluster):
"""
Check the status of an OSD. Make sure all are up and in
What good output would look like::
{
"epoch": 8,
"num_osds": 1,
"num_up_osds": 1,
"num_in_osds": "1",
"full": "false",
"nearfull": "false... | [
"def",
"osd_tree",
"(",
"conn",
",",
"cluster",
")",
":",
"ceph_executable",
"=",
"system",
".",
"executable_path",
"(",
"conn",
",",
"'ceph'",
")",
"command",
"=",
"[",
"ceph_executable",
",",
"'--cluster={cluster}'",
".",
"format",
"(",
"cluster",
"=",
"cl... | Check the status of an OSD. Make sure all are up and in
What good output would look like::
{
"epoch": 8,
"num_osds": 1,
"num_up_osds": 1,
"num_in_osds": "1",
"full": "false",
"nearfull": "false"
}
Note how the booleans ar... | [
"Check",
"the",
"status",
"of",
"an",
"OSD",
".",
"Make",
"sure",
"all",
"are",
"up",
"and",
"in"
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/osd.py#L42-L85 | train |
ceph/ceph-deploy | ceph_deploy/osd.py | catch_osd_errors | def catch_osd_errors(conn, logger, args):
"""
Look for possible issues when checking the status of an OSD and
report them back to the user.
"""
logger.info('checking OSD status...')
status = osd_status_check(conn, args.cluster)
osds = int(status.get('num_osds', 0))
up_osds = int(status.g... | python | def catch_osd_errors(conn, logger, args):
"""
Look for possible issues when checking the status of an OSD and
report them back to the user.
"""
logger.info('checking OSD status...')
status = osd_status_check(conn, args.cluster)
osds = int(status.get('num_osds', 0))
up_osds = int(status.g... | [
"def",
"catch_osd_errors",
"(",
"conn",
",",
"logger",
",",
"args",
")",
":",
"logger",
".",
"info",
"(",
"'checking OSD status...'",
")",
"status",
"=",
"osd_status_check",
"(",
"conn",
",",
"args",
".",
"cluster",
")",
"osds",
"=",
"int",
"(",
"status",
... | Look for possible issues when checking the status of an OSD and
report them back to the user. | [
"Look",
"for",
"possible",
"issues",
"when",
"checking",
"the",
"status",
"of",
"an",
"OSD",
"and",
"report",
"them",
"back",
"to",
"the",
"user",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/osd.py#L141-L174 | train |
ceph/ceph-deploy | ceph_deploy/osd.py | create_osd | def create_osd(
conn,
cluster,
data,
journal,
zap,
fs_type,
dmcrypt,
dmcrypt_dir,
storetype,
block_wal,
block_db,
**kw):
"""
Run on osd node, creates an OSD from a data disk.
"""
ceph_volume_executable = syst... | python | def create_osd(
conn,
cluster,
data,
journal,
zap,
fs_type,
dmcrypt,
dmcrypt_dir,
storetype,
block_wal,
block_db,
**kw):
"""
Run on osd node, creates an OSD from a data disk.
"""
ceph_volume_executable = syst... | [
"def",
"create_osd",
"(",
"conn",
",",
"cluster",
",",
"data",
",",
"journal",
",",
"zap",
",",
"fs_type",
",",
"dmcrypt",
",",
"dmcrypt_dir",
",",
"storetype",
",",
"block_wal",
",",
"block_db",
",",
"**",
"kw",
")",
":",
"ceph_volume_executable",
"=",
... | Run on osd node, creates an OSD from a data disk. | [
"Run",
"on",
"osd",
"node",
"creates",
"an",
"OSD",
"from",
"a",
"data",
"disk",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/osd.py#L177-L233 | train |
ceph/ceph-deploy | ceph_deploy/osd.py | make | def make(parser):
"""
Prepare a data disk on remote host.
"""
sub_command_help = dedent("""
Create OSDs from a data disk on a remote host:
ceph-deploy osd create {node} --data /path/to/device
For bluestore, optional devices can be used::
ceph-deploy osd create {node} --data /p... | python | def make(parser):
"""
Prepare a data disk on remote host.
"""
sub_command_help = dedent("""
Create OSDs from a data disk on a remote host:
ceph-deploy osd create {node} --data /path/to/device
For bluestore, optional devices can be used::
ceph-deploy osd create {node} --data /p... | [
"def",
"make",
"(",
"parser",
")",
":",
"sub_command_help",
"=",
"dedent",
"(",
")",
"parser",
".",
"formatter_class",
"=",
"argparse",
".",
"RawDescriptionHelpFormatter",
"parser",
".",
"description",
"=",
"sub_command_help",
"osd_parser",
"=",
"parser",
".",
"... | Prepare a data disk on remote host. | [
"Prepare",
"a",
"data",
"disk",
"on",
"remote",
"host",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/osd.py#L445-L561 | train |
ceph/ceph-deploy | ceph_deploy/osd.py | make_disk | def make_disk(parser):
"""
Manage disks on a remote host.
"""
disk_parser = parser.add_subparsers(dest='subcommand')
disk_parser.required = True
disk_zap = disk_parser.add_parser(
'zap',
help='destroy existing data and filesystem on LV or partition',
)
disk_zap.add_a... | python | def make_disk(parser):
"""
Manage disks on a remote host.
"""
disk_parser = parser.add_subparsers(dest='subcommand')
disk_parser.required = True
disk_zap = disk_parser.add_parser(
'zap',
help='destroy existing data and filesystem on LV or partition',
)
disk_zap.add_a... | [
"def",
"make_disk",
"(",
"parser",
")",
":",
"disk_parser",
"=",
"parser",
".",
"add_subparsers",
"(",
"dest",
"=",
"'subcommand'",
")",
"disk_parser",
".",
"required",
"=",
"True",
"disk_zap",
"=",
"disk_parser",
".",
"add_parser",
"(",
"'zap'",
",",
"help"... | Manage disks on a remote host. | [
"Manage",
"disks",
"on",
"a",
"remote",
"host",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/osd.py#L565-L610 | train |
ceph/ceph-deploy | ceph_deploy/hosts/centos/install.py | repository_url_part | def repository_url_part(distro):
"""
Historically everything CentOS, RHEL, and Scientific has been mapped to
`el6` urls, but as we are adding repositories for `rhel`, the URLs should
map correctly to, say, `rhel6` or `rhel7`.
This function looks into the `distro` object and determines the right url... | python | def repository_url_part(distro):
"""
Historically everything CentOS, RHEL, and Scientific has been mapped to
`el6` urls, but as we are adding repositories for `rhel`, the URLs should
map correctly to, say, `rhel6` or `rhel7`.
This function looks into the `distro` object and determines the right url... | [
"def",
"repository_url_part",
"(",
"distro",
")",
":",
"if",
"distro",
".",
"normalized_release",
".",
"int_major",
">=",
"6",
":",
"if",
"distro",
".",
"normalized_name",
"==",
"'redhat'",
":",
"return",
"'rhel'",
"+",
"distro",
".",
"normalized_release",
"."... | Historically everything CentOS, RHEL, and Scientific has been mapped to
`el6` urls, but as we are adding repositories for `rhel`, the URLs should
map correctly to, say, `rhel6` or `rhel7`.
This function looks into the `distro` object and determines the right url
part for the given distro, falling back ... | [
"Historically",
"everything",
"CentOS",
"RHEL",
"and",
"Scientific",
"has",
"been",
"mapped",
"to",
"el6",
"urls",
"but",
"as",
"we",
"are",
"adding",
"repositories",
"for",
"rhel",
"the",
"URLs",
"should",
"map",
"correctly",
"to",
"say",
"rhel6",
"or",
"rh... | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/hosts/centos/install.py#L19-L41 | train |
ceph/ceph-deploy | ceph_deploy/install.py | sanitize_args | def sanitize_args(args):
"""
args may need a bunch of logic to set proper defaults that argparse is
not well suited for.
"""
if args.release is None:
args.release = 'nautilus'
args.default_release = True
# XXX This whole dance is because --stable is getting deprecated
if arg... | python | def sanitize_args(args):
"""
args may need a bunch of logic to set proper defaults that argparse is
not well suited for.
"""
if args.release is None:
args.release = 'nautilus'
args.default_release = True
# XXX This whole dance is because --stable is getting deprecated
if arg... | [
"def",
"sanitize_args",
"(",
"args",
")",
":",
"if",
"args",
".",
"release",
"is",
"None",
":",
"args",
".",
"release",
"=",
"'nautilus'",
"args",
".",
"default_release",
"=",
"True",
"if",
"args",
".",
"stable",
"is",
"not",
"None",
":",
"LOG",
".",
... | args may need a bunch of logic to set proper defaults that argparse is
not well suited for. | [
"args",
"may",
"need",
"a",
"bunch",
"of",
"logic",
"to",
"set",
"proper",
"defaults",
"that",
"argparse",
"is",
"not",
"well",
"suited",
"for",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/install.py#L14-L29 | train |
ceph/ceph-deploy | ceph_deploy/install.py | should_use_custom_repo | def should_use_custom_repo(args, cd_conf, repo_url):
"""
A boolean to determine the logic needed to proceed with a custom repo
installation instead of cramming everything nect to the logic operator.
"""
if repo_url:
# repo_url signals a CLI override, return False immediately
return F... | python | def should_use_custom_repo(args, cd_conf, repo_url):
"""
A boolean to determine the logic needed to proceed with a custom repo
installation instead of cramming everything nect to the logic operator.
"""
if repo_url:
# repo_url signals a CLI override, return False immediately
return F... | [
"def",
"should_use_custom_repo",
"(",
"args",
",",
"cd_conf",
",",
"repo_url",
")",
":",
"if",
"repo_url",
":",
"return",
"False",
"if",
"cd_conf",
":",
"if",
"cd_conf",
".",
"has_repos",
":",
"has_valid_release",
"=",
"args",
".",
"release",
"in",
"cd_conf"... | A boolean to determine the logic needed to proceed with a custom repo
installation instead of cramming everything nect to the logic operator. | [
"A",
"boolean",
"to",
"determine",
"the",
"logic",
"needed",
"to",
"proceed",
"with",
"a",
"custom",
"repo",
"installation",
"instead",
"of",
"cramming",
"everything",
"nect",
"to",
"the",
"logic",
"operator",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/install.py#L215-L229 | train |
ceph/ceph-deploy | ceph_deploy/install.py | make_uninstall | def make_uninstall(parser):
"""
Remove Ceph packages from remote hosts.
"""
parser.add_argument(
'host',
metavar='HOST',
nargs='+',
help='hosts to uninstall Ceph from',
)
parser.set_defaults(
func=uninstall,
) | python | def make_uninstall(parser):
"""
Remove Ceph packages from remote hosts.
"""
parser.add_argument(
'host',
metavar='HOST',
nargs='+',
help='hosts to uninstall Ceph from',
)
parser.set_defaults(
func=uninstall,
) | [
"def",
"make_uninstall",
"(",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'host'",
",",
"metavar",
"=",
"'HOST'",
",",
"nargs",
"=",
"'+'",
",",
"help",
"=",
"'hosts to uninstall Ceph from'",
",",
")",
"parser",
".",
"set_defaults",
"(",
"func",... | Remove Ceph packages from remote hosts. | [
"Remove",
"Ceph",
"packages",
"from",
"remote",
"hosts",
"."
] | 86943fcc454cd4c99a86e3493e9e93a59c661fef | https://github.com/ceph/ceph-deploy/blob/86943fcc454cd4c99a86e3493e9e93a59c661fef/ceph_deploy/install.py#L626-L638 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.