Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Add UI extensions commands #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ docs/_build/
target/

.idea/
.vscode/

docs/.bundle
docs/_site
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python:
install:
- pip install git+https://github.com/vmware/pyvcloud.git
- pip install -r requirements.txt
- pip install -e .
- python setup.py install
- pip install tox

Expand Down
1 change: 1 addition & 0 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ D=`dirname $0`
$D/tenant-onboard.sh
$D/tenant-operations.sh
$D/cleanup.sh
$D/ui-ext-test.sh
21 changes: 21 additions & 0 deletions tests/ui-ext-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -e

VCD="path/to/vcd/exe"
VCD_UI_EXT_ABS_PATH=path/to/existing/ui/plugin
VCD_HOST=host.vmware.com
VCD_ORG=Org
VCD_USER=user
VCD_PASSWORD='********'

# $VCD login $VCD_HOST $VCD_ORG $VCD_USER --password $VCD_PASSWORD

$VCD version

echo 'This should deploy ui extension'
$VCD uiext deploy --path $VCD_UI_EXT_ABS_PATH -p -pr
echo 'This should list all ui extensions'
$VCD uiext list
echo 'This should delete all ui extension'
$VCD uiext delete --all
12 changes: 12 additions & 0 deletions utilities/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from enum import Enum

Colors = Enum('Colors', {
'HEADER': '\033[95m',
'OKBLUE': '\033[94m',
'OKGREEN': '\033[92m',
'WARNING': '\033[93m',
'FAIL': '\033[91m',
'ENDC': '\033[0m',
'BOLD': '\033[1m',
'UNDERLINE': '\033[4m'
})
2 changes: 2 additions & 0 deletions utilities/prompt_launcher/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from utilities.prompt_launcher.prompt_launcher import PromptLauncher
from utilities.prompt_launcher.prompt import Prompt
149 changes: 149 additions & 0 deletions utilities/prompt_launcher/prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
class Prompt:
"""Represent abstraction of python click
propmt data.
"""
def __init__(self, name, type, message=None, default=None, validator=None,
err_message=None):
self.name = name
self.type = type
self.message = message
self.default = default
self.validator = validator
self.error_message = err_message

@property
def name(self):
"""Getter for name property.
Returns
-------
name : str
name value
"""
return self._name

@name.setter
def name(self, name):
"""Setter for name property.
Parameters
----------
name : str
Defines the name value
"""

if len(name) < 1:
raise Exception("""The name property can not be
with lenght less ten 1.""")

self._name = name

@property
def type(self):
"""Getter for type property.
Returns
-------
type | str
type value
"""
return self._type

@type.setter
def type(self, type):
"""Setter for type property.
Parameters
----------
type : str
Defines the name value
"""

self._type = type

@property
def message(self):
"""Getter for message property.
Returns
-------
message | str
message value
"""

return self._message

@message.setter
def message(self, message=None):
"""Setter for message property.
Parameters
----------
message : str
Defines the message value
"""

if type(message) is not str:
raise Exception("The message property has to be string")

self._message = message

@property
def default(self):
"""Getter for default property.
Returns
-------
default | any
default value
"""

return self._default

@default.setter
def default(self, default):
"""Setter for default property.
Parameters
----------
default : any
Defines the message value
"""

self._default = default

@property
def validator(self):
"""Getter for validator property.
Returns
-------
validator | Validator / Validator[]
validator value
"""

return self._validator

@validator.setter
def validator(self, validator):
"""Setter for validator property.
Parameters
----------
validator : Validator | Validator[]
Defines the validator value
"""

self._validator = validator

@property
def error_message(self):
"""Getter for error_message property.
Returns
-------
error_message | boolean
error_message value
"""
return self._error_message

@error_message.setter
def error_message(self, err_message):
"""Setter for error_message property.
Parameters
----------
error_message : boolean
Defines the error_message value
"""

if err_message is not None:
self._error_message = err_message
105 changes: 105 additions & 0 deletions utilities/prompt_launcher/prompt_launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import click

from utilities.colors import Colors


class PromptLauncher:
"""Collect and execute prompt objects.
"""
def __init__(self, prompts=[]):
"""Constructs the PromptLauncher object.
Paramenters
-------
prompts | Prompt

click | Click ( lib for python CLI )

Returns
-------
None
"""
self._prompts = prompts

def add(self, propmts):
"""Add new items to dict with concat
Returns
-------
None
"""

self._prompts = self._prompts + propmts

def pop_prompt(self):
"""Pop the first element from the prompts list.
Returns
-------
prompt | Prompt
prompt value
"""
return self._prompts.pop(0)

def recuresive_prompt(self, prompt, valuedict):
return self.prompt(prompt, valuedict)

def prompt(self, prompt, valuedict={}):
"""Execute given prompt object.
Returns
-------
valuedict | Dictionary
valuedict value
"""

if prompt.validator:
value = None

err_msg = prompt.error_message
fail_clr = Colors['FAIL'].value
reset_clr = Colors['ENDC'].value

if type(prompt.validator) is list:
userInput = click.prompt(
prompt._message,
type=prompt.type,
default=prompt.default
)

for validator in prompt.validator:
validator_return = validator.validate(userInput)

if validator_return is None:
print(Colors['FAIL'].value + err_msg + reset_clr)
return self.recuresive_prompt(prompt, valuedict)

value = validator_return
else:
value = prompt.validator.validate(input=click.prompt(
prompt._message,
type=prompt.type,
default=prompt.default))
if value is not None:
valuedict[prompt.name] = value
else:
print(fail_clr + err_msg + reset_clr)
return self.recuresive_prompt(prompt, valuedict)
else:
valuedict[prompt.name] = click.prompt(
prompt._message,
type=prompt.type,
default=prompt.default,
)

return valuedict

def multi_prompt(self):
"""Prompt the user with questions.
Returns
-------
thisdict | Dictionary
thisdict value
"""
thisdict = {}

while len(self._prompts) > 0:
prompt = self._prompts.pop(0)
thisdict = self.prompt(prompt, thisdict)
return thisdict
Loading