Skip to content

Commit a3599d6

Browse files
authored
Releasing version 2.4.12 (#28)
1 parent 4cb1b74 commit a3599d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1800
-293
lines changed

CHANGELOG.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,24 @@ All notable changes to this project will be documented in this file.
77
The format is based on `Keep a
88
Changelog <http://keepachangelog.com/>`__.
99

10+
2.4.12 - 2017-11-27
11+
-------------------
12+
13+
Added
14+
~~~~~~~~~~
15+
* Support option for using second physical NIC on X7 Bare Metal instances (--nic-index option on 'oci compute instance attach-vnic')
16+
* Support for Local Peering Gateway operations ('oci network local-peering-gateway')
17+
* Support for specifying a default for the --profile option in the oci_cli_rc file
18+
* Support create database from backup (oci db database create-from-backup)
19+
* Support for getting archived object restore status ('oci os object restore-status') more details in sample (https://github.com/oracle/oci-cli/scripts/restore_archived_object.sh)
20+
21+
Changed
22+
~~~~~~~~~~
23+
* Help displayed via the --help/-h/-? option is now formatted like man pages found on Unix (or Unix-like) systems. To switch back to the previous way of displaying help, add `use_click_help = True` to the `OCI_CLI_SETTINGS` section of your oci_cli_rc file
24+
1025
2.4.11 - 2017-11-02
1126
-------------------
27+
1228
Added
1329
~~~~~~~~~~
1430
* 'oci setup oci-cli-rc' command to generate an oci_cli_rc file with default aliases and pre-defined queries

MANIFEST.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include LICENSE.txt
22
include README.rst
3-
include CHANGELOG.md
3+
include CHANGELOG.rst
44
include src/oci_cli/bin/oci_autocomplete.sh
55
include src/oci_cli/bin/OciTabExpansion.ps1
6-
exclude setup.cfg
6+
recursive-include src/oci_cli/help_text_producer/data_files *
7+
exclude setup.cfg

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Jinja2==2.9.6
1212
jmespath==0.9.3
1313
ndg-httpsclient==0.4.2
1414
mock==2.0.0
15-
oci==1.3.9
15+
oci==1.3.10
1616
packaging==16.8
1717
pluggy==0.4.0
1818
py==1.4.32

scripts/restore_archived_object.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
# Restore an archived object and download it
3+
# The archived object is not available for download initialy. Issue the restore
4+
# command will kick off the process and it will be available for download in about
5+
# 4 hours.
6+
# Example run: ./scripts/restore_archived_object.sh namespace buckect object file
7+
8+
set -e
9+
10+
# Setup
11+
mkdir -p scripts/temp
12+
NS=$1
13+
BUCKET=$2
14+
OBJECT=$3
15+
FILE=$4
16+
17+
# Show time elapsed in waiting for object restoring to be completed
18+
function show_time_elapsed () {
19+
num=$SECONDS
20+
min=0
21+
hour=0
22+
if((num>59));then
23+
((sec=num%60))
24+
((num=num/60))
25+
if((num>59));then
26+
((min=num%60))
27+
((num=num/60))
28+
((hour=num))
29+
else
30+
((min=num))
31+
fi
32+
else
33+
((sec=num))
34+
fi
35+
echo -ne "Restoring time elapsed: $hour"h "$min"m "$sec"s.\\r
36+
}
37+
38+
# Get object's restore status
39+
STATUS=$(oci os object restore-status -ns $NS -bn $BUCKET --name $OBJECT 2>&1)
40+
echo $STATUS
41+
42+
# Object is archived, call restore command to start the restoring process
43+
if [[ $STATUS == Archived* ]] ;
44+
then
45+
echo "Archived, restore the object"
46+
oci os object restore -ns $NS -bn $BUCKET --name $OBJECT
47+
STATUS=$(oci os object restore-status -ns $NS -bn $BUCKET --name $OBJECT 2>&1)
48+
fi
49+
50+
# Object is in restoring process it could take up to 4 hours to be available for download
51+
# Pulling every 10 minutes to check the status
52+
if [[ $STATUS == Restoring* ]] ;
53+
then
54+
SECONDS=0
55+
while [[ $STATUS == Restoring* ]]
56+
do
57+
STATUS=$(oci os object restore-status -ns $NS -bn $BUCKET --name $OBJECT 2>&1)
58+
show_time_elapsed
59+
sleep 600
60+
done
61+
fi
62+
63+
# Object is available for download, go ahead download it
64+
if [[ $STATUS == Available* ]] || [[ $STATUS == Restored* ]] ;
65+
then
66+
oci os object get -ns $NS -bn $BUCKET --name $OBJECT --file $FILE
67+
echo "File is downloaded to $FILE"
68+
fi

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def open_relative(*path):
3030

3131

3232
requires = [
33-
'oci==1.3.9',
33+
'oci==1.3.10',
3434
'arrow==0.10.0',
3535
'certifi',
3636
'click==6.7',

src/oci_cli/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
from . import retry_utils # noqa: F401
2727
from . import json_skeleton_utils # noqa: F401
2828
from . import string_utils # noqa: F401
29+
from . import help_text_producer # noqa: F401
2930
from oci import config # noqa: F401
3031
from .version import __version__ # noqa: F401

src/oci_cli/bin/OciTabExpansion.ps1

Lines changed: 127 additions & 50 deletions
Large diffs are not rendered by default.

src/oci_cli/cli_root.py

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
33

44
import sys
5-
from oci.config import DEFAULT_LOCATION
5+
from oci.config import DEFAULT_LOCATION, DEFAULT_PROFILE
66
import click
77
import configparser
88
import os.path
99
import logging
10+
from oci.util import Sentinel
11+
import six
1012

1113
from .version import __version__
12-
1314
from .aliasing import parameter_alias, CommandGroupWithAlias
14-
15+
from . import help_text_producer
16+
from . import cli_util
1517

1618
# Enable WARN logging to surface important warnings attached to loading
1719
# defaults, automatic coercion, or fallback values/endpoints that may impact
@@ -34,6 +36,10 @@
3436
CLI_RC_CANNED_QUERIES_SECTION_NAME = 'OCI_CLI_CANNED_QUERIES'
3537
CLI_RC_COMMAND_ALIASES_SECTION_NAME = 'OCI_CLI_COMMAND_ALIASES'
3638
CLI_RC_PARAM_ALIASES_SECTION_NAME = 'OCI_CLI_PARAM_ALIASES'
39+
CLI_RC_GENERIC_SETTINGS_SECTION_NAME = 'OCI_CLI_SETTINGS'
40+
41+
CLI_RC_GENERIC_SETTINGS_DEFAULT_PROFILE_KEY = 'default_profile'
42+
CLI_RC_GENERIC_SETTINGS_USE_CLICK_HELP = 'use_click_help'
3743

3844

3945
def eager_load_cli_rc_file(ctx, param, value):
@@ -45,7 +51,8 @@ def eager_load_cli_rc_file(ctx, param, value):
4551
'canned_queries': {},
4652
'global_command_alias': {},
4753
'command_sequence_alias': {},
48-
'parameter_aliases': {}
54+
'parameter_aliases': {},
55+
'settings': {}
4956
}
5057

5158
# Try and find the configuration file. This is checked in the following order:
@@ -59,27 +66,39 @@ def eager_load_cli_rc_file(ctx, param, value):
5966
parser_without_defaults = configparser.ConfigParser(interpolation=None, default_section=None) # Don't use DEFAULT as the default section, so this doesn't bring in any extra stuff
6067
if os.path.exists(file_location):
6168
parser_without_defaults.read(file_location)
62-
populate_aliases_and_canned_queries(ctx, parser_without_defaults)
69+
populate_aliases_canned_queries_and_settings(ctx, parser_without_defaults)
6370

6471
return file_location
6572
elif os.path.exists(expanded_rc_default_location):
6673
parser_without_defaults.read(expanded_rc_default_location)
67-
populate_aliases_and_canned_queries(ctx, parser_without_defaults)
74+
populate_aliases_canned_queries_and_settings(ctx, parser_without_defaults)
6875

6976
return expanded_rc_default_location
7077
elif os.path.exists(expanded_rc_fallback_location):
7178
parser_without_defaults.read(expanded_rc_fallback_location)
72-
populate_aliases_and_canned_queries(ctx, parser_without_defaults)
79+
populate_aliases_canned_queries_and_settings(ctx, parser_without_defaults)
7380

7481
return expanded_rc_fallback_location
7582
else:
7683
return value
7784

7885

79-
def populate_aliases_and_canned_queries(ctx, parser_without_defaults):
86+
def populate_aliases_canned_queries_and_settings(ctx, parser_without_defaults):
8087
populate_canned_queries(ctx, parser_without_defaults)
8188
populate_command_aliases(ctx, parser_without_defaults)
8289
populate_parameter_aliases(ctx, parser_without_defaults)
90+
populate_settings(ctx, parser_without_defaults)
91+
92+
93+
def populate_settings(ctx, parser_without_defaults):
94+
raw_settings = get_section_without_defaults(parser_without_defaults, CLI_RC_GENERIC_SETTINGS_SECTION_NAME)
95+
96+
settings = {}
97+
if raw_settings:
98+
for setting in raw_settings:
99+
settings[setting[0]] = setting[1]
100+
101+
ctx.obj['settings'] = settings
83102

84103

85104
def populate_command_aliases(ctx, parser_without_defaults):
@@ -178,8 +197,8 @@ def get_section_without_defaults(parser_without_defaults, section_name):
178197
default=DEFAULT_LOCATION, show_default=True,
179198
help='The path to the config file.')
180199
@click.option('--profile',
181-
default='DEFAULT', show_default=True,
182-
help='The profile in the config file to load. This profile will also be used to locate any default parameter values which have been specified in the OCI CLI-specific configuration file')
200+
default=Sentinel(DEFAULT_PROFILE), show_default=False,
201+
help='The profile in the config file to load. This profile will also be used to locate any default parameter values which have been specified in the OCI CLI-specific configuration file. [default: DEFAULT]')
183202
@click.option('--cli-rc-file', '--defaults-file',
184203
default=CLI_RC_DEFAULT_LOCATION, show_default=True,
185204
is_eager=True, callback=eager_load_cli_rc_file,
@@ -206,6 +225,15 @@ def cli(ctx, config_file, profile, defaults_file, request_id, region, endpoint,
206225
click.echo(ctx.get_help(), color=ctx.color)
207226
ctx.exit()
208227

228+
if profile == Sentinel(DEFAULT_PROFILE):
229+
# if --profile is not supplied, check if default_profile is specified in oci_cli_rc and use it if present
230+
# --profile cannot be specified as a regular default because we use it to determine which
231+
# section of the default file to read from
232+
if 'settings' in ctx.obj and CLI_RC_GENERIC_SETTINGS_DEFAULT_PROFILE_KEY in ctx.obj['settings']:
233+
profile = ctx.obj['settings'][CLI_RC_GENERIC_SETTINGS_DEFAULT_PROFILE_KEY]
234+
else:
235+
profile = DEFAULT_PROFILE
236+
209237
initial_dict = {
210238
'config_file': config_file,
211239
'profile': profile,
@@ -228,6 +256,24 @@ def cli(ctx, config_file, profile, defaults_file, request_id, region, endpoint,
228256

229257
if help:
230258
ctx.obj['help'] = True
259+
if is_top_level_help(ctx) and not cli_util.parse_boolean(ctx.obj.get('settings', {}).get(CLI_RC_GENERIC_SETTINGS_USE_CLICK_HELP, False)):
260+
help_text_producer.render_help_text(ctx, [sys.argv[1]])
261+
262+
263+
def is_top_level_help(ctx):
264+
if len(sys.argv) != 3:
265+
return False
266+
267+
top_level_command_tuples = []
268+
for cmd_name, cmd_obj in six.iteritems(ctx.command.commands):
269+
if isinstance(cmd_obj, click.Group):
270+
top_level_command_tuples.append((cmd_name, cmd_obj))
271+
272+
for cmd_tuple in top_level_command_tuples:
273+
if cmd_tuple[0] == sys.argv[1] and sys.argv[2] in ['-?', '-h', '--help']:
274+
return True
275+
276+
return False
231277

232278

233279
def load_default_values(ctx, defaults_file, profile):

src/oci_cli/cli_setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import click
66
from .cli_root import cli, CLI_RC_CANNED_QUERIES_SECTION_NAME, CLI_RC_COMMAND_ALIASES_SECTION_NAME, CLI_RC_PARAM_ALIASES_SECTION_NAME
77
from . import cli_util
8+
from .cli_root import CLI_RC_DEFAULT_LOCATION
89

910
import base64
1011
import hashlib
@@ -232,7 +233,7 @@ def generate_oci_config():
232233
233234
This command will populate the file with some default aliases and predefined queries.
234235
""")
235-
@click.option('--file', type=click.File(mode='a+b'), required=True, help="The file into which default aliases and predefined queries will be loaded")
236+
@click.option('--file', default=os.path.expanduser(CLI_RC_DEFAULT_LOCATION), type=click.File(mode='a+b'), required=True, help="The file into which default aliases and predefined queries will be loaded")
236237
@cli_util.help_option
237238
def setup_cli_rc(file):
238239
if hasattr(file, 'name') and file.name == '<stdout>':

src/oci_cli/cli_util.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from .version import __version__
4444

4545
from . import string_utils
46+
from . import help_text_producer
4647

4748
try:
4849
# PY3+
@@ -599,17 +600,39 @@ def filter_object_headers(headers, whitelist):
599600

600601

601602
def help_callback(ctx, param, value):
603+
from . import cli_root
602604
if ctx.obj.get("help", False):
605+
if not parse_boolean(ctx.obj.get('settings', {}).get(cli_root.CLI_RC_GENERIC_SETTINGS_USE_CLICK_HELP, False)):
606+
help_text_producer.render_help_text(ctx)
607+
608+
# We should only fall down here if the man/text-formatted help is unavailable or if the customer wanted
609+
# the click help
603610
click.echo(ctx.get_help(), color=ctx.color)
604611
ctx.exit()
605612

606613

614+
def group_help_callback(ctx, param, value):
615+
from . import cli_root
616+
args = sys.argv[1:]
617+
filtered_args = []
618+
for a in args:
619+
if not a.startswith('-'):
620+
filtered_args.append(a)
621+
622+
# It is OK to not have an alternate path here (e.g. if help_text_producer did nothing and didn't exit) because
623+
# we'll just fall back to click's handling of group help. Note that using ctx.get_help() directly doesn't
624+
# work in this group help scenario, so we have to rely on click to do the right thing
625+
if ctx.obj.get("help", False):
626+
if not parse_boolean(ctx.obj.get('settings', {}).get(cli_root.CLI_RC_GENERIC_SETTINGS_USE_CLICK_HELP, False)):
627+
help_text_producer.render_help_text(ctx, filtered_args)
628+
629+
607630
'''Help option to use for commands.'''
608631
help_option = click.option('-?', '-h', '--help', is_flag=True, help='Show this message and exit.', expose_value=False, is_eager=True, callback=help_callback)
609632

610633

611634
'''Help option to use for groups (except for oci).'''
612-
help_option_group = click.help_option('-?', '-h', '--help', help='Show this message and exit.')
635+
help_option_group = click.option('-?', '-h', '--help', is_flag=True, help='Show this message and exit.', expose_value=False, is_eager=False, callback=group_help_callback)
613636

614637

615638
def confirmation_callback(ctx, param, value):
@@ -1042,3 +1065,13 @@ def resolve_jmespath_query(ctx, query):
10421065
raise click.UsageError('Query {} is not defined in your OCI CLI configuration file: {}'.format(query_name, ctx.obj['defaults_file']))
10431066
else:
10441067
return query
1068+
1069+
1070+
def parse_boolean(obj):
1071+
if not str:
1072+
return False
1073+
1074+
if isinstance(obj, bool):
1075+
return obj
1076+
1077+
return str(obj).lower() in DEFAULT_FILE_CONVERT_PARAM_TRUTHY_VALUES

0 commit comments

Comments
 (0)