Skip to content

Commit

Permalink
Minor private cloud api improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero committed Dec 9, 2024
1 parent 013bb6c commit a491905
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 25 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
os: [ubuntu-22.04, ubuntu-20.04, macos-12, macos-13, windows-latest]
os: [ubuntu-22.04, ubuntu-20.04, macos-13, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:

strategy:
matrix:
os: [ubuntu-22.04, macos-12, windows-latest]
os: [ubuntu-22.04, macos-13, windows-latest]
python-version: ["3.10"]

# on a new tag (release), after 'test' and 'release' have ended we will run this
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
shell: bash

- name: Create Portable Macos
if: matrix.os == 'macos-12' || matrix.os == 'macos-11'
if: matrix.os == 'macos-13'
env:
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_CERTIFICATE_PWD }}
Expand All @@ -123,7 +123,7 @@ jobs:
shell: bash

- name: Zip package and notarize Macos
if: matrix.os == 'macos-12'
if: matrix.os == 'macos-13'
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
Expand Down
59 changes: 45 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ A locally-focused workflow (local development, local execution) with the CLI may
- [`lean object-store properties`](#lean-object-store-properties)
- [`lean object-store set`](#lean-object-store-set)
- [`lean optimize`](#lean-optimize)
- [`lean private-cloud add-compute`](#lean-private-cloud-add-compute)
- [`lean private-cloud start`](#lean-private-cloud-start)
- [`lean private-cloud stop`](#lean-private-cloud-stop)
- [`lean project-create`](#lean-project-create)
Expand Down Expand Up @@ -1818,6 +1819,34 @@ Options:

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

### `lean private-cloud add-compute`

Add private cloud compute

```
Usage: lean private-cloud add-compute [OPTIONS]
Add private cloud compute
Options:
--token TEXT The master server token
--master-domain, --master-ip TEXT
The master server domain
--master-port INTEGER The master server port
--slave-domain, --slave-ip TEXT
The slave server domain
--update Pull the latest image before starting
--no-update Do not update to the latest version
--compute TEXT Compute configuration to use
--extra-docker-config TEXT Extra docker configuration as a JSON string
--stop Stop any existing deployment
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
--verbose Enable debug logging
--help Show this message and exit.
```

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

### `lean private-cloud start`

Start a new private cloud
Expand All @@ -1828,20 +1857,22 @@ Usage: lean private-cloud start [OPTIONS]
Start a new private cloud
Options:
--master Run in master mode
--slave Run in slave mode
--token TEXT The master server token
--master-domain TEXT The master server domain
--master-port INTEGER The master server port
--slave-domain TEXT The slave server domain
--update Pull the latest image before starting
--no-update Do not update to the latest version
--compute TEXT Compute configuration to use
--extra-docker-config TEXT Extra docker configuration as a JSON string
--stop Stop any existing deployment
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
--verbose Enable debug logging
--help Show this message and exit.
--master Run in master mode
--slave Run in slave mode
--token TEXT The master server token
--master-domain, --master-ip TEXT
The master server domain
--master-port INTEGER The master server port
--slave-domain, --slave-ip TEXT
The slave server domain
--update Pull the latest image before starting
--no-update Do not update to the latest version
--compute TEXT Compute configuration to use
--extra-docker-config TEXT Extra docker configuration as a JSON string
--stop Stop any existing deployment
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
--verbose Enable debug logging
--help Show this message and exit.
```

_See code: [lean/commands/private_cloud/start.py](lean/commands/private_cloud/start.py)_
Expand Down
2 changes: 2 additions & 0 deletions lean/commands/private_cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from lean.commands.private_cloud.start import start
from lean.commands.private_cloud.stop import stop
from lean.commands.private_cloud.add_compute import add_compute


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

private_cloud.add_command(start)
private_cloud.add_command(stop)
private_cloud.add_command(add_compute)
53 changes: 53 additions & 0 deletions lean/commands/private_cloud/add_compute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
# Lean CLI v1.0. Copyright 2021 QuantConnect Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional

from click import option, command

from lean.click import LeanCommand
from lean.commands.private_cloud.start import start_command


@command(cls=LeanCommand, requires_lean_config=True, requires_docker=True, help="Add private cloud compute")
@option("--token", type=str, required=False, help="The master server token")
@option("--master-domain", "--master-ip", type=str, required=False, help="The master server domain")
@option("--master-port", type=int, required=False, default=443, help="The master server port")
@option("--slave-domain", "--slave-ip", type=str, required=False, help="The slave server domain")
@option("--update", is_flag=True, default=False, help="Pull the latest image before starting")
@option("--no-update", is_flag=True, default=False, help="Do not update to the latest version")
@option("--compute", type=str, required=False, help="Compute configuration to use")
@option("--extra-docker-config", type=str, default="{}", help="Extra docker configuration as a JSON string")
@option("--image", type=str, hidden=True)
@option("--stop", is_flag=True, default=False, help="Stop any existing deployment")
def add_compute(token: str,
master_domain: str,
slave_domain: str,
master_port: int,
update: bool,
no_update: bool,
compute: Optional[str],
extra_docker_config: Optional[str],
image: Optional[str],
stop: bool) -> None:
start_command(False,
True,
token,
master_domain,
slave_domain,
master_port,
update,
no_update,
compute,
extra_docker_config,
image,
stop)
40 changes: 33 additions & 7 deletions lean/commands/private_cloud/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from typing import Optional
from json import loads

from click import command, option
from click import command, option, prompt
from docker.errors import APIError
from docker.types import Mount

Expand Down Expand Up @@ -106,9 +106,9 @@ def get_ip_address():
@option("--master", is_flag=True, default=False, help="Run in master mode")
@option("--slave", is_flag=True, default=False, help="Run in slave mode")
@option("--token", type=str, required=False, help="The master server token")
@option("--master-domain", type=str, required=False, help="The master server domain")
@option("--master-domain", "--master-ip", type=str, required=False, help="The master server domain")
@option("--master-port", type=int, required=False, default=443, help="The master server port")
@option("--slave-domain", type=str, required=False, help="The slave server domain")
@option("--slave-domain", "--slave-ip", type=str, required=False, help="The slave server domain")
@option("--update", is_flag=True, default=False, help="Pull the latest image before starting")
@option("--no-update", is_flag=True, default=False, help="Do not update to the latest version")
@option("--compute", type=str, required=False, help="Compute configuration to use")
Expand All @@ -127,6 +127,32 @@ def start(master: bool,
extra_docker_config: Optional[str],
image: Optional[str],
stop: bool) -> None:
start_command(master,
slave,
token,
master_domain,
slave_domain,
master_port,
update,
no_update,
compute,
extra_docker_config,
image,
stop)


def start_command(master: bool,
slave: bool,
token: str,
master_domain: str,
slave_domain: str,
master_port: int,
update: bool,
no_update: bool,
compute: Optional[str],
extra_docker_config: Optional[str],
image: Optional[str],
stop: bool) -> None:
logger = container.logger

if stop:
Expand All @@ -139,8 +165,7 @@ def start(master: bool,
slave = True

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

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

if slave:
if not token:
raise RuntimeError(f"Master token '--token' is required when running as slave")
token = prompt("Master token")
else:
if not token:
from uuid import uuid4
Expand Down Expand Up @@ -199,7 +224,8 @@ def start(master: bool,
try:
from requests import get
resp = get(f'http://{master_domain}:{master_port}', stream=True)
slave_domain = resp.raw._connection.sock.getsockname()[0]
potential_slave_domain = resp.raw._connection.sock.getsockname()[0]
slave_domain = prompt("Slave domain", potential_slave_domain)
break
except Exception as e:
from time import sleep
Expand Down

0 comments on commit a491905

Please sign in to comment.