Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated SSH-related commands from the client #700

Merged
merged 8 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.D/700.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove deprecated functionality: `neuro model`, `neuro config id_rsa` and `neuro job submit --ssh` option.
20 changes: 4 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Name | Description|
| _[neuro ps](#neuro-ps)_| List all jobs |
| _[neuro status](#neuro-status)_| Display status of a job |
| _[neuro exec](#neuro-exec)_| Execute command in a running job |
| _[neuro port-forward](#neuro-port-forward)_| Forward a port of a running job exposed with -ssh option to a local port |
| _[neuro port-forward](#neuro-port-forward)_| Forward a port of a running job to a local port |
| _[neuro logs](#neuro-logs)_| Print the logs for a container |
| _[neuro kill](#neuro-kill)_| Kill job\(s) |
| _[neuro top](#neuro-top)_| Display GPU/CPU/Memory usage |
Expand Down Expand Up @@ -150,7 +150,7 @@ Name | Description|
| _[neuro job ls](#neuro-job-ls)_| List all jobs |
| _[neuro job status](#neuro-job-status)_| Display status of a job |
| _[neuro job exec](#neuro-job-exec)_| Execute command in a running job |
| _[neuro job port-forward](#neuro-job-port-forward)_| Forward a port of a running job exposed with -ssh option to a local port |
| _[neuro job port-forward](#neuro-job-port-forward)_| Forward a port of a running job to a local port |
| _[neuro job logs](#neuro-job-logs)_| Print the logs for a container |
| _[neuro job kill](#neuro-job-kill)_| Kill job\(s) |
| _[neuro job top](#neuro-job-top)_| Display GPU/CPU/Memory usage |
Expand All @@ -177,11 +177,6 @@ neuro job submit [OPTIONS] IMAGE [CMD]...
# Directory /mod mounted to /mod directory in read-write mode.
neuro job submit --volume storage:/q1:/qm:ro --volume storage:/mod:/mod:rw pytorch:latest

# Starts a container pytorch:latest with connection enabled to port 22 and
# sets PYTHONPATH environment value to /python.
# Please note that SSH server should be provided by container.
neuro job submit --env PYTHONPATH=/python --volume storage:/data/2018q1:/data:ro --ssh 22 pytorch:latest

```

**Options:**
Expand All @@ -195,7 +190,6 @@ Name | Description|
|_\-x, --extshm / -X, --no-extshm_|Request extended '/dev/shm' space \[default: True]|
|_--http INTEGER_|Enable HTTP port forwarding to container|
|_\--http-auth / --no-http-auth_|Enable HTTP authentication for forwarded HTTP port \[default: True]|
|_--ssh INTEGER_|Enable SSH port forwarding to container|
|_\-p, --preemptible / -P, --non-preemptible_|Run job on a lower-cost preemptible instance \[default: True]|
|_\-n, --name NAME_|Optional job name|
|_\-d, --description DESC_|Optional job description in free format|
Expand Down Expand Up @@ -285,7 +279,7 @@ Name | Description|

### neuro job port-forward

Forward a port of a running job exposed with -ssh option to a local port.
Forward a port of a running job to a local port.

**Usage:**

Expand Down Expand Up @@ -882,11 +876,6 @@ neuro submit [OPTIONS] IMAGE [CMD]...
# Directory /mod mounted to /mod directory in read-write mode.
neuro job submit --volume storage:/q1:/qm:ro --volume storage:/mod:/mod:rw pytorch:latest

# Starts a container pytorch:latest with connection enabled to port 22 and
# sets PYTHONPATH environment value to /python.
# Please note that SSH server should be provided by container.
neuro job submit --env PYTHONPATH=/python --volume storage:/data/2018q1:/data:ro --ssh 22 pytorch:latest

```

**Options:**
Expand All @@ -900,7 +889,6 @@ Name | Description|
|_\-x, --extshm / -X, --no-extshm_|Request extended '/dev/shm' space \[default: True]|
|_--http INTEGER_|Enable HTTP port forwarding to container|
|_\--http-auth / --no-http-auth_|Enable HTTP authentication for forwarded HTTP port \[default: True]|
|_--ssh INTEGER_|Enable SSH port forwarding to container|
|_\-p, --preemptible / -P, --non-preemptible_|Run job on a lower-cost preemptible instance \[default: True]|
|_\-n, --name NAME_|Optional job name|
|_\-d, --description DESC_|Optional job description in free format|
Expand Down Expand Up @@ -990,7 +978,7 @@ Name | Description|

## neuro port-forward

Forward a port of a running job exposed with -ssh option to a local port.
Forward a port of a running job to a local port.

**Usage:**

Expand Down
46 changes: 8 additions & 38 deletions neuromation/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Sequence,
Set,
SupportsInt,
Tuple,
)

from aiohttp import WSServerHandshakeError
Expand Down Expand Up @@ -65,14 +64,12 @@ class NetworkPortForwarding:

@classmethod
def from_cli(
cls, http: SupportsInt, ssh: SupportsInt, http_auth: bool = False
cls, http: SupportsInt, http_auth: bool = False
) -> Optional["NetworkPortForwarding"]:
net = None
ports: Dict[str, int] = {}
if http:
ports["http"] = int(http)
if ssh:
ports["ssh"] = int(ssh)
if ports:
net = NetworkPortForwarding(ports=ports, http_auth=http_auth)
return net
Expand Down Expand Up @@ -178,32 +175,13 @@ def from_api(cls, data: Dict[str, Any]) -> "HTTPPort":
)


@dataclass(frozen=True)
class SSHPort:
port: int

def to_api(self) -> Dict[str, Any]:
ret = {"port": self.port}
return ret

@classmethod
def from_api(cls, data: Dict[str, Any]) -> "SSHPort":
return SSHPort(port=data.get("port", -1))


def network_to_api(
network: Optional["NetworkPortForwarding"]
) -> Tuple[Optional[HTTPPort], Optional[SSHPort]]:
def network_to_api(network: Optional["NetworkPortForwarding"]) -> Optional[HTTPPort]:
http = None
ssh = None
if network:
if "http" in network.ports:
http = HTTPPort.from_api(
{"port": network.ports["http"], "requires_auth": network.http_auth}
)
if "ssh" in network.ports:
ssh = SSHPort.from_api({"port": network.ports["ssh"]})
return http, ssh
if network and "http" in network.ports:
http = HTTPPort.from_api(
{"port": network.ports["http"], "requires_auth": network.http_auth}
)
return http


@dataclass(frozen=True)
Expand All @@ -212,7 +190,6 @@ class Container:
resources: Resources
command: Optional[str] = None
http: Optional[HTTPPort] = None
ssh: Optional[SSHPort] = None
# TODO (ASvetlov): replace mutable Dict and List with immutable Mapping and Sequence
env: Dict[str, str] = field(default_factory=dict)
volumes: Sequence[Volume] = field(default_factory=list)
Expand All @@ -224,7 +201,6 @@ def from_api(cls, data: Dict[str, Any]) -> "Container":
resources=Resources.from_api(data["resources"]),
command=data.get("command", None),
http=HTTPPort.from_api(data["http"]) if "http" in data else None,
ssh=SSHPort.from_api(data["ssh"]) if "ssh" in data else None,
env=data.get("env", dict()),
volumes=[Volume.from_api(v) for v in data.get("volumes", [])],
)
Expand All @@ -238,8 +214,6 @@ def to_api(self) -> Dict[str, Any]:
primitive["command"] = self.command
if self.http:
primitive["http"] = self.http.to_api()
if self.ssh:
primitive["ssh"] = self.ssh.to_api()
if self.env:
primitive["env"] = self.env
if self.volumes:
Expand All @@ -252,7 +226,6 @@ class ContainerPayload:
image: str
command: Optional[str]
http: Optional[Mapping[str, int]]
ssh: Optional[Mapping[str, int]]
resources: Resources
env: Optional[Mapping[str, str]] = None

Expand All @@ -262,8 +235,6 @@ def to_primitive(self) -> Dict[str, Any]:
primitive["command"] = self.command
if self.http:
primitive["http"] = self.http
if self.ssh:
primitive["ssh"] = self.ssh
if self.env:
primitive["env"] = self.env
return primitive
Expand Down Expand Up @@ -370,7 +341,7 @@ async def submit(
is_preemptible: bool = False,
env: Optional[Dict[str, str]] = None,
) -> JobDescription:
http, ssh = network_to_api(network)
http = network_to_api(network)
if env is None:
real_env: Dict[str, str] = {}
else:
Expand All @@ -383,7 +354,6 @@ async def submit(
image=image.image,
command=image.command,
http=http,
ssh=ssh,
resources=resources,
env=real_env,
volumes=volumes,
Expand Down
8 changes: 2 additions & 6 deletions neuromation/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ async def train(
network: Optional[NetworkPortForwarding] = None,
is_preemptible: bool = True,
) -> TrainResult:
http, ssh = network_to_api(network)
http = network_to_api(network)

container = Container(
image=image.image,
command=image.command,
http=http,
ssh=ssh,
resources=resources,
image=image.image, command=image.command, http=http, resources=resources
)

payload = {
Expand Down
15 changes: 0 additions & 15 deletions neuromation/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ async def url(cfg: Config, url: str) -> None:
await rc.ConfigFactory.update_api_url(url)


@command(hidden=True, name="id_rsa")
@click.argument("file", type=click.Path(exists=True, readable=True, dir_okay=False))
def id_rsa(file: str) -> None:
"""
Update path to id_rsa file with private key.

FILE is being used for accessing remote shell, remote debug.

Note: this is temporal and going to be
replaced in future by JWT token.
"""
rc.ConfigFactory.update_github_rsa_path(file)


@command()
@click.pass_obj
def show(cfg: Config) -> None:
Expand Down Expand Up @@ -151,5 +137,4 @@ def docker(cfg: Config, docker_config: str) -> None:
config.add_command(logout)

config.add_command(url)
config.add_command(id_rsa)
config.add_command(forget)
3 changes: 0 additions & 3 deletions neuromation/cli/formatters/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ def __call__(self, config: Config) -> str:
lines.append(
style("Docker Registry URL", bold=True) + f": {config.registry_url}"
)
lines.append(
style("Github RSA Path", bold=True) + f": {config.github_rsa_path}"
)
indent = " "
return (
style("User Configuration", bold=True)
Expand Down
41 changes: 2 additions & 39 deletions neuromation/cli/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
JOB_GPU_MODEL,
JOB_GPU_NUMBER,
JOB_MEMORY_AMOUNT,
JOB_SSH_USER,
)
from .formatters import (
BaseJobsFormatter,
Expand All @@ -37,7 +36,6 @@
TabularJobsFormatter,
)
from .rc import Config
from .ssh_utils import connect_ssh
from .utils import (
ImageType,
alias,
Expand Down Expand Up @@ -113,7 +111,6 @@ def job() -> None:
default=True,
show_default=True,
)
@click.option("--ssh", type=int, help="Enable SSH port forwarding to container")
@click.option(
"--preemptible/--non-preemptible",
"-p/-P",
Expand Down Expand Up @@ -177,7 +174,6 @@ async def submit(
extshm: bool,
http: int,
http_auth: bool,
ssh: int,
cmd: Sequence[str],
volume: Sequence[str],
env: Sequence[str],
Expand All @@ -202,12 +198,6 @@ async def submit(
# Directory /mod mounted to /mod directory in read-write mode.
neuro job submit --volume storage:/q1:/qm:ro --volume storage:/mod:/mod:rw \
pytorch:latest

# Starts a container pytorch:latest with connection enabled to port 22 and
# sets PYTHONPATH environment value to /python.
# Please note that SSH server should be provided by container.
neuro job submit --env PYTHONPATH=/python --volume \
storage:/data/2018q1:/data:ro --ssh 22 pytorch:latest
"""

username = cfg.username
Expand Down Expand Up @@ -238,7 +228,7 @@ async def submit(
log.debug(f"IMAGE: {image}")
image_obj = Image(image=image.as_repo_str(), command=cmd)

network = NetworkPortForwarding.from_cli(http, ssh, http_auth)
network = NetworkPortForwarding.from_cli(http, http_auth)
resources = Resources.create(cpu, gpu, gpu_model, memory, extshm)
volumes = Volume.from_cli_list(username, volume)
if volumes and not quiet:
Expand Down Expand Up @@ -311,8 +301,7 @@ async def port_forward(
cfg: Config, job: str, no_key_check: bool, local_port: int, remote_port: int
) -> None:
"""
Forward a port of a running job exposed with -ssh option
to a local port.
Forward a port of a running job to a local port.
"""
async with cfg.make_client() as client:
id = await resolve_job(client, job)
Expand All @@ -322,30 +311,6 @@ async def port_forward(
sys.exit(retcode)
asvetlov marked this conversation as resolved.
Show resolved Hide resolved


@command(deprecated=True, hidden=True)
@click.argument("job")
@click.option(
"--user", help="Container user name", default=JOB_SSH_USER, show_default=True
)
@click.option("--key", help="Path to container private key.")
@async_cmd
async def ssh(cfg: Config, job: str, user: str, key: str) -> None:
"""
Starts ssh terminal connected to running job.

Job should be started with SSH support enabled.

Examples:

neuro job ssh --user alfa --key ./my_docker_id_rsa job-abc-def-ghk
"""
git_key = cfg.github_rsa_path

async with cfg.make_client() as client:
id = await resolve_job(client, job)
await connect_ssh(client, id, git_key, user, key)


@command()
@click.argument("job")
@async_cmd
Expand Down Expand Up @@ -502,5 +467,3 @@ def format_fail(job: str, reason: Exception) -> str:

job.add_command(alias(ls, "list", hidden=True))
job.add_command(alias(logs, "monitor", hidden=True))

job.add_command(ssh)
3 changes: 1 addition & 2 deletions neuromation/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import neuromation
from neuromation.cli.rc import RCException

from . import completion, config, image, job, model, rc, share, storage
from . import completion, config, image, job, rc, share, storage
from .const import EX_DATAERR, EX_IOERR, EX_NOPERM, EX_OSFILE, EX_PROTOCOL, EX_SOFTWARE
from .log_formatter import ConsoleHandler, ConsoleWarningFormatter
from .utils import Context, DeprecatedGroup, MainGroup, alias, format_example
Expand Down Expand Up @@ -213,7 +213,6 @@ def help(ctx: click.Context, command: Sequence[str]) -> None:
cli.add_command(config.config)
cli.add_command(completion.completion)

cli.add_command(model.model)
cli.add_command(DeprecatedGroup(storage.storage, name="store", hidden=True))

cli.add_command(job.submit)
Expand Down
Loading