101
101
def intercept_exception (wrapped , instance , args , kwargs ):
102
102
"""Handle Exceptions.""" # noqa: D202
103
103
104
- def _handle_unknown_exception (ex ):
104
+ def _unknown_exception_handler (ex ):
105
105
"""Handle unknown exceptions."""
106
106
if _log .level == 10 : # "DEBUG"
107
107
print (
@@ -125,7 +125,7 @@ def _handle_unknown_exception(ex):
125
125
print (ae , file = sys .stderr )
126
126
sys .exit (1 )
127
127
except APIUnknownException as ue :
128
- _handle_unknown_exception (ue )
128
+ _unknown_exception_handler (ue )
129
129
except (
130
130
APIException ,
131
131
APIItemNotFoundException ,
@@ -136,7 +136,7 @@ def _handle_unknown_exception(ex):
136
136
print (e .message , file = sys .stderr )
137
137
sys .exit (1 )
138
138
except Exception as ex :
139
- _handle_unknown_exception (ex )
139
+ _unknown_exception_handler (ex )
140
140
141
141
142
142
@intercept_exception
@@ -181,17 +181,17 @@ def get(self, id, output="yaml", params=None):
181
181
self .client , self .client_module_name
182
182
)
183
183
response = self .client_module_property .get (id = id , params = params )
184
+ json_data = response .json
184
185
185
186
if output == "json" :
186
- print (json .dumps (response . json ))
187
+ print (json .dumps (json_data ))
187
188
elif output == "json-pp" :
188
- print (json .dumps (response . json , indent = 4 , sort_keys = True ,))
189
+ print (json .dumps (json_data , indent = 4 , sort_keys = True ,))
189
190
else :
191
+
190
192
print (
191
193
yaml .dump (
192
- yaml .load (
193
- json .dumps (response .json ), Loader = yaml .FullLoader ,
194
- )
194
+ yaml .load (json .dumps (json_data ), Loader = yaml .FullLoader ,)
195
195
)
196
196
)
197
197
@@ -679,7 +679,7 @@ def create_with_ssh_key(
679
679
) and wait_for_operation_secs == 0 :
680
680
print (
681
681
(
682
- "if setting disks 'wait-for-operation-secs' parameter"
682
+ "If setting disks, 'wait-for-operation-secs' parameter"
683
683
" must be greater than zero (recommended 600 seconds)"
684
684
),
685
685
file = sys .stderr ,
@@ -693,10 +693,22 @@ def create_with_ssh_key(
693
693
if wait_for_operation_secs > 0 :
694
694
self .wait_for_status (
695
695
id = worker_id ,
696
- status = ["storage_pending" ],
696
+ status = ["storage_pending" , "error" ],
697
697
timeout_secs = wait_for_operation_secs ,
698
698
)
699
699
700
+ if get_client ().k8s_worker .get (id = worker_id ).status == "error" :
701
+ print (
702
+ (
703
+ "Create request has errored. "
704
+ "Check status message with `hpecp k8sworker get {}" .format (
705
+ id
706
+ )
707
+ ),
708
+ file = sys .stderr ,
709
+ )
710
+ sys .exit (1 )
711
+
700
712
if ephemeral_disks is not None or persistent_disks is not None :
701
713
self .set_storage (
702
714
id = worker_id ,
@@ -1635,36 +1647,120 @@ def bash(self,):
1635
1647
cur=${COMP_WORDS[COMP_CWORD]}
1636
1648
prev=${COMP_WORDS[COMP_CWORD-1]}
1637
1649
1638
- COMP_WORDS_AS_STRING=$(IFS=. ; echo "$ {COMP_WORDS[*]}")
1650
+ MODULE=$ {COMP_WORDS[1]}
1639
1651
1640
- # if the last parameter was --*file
1641
- if echo "${prev}" | grep -q '\-\-.*file$'
1642
- then
1643
- _filedir;
1644
- return
1645
- fi
1652
+ COMP_WORDS_AS_STRING=$(IFS=. ; echo "${COMP_WORDS[*]}")
1646
1653
1654
+ # if last input was > for redirecting to a file
1655
+ # perform file and directory autocompletion
1647
1656
if echo "${prev}" | grep -q '>'
1648
1657
then
1649
1658
_filedir;
1650
1659
return
1651
1660
fi
1652
1661
1662
+ # from: https://stackoverflow.com/a/58221008/1033422
1663
+
1664
+ declare -A MODULE_COLUMNS=(
1665
+ {% for module_name in modules %}
1666
+ {% set column_names = " ".join(columns[module_name]) %}
1667
+ ['{{module_name}}']="{{column_names}}"
1668
+ {% endfor %}
1669
+ )
1670
+
1653
1671
{% raw %}
1654
- for (( idx=${#COMP_WORDS[@]}-1 ; idx>=0 ; idx-- )) ; do
1655
- item="${COMP_WORDS[idx]}"
1656
- if [[ "${item:0:2}" == "--" ]]; then
1657
- if [[ "${item}" == "--columns" ]]
1672
+ # list has uniform behaviour as it is implemented in BaseProxy
1673
+ if [[ "${COMP_WORDS[2]}" == "list" ]];
1674
+ then
1675
+
1676
+ # if 'list' was the last word
1677
+ if [[ "${prev}" == "list" ]];
1678
+ then
1679
+ COMPREPLY=( $(compgen -W "--columns --query" -- $cur) )
1680
+ return
1681
+ fi
1682
+
1683
+ # FIXME: https://unix.stackexchange.com/questions/124539/bash-completion-for-comma-separated-values
1684
+
1685
+ # '--columns' was the last word and user is entering column names
1686
+ if [[ "${COMP_WORDS[3]}" == "--columns"* && ${#COMP_WORDS[@]} -le 5 ]];
1687
+ then
1688
+ declare -a COLUMNS=(${MODULE_COLUMNS[$MODULE]})
1689
+
1690
+ local realcur prefix
1691
+ realcur=${cur##*,} # everything after the last comma, e.g. a,b,c,d -> d
1692
+ prefix=${cur%,*} # everything before the lat comma, e.g. a,b,c,d -> a,b,c
1693
+
1694
+ if [[ "$cur" == *,* ]];
1658
1695
then
1659
- LAST_PARAM_IS_COLUMNS=1
1696
+ IFS=',' ENTERED_COLUMNS_LIST=($prefix)
1697
+ unset IFS
1660
1698
else
1661
- LAST_PARAM_IS_COLUMNS=0
1699
+ IFS=',' ENTERED_COLUMNS_LIST=($prev)
1700
+ unset IFS
1701
+ fi
1702
+
1703
+ for COLUMN in ${COLUMNS[@]}; do
1704
+ for ENTERED_COLUMN in ${ENTERED_COLUMNS_LIST[@]}; do
1705
+ if [[ "${ENTERED_COLUMN}" == "${COLUMN}" ]]
1706
+ then
1707
+ # remove columns already entered by user
1708
+ COLUMNS=(${COLUMNS[*]//$ENTERED_COLUMN/})
1709
+ fi
1710
+ done
1711
+ done
1712
+
1713
+ if [[ "$cur" == *,* ]];
1714
+ then
1715
+ COMPREPLY=( $(compgen -W "${COLUMNS[*]}" -P "${prefix}," -S "," -- ${realcur}) )
1716
+ compopt -o nospace
1717
+ return
1718
+ else
1719
+ COMPREPLY=( $(compgen -W "${COLUMNS[*]}" -S "," -- ${realcur}) )
1720
+ compopt -o nospace
1721
+ return
1662
1722
fi
1663
- break
1664
1723
fi
1665
- done
1724
+
1725
+ # user has finished entering column list or query
1726
+ if [[ ${#COMP_WORDS[@]} == 6 ]];
1727
+ then
1728
+ COMPREPLY=( $(compgen -W "--output" -- $cur) )
1729
+ return
1730
+ fi
1731
+
1732
+ if [[ "${COMP_WORDS[5]}" == "--output"* ]];
1733
+ then
1734
+ if [[ "${COMP_WORDS[3]}" == "--columns"* ]];
1735
+ then
1736
+ COMPREPLY=( $(compgen -W "table text" -- $cur) )
1737
+ return
1738
+ else
1739
+ COMPREPLY=( $(compgen -W "json json-pp text" -- $cur) )
1740
+ return
1741
+ fi
1742
+ fi
1743
+
1744
+ return
1745
+ fi
1666
1746
{% endraw %}
1667
1747
1748
+ # if the last parameter was --*file perform
1749
+ # file and directory autocompletion
1750
+ if echo "${prev}" | grep -q '\-\-.*file$'
1751
+ then
1752
+ _filedir;
1753
+ return
1754
+ fi
1755
+
1756
+ # if last input was > for redirecting to a file
1757
+ # perform file and directory autocompletion
1758
+ if echo "${prev}" | grep -q '>'
1759
+ then
1760
+ _filedir;
1761
+ return
1762
+ fi
1763
+
1668
1764
case "$COMP_WORDS_AS_STRING" in
1669
1765
1670
1766
{% set module_names = " ".join(modules.keys()) %}
@@ -1673,27 +1769,7 @@ def bash(self,):
1673
1769
{% for function_name in modules[module_name] %}
1674
1770
{% set param_names = " ".join(modules[module_name][function_name]).replace('_', '-') %}
1675
1771
{% if function_name == "list" %}
1676
- *"hpecp.{{module_name}}.{{function_name.replace('_', '-')}}."*)
1677
- PARAM_NAMES="{{param_names}}"
1678
- for PARAM in ${PARAM_NAMES[@]}; do
1679
- PARAM="${PARAM//'\' }"
1680
- for WORD in ${COMP_WORDS[@]}; do
1681
- if [[ "${WORD}" == "${PARAM}" ]]
1682
- then
1683
- # remove parameters already entered by user
1684
- PARAM_NAMES=${PARAM_NAMES//$WORD/}
1685
- fi
1686
- done
1687
- done
1688
- if [[ $LAST_PARAM_IS_COLUMNS == 1 ]]
1689
- then
1690
- {% set column_names = " ".join(columns[module_name]) %}
1691
- COMPREPLY=( $(compgen -W "{{column_names}}" -- $cur) )
1692
- COMPREPLY+=( $(compgen -W "$PARAM_NAMES" -- $cur) )
1693
- else
1694
- COMPREPLY=( $(compgen -W "$PARAM_NAMES" -- $cur) )
1695
- fi
1696
- ;;
1772
+ # do nothing - already handled above
1697
1773
{% else %}
1698
1774
*"hpecp.{{module_name}}.{{function_name.replace('_', '-')}}."*)
1699
1775
PARAM_NAMES="{{param_names}}"
0 commit comments