Auto-generated documentation for ocs_ci.ocs.ocp module.
General OCP object
- Ocs-ci / Modules / Ocs Ci / Ocs / OCP
- OCP
- OCP().add_label
- OCP().api_version
- OCP().apply
- OCP().check_function_supported
- OCP().check_name_is_specified
- OCP().check_phase
- OCP().create
- OCP().data
- OCP().delete
- OCP().describe
- OCP().exec_oc_cmd
- OCP().exec_oc_debug_cmd
- OCP().get
- OCP().get_resource_status
- OCP().get_user_token
- OCP().kind
- OCP().login
- OCP().namespace
- OCP().new_project
- OCP().patch
- OCP().reload_data
- OCP().resource_name
- OCP().wait_for_delete
- OCP().wait_for_phase
- OCP().wait_for_resource
- rsync
- switch_to_default_rook_cluster_project
- switch_to_project
- OCP
class OCP(object):
def __init__(
api_version='v1',
kind='Service',
namespace=None,
resource_name='',
):
A basic OCP object to run basic 'oc' commands
def add_label(resource_name, label):
Adds a new label for this pod
resource_name
str - Name of the resource you want to labellabel
str - New label to be assigned for this podE.g
- "label=app='rook-ceph-mds'"
@property
def api_version():
def apply(yaml_file):
Applies configuration changes to a resource
yaml_file
str - Path to a yaml file to use in 'oc apply -f file.yaml
dict
- Dictionary represents a returned yaml file
def check_function_supported(support_var):
Check if the resource supports the functionality based on the support_var.
support_var
bool - True if functionality is supported, False otherwise.
NotSupportedFunctionError
- If support_var == False
def check_name_is_specified(resource_name=''):
Check if the name of the resource is specified in class level and if not raise the exception.
ResourceNameNotSpecifiedException
- in case the name is not specified.
def check_phase(phase):
Check phase of resource
phase
str - Phase of resource object
bool
- True if phase of object is the same as passed one, False otherwise.
NotSupportedFunctionError
- If resource doesn't have phase!ResourceNameNotSpecifiedException
- in case the name is not specified.
def create(yaml_file=None, resource_name='', out_yaml_format=True):
Creates a new resource
yaml_file
str - Path to a yaml file to use in 'oc create -f file.yamlresource_name
str - Name of the resource you want to createout_yaml_format
bool - Determines if the output should be formatted to a yaml like string
dict
- Dictionary represents a returned yaml file
@property
def data():
def delete(yaml_file=None, resource_name='', wait=True, force=False):
Deletes a resource
yaml_file
str - Path to a yaml file to use in 'oc delete -f file.yamlresource_name
str - Name of the resource you want to deletewait
bool - Determines if the delete command should wait to completionforce
bool - True for force deletion with --grace-period=0, False otherwise
dict
- Dictionary represents a returned yaml file
CommandFailed
- In case yaml_file and resource_name wasn't provided
def describe(resource_name='', selector=None, all_namespaces=False):
Get command - 'oc describe '
resource_name
str - The resource name to fetchselector
str - The label selector to look forall_namespaces
bool - Equal to oc describe -A
describe('my-pv1')
dict
- Dictionary represents a returned yaml file
def exec_oc_cmd(command, out_yaml_format=True, secrets=None, **kwargs):
Executing 'oc' command
-
command
str - The command to execute (e.g. create -f file.yaml) without the initial 'oc' at the beginning -
out_yaml_format
bool - whether to return yaml loaded python object or raw output -
secrets
list - A list of secrets to be masked with asterisks This kwarg is popped in order to not interfere with subprocess.run(**kwargs)
dict
- Dictionary represents a returned yaml file
def exec_oc_debug_cmd(node, cmd_list):
Function to execute "oc debug" command on OCP node
node
str - Node name where the command to be executedcmd_list
list - List of commands eg: ['cmd1', 'cmd2']
out
str - Returns output of the executed command/commands
CommandFailed
- When failure in command execution
def get(
resource_name='',
out_yaml_format=True,
selector=None,
all_namespaces=False,
):
Get command - 'oc get '
resource_name
str - The resource name to fetchout_yaml_format
bool - Adding '-o yaml' to oc commandselector
str - The label selector to look forall_namespaces
bool - Equal to oc get -A
get('my-pv1')
dict
- Dictionary represents a returned yaml file
def get_resource_status(resource_name):
Get the resource status based on: 'oc get <resource_kind> <resource_name>' command
resource_name
str - The name of the resource to get its status
str
- The status returned by 'oc get' command not in the 'yaml' format
def get_user_token():
Get user access token
str
- access token
@property
def kind():
def login(user, password):
Logs user in
user
str - Name of user to be logged inpassword
str - Password of user to be logged in
str
- output of login command
@property
def namespace():
def new_project(project_name):
Creates a new project
project_name
str - Name of the project to be created
bool
- True in case project creation succeeded, False otherwise
def patch(resource_name, params, type='json'):
Applies changes to resources
resource_name
str - Name of the resourceparams
str - Changes to be added to the resourcetype
str - Type of the operation
bool
- True in case if changes are applied. False otherwise
def reload_data():
Reloading data of OCP object
@property
def resource_name():
def wait_for_delete(resource_name='', timeout=60, sleep=3):
Wait for a resource to be deleted
resource_name
str - The name of the resource to wait for (e.g.my-pv1)timeout
int - Time in seconds to waitsleep
int - Sampling time in seconds
CommandFailed
- If failed to verify the resource deletionTimeoutError
- If resource is not deleted within specified timeout
bool
- True in case resource deletion is successful
@retry(ResourceInUnexpectedState, tries=4, delay=5, backoff=1)
def wait_for_phase(phase, timeout=300, sleep=5):
Wait till phase of resource is the same as required one passed in the phase parameter.
phase
str - Desired phase of resource objecttimeout
int - Timeout in seconds to wait for desired phasesleep
int - Time in seconds to sleep between attempts
ResourceInUnexpectedState
- In case the resource is not in expected phase.NotSupportedFunctionError
- If resource doesn't have phase!ResourceNameNotSpecifiedException
- in case the name is not specified.
def wait_for_resource(
condition,
resource_name='',
selector=None,
resource_count=0,
timeout=60,
sleep=3,
):
Wait for a resource to reach to a desired condition
condition
str - The desired state the resource that is sampled from 'oc get <resource_name>' commandresource_name
str - The name of the resource to wait for (e.g.my-pv1)selector
str - The resource selector to search with.Example
- 'app=rook-ceph-mds'
resource_count
int - How many resources expected to betimeout
int - Time in seconds to waitsleep
int - Sampling time in seconds
bool
- True in case all resources reached desired condition, False otherwise
def rsync(src, dst, node, dst_node=True, extra_params=''):
This function will rsync source folder to destination path. You can rsync local folder to the node or vice versa depends on dst_node parameter. By default the rsync is from local to the node.
src
str - Source path of folder to rsync.dst
str - Destination path where to rsync.node
str - Node to/from copy.dst_node
bool - True if the destination (dst) is the node, False when dst is the local folder.extra_params
str - "See: oc rsync --help for the extra params"
def switch_to_default_rook_cluster_project():
Switch to default project
bool
- True on success, False otherwise
def switch_to_project(project_name):
Switch to another project
project_name
str - Name of the project to be switched to
bool
- True on success, False otherwise