# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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 openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("reset-cache", "Reset cached entities") def __init__(conf: Configuration): for cache_item in conf.list_cache_ext: print(f"Invalidate cache extention '{cache_item}'...") conf.get_cache_ext(cache_item).invalidate_all() print("Cached data flushed")
# 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 os import sys import subprocess from typing import Dict, List from openstack_cli.modules.apputils.terminal import TableOutput, TableColumn, Console from openstack_cli.modules.openstack.objects import OpenStackVMInfo from openstack_cli.modules.openstack import OpenStack from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("sftp", "Establish an SFTP connection to a cluster node") __args__ = __module__.arg_builder\ .add_default_argument("name", str, "full node name or cluster name")\ .add_default_argument("node_number", int, "node number of the cluster to connect to", default=-1)\ .add_argument("user_name", str, "User name to login", alias="user-name", default="root")\ .add_argument("use_password", bool, "Use password auth instead of key", alias="use-password", default=False)\ .add_argument("use_key", str, "Private key to use instead of one detected automatically", alias="use-key", default="None")\ .add_argument("own", bool, "Display only own clusters", default=False)\ .add_argument("port", int, "SSH Port", default=22) IS_WIN: bool = sys.platform == "win32" def _locate_binary(name: str) -> str: _default: str = "c:\\windows\\system32\\openssh" if IS_WIN else "/usr/bin/ssh" name = f"{name}.exe" if IS_WIN else name
# 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 openstack_cli.core.output import StatusOutput from openstack_cli.modules.apputils.terminal import Console from openstack_cli.commands.conf.keys.list import _keys_list from openstack_cli.modules.openstack import OpenStack from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("rm", "Remove ssh key") __args__ = __module__.arg_builder\ .add_default_argument("name", str, "Name of the key to be removed", default="")\ .add_argument("force", bool, "Force key removal", default=False) def _keys_del(conf: Configuration, ostack: OpenStack, name: str, force: bool = False): if not name: _keys = _keys_list(conf, ostack, True) item = Console.ask("Select key to remove", _type=int) if item is None or item > len(_keys) - 1: Console.print_warning("Invalid selection, aborting") return
# limitations under the License. import os from calendar import timegm from datetime import datetime from time import strptime from typing import List, Tuple from openstack_cli.modules.apputils.terminal.colors import Colors from openstack_cli.modules.apputils.curl import curl from openstack_cli.modules.apputils.json2obj import SerializableObject from openstack_cli import __app_name__, __app_version__, __my_root_dir__, __properties_file__ from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo( "version", "Display application version and available updates") __args__ = __module__.arg_builder class ConfProperties(SerializableObject): app_name: str = "" app_version: str = "" commit_hash: str = "" update_src: str = "" @property def short_hash(self): return self.commit_hash[:10] @property def version(self) -> float:
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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 openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo, NotImplementedCommandException __module__ = CommandMetaInfo("scripts", item_help="Manage user scripts", default_sub_command="list", exec_with_child=True) def __init__(conf: Configuration, **kwargs): print("====Wait for version 1.3=====") raise NotImplementedCommandException()
# See the License for the specific language governing permissions and # limitations under the License. from enum import Enum from typing import Dict, List from openstack_cli.modules.apputils.terminal import TableOutput, TableColumn from openstack_cli.modules.openstack.objects import ServerPowerState, OpenStackVMInfo from openstack_cli.modules.apputils.terminal.colors import Colors, Symbols from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo from openstack_cli.modules.openstack import OpenStack from openstack_cli.modules.utils import ValueHolder __module__ = CommandMetaInfo( "info", "Shows the detailed information about requested VMs") __args__ = __module__.arg_builder\ .add_default_argument("search_pattern", str, "Search query", default="") \ .add_argument("own", bool, "Display only owned by user items", default=False) \ .add_argument("showid", bool, "Display instances ID", default=False) class WidthConst(Enum): max_fqdn_len = 0 max_key_len = 1 max_net_len = 2 def print_cluster(servers: Dict[str, List[OpenStackVMInfo]], vh: ValueHolder = None, ostack: OpenStack = None,
# limitations under the License. from datetime import datetime from enum import Enum from typing import List, Dict from openstack_cli.modules.apputils.terminal import TableOutput, TableColumn from openstack_cli.modules.apputils.terminal.colors import Colors, Symbols from openstack_cli.modules.apputils.discovery import CommandMetaInfo from openstack_cli.core.config import Configuration from openstack_cli.modules.utils import ValueHolder from openstack_cli.modules.openstack import OpenStack from openstack_cli.modules.openstack.objects import ServerPowerState, OpenStackVMInfo __module__ = CommandMetaInfo("list", "Shows information about available clusters") __args__ = __module__.arg_builder\ .add_default_argument("search_pattern", str, "Search query", default="")\ .add_argument("own", bool, "Display only owned by user items", default=False) class WidthConst(Enum): max_cluster_name = 0 max_vm_type_len = 1 def get_lifetime(timestamp: datetime): now = datetime.utcnow() d = now - timestamp if 5 < d.days < 31: days = Colors.YELLOW.wrap(d.days) elif d.days > 31:
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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 openstack_cli.modules.apputils.terminal import TableOutput, TableColumn, TableSizeColumn, TableMaxValue from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo from openstack_cli.modules.openstack import OpenStack, OSImageInfo, DiskImageInfo __module__ = CommandMetaInfo("rm", item_help="Remove snap item", default_sub_command="list") __args__ = __module__.arg_builder \ .add_default_argument("search_pattern", str, "search filter", default="") \ .add_argument("own", bool, "Show only own items", default=False) def __init__(conf: Configuration): pass
# 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 os from typing import Tuple from openstack_cli.core import dialogs from openstack_cli.modules.openstack.api_objects import VMKeyPairItemBuilder from openstack_cli.commands.conf.keys.rm import _keys_del from openstack_cli.commands.conf.keys.create import _create_key from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("import", "import ssh fyes from disk") __args__ = __module__.arg_builder \ .add_default_argument("name", str, "Name of the key to be exported")\ .add_argument("private", str, "Path to private key", default="")\ .add_argument("public", str, "Path to public key", default="") from openstack_cli.modules.openstack import OpenStack def _check_keys(private: str, public: str, private_required: bool, public_required: bool) -> Tuple[str, str]: if not private and private_required: private = dialogs.ask_open_file("Select PRIVATE key") if not public and public_required: public = dialogs.ask_open_file("Select PUBLIC key")
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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 openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo, NotImplementedCommandException __module__ = CommandMetaInfo("snap", item_help="Manage OpenStack Snapshoots", default_sub_command="list", exec_with_child=True) def __init__(conf: Configuration, **kwargs): print("====Wait for version 1.3=====") raise NotImplementedCommandException()
# 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 openstack_cli.core.output import StatusOutput, Console from openstack_cli.modules.openstack import OpenStack, OpenStackVMInfo, ServerPowerState from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("start", "Starts requested VMs") __args__ = __module__.arg_builder\ .add_default_argument("name", str, "Name of the cluster or vm") \ .add_argument("own", bool, "Display only own clusters", default=False) def __init__(conf: Configuration, name: str, own: bool): ostack = OpenStack(conf) def __work_unit(value: OpenStackVMInfo) -> bool: return ostack.start_instance(value) so = StatusOutput(__work_unit, pool_size=5, additional_errors=ostack.last_errors)
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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 openstack_cli.core.config import Configuration from openstack_cli.core.dialogs import ask_open_directory from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("list", item_help="List available scripts") __args__ = __module__.arg_builder\ .add_default_argument("name", str, "", default="")\ .add_argument("test", str, "", default="dda") def __init__(conf: Configuration, name: str , test: str): print(f"Args name: {name}; test: {test}") print(ask_open_directory("Lol"))
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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 openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo, NotImplementedCommandException __module__ = CommandMetaInfo("conf", "Manage configuration of the application") def __init__(conf: Configuration): raise NotImplementedCommandException()
# # 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 List, Dict from openstack_cli.modules.apputils.terminal import TableOutput, TableColumn, TableSizeColumn, TableMaxValue from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo from openstack_cli.modules.openstack import OpenStack, OSImageInfo, DiskImageInfo __module__ = CommandMetaInfo("list", item_help="Manage OpenStack Snapshoots", default_sub_command="list") __args__ = __module__.arg_builder\ .add_default_argument("search_pattern", str, "search filter", default="")\ .add_argument("own", bool, "Show only own items", default=False) def __init__(conf: Configuration, search_pattern: str, own: bool): ostack = OpenStack(conf) image_id_ref: Dict[str, DiskImageInfo] = {img.id: img for img in ostack.images} images: List[tuple[DiskImageInfo, str, DiskImageInfo]] = [ ] # Snap Image, Base Image Name, Base Image user_id = conf.user_id
# See the License for the specific language governing permissions and # limitations under the License. from time import sleep from typing import List from openstack_cli.modules.apputils.terminal.colors import Colors from openstack_cli.commands.list import print_cluster from openstack_cli.core.output import StatusOutput, Console from openstack_cli.modules.openstack import OpenStack, OpenStackVMInfo from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.terminal import TableOutput, TableColumn from openstack_cli.modules.apputils.discovery import CommandMetaInfo from openstack_cli.modules.openstack.objects import ServerState, OSImageInfo, OSFlavor __module__ = CommandMetaInfo("up", "Deploys new cluster") __args__ = __module__.arg_builder\ .add_default_argument("name", str, "Name of the cluster")\ .add_default_argument("count", int, "Amount of nodes")\ .add_argument("flavor", str, "Host flavor", default="m1.large")\ .add_argument("image", str, "VM OS to spin up", default="centos-761810")\ .add_argument("key", str, "Key to use for login", default="")\ .add_argument("password", str, "Password to use for login", default="") from openstack_cli.modules.utils import ValueHolder def __init__(conf: Configuration, name: str, count: int, flavor: str, image: str, key: str, password: str): def __work_unit(x: OpenStackVMInfo) -> bool: while True:
# 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 openstack_cli.core.output import StatusOutput from openstack_cli.modules.apputils.terminal import Console from openstack_cli.modules.openstack import OpenStack from openstack_cli.modules.openstack.api_objects import VMKeyPairItemBuilder from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("create", "Create new ssh keys") __args__ = __module__.arg_builder\ .add_default_argument("name", str, "Name of the key") def _create_key(conf: Configuration, ostack: OpenStack, keyBuilder: VMKeyPairItemBuilder): key = keyBuilder.build() try: conf.add_key(key) ostack.create_key(key) Console.print(f"Key with name '{key.name}' successfully added") except ValueError as e: if ostack.has_errors:
# 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 openstack_cli.core.output import StatusOutput, Console from openstack_cli.modules.openstack import OpenStack, OpenStackVMInfo, ServerPowerState from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo( "destroy", item_help="Destroys all VMs that belong to a specific cluster") __args__ = __module__.arg_builder \ .add_default_argument("name", str, "Name of the cluster or vm", default="") \ .add_argument("own", bool, "Display only own clusters", default=False) def __init__(conf: Configuration, name: str, own: bool): ostack = OpenStack(conf) def __work_unit(value: OpenStackVMInfo) -> bool: return ostack.delete_instance(value) so = StatusOutput(__work_unit, pool_size=5, additional_errors=ostack.last_errors)
# # 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 openstack_cli.modules.openstack import OpenStack from openstack_cli.core.output import Console from openstack_cli.modules.apputils.terminal import TableOutput, TableColumn, TableSizeColumn from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("flavors", "Display available VM resource configurations") __args__ = __module__.arg_builder\ .add_default_argument("image_name", str, "Image name (alias)", default="")\ .add_argument("sort_by_name", bool, "Sort the list by name", alias="by-name", default=False)\ .add_argument("all", bool, "Show all flavors", default=False) def __init__(conf: Configuration, image_name: str, sort_by_name: bool, all: bool): sort_keys = { True: lambda x: x.name, False: lambda x: (x.vcpus, x.ram, x.disk, x.ephemeral_disk) } ostack = OpenStack(conf) if image_name: images = list(ostack.get_image_by_alias(image_name))
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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 openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("reset", "Completely reset application configuration") def __init__(conf: Configuration): conf.reset() print("Configuration reset completed")
# limitations under the License. import os import sys import subprocess from typing import Dict, List from openstack_cli.core.shell import shell from openstack_cli.modules.apputils.terminal.get_terminal_size import get_terminal_size from openstack_cli.modules.apputils.terminal import TableOutput, TableColumn, Console from openstack_cli.modules.openstack.objects import OpenStackVMInfo from openstack_cli.modules.openstack import OpenStack from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("ssh", "Establish an SSH connection to a cluster node") __args__ = __module__.arg_builder\ .add_default_argument("name", str, "full node name or cluster name")\ .add_default_argument("node_number", int, "node number of the cluster to connect to", default=-1)\ .add_argument("user_name", str, "User name to login", alias="user-name", default="root")\ .add_argument("use_password", bool, "Use password auth instead of key", alias="use-password", default=False)\ .add_argument("use_key", str, "Private key to use instead of one detected automatically", alias="use-key", default="None")\ .add_argument("own", bool, "Display only own clusters", default=False)\ .add_argument("port", int, "SSH Port", default=22)\ .add_argument("internal", bool, "Use internal SSH Client", alias="buildin", default=False) IS_WIN: bool = sys.platform == "win32" def _locate_binary(name: str) -> str:
# # 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 openstack_cli.modules.openstack.objects import OSNetworkItem from openstack_cli.core.output import Console from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("network", "Reconfigure default network interface for the new VM") def configure_network(conf: Configuration): from openstack_cli.modules.openstack import OpenStack from openstack_cli.commands.networks import get_default_network old_network = conf.default_network if old_network: Console.print_warning(f"Previous network name: {old_network.name}") Console.print_warning("!!! THIS WILL CHANGE DEFAULT NETWORK !!!") net: OSNetworkItem = get_default_network(conf, OpenStack(conf), force=True) if net:
# 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 openstack_cli.core.output import StatusOutput, Console from openstack_cli.modules.openstack import OpenStack, OpenStackVMInfo, ServerPowerState from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("stop", item_help="Stops requested VMs") __args__ = __module__.arg_builder\ .add_default_argument("name", str, "Name of the cluster or vm") \ .add_argument("own", bool, "Display only own clusters", default=False) def __init__(conf: Configuration, name: str, own: bool): ostack = OpenStack(conf) def __work_unit(value: OpenStackVMInfo) -> bool: return ostack.stop_instance(value) so = StatusOutput(__work_unit, pool_size=5, additional_errors=ostack.last_errors)
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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 openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("exec", "Execute command on host") def __init__(conf: Configuration): pass
# 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 List from openstack_cli.modules.apputils.terminal import TableOutput, TableColumn, TableStyle from openstack_cli.modules.openstack import OpenStack from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("networks", "Shows available networks") from openstack_cli.modules.openstack.objects import OSNetworkItem def get_default_network(conf: Configuration, ostack: OpenStack, force: bool = False) -> OSNetworkItem: net: OSNetworkItem or None = conf.default_network if not net or force: net = print_networks(ostack, True) if net: conf.default_network = net return net
# # 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 os from openstack_cli.commands.conf.keys.list import _keys_list from openstack_cli.modules.apputils.terminal import Console from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo from openstack_cli.modules.openstack import VMKeypairItemValue, OpenStack __module__ = CommandMetaInfo("export", "Export ssh keys to disk") __args__ = __module__.arg_builder\ .add_default_argument("name", str, "Name of the key to be exported", default="") def _keys_export(conf: Configuration, ostack: OpenStack, name: str): if not name: _keys = _keys_list(conf, ostack, True) item = Console.ask("Select key to export", _type=int) if item is None or item > len(_keys) - 1: Console.print_warning("Invalid selection, aborting") return name = _keys[item].name _key: VMKeypairItemValue try:
# 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 openstack_cli.core.output import StatusOutput, Console from openstack_cli.modules.openstack import OpenStack, OpenStackVMInfo, ServerPowerState from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("reboot", item_help="Reboots the requested VMs") __args__ = __module__.arg_builder\ .add_default_argument("name", str, "Name of the cluster or vm")\ .add_argument("hard", bool, "Hard reset the VM", default=False) \ .add_argument("own", bool, "Display only own clusters", default=False) def __init__(conf: Configuration, name: str, hard: bool, own: bool): ostack = OpenStack(conf) def __work_unit(value: OpenStackVMInfo) -> bool: return ostack.start_instance(value) so = StatusOutput(__work_unit, pool_size=5, additional_errors=ostack.last_errors)
# # 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 Dict, List from openstack_cli.core.output import Console from openstack_cli.modules.apputils.terminal import TableColumnPosition, TableColumn, TableOutput from openstack_cli.commands.conf.keys import CHECK_ICON, KEY_ICON, UNCHECK_ICON from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo from openstack_cli.modules.openstack import VMKeypairItemValue, OpenStack __module__ = CommandMetaInfo("list", "list available ssh keys") def _keys_list(conf: Configuration, ostack: OpenStack, show_row_nums: bool = False) -> List[VMKeypairItemValue]: server_keypairs: Dict[int, VMKeypairItemValue] = { hash(key): key for key in ostack.get_keypairs() } conf_keys = conf.get_keys() if not conf_keys: Console.print_warning("No keys found, add new ones") return [] max_key_len = len(max(conf.key_names))
# 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 Dict, List from openstack_cli.modules.apputils.terminal import TableOutput, TableColumn, TableColumnPosition from openstack_cli.modules.apputils.terminal.get_terminal_size import get_terminal_size from openstack_cli.modules.apputils.terminal.colors import Colors from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo from openstack_cli.modules.openstack import OpenStack, OpenStackQuotas, OpenStackQuotaType, OpenStackUsers __module__ = CommandMetaInfo( "quota", item_help="Show the allowed resource limits for the project") __args__ = __module__.arg_builder\ .add_argument("details", bool, "Show detailed resource consumption", default=False)\ .add_argument("graph", bool, "Show Graphical statistic per-user", default=False)\ .add_argument("show_clusters", bool, "Show user instances on details page", alias="show-clusters", default=False) def get_percents(current: float, fmax: float): if fmax == 0: return 0 return (current * 100) / fmax def get_plain_progress(percents, color: str = "",
# 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 openstack_cli.modules.apputils.terminal import TableOutput, TableColumn, TableSizeColumn from openstack_cli.modules.openstack import OpenStack from openstack_cli.core.config import Configuration from openstack_cli.modules.apputils.discovery import CommandMetaInfo __module__ = CommandMetaInfo("images", item_help="Display available VM Images") __args__ = __module__.arg_builder \ .add_default_argument("search_pattern", str, "Search query", default="")\ .add_argument("all", bool, "Display all available images", default=False)\ .add_argument("snapshots", bool, "Display only snapshots", default=False)\ .add_argument("own", bool, "Display only own items", default=False) def __init__(conf: Configuration, search_pattern: str, snapshots: bool, all: bool, own: bool): ostack = OpenStack(conf) if snapshots: show_snap(conf, ostack, search_pattern, own) elif all: show_all(conf, ostack, search_pattern, own) else: