Skip to content

Latest commit

 

History

History
988 lines (626 loc) · 23.3 KB

deployhub.md

File metadata and controls

988 lines (626 loc) · 23.3 KB

__init__

DeployHub REST API Client module.

dhapi

DeployHub RESTapi interface for Python.

fspath

fspath(path)

See https://www.python.org/dev/peps/pep-0519/`os` for details.

get_json

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

post_json(url, payload, cookies)

Post URL as json string.

Arguments:

  • url string - url to server
  • payload string - json payload to post
  • cookies string - login cookies

Returns:

  • string - The json string.

post_json_with_header

post_json_with_header(url, token)

Post URL as json string.

Arguments:

  • url string - url to server
  • token string - CircleCI token for header

Returns:

  • string - The json string

is_empty

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

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

login(dhurl, user, password, errors)

Login to DeployHub using the DH Url, userid and password.

Arguments:

  • dhurl string - url to server
  • user string - username to login with
  • password string - password for login
  • errors 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

deploy_application_by_appid(dhurl, cookies, appid, env)

Deploy the application to the environment.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • appid int - id to the application
  • env string - full name of the environemt

Returns:

  • list - [deployment_id (int) -1 for error, message (string)].

deploy_application

deploy_application(dhurl, cookies, appname, appversion, env)

Deploy the application to the environment.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • appname string - name of the application including domain name
  • appversion 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

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 server
  • cookies string - cookies from login
  • appname string - name of the application including domain name
  • appversion string - version of application. Should include vairiant if used.
  • from_domain string - full name of the domain to move from
  • task string - task to use to do the move

Returns:

  • list - [appid (int) -1 for error, message (string)].

approve_application

approve_application(dhurl, cookies, appname, appversion)

Approve the application for the current domain that it is in.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • appname string - name of the application including domain name
  • appversion string - version of application. Should include vairiant if used.

Returns:

  • list - [appid (int) -1 for error, message (string)].

is_deployment_done

is_deployment_done(dhurl, cookies, deployment_id)

Check to see if the deployment has completed.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • deployment_id int - id of the deployment to check

Returns:

  • list - [True if done, otherwise False (boolean), message (string)].

get_logs

get_logs(dhurl, cookies, deployid)

Get the logs for the deployment.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • deployment_id int - id of the deployment to check

Returns:

  • list - [True if successful fetch, otherwise False (boolean), output lines (string)].

get_attrs

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 server
  • cookies string - cookies from login
  • appname string - name of the application including domain name.
  • compname string - name of the component including domain name
  • env string - name of the environment including domain name
  • srv string - name of the end-point including domain name

Returns:

  • dict - key/value pair of attributes.

get_application_attrs

get_application_attrs(dhurl, cookies, appid)

Get the attributes for an application.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • appid id - id of the application

Returns:

  • string - json string of the key/value attributes.

find_domain

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 server
  • cookies string - cookies from login
  • findname string - domain name to match

Returns:

string or None if not found: the full domain name

clean_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

get_component(dhurl, cookies, compname, compvariant, compversion, id_only, latest)

Get the component json string.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • compname string - name of the component including domain name
  • compvariant string - variant of the component, optional
  • compversion string - version of the component, optional
  • id_only boolean - return just the id and not the whole json string
  • latest boolean - return the latest version

Returns:

  • int - if id_only = True
  • string - if id_only = False. If latest = True then latest version json is returned otherwise current version json string is returned.

get_environment

get_environment(dhurl, cookies, env)

Get the environment json string.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • env 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

get_component_name(dhurl, cookies, compid)

Get the full component name.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • compid int - id of the component

Returns:

  • string - full name of the component

get_component_fromid

get_component_fromid(dhurl, cookies, compid)

Get the component json string.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • compid int - id of the component

Returns:

  • string - json string for the component

get_component_attrs

get_component_attrs(dhurl, cookies, compid)

Get the component attributes json string.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • compid int - id of the component

Returns:

  • dict - json string to the attributes

get_application_name

get_application_name(dhurl, cookies, appid)

Get the application name.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • appid int - id of the application

Returns:

  • string - full name of the application

new_component_version

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 server
  • cookies string - cookies from login
  • compname string - name of the component including domain
  • compvariant string - variant of the component, optional
  • compversion string - version of the component, optional
  • kind string - docker or file
  • component_items list - component items for the file type
  • compautoinc 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

new_docker_component(dhurl, cookies, compname, compvariant, compversion, parent_compid)

Create a new docker component.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • compname string - name of the component including domain
  • compvariant string - variant of the component, optional
  • compversion string - version of the component, optional
  • parent_compid int - parent component version for the new component

Returns:

  • int - id of the new component, -1 if an error occurred.

new_file_component

new_file_component(dhurl, cookies, compname, compvariant, compversion, parent_compid, component_items)

Create a new file component.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • compname string - name of the component including domain
  • compvariant string - variant of the component, optional
  • compversion string - version of the component, optional
  • parent_compid int - parent component version for the new component
  • component_items list - list of items for the component

Returns:

  • int - id of the new component, -1 if an error occurred.

new_component_item

new_component_item(dhurl, cookies, compid, kind, component_items)

Create a new component item for the component.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • compname string - name of the component including domain
  • compvariant string - variant of the component, optional
  • compversion string - version of the component, optional
  • kind string - docker or file for the component kind

Returns:

  • int - id of the new component item, -1 if an error occurred.

update_name

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 server
  • cookies string - cookies from login
  • compname string - name of the component including domain
  • compvariant string - variant of the component, optional
  • compversion string - version of the component, optional
  • compid int - id to the component to update the name of

Returns:

  • string - json string of the component update.

new_component

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 server
  • cookies string - cookies from login
  • compname string - name of the component including domain
  • compvariant string - variant of the component, optional
  • compversion string - version of the component, optional
  • kind string - docker or file for the kind of component
  • parent_compid - id of the parent component version

Returns:

  • int - component id of the new component otherwise None.

update_component_attrs

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 server
  • cookies string - cookies from login
  • compname string - name of the component including domain
  • compvariant string - variant of the component, optional
  • compversion string - version of the component, optional
  • attrs dict - key/value dictionary
  • crdatasource string - name of the CR data source
  • cdlist 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

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 server
  • cookies string - cookies from login
  • compid int - id of the component to update
  • attrs dict - key/value dictionary
  • crdatasource string - name of the CR data source
  • cdlist 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

update_envid_attrs(dhurl, cookies, envid, attrs)

Update the attributes, key/value pairs, for the environment.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • envid int - id of the environment to update
  • attrs dict - key/value dictionary

Returns:

  • list - [True for success, otherwise False, json string of update, url for update].

get_application

get_application(dhurl, cookies, appname, appversion, id_only)

Get the application json string.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • appid int - id of the application
  • id_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

get_application_fromid(dhurl, cookies, appid, appversion)

Get the application json string.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • appid int - id of the application
  • appversion string - 'latest' to get the last application version

Returns:

  • list - [id or -1 if not found, application name, latest version id].

get_base_component

get_base_component(dhurl, cookies, compid, id_only)

Get the base component json string.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • compid int - id of the component
  • id_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

get_component_from_tag(dhurl, cookies, image_tag)

Get the component based on the docker tag.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • image_tag string - image tag

Returns:

  • int - return the compid if found otherwise -1.

new_application

new_application(dhurl, cookies, appname, appversion, appautoinc, envs)

Create a new application version and base version if needed.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • appname string - name of the application including domain
  • compversion string - version of the application, optional
  • appautoinc 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

add_compver_to_appver(dhurl, cookies, appid, compid)

Add a component version to an application version.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • appid int - id of the application
  • compid int - id of the component to add to the application

Returns:

no data returned

assign_comp_to_app

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 server
  • cookies string - cookies from login
  • appid int - id of the application
  • compid int - id of the component to add to the application
  • parent_compid int - parent component in the layout panel
  • xpos int - xpos in the layout panel
  • ypos int - ypos in the layout panel

Returns:

no data returned

assign_app_to_env

assign_app_to_env(dhurl, cookies, appname, envs)

Assign an application to environment to enable deployments.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • appname string - name of application
  • envs list - list of environments to assign the application to

Returns:

no data returned

clone_repo

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

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 server
  • cookies string - cookies from login
  • kubeyaml string - path to the output for the deployment yaml
  • defaultdomain string - domain name to use for the component

Returns:

list of dict: a list of dictionary items defining the component found.

log_deploy_application

log_deploy_application(dhurl, cookies, deploydata)

Record a deployment of an application to an environment.

Arguments:

  • dhurl string - url to the server
  • cookies string - cookies from login
  • deploydata 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

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

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 server
  • cookies string - cookies from login
  • fullcompname string - full name of the component including variant and version
  • chart string - name of the chart. "chart org/chart name"
  • chartversion string - version of the chart. "" for no version
  • chartvalues string - path name to the values file for the chart
  • helmrepo string - name of the helm repo
  • helmrepouser string - username to use to login to a private repo
  • helmrepopass string - password for the helmrepouser
  • helmrepourl string - url for the helm repo
  • helmopts string - additional helm options used for the deployment
  • deployid int - deployment id to associate the helm capture to
  • dockeruser string - docker repo user used to get the image digest
  • dockerpass string - password for the dockeruser
  • helmtemplate string - path name to the file that contains the helm template output

Returns:

Void

set_kvconfig

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 server
  • cookies string - cookies from login
  • kvconfig string - a git repo or a directory to search for properties files
  • appname string - name of the application
  • appversion string - version of the application
  • appautoinc boolean - automatically create a new application version
  • compname string - name of the component
  • compvariant string - variant of the component, optional
  • compversion string - version of the component, optional
  • compautoinc boolean - automatically create a new component version
  • kind string - docker or file kind for the component
  • env string - environment to assign the key/value component to
  • crdatasource string - name of the CR data source
  • crlist list - list of CR to assign to the component

Returns:

no data returned