-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[App] Enable to register data connections #16670
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
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
23825b4
update
1478c4f
update
41919c5
update
4488c4b
update
1b41080
update
4ed3a48
update
98e3734
update
1d423f9
Merge branch 'master' into mount
tchaton 9447dd4
update
646fe65
Merge branch 'mount' of https://github.com/Lightning-AI/lightning int…
9aeaaff
update
a939bd2
update
50d7f21
update
87e76ea
update
b30c522
update
3f39949
Merge branch 'master' into mount
tchaton ad7046c
update
6d983e0
Merge branch 'mount' of https://github.com/Lightning-AI/lightning int…
0bf0f8b
update
39ae28e
update
9086167
update
033772b
Merge branch 'master' into mount
3ebacf1
update
e480767
update
6ac9476
update
c8d5aba
update
4d833fc
Merge branch 'master' into mount
tchaton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Copyright The Lightning team. | ||
| # | ||
| # 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. | ||
|
|
||
| import sys | ||
|
|
||
| import click | ||
| import rich | ||
| from lightning_cloud.openapi import ProjectIdDataConnectionsBody | ||
| from rich.live import Live | ||
| from rich.spinner import Spinner | ||
| from rich.text import Text | ||
|
|
||
| from lightning.app.utilities.app_helpers import Logger | ||
| from lightning.app.utilities.cli_helpers import _error_and_exit | ||
| from lightning.app.utilities.cloud import _get_project | ||
| from lightning.app.utilities.network import LightningClient | ||
|
|
||
| logger = Logger(__name__) | ||
|
|
||
|
|
||
| @click.argument("name", required=True) | ||
| @click.argument("region", required=True) | ||
| @click.argument("source", required=True) | ||
| @click.argument("destination", required=False) | ||
| @click.argument("project_name", required=False) | ||
| def connect_data( | ||
| name: str, | ||
| region: str, | ||
| source: str, | ||
| destination: str = "", | ||
| project_name: str = "", | ||
| ) -> None: | ||
| """Create a new data connection.""" | ||
|
|
||
| if sys.platform == "win32": | ||
| _error_and_exit("Data connection isn't supported on windows. Open an issue on Github.") | ||
|
|
||
| with Live(Spinner("point", text=Text("pending...", style="white")), transient=True) as live: | ||
|
|
||
| live.stop() | ||
|
|
||
| client = LightningClient() | ||
| projects = client.projects_service_list_memberships() | ||
|
|
||
| project_id = None | ||
|
|
||
| for project in projects.memberships: | ||
|
|
||
| if project.name == project_name: | ||
| project_id = project.project_id | ||
| break | ||
|
|
||
| if project_id is None: | ||
| project_id = _get_project(client).project_id | ||
|
|
||
| if not source.startswith("s3://"): | ||
| return _error_and_exit( | ||
| "Only public S3 folders are supported for now. Please, open a Github issue with your use case." | ||
| ) | ||
|
|
||
| try: | ||
| _ = client.data_connection_service_create_data_connection( | ||
| body=ProjectIdDataConnectionsBody( | ||
| name=name, | ||
| region=region, | ||
| source=source, | ||
| destination=destination, | ||
| ), | ||
| project_id=project_id, | ||
| ) | ||
|
|
||
| # Note: Expose through lightning show data {DATA_NAME} | ||
| # response = client.data_connection_service_list_data_connection_artifacts( | ||
| # project_id=project_id, | ||
| # id=response.id, | ||
| # ) | ||
| # print(response) | ||
| except Exception: | ||
| _error_and_exit("The data connection creation failed.") | ||
|
|
||
| rich.print(f"[green]Succeeded[/green]: You have created a new data connection {name}.") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.