DeployHub REST API Client module.
DeployHub RESTapi interface for Python.
fspath(path)
See https://www.python.org/dev/peps/pep-0519/`os` for details.
get_json(url, cookies)
Get URL as json string.
Arguments:
url
string - url to server cookies (string) - login cookies
Returns:
string
- The json string.
post_json(url, payload, cookies)
Post URL as json string.
Arguments:
url
string - url to serverpayload
string - json payload to postcookies
string - login cookies
Returns:
string
- The json string.
post_json_with_header(url, token)
Post URL as json string.
Arguments:
url
string - url to servertoken
string - CircleCI token for header
Returns:
string
- The json string
is_empty(my_string)
Is the string empty.
Arguments:
my_string
string - string to check emptyness on
Returns:
boolean
- True if the string is None or blank, otherwise False.
is_not_empty(my_string)
Is the string NOT empty.
Arguments:
my_string
string - string to check emptyness on
Returns:
boolean
- False if the string is None or blank, otherwise True.
login(dhurl, user, password, errors)
Login to DeployHub using the DH Url, userid and password.
Arguments:
dhurl
string - url to serveruser
string - username to login withpassword
string - password for loginerrors
list - list to return any errors back to the caller
Returns:
string
- the cookies to be used in subsequent API calls.
deploy_application_by_appid(dhurl, cookies, appid, env)
Deploy the application to the environment.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappid
int - id to the applicationenv
string - full name of the environemt
Returns:
list
- [deployment_id (int) -1 for error, message (string)].
deploy_application(dhurl, cookies, appname, appversion, env)
Deploy the application to the environment.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappname
string - name of the application including domain nameappversion
string - version of application. Should include vairiant if used.env
string - full name of the environment
Returns:
list
- [deployment_id (int) -1 for error, message (string)].
move_application(dhurl, cookies, appname, appversion, from_domain, task)
Move an application from the from_domain using the task.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappname
string - name of the application including domain nameappversion
string - version of application. Should include vairiant if used.from_domain
string - full name of the domain to move fromtask
string - task to use to do the move
Returns:
list
- [appid (int) -1 for error, message (string)].
approve_application(dhurl, cookies, appname, appversion)
Approve the application for the current domain that it is in.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappname
string - name of the application including domain nameappversion
string - version of application. Should include vairiant if used.
Returns:
list
- [appid (int) -1 for error, message (string)].
is_deployment_done(dhurl, cookies, deployment_id)
Check to see if the deployment has completed.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logindeployment_id
int - id of the deployment to check
Returns:
list
- [True if done, otherwise False (boolean), message (string)].
get_logs(dhurl, cookies, deployid)
Get the logs for the deployment.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logindeployment_id
int - id of the deployment to check
Returns:
list
- [True if successful fetch, otherwise False (boolean), output lines (string)].
get_attrs(dhurl, cookies, app, comp, env, srv)
Get the attributes for this deployment base on app version and env.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappname
string - name of the application including domain name.compname
string - name of the component including domain nameenv
string - name of the environment including domain namesrv
string - name of the end-point including domain name
Returns:
dict
- key/value pair of attributes.
get_application_attrs(dhurl, cookies, appid)
Get the attributes for an application.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappid
id - id of the application
Returns:
string
- json string of the key/value attributes.
find_domain(dhurl, cookies, findname)
Get the domain name and id that matches best with the passed in name.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginfindname
string - domain name to match
Returns:
string or None if not found: the full domain name
clean_name(name)
Remove periods and dashes from the name.
Arguments:
name
string - string to clean
Returns:
string
- the name with periods and dashes changed to userscores.
get_component(dhurl, cookies, compname, compvariant, compversion, id_only, latest)
Get the component json string.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompname
string - name of the component including domain namecompvariant
string - variant of the component, optionalcompversion
string - version of the component, optionalid_only
boolean - return just the id and not the whole json stringlatest
boolean - return the latest version
Returns:
int
- if id_only = Truestring
- if id_only = False. If latest = True then latest version json is returned otherwise current version json string is returned.
get_environment(dhurl, cookies, env)
Get the environment json string.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginenv
string - name of the environment
Returns:
list
- [envid or -1 if not found, name (string)]string
- if id_only = False. If latest = True then latest version json is returned otherwise current version json string is returned.
get_component_name(dhurl, cookies, compid)
Get the full component name.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompid
int - id of the component
Returns:
string
- full name of the component
get_component_fromid(dhurl, cookies, compid)
Get the component json string.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompid
int - id of the component
Returns:
string
- json string for the component
get_component_attrs(dhurl, cookies, compid)
Get the component attributes json string.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompid
int - id of the component
Returns:
dict
- json string to the attributes
get_application_name(dhurl, cookies, appid)
Get the application name.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappid
int - id of the application
Returns:
string
- full name of the application
new_component_version(dhurl, cookies, compname, compvariant, compversion, kind, component_items, compautoinc)
Create a new component version and base version if needed.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompname
string - name of the component including domaincompvariant
string - variant of the component, optionalcompversion
string - version of the component, optionalkind
string - docker or filecomponent_items
list - component items for the file typecompautoinc
boolean - auto increment an existing version to the new version
Returns:
int
- id of the new component, -1 if an error occurred.
new_docker_component(dhurl, cookies, compname, compvariant, compversion, parent_compid)
Create a new docker component.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompname
string - name of the component including domaincompvariant
string - variant of the component, optionalcompversion
string - version of the component, optionalparent_compid
int - parent component version for the new component
Returns:
int
- id of the new component, -1 if an error occurred.
new_file_component(dhurl, cookies, compname, compvariant, compversion, parent_compid, component_items)
Create a new file component.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompname
string - name of the component including domaincompvariant
string - variant of the component, optionalcompversion
string - version of the component, optionalparent_compid
int - parent component version for the new componentcomponent_items
list - list of items for the component
Returns:
int
- id of the new component, -1 if an error occurred.
new_component_item(dhurl, cookies, compid, kind, component_items)
Create a new component item for the component.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompname
string - name of the component including domaincompvariant
string - variant of the component, optionalcompversion
string - version of the component, optionalkind
string - docker or file for the component kind
Returns:
int
- id of the new component item, -1 if an error occurred.
update_name(dhurl, cookies, compname, compvariant, compversion, compid)
Update the name of the component for the compid to the new name.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompname
string - name of the component including domaincompvariant
string - variant of the component, optionalcompversion
string - version of the component, optionalcompid
int - id to the component to update the name of
Returns:
string
- json string of the component update.
new_component(dhurl, cookies, compname, compvariant, compversion, kind, parent_compid)
Create the component object based on the component name and variant.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompname
string - name of the component including domaincompvariant
string - variant of the component, optionalcompversion
string - version of the component, optionalkind
string - docker or file for the kind of componentparent_compid
- id of the parent component version
Returns:
int
- component id of the new component otherwise None.
update_component_attrs(dhurl, cookies, compname, compvariant, compversion, attrs, crdatasource, crlist)
Update the attributes, key/value pairs, for the component and CR list.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompname
string - name of the component including domaincompvariant
string - variant of the component, optionalcompversion
string - version of the component, optionalattrs
dict - key/value dictionarycrdatasource
string - name of the CR data sourcecdlist
list - list of CRs to assign to the component
Returns:
list
- [True for success, otherwise False, json string of update, url for update].
update_compid_attrs(dhurl, cookies, compid, attrs, crdatasource, crlist)
Update the attributes, key/value pairs, for the component and CR list.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompid
int - id of the component to updateattrs
dict - key/value dictionarycrdatasource
string - name of the CR data sourcecdlist
list - list of CRs to assign to the component
Returns:
list
- [True for success, otherwise False, json string of update, url for update].
update_envid_attrs(dhurl, cookies, envid, attrs)
Update the attributes, key/value pairs, for the environment.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginenvid
int - id of the environment to updateattrs
dict - key/value dictionary
Returns:
list
- [True for success, otherwise False, json string of update, url for update].
get_application(dhurl, cookies, appname, appversion, id_only)
Get the application json string.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappid
int - id of the applicationid_only
boolean - True return the id only otherwise json string
Returns:
int
- if id_only = True then return the appid otherwise return json string for the application.
get_application_fromid(dhurl, cookies, appid, appversion)
Get the application json string.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappid
int - id of the applicationappversion
string - 'latest' to get the last application version
Returns:
list
- [id or -1 if not found, application name, latest version id].
get_base_component(dhurl, cookies, compid, id_only)
Get the base component json string.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logincompid
int - id of the componentid_only
boolean - True return the id only otherwise json string
Returns:
int
- if id_only = True then return the appid otherwise return json string for the component.
get_component_from_tag(dhurl, cookies, image_tag)
Get the component based on the docker tag.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginimage_tag
string - image tag
Returns:
int
- return the compid if found otherwise -1.
new_application(dhurl, cookies, appname, appversion, appautoinc, envs)
Create a new application version and base version if needed.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappname
string - name of the application including domaincompversion
string - version of the application, optionalappautoinc
boolean - auto increment an existing version to the new version
Returns:
list
- [id of the new application, -1 if an error occurred, application name]
add_compver_to_appver(dhurl, cookies, appid, compid)
Add a component version to an application version.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappid
int - id of the applicationcompid
int - id of the component to add to the application
Returns:
no data returned
assign_comp_to_app(dhurl, cookies, appid, compid, parent_compid, xpos, ypos)
Assign component to application in the correct postion in the tree.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappid
int - id of the applicationcompid
int - id of the component to add to the applicationparent_compid
int - parent component in the layout panelxpos
int - xpos in the layout panelypos
int - ypos in the layout panel
Returns:
no data returned
assign_app_to_env(dhurl, cookies, appname, envs)
Assign an application to environment to enable deployments.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginappname
string - name of applicationenvs
list - list of environments to assign the application to
Returns:
no data returned
clone_repo(project)
Clones a repo into the working directory and reads the features.toml file into a dictionary.
Arguments:
project
string - name of the github org/project to clone
Returns:
dict
- dictionary of the features.toml file. None if no features.toml is in the repo.
import_cluster(dhurl, cookies, domain, appname, appversion, appautoinc, deployenv, crdatasource, crlist, cluster_json, msname, msbranch)
Parse the kubernetes deployment yaml for component name and version.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginkubeyaml
string - path to the output for the deployment yamldefaultdomain
string - domain name to use for the component
Returns:
list of dict: a list of dictionary items defining the component found.
log_deploy_application(dhurl, cookies, deploydata)
Record a deployment of an application to an environment.
Arguments:
dhurl
string - url to the servercookies
string - cookies from logindeploydata
string - path to a json file that contains the component version, application and environment to record.
Returns:
string
- the json string from the file
run_circleci_pipeline(pipeline)
Call the CircleCI REST api to run a pipeline.
Arguments:
pipeline
string - name of the pipeline to run
Returns:
string
- result of the api call.
upload_helm(dhurl, cookies, fullcompname, chart, chartversion, chartvalues, helmrepo, helmrepouser, helmrepopass, helmrepourl, helmopts, deployid, dockeruser, dockerpass, helmtemplate)
Gather the helm chart and values and upload to the deployment log
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginfullcompname
string - full name of the component including variant and versionchart
string - name of the chart. "chart org/chart name"chartversion
string - version of the chart. "" for no versionchartvalues
string - path name to the values file for the charthelmrepo
string - name of the helm repohelmrepouser
string - username to use to login to a private repohelmrepopass
string - password for the helmrepouserhelmrepourl
string - url for the helm repohelmopts
string - additional helm options used for the deploymentdeployid
int - deployment id to associate the helm capture todockeruser
string - docker repo user used to get the image digestdockerpass
string - password for the dockeruserhelmtemplate
string - path name to the file that contains the helm template output
Returns:
Void
set_kvconfig(dhurl, cookies, kvconfig, appname, appversion, appautoinc, compname, compvariant, compversion, compautoinc, kind, env, crdatasource, crlist)
Update the attributes for the component based on the properties files found in the cloned directory.
A comparision is done to see if a new component version is needed. If a new key/values are found then the application version will be created for the environment.
Arguments:
dhurl
string - url to the servercookies
string - cookies from loginkvconfig
string - a git repo or a directory to search for properties filesappname
string - name of the applicationappversion
string - version of the applicationappautoinc
boolean - automatically create a new application versioncompname
string - name of the componentcompvariant
string - variant of the component, optionalcompversion
string - version of the component, optionalcompautoinc
boolean - automatically create a new component versionkind
string - docker or file kind for the componentenv
string - environment to assign the key/value component tocrdatasource
string - name of the CR data sourcecrlist
list - list of CR to assign to the component
Returns:
no data returned