Skip to content

Commit

Permalink
Releasing version 2.4.36 (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
mross22 authored Oct 26, 2018
1 parent 885c092 commit 5a83404
Show file tree
Hide file tree
Showing 27 changed files with 279 additions and 41 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.

The format is based on `Keep a Changelog <http://keepachangelog.com/>`__.

2.4.36 - 2018-10-26
---------------------
Fixed
~~~~~~~
* Fix malformed instance metadata keys for ``oci compute-management instance-configuration create`` and ``oci compute-management instance-configuration launch-compute-instance``. This was preventing SSH access to instances created through these commands.

2.4.35 - 2018-10-18
---------------------
Added
Expand Down Expand Up @@ -64,7 +70,7 @@ Changed
* New Attribute ``allConnectionStrings`` is included in the GET Response for Autonomous Transaction Processing Database and Autonomous Data Warehouse.

Known Issues
~~~~~~~~~~~~
~~~~~~~~
* Block Storage service for copying volume backups across regions is not enabled.

2.4.34 - 2018-10-04
Expand Down
115 changes: 115 additions & 0 deletions scripts/examples/compartment_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
# This script provides an example of how to use compartments in the CLI in terms of:
#
# - Managing compartments by performing create, read (get/list) operations on them.
#
# WARNING: Compartments currently does not supporting the hard delete. Once you created the compartments with the script, you cannot hard delete them.
# WARNING: Compartments supported operations can be found https://docs.cloud.oracle.com/iaas/api/#/en/identity/20160918/Compartment/.
#
# Requirements for running this script:
# - OCI CLI v2.4.35 or later (you can check this by running oci --version).
# - jq (https://stedolan.github.io/jq/) for JSON querying and manipulation of CLI output. This may be a useful utility in general
# and may help cater to scenarios which can't be wholly addressed by the --query option in the CLI.

TENANCY_ID="" # Your tenancy ID

# script to exit on first error
set -e

##########################################################
# Setup the compartments like the following tree
# Here is the compartment Tree in this Test
# Tenancy
# |
# --- CP-1
# |
# |
# --- CP-2
# | |
# | --- CP-21
# | |
# | --- CP-211
# |
# --- CP-3
# |
# --- CP-31
##########################################################

echo "WARNING: Compartments currently does not supporting the hard delete.Once you created the compartments with the script, you cannot hard delete them"
echo "WARNING: Compartments supported operations can be found https://docs.cloud.oracle.com/iaas/api/#/en/identity/20160918/Compartment/"

# Create first level of compartments (CP1, CP2, CP3)
echo "Creating Compartment CP1"
CREATED_COMPARTMENT=$(oci iam compartment create --compartment-id $TENANCY_ID --name CP-1 --description "CP1")
COMPARTMENT_CP1_ID=$(jq -r '.data.id' <<< "$CREATED_COMPARTMENT")
echo "Compartment-CP1 OCID: ${COMPARTMENT_CP1_ID}"

echo "Creating Compartment CP2"
CREATED_COMPARTMENT=$(oci iam compartment create --compartment-id $TENANCY_ID --name CP-2 --description "CP2")
COMPARTMENT_CP2_ID=$(jq -r '.data.id' <<< "$CREATED_COMPARTMENT")
echo "Compartment-CP2 OCID: ${COMPARTMENT_CP2_ID}"

echo "Creating Compartment CP3"
CREATED_COMPARTMENT=$(oci iam compartment create --compartment-id $TENANCY_ID --name CP-3 --description "CP3")
COMPARTMENT_CP3_ID=$(jq -r '.data.id' <<< "$CREATED_COMPARTMENT")
echo "Compartment-CP3 OCID: ${COMPARTMENT_CP3_ID}"

# List first level compartments under tenancy
echo "List Compartments under Tenancy"
LIST_COMPARTMENTS=$(oci iam compartment list --compartment-id $TENANCY_ID)

echo "List Compartments under Tenancy with accessibleLevel == accessible"
LIST_COMPARTMENTS=$(oci iam compartment list --compartment-id $TENANCY_ID --access-level accessible)


# If we create/update and then try to use compartments straight away, sometimes we can get a 404. To try and avoid this, the script
# adds a short delay between the compartment management operations.
# Also sleep is not needed but kept as a safety measure for worst case for data plane sync with control plan changes.
sleep 10

# Create second level of compartments (CP21, CP31)
echo "Creating Compartment CP21 under CP2"
CREATED_COMPARTMENT=$(oci iam compartment create --compartment-id $COMPARTMENT_CP2_ID --name CP-21 --description "CP21")
COMPARTMENT_CP21_ID=$(jq -r '.data.id' <<< "$CREATED_COMPARTMENT")
echo "Compartment-CP21 OCID: ${COMPARTMENT_CP21_ID}"

echo "Creating Compartment CP31 under CP3"
CREATED_COMPARTMENT=$(oci iam compartment create --compartment-id $COMPARTMENT_CP3_ID --name CP-31 --description "CP31")
COMPARTMENT_CP31_ID=$(jq -r '.data.id' <<< "$CREATED_COMPARTMENT")
echo "Compartment-CP31 OCID: ${COMPARTMENT_CP31_ID}"


# If we create/update and then try to use compartments straight away, sometimes we can get a 404. To try and avoid this, the script
# adds a short delay between the compartment management operations.
# Also sleep is not needed but kept as a safety measure for worst case for data plane sync with control plan changes.
sleep 10

# Create third level of compartments (CP211)
echo "Creating Compartment CP211 under CP21"
CREATED_COMPARTMENT=$(oci iam compartment create --compartment-id $COMPARTMENT_CP21_ID --name CP-211 --description "CP211")
COMPARTMENT_CP211_ID=$(jq -r '.data.id' <<< "$CREATED_COMPARTMENT")
echo "Compartment-CP21 OCID: ${COMPARTMENT_CP211_ID}"


# List all level compartments under tenancy
echo "List Compartments under Tenancy with compartment-id-in-subtree == true"
LIST_COMPARTMENTS=$(oci iam compartment list --compartment-id $TENANCY_ID --compartment-id-in-subtree true)

# List all level compartments under tenancy with accessLevel == Accessible
echo "List Compartments under Tenancy with compartment-id-in-subtree == true and accessLevel == accessible"
LIST_COMPARTMENTS=$(oci iam compartment list --compartment-id $TENANCY_ID --access-level accessible --compartment-id-in-subtree true)

# List first level compartments under CP2
echo "List Compartments under CP2"
LIST_COMPARTMENTS=$(oci iam compartment list --compartment-id $COMPARTMENT_CP2_ID)

# List first level compartments under CP21
echo "List Compartments under CP21"
LIST_COMPARTMENTS=$(oci iam compartment list --compartment-id $COMPARTMENT_CP21_ID)

# List first level compartments under CP3
echo "List Compartments under CP3"
LIST_COMPARTMENTS=$(oci iam compartment list --compartment-id $COMPARTMENT_CP3_ID)

echo "DONE"
84 changes: 84 additions & 0 deletions scripts/examples/nat_gateway_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
# This script provides a basic example of how to use the Nat Gateway service in the CLI.
# The two variables at the beginning of the script must be specified accordingly:
#
# * COMPARTMENT_ID: The OCID of the compartment where we'll create our file system and related resources
#
# The script will demonstrate:
#
# * Creating a new nat gateway
# * Getting a nat gateway
# * Updating a nat gateway
# * Deleting a nat gateway
#
#
# Requirements for running this script:
# - OCI CLI v2.4.34 or later (you can check this by running oci --version)
# - jq (https://stedolan.github.io/jq/) for JSON querying of CLI output. This may be a useful utility in general and may help cater to scenarios
# which can't be wholly addressed by the --query option in the CLI

set -e

COMPARTMENT_ID=""

# First we will create a VCN and a subnet. Since these resources have a lifecycle state, we can create them and use
# the --wait-for-state option so that our command will only return/complete when the resouce enters the desired
# state (in this case AVAILABLE)
VCN_ID=$(oci network vcn create -c $COMPARTMENT_ID --display-name createNatgwExampleVcn --cidr-block 10.0.0.0/16 --wait-for-state AVAILABLE --query 'data.id' --raw-output 2>/dev/null)
echo "VCN OCID: ${VCN_ID}"

echo
# First we create a nat gateway. A nat gateway has a lifecycle state so we can use the --wait-for-state
# option so that our command will only return/complete when the nat gateway reaches the desired state.
NAT_GATEWAY_ID=$(oci network nat-gateway create -c $COMPARTMENT_ID --vcn-id $VCN_ID --display-name exampleNatGateway --wait-for-state AVAILABLE --query data.id --raw-output)
echo "Nat Gateway OCID: $NAT_GATEWAY_ID"
echo ""

# Update routing for the subnet by creating a route table with a route rule that directs internet-bound traffic to the Nat Gateway
# Create route table and wait for it to become available
ROUTE_RULE='[{"cidrBlock":"0.0.0.0/0","networkEntityId":"'${NAT_GATEWAY_ID}'"}]'
echo "Create route table and add Nat Gateway rule"
echo "========================="
ROUTE_TABLE_ID=$(oci network route-table create -c $COMPARTMENT_ID --route-rules $ROUTE_RULE --vcn-id $VCN_ID --wait-for-state AVAILABLE --query data.id --raw-output)
echo "Route Table OCID: $ROUTE_TABLE_ID"
echo ""

# We can show the route table directed to the nat gateway
echo "Get route table"
echo "========================="
oci network route-table get --rt-id $ROUTE_TABLE_ID
echo ""

# We can list all nat gateways in a compartment. This is a paginated call and we can use the --all option to get
# all results rather than having to manually deal with page tokens
echo "Listing all nat gateways"
echo "========================="
oci network nat-gateway list -c $COMPARTMENT_ID --all
echo ""

# We can get a specific nat gateway
echo "Get nat gateway"
echo "========================="
oci network nat-gateway get --nat-gateway-id $NAT_GATEWAY_ID
echo ""

# We can update a nat gateway to block traffic through it
echo "Update nat gateway"
echo "========================="
oci network nat-gateway update --nat-gateway-id $NAT_GATEWAY_ID --block-traffic true
echo ""

# Now clean up resources. Since these resources have lifecycle states, we can use --wait-for-state so that the command
# In order to delete nat gateway, There must not be a route table that lists the NAT gateway as a target.
# only completes/returns when the resource has entered the DELETED (or equivalent) state
oci network route-table delete --rt-id $ROUTE_TABLE_ID --force --wait-for-state TERMINATED
echo "Deleted Route Table"

oci network nat-gateway delete --nat-gateway-id $NAT_GATEWAY_ID --force --wait-for-state TERMINATED
echo "Deleted Nat Gateway"

oci network vcn delete --vcn-id $VCN_ID --force --wait-for-state TERMINATED
echo "Deleted VCN"
echo ""

echo "Script Finished"
2 changes: 1 addition & 1 deletion scripts/install/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def handle_path_and_tab_completion(completion_file_path, exec_filepath, exec_dir

# powershell one-liner to append the exec_dir to the USER path permanently
# makes the assumption that powershell is on the PATH already
command = "powershell -Command \"[Environment]::SetEnvironmentVariable(\\\"PATH\\\", \\\"{};\\\" + (Get-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\Environment' -Name PATH).Path, \\\"User\\\")".format(exec_dir)
command = "powershell -Command \"[Environment]::SetEnvironmentVariable(\\\"PATH\\\", \\\"{};\\\" + (Get-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\Environment' -Name PATH).Path, \\\"User\\\")".format(exec_dir) # noqa: W605
subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)
print_status()
print_status('** Close and re-open PowerShell to reload changes to your PATH **')
Expand Down
45 changes: 34 additions & 11 deletions src/oci_cli/cli_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def make_dict_keys_camel_case(original_obj, parameter_name=None, complex_paramet
param_type_to_pass = None
if complex_type_definition:
if complex_type_definition['class'].find("dict(") == 0:
param_type_to_pass = {
param_type_to_pass = { # noqa: W605
'module': complex_type_definition['module'],
'class': re.match('dict\(([^,]*), (.*)\)', complex_type_definition['class']).group(2)
}
Expand All @@ -667,13 +667,26 @@ def make_dict_keys_camel_case(original_obj, parameter_name=None, complex_paramet
else:
cls_type = MODULE_TO_TYPE_MAPPINGS[complex_type_definition['module']][complex_type_definition['class']]
instance = cls_type()
for underscored_name, camelized_name in instance.attribute_map.items():
if camelized_key == camelized_name:
param_type_to_pass = {
'module': complex_type_definition['module'],
'class': instance.swagger_types[underscored_name]
}
break
possible_instances = [instance]

# if the declared input type has subtypes, the actual data passed in may be a subtype
# in this case we need to check which subtype the input data is, and try to camelize based on that subtype
# if we try to camelize exclusively based on the base type, we dont know how to treat fields that are only present
# on the subtype (for example, if a field that is only present on the subtype is a dict, we need to that so we can
# skip camelizing it)
possible_subtype_instance = get_possible_subtype_based_on_payload(cls_type, complex_type_definition['module'], original_obj)
if possible_subtype_instance:
possible_instances.append(possible_subtype_instance)

# try to process this as either the base type or the subtype we found based on discriminator value
for instance in possible_instances:
for underscored_name, camelized_name in instance.attribute_map.items():
if camelized_key == camelized_name:
param_type_to_pass = {
'module': complex_type_definition['module'],
'class': instance.swagger_types[underscored_name]
}
break

if camelize_keys:
new_dict[camelized_key] = make_dict_keys_camel_case(value, parameter_name=key, complex_parameter_type=param_type_to_pass)
Expand All @@ -686,7 +699,7 @@ def make_dict_keys_camel_case(original_obj, parameter_name=None, complex_paramet
new_list = []
list_type = None
if complex_type_definition and complex_type_definition['class'].find('list[') == 0:
list_type = {'module': complex_type_definition['module'], 'class': re.match('list\[(.*)\]', complex_type_definition['class']).group(1)}
list_type = {'module': complex_type_definition['module'], 'class': re.match('list\[(.*)\]', complex_type_definition['class']).group(1)} # noqa: W605

for obj in original_obj:
new_list.append(make_dict_keys_camel_case(obj, complex_parameter_type=list_type))
Expand Down Expand Up @@ -729,6 +742,16 @@ def get_complex_type_definition_for_key_camelization(parameter_name, ctx=None):
return None


def get_possible_subtype_based_on_payload(declared_type, module, payload):
if hasattr(declared_type, 'get_subtype'):
# get_subtype method checks the discriminator field on the input object to determine which type it is
# it expects the keys to be camelized so thus we are passing in camelized_top_level_keys instead of just original_obj
camelized_top_level_keys = {string_utils.camelize(key): value for key, value in six.iteritems(payload)}
subtype_name_of_input_data = declared_type.get_subtype(camelized_top_level_keys)
subtype_of_input_data = getattr(getattr(getattr(oci, module), 'models'), subtype_name_of_input_data)
return subtype_of_input_data()


def get_param(command, param_name):
for param in command.params:
if param.name == param_name:
Expand Down Expand Up @@ -1629,7 +1652,7 @@ def stream_page(is_json, page_index, call_result, ctx, previous_page_has_data):
# first page: [ {. . .}, {. . .
# subsequent pages: }, {. . .}, {. . .
# last page: }, {. . .}, {. . .} ]
json_page_matcher = re.compile("(^\s*\[)([\s\S]*?)(}\s*\]$)")
json_page_matcher = re.compile("(^\s*\[)([\s\S]*?)(}\s*\]$)") # noqa: W605
if is_json:
if 'skip_deserialization' in ctx.obj:
display_dictionary = {}
Expand Down Expand Up @@ -1683,7 +1706,7 @@ def build_query_expression(ctx):
click.echo('In bash or similar "NIX" based shells used in "NIX" environment, escaping can be done by'
'using double quotes inside single quotes.\ne.g. --query \'data[*]."display-name"\'', # noqa: E127
file=sys.stderr)
click.echo('If using PowerShell in Windows environment, escaping can be done by using double quotes'
click.echo('If using PowerShell in Windows environment, escaping can be done by using double quotes' # noqa: W605
'with double escape character \`.\ne.g. --query data[*].\`"display-name\`"', # noqa: E127
file=sys.stderr)
raise
Expand Down
2 changes: 1 addition & 1 deletion src/oci_cli/extended/core_cli_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ..aliasing import CommandGroupWithAlias
from ..cli_util import option

INSTANCE_CONSOLE_CONNECTION_STRING_INTERMEDIATE_HOST_REGEX = "(instance-console\.[a-z0-9-]+\.(oraclecloud|oracleiaas)\.com)"
INSTANCE_CONSOLE_CONNECTION_STRING_INTERMEDIATE_HOST_REGEX = "(instance-console\.[a-z0-9-]+\.(oraclecloud|oracleiaas)\.com)" # noqa: W605
DEFAULT_LOCAL_VNC_PORT = 5900
DEFAULT_SSH_PROXY_PORT = 5905

Expand Down
6 changes: 3 additions & 3 deletions src/oci_cli/json_skeleton_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def translate_complex_param_to_example_object(complex_param_entry):

# For lists we produce an example 2 element list containing objects of whatever the list type is
if cls.startswith('list['):
sub_kls = re.match('list\[(.*)\]', cls).group(1)
sub_kls = re.match('list\[(.*)\]', cls).group(1) # noqa: W605
return [
translate_complex_param_to_example_object({'module': complex_param_entry['module'], 'class': sub_kls}),
translate_complex_param_to_example_object({'module': complex_param_entry['module'], 'class': sub_kls})
Expand All @@ -243,8 +243,8 @@ def translate_complex_param_to_example_object(complex_param_entry):
key_sub_kls = 'str'
value_sub_kls = 'str'
else:
key_sub_kls = re.match('dict\(([^,]*), (.*)\)', cls).group(1)
value_sub_kls = re.match('dict\(([^,]*), (.*)\)', cls).group(2)
key_sub_kls = re.match('dict\(([^,]*), (.*)\)', cls).group(1) # noqa: W605
value_sub_kls = re.match('dict\(([^,]*), (.*)\)', cls).group(2) # noqa: W605

value = translate_complex_param_to_example_object({'module': complex_param_entry['module'], 'class': value_sub_kls})
return {PRIMITIVE_TYPES_TO_EXAMPLE_KEY_VALUES[key_sub_kls][0]: value, PRIMITIVE_TYPES_TO_EXAMPLE_KEY_VALUES[key_sub_kls][1]: value}
Expand Down
Loading

0 comments on commit 5a83404

Please sign in to comment.