Skip to content

Commit 23f802b

Browse files
Minor private cloud api improvements
1 parent 013bb6c commit 23f802b

File tree

5 files changed

+134
-22
lines changed

5 files changed

+134
-22
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
os: [ubuntu-22.04, ubuntu-20.04, macos-12, macos-13, windows-latest]
11+
os: [ubuntu-22.04, ubuntu-20.04, macos-13, macos-14, windows-latest]
1212
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1313

1414
steps:

README.md

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ A locally-focused workflow (local development, local execution) with the CLI may
118118
- [`lean object-store properties`](#lean-object-store-properties)
119119
- [`lean object-store set`](#lean-object-store-set)
120120
- [`lean optimize`](#lean-optimize)
121+
- [`lean private-cloud add-compute`](#lean-private-cloud-add-compute)
121122
- [`lean private-cloud start`](#lean-private-cloud-start)
122123
- [`lean private-cloud stop`](#lean-private-cloud-stop)
123124
- [`lean project-create`](#lean-project-create)
@@ -1818,6 +1819,34 @@ Options:
18181819

18191820
_See code: [lean/commands/optimize.py](lean/commands/optimize.py)_
18201821

1822+
### `lean private-cloud add-compute`
1823+
1824+
Add private cloud compute
1825+
1826+
```
1827+
Usage: lean private-cloud add-compute [OPTIONS]
1828+
1829+
Add private cloud compute
1830+
1831+
Options:
1832+
--token TEXT The master server token
1833+
--master-domain, --master-ip TEXT
1834+
The master server domain
1835+
--master-port INTEGER The master server port
1836+
--slave-domain, --slave-ip TEXT
1837+
The slave server domain
1838+
--update Pull the latest image before starting
1839+
--no-update Do not update to the latest version
1840+
--compute TEXT Compute configuration to use
1841+
--extra-docker-config TEXT Extra docker configuration as a JSON string
1842+
--stop Stop any existing deployment
1843+
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
1844+
--verbose Enable debug logging
1845+
--help Show this message and exit.
1846+
```
1847+
1848+
_See code: [lean/commands/private_cloud/add_compute.py](lean/commands/private_cloud/add_compute.py)_
1849+
18211850
### `lean private-cloud start`
18221851

18231852
Start a new private cloud
@@ -1828,20 +1857,22 @@ Usage: lean private-cloud start [OPTIONS]
18281857
Start a new private cloud
18291858
18301859
Options:
1831-
--master Run in master mode
1832-
--slave Run in slave mode
1833-
--token TEXT The master server token
1834-
--master-domain TEXT The master server domain
1835-
--master-port INTEGER The master server port
1836-
--slave-domain TEXT The slave server domain
1837-
--update Pull the latest image before starting
1838-
--no-update Do not update to the latest version
1839-
--compute TEXT Compute configuration to use
1840-
--extra-docker-config TEXT Extra docker configuration as a JSON string
1841-
--stop Stop any existing deployment
1842-
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
1843-
--verbose Enable debug logging
1844-
--help Show this message and exit.
1860+
--master Run in master mode
1861+
--slave Run in slave mode
1862+
--token TEXT The master server token
1863+
--master-domain, --master-ip TEXT
1864+
The master server domain
1865+
--master-port INTEGER The master server port
1866+
--slave-domain, --slave-ip TEXT
1867+
The slave server domain
1868+
--update Pull the latest image before starting
1869+
--no-update Do not update to the latest version
1870+
--compute TEXT Compute configuration to use
1871+
--extra-docker-config TEXT Extra docker configuration as a JSON string
1872+
--stop Stop any existing deployment
1873+
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
1874+
--verbose Enable debug logging
1875+
--help Show this message and exit.
18451876
```
18461877

18471878
_See code: [lean/commands/private_cloud/start.py](lean/commands/private_cloud/start.py)_

lean/commands/private_cloud/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from lean.commands.private_cloud.start import start
1717
from lean.commands.private_cloud.stop import stop
18+
from lean.commands.private_cloud.add_compute import add_compute
1819

1920

2021
@group()
@@ -27,3 +28,4 @@ def private_cloud() -> None:
2728

2829
private_cloud.add_command(start)
2930
private_cloud.add_command(stop)
31+
private_cloud.add_command(add_compute)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
2+
# Lean CLI v1.0. Copyright 2021 QuantConnect Corporation.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
from typing import Optional
14+
15+
from click import option, command
16+
17+
from lean.click import LeanCommand
18+
from lean.commands.private_cloud.start import start_command
19+
20+
21+
@command(cls=LeanCommand, requires_lean_config=True, requires_docker=True, help="Add private cloud compute")
22+
@option("--token", type=str, required=False, help="The master server token")
23+
@option("--master-domain", "--master-ip", type=str, required=False, help="The master server domain")
24+
@option("--master-port", type=int, required=False, default=443, help="The master server port")
25+
@option("--slave-domain", "--slave-ip", type=str, required=False, help="The slave server domain")
26+
@option("--update", is_flag=True, default=False, help="Pull the latest image before starting")
27+
@option("--no-update", is_flag=True, default=False, help="Do not update to the latest version")
28+
@option("--compute", type=str, required=False, help="Compute configuration to use")
29+
@option("--extra-docker-config", type=str, default="{}", help="Extra docker configuration as a JSON string")
30+
@option("--image", type=str, hidden=True)
31+
@option("--stop", is_flag=True, default=False, help="Stop any existing deployment")
32+
def add_compute(token: str,
33+
master_domain: str,
34+
slave_domain: str,
35+
master_port: int,
36+
update: bool,
37+
no_update: bool,
38+
compute: Optional[str],
39+
extra_docker_config: Optional[str],
40+
image: Optional[str],
41+
stop: bool) -> None:
42+
start_command(False,
43+
True,
44+
token,
45+
master_domain,
46+
slave_domain,
47+
master_port,
48+
update,
49+
no_update,
50+
compute,
51+
extra_docker_config,
52+
image,
53+
stop)

lean/commands/private_cloud/start.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from typing import Optional
1616
from json import loads
1717

18-
from click import command, option
18+
from click import command, option, prompt
1919
from docker.errors import APIError
2020
from docker.types import Mount
2121

@@ -106,9 +106,9 @@ def get_ip_address():
106106
@option("--master", is_flag=True, default=False, help="Run in master mode")
107107
@option("--slave", is_flag=True, default=False, help="Run in slave mode")
108108
@option("--token", type=str, required=False, help="The master server token")
109-
@option("--master-domain", type=str, required=False, help="The master server domain")
109+
@option("--master-domain", "--master-ip", type=str, required=False, help="The master server domain")
110110
@option("--master-port", type=int, required=False, default=443, help="The master server port")
111-
@option("--slave-domain", type=str, required=False, help="The slave server domain")
111+
@option("--slave-domain", "--slave-ip", type=str, required=False, help="The slave server domain")
112112
@option("--update", is_flag=True, default=False, help="Pull the latest image before starting")
113113
@option("--no-update", is_flag=True, default=False, help="Do not update to the latest version")
114114
@option("--compute", type=str, required=False, help="Compute configuration to use")
@@ -127,6 +127,32 @@ def start(master: bool,
127127
extra_docker_config: Optional[str],
128128
image: Optional[str],
129129
stop: bool) -> None:
130+
start_command(master,
131+
slave,
132+
token,
133+
master_domain,
134+
slave_domain,
135+
master_port,
136+
update,
137+
no_update,
138+
compute,
139+
extra_docker_config,
140+
image,
141+
stop)
142+
143+
144+
def start_command(master: bool,
145+
slave: bool,
146+
token: str,
147+
master_domain: str,
148+
slave_domain: str,
149+
master_port: int,
150+
update: bool,
151+
no_update: bool,
152+
compute: Optional[str],
153+
extra_docker_config: Optional[str],
154+
image: Optional[str],
155+
stop: bool) -> None:
130156
logger = container.logger
131157

132158
if stop:
@@ -139,8 +165,7 @@ def start(master: bool,
139165
slave = True
140166

141167
if not master_domain:
142-
master_domain = get_ip_address()
143-
logger.info(f"'--master-domain' was not provided using '{master_domain}'")
168+
master_domain = prompt("Master domain", get_ip_address())
144169

145170
str_mode = 'slave' if slave else 'master'
146171
logger.info(f'Start running in {str_mode} mode')
@@ -157,7 +182,7 @@ def start(master: bool,
157182

158183
if slave:
159184
if not token:
160-
raise RuntimeError(f"Master token '--token' is required when running as slave")
185+
token = prompt("Master token")
161186
else:
162187
if not token:
163188
from uuid import uuid4
@@ -199,7 +224,8 @@ def start(master: bool,
199224
try:
200225
from requests import get
201226
resp = get(f'http://{master_domain}:{master_port}', stream=True)
202-
slave_domain = resp.raw._connection.sock.getsockname()[0]
227+
potential_slave_domain = resp.raw._connection.sock.getsockname()[0]
228+
slave_domain = prompt("Slave domain", potential_slave_domain)
203229
break
204230
except Exception as e:
205231
from time import sleep

0 commit comments

Comments
 (0)