def new(s, architecture, mac_addresses, autodetect_nodegroup=True, min_hwe_kernel=None, subarchitecture=None, hostname=None, power_type=None, nodegroup=None): center(s.__class__.__name__) data = [] data.append(('architecture', architecture)) data.append(('mac_addresses', mac_addresses)) data.append(('autodetect_nodegroup', autodetect_nodegroup)) if min_hwe_kernel: data.append(('min_hwe_kenrel', min_hwe_kernel)) if subarchitecture: data.append(('subarchitecture', subarchitecture)) if hostname: data.append(('hostname', hostname)) if power_type: data.append(('power_type', power_type)) if nodegroup: data.append(('nodegroup', nodegroup)) response = s.__maas.post(u'/nodes/', op='new', data=data) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def details(s): ''' A collection of detailed information about all of the nodes in a particular nodegroup. ''' center(s.__class__.__name__) #from client import MCA # Will probably produce a Nodes object but for now just return what comes # back from the rest interface. # response = s.__maas.post(u'/nodegroups/%s/' % s['uuid'], op='details') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) data = bson.BSON.decode(response.data) cdebug(json.dumps(data, sort_keys=True, indent=4)) retval = response.data cleave(s.__class__.__name__) return retval
def delete(s): center(s.__class__.__name__) response = s.__maas.delete(u'/tags/%s/' % s.name, op='delete') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def __delitem__(s, key): center(s.__class__.__name__) response = s.__maas.delete(u'/zones/%s/' % key) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__zones = None cleave(s.__class__.__name__)
def check_commissioning(s): center(s.__class__.__name__) response = s.__maas.post(u'/nodes/', op='check_commissioning') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def accept_all(s): center(s.__class__.__name__) response = s.__maas.post(u'/nodes/', op='accept') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def rebuild(s): center(s.__class__.__name__) response = s.__maas.post(u'/tags/%s/' % s.name, op='rebuild') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def __delitem__(s, key): center(s.__class__.__name__) response = s.__maas.delete(u'/account/prefs/sslkeys/%s/' % s.__keys[key]['id']) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__keys = None cleave(s.__class__.__name__)
def version(s): center(s.__class__.__name__) response = s.get(u'/version/') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) retval = Version(response.data) cleave(s.__class__.__name__) return retval
def __fetch_if_needed(s): center(s.__class__.__name__) if s.__zones is None: response = s.__maas.get(u'/zones/') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__zones = response.data cdebug(' fetched') cleave(s.__class__.__name__)
def __fetch_if_needed(s): center(s.__class__.__name__) if s.__boot_images is None: response = s.__maas.get(u'/nodegroups/%s/boot-images/' % s.__uuid) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__boot_images = response.data cdebug(' fetched') cleave(s.__class__.__name__)
def __setitem__(s, key, item): center(s.__class__.__name__) # item must be a string # response = s.__maas.post(u'/zones/', data=[('name', key), ('description', item)]) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__zones = None cleave(s.__class__.__name__)
def power_parameters(s, node_ids=[]): center(s.__class__.__name__) data = [] for n in node_ids: data.append(('nodes', n)) response = s.__maas.get(u'/nodes/', op='power_parameters', data=data) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def __fetch_if_needed(s): center('Interfaces.__fetch_if_needed') if s.__interfaces is None: response = s.__maas.get(u'/nodegroups/%s/interfaces/' % s.__uuid, op='list') if not response.ok: if type(response.data) == str: cleave('Interfaces.__fetch_if_needed') raise MapiError(response.data) s.__interfaces = response.data cdebug(' fetched') cleave('Interfaces.__fetch_if_needed')
def __fetch_if_needed(s): center(s.__class__.__name__) if s.__power_types is None: response = s.__maas.get(u'/nodegroups/', op='describe_power_types') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__power_types = response.data cdebug(' fetched') cleave(s.__class__.__name__)
def deployment_status(s, node_ids): center(s.__class__.__name__) data = [] for n in node_ids: data.append(('nodes', n)) response = s.__maas.get(u'/nodes/', op='deployment_status', data=data) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def __fetch_if_needed(s): center(s.__class__.__name__) if s.__keys is None: response = s.__maas.get(u'/account/prefs/sslkeys/', op='list') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__keys = response.data cdebug(' fetched') cleave(s.__class__.__name__)
def __fetch_if_needed(s): center(s.__class__.__name__) if s.__groups is None: response = s.__maas.get(u'/nodes/%s/volume-groups/' % s.__system_id) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__groups = response.data cdebug(' fetched') cleave(s.__class__.__name__)
def acquire(s, name=None, arch=None, cpu_count=None, mem=None, tags=[], not_tags=[], networks=[], not_networks=[], connected_to=[], not_connected_to=[], zone=None, not_in_zone=[], agent_name=None): center(s.__class__.__name__) data = [] if name: data.append(('name', name)) if arch: data.append(('arch', arch)) if cpu_count: data.append(('cpu_count', cpu_count)) if mem: data.append(('mem', mem)) for t in tags: data.append(('tags', t)) for t in not_tags: data.append(('not_tags', t)) for n in networks: data.append(('networks', n)) for n in not_networks: data.append(('not_networks', n)) for c in connected_to: data.append(('connected_to', c)) for c in not_connected_to: data.append(('not_connected_to', c)) for z in zone: data.append(('zone', z)) for z in not_in_zone: data.append(('not_in_zone', z)) if agent_name: data.append(('agent_name', agent_name)) response = s.__maas.post(u'/nodes/', op='accept', data=data) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def add(s, user): center(s.__class__.__name__) if type(user) != User: raise TypeError, "Object is of type %s but must be of type User." % type( user) response = s.__maas.post(u'/users/', data=user.to_rest_data()) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__users = None cleave(s.__class__.__name__) return response.data
def set_zone(s, zone=None, node_ids=[]): center(s.__class__.__name__) data = [] if zone: data.append(('zone', zone)) for n in node_ids: data.append(('nodes', n)) response = s.__maas.post(u'/nodes/', op='set_zone', data=data) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def delete(s, tag): center(s.__class__.__name__) if type(tag) != Tag: raise TypeError, "Object is of type %s but must be of type Tag." % type( tag) response = s.__maas.delete(u'/tags/%s/' % tag.name) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__tags = None cleave(s.__class__.__name__) return response.data
def __fetch_if_needed(s): center(s.__class__.__name__) if s.__events is None: response = s.__maas.get(u'/events/', op='query') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__prev_uri = response.data['prev_uri'] s.__next_uri = response.data['next_uri'] s.__count = response.data['count'] s.__events = response.data['events'] cdebug(' fetched') cleave(s.__class__.__name__)
def update(s, name=None, comment=None, definition=None): center(s.__class__.__name__) utag = Tag(client=s.__maas, name=name, comment=comment, definition=definition) utag_data = utag.to_rest_data() response = s.__maas.put(u'/tags/%s/' % s.name, data=utag_data) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def new(s, key): center(s.__class__.__name__) data = [] data.append((u'key', unicode(key))) try: response = s.__maas.post(u'/account/prefs/sslkeys/', op='new', data=data) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__keys = None except MaasApiHttpBadRequest as e: raise MaasApiBadSSLKey(e.status, e.message) cleave(s.__class__.__name__) return response.data
def new(s, name, comment=None, definition=None, kernel_opts=None): center(s.__class__.__name__) data = [] data.append(('name', name)) if comment: data.append(('comment', comment)) if definition: data.append(('definition', definition)) if kernel_opts: data.append(('kernel_opts', kernel_opts)) response = s.__maas.post(u'/tags/', op='new', data=data) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) s.__tags = None cleave(s.__class__.__name__) return response.data
def remove_nodes(s, system_ids=[], description=None, nodegroup=None): center(s.__class__.__name__) data = [] for node in system_ids: data.append(('add', node)) if description: data.append(('description', description)) if nodegroup: data.append(('nodegroup', nodegroup)) response = s.__maas.post(u'/tags/%s/' % s.name, op='update_nodes', data=data) if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) cleave(s.__class__.__name__) return response.data
def nodes(s): ''' A collection of all of the nodes in a particular nodegroup. ''' center(s.__class__.__name__) # Will probably produce a Nodes object but for now just return what comes # back from the rest interface. # response = s.__maas.get(u'/nodegroups/%s/' % s['uuid'], op='list_nodes') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) retval = response.data cleave(s.__class__.__name__) return retval
def import_boot_images(s): ''' Import the boot image files for a particular nodegroup. ''' center(s.__class__.__name__) # Will probably produce a Nodes object but for now just return what comes # back from the rest interface. # response = s.__maas.post(u'/nodegroups/%s/' % s['uuid'], op='import_boot_images') if not response.ok: if type(response.data) == str: cleave(s.__class__.__name__) raise MapiError(response.data) retval = response.data cleave(s.__class__.__name__) return retval