desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'run the idempotent ansible code'
| @staticmethod
def run_ansible(params, check_mode):
| node_selector = None
if (params['node_selector'] is not None):
node_selector = ','.join(params['node_selector'])
pconfig = ProjectConfig(params['name'], 'None', params['kubeconfig'], {'admin': {'value': params['admin'], 'include': True}, 'admin_role': {'value': params['admin_role'], 'include': True}... |
'Constructor for OpenshiftOC'
| def __init__(self, namespace, tname=None, params=None, create=False, kubeconfig='/etc/origin/master/admin.kubeconfig', tdata=None, verbose=False):
| super(OCProcess, self).__init__(namespace, kubeconfig=kubeconfig, verbose=verbose)
self.name = tname
self.data = tdata
self.params = params
self.create = create
self._template = None
|
'template property'
| @property
def template(self):
| if (self._template is None):
results = self._process(self.name, False, self.params, self.data)
if (results['returncode'] != 0):
raise OpenShiftCLIError(('Error processing template [%s]: %s' % (self.name, results)))
self._template = results['results']['items']
retu... |
'get the template'
| def get(self):
| results = self._get('template', self.name)
if (results['returncode'] != 0):
if ('not found' in results['stderr']):
results['returncode'] = 0
results['exists'] = False
results['results'] = []
return results
|
'delete a resource'
| def delete(self, obj):
| return self._delete(obj['kind'], obj['metadata']['name'])
|
'create a resource'
| def create_obj(self, obj):
| return self._create_from_content(obj['metadata']['name'], obj)
|
'process a template'
| def process(self, create=None):
| do_create = False
if (create != None):
do_create = create
else:
do_create = self.create
return self._process(self.name, do_create, self.params, self.data)
|
'return whether the template exists'
| def exists(self):
| if self.data:
return True
t_results = self._get('template', self.name)
if (t_results['returncode'] != 0):
if ('not found' in t_results['stderr']):
return False
else:
raise OpenShiftCLIError(('Something went wrong. %s' % t_results))
return True
|
'attempt to process the template and return it for comparison with oc objects'
| def needs_update(self):
| obj_results = []
for obj in self.template:
skip = []
if (obj['kind'] == 'ServiceAccount'):
skip.extend(['secrets', 'imagePullSecrets'])
if (obj['kind'] == 'BuildConfig'):
skip.extend(['lastTriggeredImageID'])
if (obj['kind'] == 'ImageStream'):
... |
'run the ansible idempotent code'
| @staticmethod
def run_ansible(params, check_mode):
| ocprocess = OCProcess(params['namespace'], params['template_name'], params['params'], params['create'], kubeconfig=params['kubeconfig'], tdata=params['content'], verbose=params['debug'])
state = params['state']
api_rval = ocprocess.get()
if (state == 'list'):
if (api_rval['returncode'] != 0):
... |
'Constructor for OCUser'
| def __init__(self, config, groups=None, verbose=False):
| super(OCUser, self).__init__('default', config.kubeconfig)
self.config = config
self.groups = groups
self._user = None
|
'property function user'
| @property
def user(self):
| if (not self._user):
self.get()
return self._user
|
'setter function for user'
| @user.setter
def user(self, data):
| self._user = data
|
'return whether a user exists'
| def exists(self):
| if self.user:
return True
return False
|
'return user information'
| def get(self):
| result = self._get(self.kind, self.config.username)
if (result['returncode'] == 0):
self.user = User(content=result['results'][0])
elif (('users "%s" not found' % self.config.username) in result['stderr']):
result['returncode'] = 0
result['results'] = [{}]
return result
|
'delete the object'
| def delete(self):
| return self._delete(self.kind, self.config.username)
|
'make entries for user to the provided group list'
| def create_group_entries(self):
| if (self.groups != None):
for group in self.groups:
cmd = ['groups', 'add-users', group, self.config.username]
rval = self.openshift_cmd(cmd, oadm=True)
if (rval['returncode'] != 0):
return rval
return rval
return {'returncode': 0}
|
'create the object'
| def create(self):
| rval = self.create_group_entries()
if (rval['returncode'] != 0):
return rval
return self._create_from_content(self.config.username, self.config.data)
|
'update group membership'
| def group_update(self):
| rval = {'returncode': 0}
cmd = ['get', 'groups', '-o', 'json']
all_groups = self.openshift_cmd(cmd, output=True)
for group in all_groups['results']['items']:
if ((group['metadata']['name'] in self.groups) and ((group['users'] is None) or (self.config.username not in group['users']))):
... |
'update the object'
| def update(self):
| rval = self.group_update()
if (rval['returncode'] != 0):
return rval
return self._replace_content(self.kind, self.config.username, self.config.data, force=True)
|
'check if there are group membership changes'
| def needs_group_update(self):
| cmd = ['get', 'groups', '-o', 'json']
all_groups = self.openshift_cmd(cmd, output=True)
for group in all_groups['results']['items']:
if ((group['metadata']['name'] in self.groups) and ((group['users'] is None) or (self.config.username not in group['users']))):
return True
elif ((... |
'verify an update is needed'
| def needs_update(self):
| skip = []
if self.needs_group_update():
return True
return (not Utils.check_def_equal(self.config.data, self.user.yaml_dict, skip_keys=skip, debug=True))
|
'run the idempotent ansible code
params comes from the ansible portion of this module
check_mode: does the module support check mode. (module.check_mode)'
| @staticmethod
def run_ansible(params, check_mode=False):
| uconfig = UserConfig(params['kubeconfig'], params['username'], params['full_name'])
oc_user = OCUser(uconfig, params['groups'], verbose=params['debug'])
state = params['state']
api_rval = oc_user.get()
if (state == 'list'):
return {'changed': False, 'results': api_rval['results'], 'state': '... |
'Constructor for OCLabel'
| def __init__(self, name, namespace, kind, kubeconfig, labels=None, selector=None, verbose=False):
| super(OCLabel, self).__init__(namespace, kubeconfig=kubeconfig, verbose=verbose)
self.name = name
self.kind = kind
self.labels = labels
self._curr_labels = None
self.selector = selector
|
'property for the current labels'
| @property
def current_labels(self):
| if (self._curr_labels is None):
results = self.get()
self._curr_labels = results['labels']
return self._curr_labels
|
'property setter for current labels'
| @current_labels.setter
def current_labels(self, data):
| self._curr_labels = data
|
'compare incoming labels against current labels'
| def compare_labels(self, host_labels):
| for label in self.labels:
if ((label['key'] not in host_labels) or (label['value'] != host_labels[label['key']])):
return False
return True
|
'return whether all the labels already exist'
| def all_user_labels_exist(self):
| for current_host_labels in self.current_labels:
rbool = self.compare_labels(current_host_labels)
if (not rbool):
return False
return True
|
'return whether any single label already exists'
| def any_label_exists(self):
| for current_host_labels in self.current_labels:
for label in self.labels:
if (label['key'] in current_host_labels):
return True
return False
|
'go through list of user key:values and return all keys'
| def get_user_keys(self):
| user_keys = []
for label in self.labels:
user_keys.append(label['key'])
return user_keys
|
'collect all the current label keys'
| def get_current_label_keys(self):
| current_label_keys = []
for current_host_labels in self.current_labels:
for key in current_host_labels.keys():
current_label_keys.append(key)
return list(set(current_label_keys))
|
'return list of labels that are currently stored, but aren\'t
in user-provided list'
| def get_extra_current_labels(self):
| extra_labels = []
user_label_keys = self.get_user_keys()
current_label_keys = self.get_current_label_keys()
for current_key in current_label_keys:
if (current_key not in user_label_keys):
extra_labels.append(current_key)
return extra_labels
|
'return whether there are labels currently stored that user
hasn\'t directly provided'
| def extra_current_labels(self):
| extra_labels = self.get_extra_current_labels()
if (len(extra_labels) > 0):
return True
return False
|
'replace currently stored labels with user provided labels'
| def replace(self):
| cmd = self.cmd_template()
extra_labels = self.get_extra_current_labels()
if (len(extra_labels) > 0):
for label in extra_labels:
cmd.append('{}-'.format(label))
if (len(self.labels) > 0):
for label in self.labels:
cmd.append('{}={}'.format(label['key'], label['valu... |
'return label information'
| def get(self):
| result_dict = {}
label_list = []
if self.name:
result = self._get(resource=self.kind, name=self.name, selector=self.selector)
if (result['results'][0] and ('labels' in result['results'][0]['metadata'])):
label_list.append(result['results'][0]['metadata']['labels'])
else:
... |
'boilerplate oc command for modifying lables on this object'
| def cmd_template(self):
| cmd = ['label', self.kind]
if self.selector:
cmd.extend(['--selector', self.selector])
elif self.name:
cmd.extend([self.name])
return cmd
|
'add labels'
| def add(self):
| cmd = self.cmd_template()
for label in self.labels:
cmd.append('{}={}'.format(label['key'], label['value']))
cmd.append('--overwrite')
return self.openshift_cmd(cmd)
|
'delete the labels'
| def delete(self):
| cmd = self.cmd_template()
for label in self.labels:
cmd.append('{}-'.format(label['key']))
return self.openshift_cmd(cmd)
|
'run the idempotent ansible code
prams comes from the ansible portion of this module
check_mode: does the module support check mode. (module.check_mode)'
| @staticmethod
def run_ansible(params, check_mode=False):
| oc_label = OCLabel(params['name'], params['namespace'], params['kind'], params['kubeconfig'], params['labels'], params['selector'], verbose=params['debug'])
state = params['state']
name = params['name']
selector = params['selector']
api_rval = oc_label.get()
if (state == 'list'):
return ... |
'Constructor for ManageNode'
| def __init__(self, config, verbose=False):
| super(ManageNode, self).__init__(None, kubeconfig=config.kubeconfig, verbose=verbose)
self.config = config
|
'formulate the params and run oadm manage-node'
| def evacuate(self):
| return self._evacuate(node=self.config.config_options['node']['value'], selector=self.config.config_options['selector']['value'], pod_selector=self.config.config_options['pod_selector']['value'], dry_run=self.config.config_options['dry_run']['value'], grace_period=self.config.config_options['grace_period']['value']... |
'perform oc get node'
| def get_nodes(self, node=None, selector=''):
| _node = None
_sel = None
if node:
_node = node
if selector:
_sel = selector
results = self._get('node', name=_node, selector=_sel)
if (results['returncode'] != 0):
return results
nodes = []
items = None
if (results['results'][0]['kind'] == 'List'):
ite... |
'return pods for a node'
| def get_pods_from_node(self, node, pod_selector=None):
| results = self._list_pods(node=[node], pod_selector=pod_selector)
if (results['returncode'] != 0):
return results
all_pods = []
if ('Listing matched' in results['results']):
listing_match = re.compile('\n^Listing matched.*$\n', flags=re.MULTILINE)
pods = listing_match.split... |
'run oadm manage-node --list-pods'
| def list_pods(self):
| _nodes = self.config.config_options['node']['value']
_selector = self.config.config_options['selector']['value']
_pod_selector = self.config.config_options['pod_selector']['value']
if (not _nodes):
_nodes = self.get_nodes(selector=_selector)
else:
_nodes = [{'name': name} for name in... |
'oadm manage-node call for making nodes unschedulable'
| def schedulable(self):
| nodes = self.config.config_options['node']['value']
selector = self.config.config_options['selector']['value']
if (not nodes):
nodes = self.get_nodes(selector=selector)
else:
tmp_nodes = []
for name in nodes:
tmp_result = self.get_nodes(name)
if isinstance... |
'run the idempotent ansible code'
| @staticmethod
def run_ansible(params, check_mode):
| nconfig = ManageNodeConfig(params['kubeconfig'], {'node': {'value': params['node'], 'include': True}, 'selector': {'value': params['selector'], 'include': True}, 'pod_selector': {'value': params['pod_selector'], 'include': True}, 'schedulable': {'value': params['schedulable'], 'include': True}, 'list_pods': {'value... |
'Constructor for OCVersion'
| def __init__(self, config, debug):
| super(OCVersion, self).__init__(None, config)
self.debug = debug
|
'get and return version information'
| def get(self):
| results = {}
version_results = self._version()
if (version_results['returncode'] == 0):
filtered_vers = Utils.filter_versions(version_results['results'])
custom_vers = Utils.add_custom_versions(filtered_vers)
results['returncode'] = version_results['returncode']
results.updat... |
'run the idempotent ansible code'
| @staticmethod
def run_ansible(params):
| oc_version = OCVersion(params['kubeconfig'], params['debug'])
if (params['state'] == 'list'):
result = oc_version.get()
return {'state': params['state'], 'results': result, 'changed': False}
|
'Constructor for OCVolume'
| def __init__(self, kind, resource_name, namespace, vol_name, mount_path, mount_type, secret_name, claim_size, claim_name, configmap_name, kubeconfig='/etc/origin/master/admin.kubeconfig', verbose=False):
| super(OCVolume, self).__init__(namespace, kubeconfig)
self.kind = kind
self.volume_info = {'name': vol_name, 'secret_name': secret_name, 'path': mount_path, 'type': mount_type, 'claimSize': claim_size, 'claimName': claim_name, 'configmap_name': configmap_name}
(self.volume, self.volume_mount) = Volume.c... |
'property function for resource var'
| @property
def resource(self):
| if (not self._resource):
self.get()
return self._resource
|
'setter function for resource var'
| @resource.setter
def resource(self, data):
| self._resource = data
|
'return whether a volume exists'
| def exists(self):
| volume_mount_found = False
volume_found = self.resource.exists_volume(self.volume)
if ((not self.volume_mount) and volume_found):
return True
if self.volume_mount:
volume_mount_found = self.resource.exists_volume_mount(self.volume_mount)
if (volume_found and self.volume_mount and vol... |
'return volume information'
| def get(self):
| vol = self._get(self.kind, self.name)
if (vol['returncode'] == 0):
if (self.kind == 'dc'):
self.resource = DeploymentConfig(content=vol['results'][0])
vol['results'] = self.resource.get_volumes()
return vol
|
'remove a volume'
| def delete(self):
| self.resource.delete_volume_by_name(self.volume)
return self._replace_content(self.kind, self.name, self.resource.yaml_dict)
|
'place volume into dc'
| def put(self):
| self.resource.update_volume(self.volume)
self.resource.get_volumes()
self.resource.update_volume_mount(self.volume_mount)
return self._replace_content(self.kind, self.name, self.resource.yaml_dict)
|
'verify an update is needed'
| def needs_update(self):
| return self.resource.needs_update_volume(self.volume, self.volume_mount)
|
'run the idempotent ansible code'
| @staticmethod
def run_ansible(params, check_mode=False):
| oc_volume = OCVolume(params['kind'], params['name'], params['namespace'], params['vol_name'], params['mount_path'], params['mount_type'], params['secret_name'], params['claim_size'], params['claim_name'], params['configmap_name'], kubeconfig=params['kubeconfig'], verbose=params['debug'])
state = params['state']... |
'Constructor for OCVolume'
| def __init__(self, config, verbose=False):
| super(OCPVC, self).__init__(config.namespace, config.kubeconfig)
self.config = config
self.namespace = config.namespace
self._pvc = None
|
'property function pvc'
| @property
def pvc(self):
| if (not self._pvc):
self.get()
return self._pvc
|
'setter function for yedit var'
| @pvc.setter
def pvc(self, data):
| self._pvc = data
|
'return whether the pvc is bound'
| def bound(self):
| if self.pvc.get_volume_name():
return True
return False
|
'return whether a pvc exists'
| def exists(self):
| if self.pvc:
return True
return False
|
'return pvc information'
| def get(self):
| result = self._get(self.kind, self.config.name)
if (result['returncode'] == 0):
self.pvc = PersistentVolumeClaim(content=result['results'][0])
elif (('"%s" not found' % self.config.name) in result['stderr']):
result['returncode'] = 0
result['results'] = [{}]
return result
|
'delete the object'
| def delete(self):
| return self._delete(self.kind, self.config.name)
|
'create the object'
| def create(self):
| return self._create_from_content(self.config.name, self.config.data)
|
'update the object'
| def update(self):
| return self._replace_content(self.kind, self.config.name, self.config.data)
|
'verify an update is needed'
| def needs_update(self):
| if (self.pvc.get_volume_name() or self.pvc.is_bound()):
return False
skip = []
return (not Utils.check_def_equal(self.config.data, self.pvc.yaml_dict, skip_keys=skip, debug=True))
|
'run the idempotent ansible code'
| @staticmethod
def run_ansible(params, check_mode):
| pconfig = PersistentVolumeClaimConfig(params['name'], params['namespace'], params['kubeconfig'], params['access_modes'], params['volume_capacity'], params['selector'], params['storage_class_name'])
oc_pvc = OCPVC(pconfig, verbose=params['debug'])
state = params['state']
api_rval = oc_pvc.get()
if (a... |
'Constructor for OCImage'
| def __init__(self, namespace, registry_url, image_name, image_tag, kubeconfig='/etc/origin/master/admin.kubeconfig', verbose=False):
| super(OCImage, self).__init__(namespace, kubeconfig)
self.registry_url = registry_url
self.image_name = image_name
self.image_tag = image_tag
self.verbose = verbose
|
'return a image by name'
| def get(self):
| results = self._get('imagestream', self.image_name)
results['exists'] = False
if ((results['returncode'] == 0) and results['results'][0]):
results['exists'] = True
if ((results['returncode'] != 0) and ('"{}" not found'.format(self.image_name) in results['stderr'])):
results['return... |
'Create an image'
| def create(self, url=None, name=None, tag=None):
| return self._import_image(url, name, tag)
|
'run the ansible idempotent code'
| @staticmethod
def run_ansible(params, check_mode):
| ocimage = OCImage(params['namespace'], params['registry_url'], params['image_name'], params['image_tag'], kubeconfig=params['kubeconfig'], verbose=params['debug'])
state = params['state']
api_rval = ocimage.get()
if (state == 'list'):
if (api_rval['returncode'] != 0):
return {'failed... |
'return the kind we are working with'
| def get_kind(self):
| if (self.config_options['resource_kind']['value'] == 'role'):
return 'rolebinding'
elif (self.config_options['resource_kind']['value'] == 'cluster-role'):
return 'clusterrolebinding'
elif (self.config_options['resource_kind']['value'] == 'scc'):
return 'scc'
return None
|
'Constructor for PolicyGroup'
| def __init__(self, config, verbose=False):
| super(PolicyGroup, self).__init__(config.namespace, config.kubeconfig, verbose)
self.config = config
self.verbose = verbose
self._rolebinding = None
self._scc = None
self._cluster_role_bindings = None
self._role_bindings = None
|
'role_binding getter'
| @property
def role_binding(self):
| return self._rolebinding
|
'role_binding setter'
| @role_binding.setter
def role_binding(self, binding):
| self._rolebinding = binding
|
'security_context_constraint getter'
| @property
def security_context_constraint(self):
| return self._scc
|
'security_context_constraint setter'
| @security_context_constraint.setter
def security_context_constraint(self, scc):
| self._scc = scc
|
'fetch the desired kind'
| def get(self):
| resource_name = self.config.config_options['name']['value']
if (resource_name == 'cluster-reader'):
resource_name += 's'
results = self._get(self.config.kind, resource_name)
if (results['returncode'] == 0):
return results
return self._get(self.config.kind, (resource_name + '-binding'... |
'return whether role_binding exists'
| def exists_role_binding(self):
| bindings = None
if (self.config.config_options['resource_kind']['value'] == 'cluster-role'):
bindings = self.clusterrolebindings
else:
bindings = self.rolebindings
if (bindings is None):
return False
for binding in bindings:
if ((binding['roleRef']['name'] == self.con... |
'return whether scc exists'
| def exists_scc(self):
| results = self.get()
if (results['returncode'] == 0):
self.security_context_constraint = SecurityContextConstraints(results['results'][0])
if (self.security_context_constraint.find_group(self.config.config_options['group']['value']) != None):
return True
return False
retu... |
'does the object exist?'
| def exists(self):
| if (self.config.config_options['resource_kind']['value'] == 'cluster-role'):
return self.exists_role_binding()
elif (self.config.config_options['resource_kind']['value'] == 'role'):
return self.exists_role_binding()
elif (self.config.config_options['resource_kind']['value'] == 'scc'):
... |
'perform action on resource'
| def perform(self):
| cmd = ['policy', self.config.config_options['action']['value'], self.config.config_options['name']['value'], self.config.config_options['group']['value']]
return self.openshift_cmd(cmd, oadm=True)
|
'run the idempotent ansible code'
| @staticmethod
def run_ansible(params, check_mode):
| state = params['state']
action = None
if (state == 'present'):
action = (('add-' + params['resource_kind']) + '-to-group')
else:
action = (('remove-' + params['resource_kind']) + '-from-group')
nconfig = PolicyGroupConfig(params['namespace'], params['kubeconfig'], {'action': {'value'... |
'getter method for separator'
| @property
def separator(self):
| return self._separator
|
'setter method for separator'
| @separator.setter
def separator(self, inc_sep):
| self._separator = inc_sep
|
'getter method for yaml_dict'
| @property
def yaml_dict(self):
| return self.__yaml_dict
|
'setter method for yaml_dict'
| @yaml_dict.setter
def yaml_dict(self, value):
| self.__yaml_dict = value
|
'parse the key allowing the appropriate separator'
| @staticmethod
def parse_key(key, sep='.'):
| common_separators = list((Yedit.com_sep - set([sep])))
return re.findall(Yedit.re_key.format(''.join(common_separators)), key)
|
'validate the incoming key'
| @staticmethod
def valid_key(key, sep='.'):
| common_separators = list((Yedit.com_sep - set([sep])))
if (not re.match(Yedit.re_valid_key.format(''.join(common_separators)), key)):
return False
return True
|
'remove data at location key'
| @staticmethod
def remove_entry(data, key, sep='.'):
| if ((key == '') and isinstance(data, dict)):
data.clear()
return True
elif ((key == '') and isinstance(data, list)):
del data[:]
return True
if ((not (key and Yedit.valid_key(key, sep))) and isinstance(data, (list, dict))):
return None
key_indexes = Yedit.parse_ke... |
'Get an item from a dictionary with key notation a.b.c
d = {\'a\': {\'b\': \'c\'}}}
key = a#b
return c'
| @staticmethod
def add_entry(data, key, item=None, sep='.'):
| if (key == ''):
pass
elif ((not (key and Yedit.valid_key(key, sep))) and isinstance(data, (list, dict))):
return None
key_indexes = Yedit.parse_key(key, sep)
for (arr_ind, dict_key) in key_indexes[:(-1)]:
if dict_key:
if (isinstance(data, dict) and (dict_key in data) ... |
'Get an item from a dictionary with key notation a.b.c
d = {\'a\': {\'b\': \'c\'}}}
key = a.b
return c'
| @staticmethod
def get_entry(data, key, sep='.'):
| if (key == ''):
pass
elif ((not (key and Yedit.valid_key(key, sep))) and isinstance(data, (list, dict))):
return None
key_indexes = Yedit.parse_key(key, sep)
for (arr_ind, dict_key) in key_indexes:
if (dict_key and isinstance(data, dict)):
data = data.get(dict_key)
... |
'Actually write the file contents to disk. This helps with mocking.'
| @staticmethod
def _write(filename, contents):
| tmp_filename = (filename + '.yedit')
with open(tmp_filename, 'w') as yfd:
yfd.write(contents)
os.rename(tmp_filename, filename)
|
'write to file'
| def write(self):
| if (not self.filename):
raise YeditException('Please specify a filename.')
if (self.backup and self.file_exists()):
shutil.copy(self.filename, (self.filename + '.orig'))
try:
self.yaml_dict.fa.set_block_style()
except AttributeError:
pass
try:
Yedit._... |
'read from file'
| def read(self):
| if ((self.filename is None) or (not self.file_exists())):
return None
contents = None
with open(self.filename) as yfd:
contents = yfd.read()
return contents
|
'return whether file exists'
| def file_exists(self):
| if os.path.exists(self.filename):
return True
return False
|
'return yaml file'
| def load(self, content_type='yaml'):
| contents = self.read()
if ((not contents) and (not self.content)):
return None
if self.content:
if isinstance(self.content, dict):
self.yaml_dict = self.content
return self.yaml_dict
elif isinstance(self.content, str):
contents = self.content
t... |
'get a specified key'
| def get(self, key):
| try:
entry = Yedit.get_entry(self.yaml_dict, key, self.separator)
except KeyError:
entry = None
return entry
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.