def host_add(host_name, group_name, attrs, user=None): """ Adds a host to the list of available hosts. First host will be checked, then all templates will be uploaded and then finally the host will be available. The result of this method is a task id that can be used to observe the check and upload progress. This operation needs admin access. Parameters: string host_name: the host name string group_name: the name of the host group dict attrs: dictionary with host attributes Host attributes in "attrs": int vmid_start: begin of the VM id range for ToMaTo int vmid_count: number of the VM ids for ToMaTo int port_start: begin of the port range for ToMaTo int port_count: number of the ports for ToMaTo int bridge_start: begin of the bridge id range for ToMaTo int bridge_count: number of the bridge ids for ToMaTo Returns: task id of the task Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) return hosts.create(host_name, group_name, attrs)
def external_network_change(type, group, params, user=None): """ Changes an external network. This operation needs admin access. Parameters: string type: type of the external network string group: name of the external network dict params: dict of all additional parameters Additional parameters in "params": int max_devices: maximal allowed connections to this external network bool avoid_duplicates: whether to make sure that connections to the same external network in a topology will be using different bridges Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) en = hosts.ExternalNetwork.objects.get(type=type, group=group) if not params.has_key("max_devices"): params["max_devices"] = None if not params.has_key("avoid_duplicates"): params["avoid_duplicates"] = False en.max_devices = params["max_devices"] en.avoid_duplicates = params["avoid_duplicates"] en.save()
def task_list(user=None): """ Returns a list of all tasks. Returns: a list of all tasks """ _admin_access(user) return [t.dict() for t in tasks.processes.values()]
def errors_all(user=None): """ Returns a list of all errors in the backend. This method requires admin access. Returns: list of all errors """ _admin_access(user) return [f.toDict() for f in fault.errors_all()]
def errors_remove(error_id=None, user=None): """ Removes an error from the error list. This method requires admin access. Parameters: int error_id: id of the error """ _admin_access(user) fault.errors_remove(error_id)
def admin_public_key(user=None): """ Returns the public key that is used for accessing the hosts. Returns: public key """ _admin_access(user) with open("%s.pub" % config.SSH_KEY, 'r') as f: key = f.read() return key
def device_profile_remove(type, name, user=None): """ Removes a device profile. This method requires admin access. Parameters: string type: profile type string name: profile name """ _admin_access(user) hosts.device_profiles.remove(type, name)
def template_set_default(template_type, name, user=None): """ Selects a template to be the default template for the given type. This method requires admin access. Parameters: string template_type: template type string name: template name """ _admin_access(user) hosts.templates.get(template_type, name).setDefault()
def template_remove(template_type, name, user=None): """ Removes a template from the template repository. This method requires admin access. Parameters: string template_type: template type string name: template name """ _admin_access(user) hosts.templates.remove(template_type, name)
def device_profile_set_default(type, name, user=None): """ Selects a device profile to be the default profile for the given type. This method requires admin access. Parameters: string type: profile type string name: profile name """ _admin_access(user) hosts.device_profiles.get(type, name).setDefault()
def device_profile_change(type, name, properties, user=None): """ Changes a device profile. This method requires admin access. Parameters: string type: profile type string name: profile name dict properties: properties of the profile """ _admin_access(user) return hosts.device_profiles.change(type, name, properties)
def device_profile_add(type, name, properties={}, user=None): """ Adds a device profile. This method requires admin access. Parameters: string type: profile type string name: profile name dict propertries: profile properties """ _admin_access(user) return hosts.device_profiles.add(type, name, properties)
def template_change(type, name, properties, user=None): """ Changes a template in the template repository. This method requires admin access. Parameters: string type: template type string name: template name string url: template download url """ _admin_access(user) return hosts.templates.change(type, name, properties)
def task_run(task_name, user=None): #@UnusedVariable, pylint: disable-msg=W0613 """ Runs a named periodic task and returns the task_id. Parameters: string task_name: name of periodic task Returns: task id """ _admin_access(user) process = tasks.periodic_processes[task_name] return process.start()
def template_add(name, template_type, url, user=None): """ Adds a template to the template repository. The template will be fetched from the given url by all hosts. This method requires admin access. Parameters: string name: template name string template_type: template type atring url: template download url Returns: task id """ _admin_access(user) return hosts.templates.add(name, template_type, url)
def template_add(type, name, properties=[], user=None): """ Adds a template to the template repository. This method requires admin access. Parameters: string type: template type string name: template name dict propertries: template properties Returns: task id """ _admin_access(user) return hosts.templates.add(type, name, properties)
def host_remove(host_name, user=None): """ Deletes a host so that the host and all elements depending on it are removed from the database. This will not remove or stop topologies from the host. This operation needs admin access. Parameters: string host_name: the host name Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) hosts.remove(host_name)
def host_update(host_name, user=None): """ Updates the host. Parameters: string host_name: the host name Returns: task id Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) host = hosts.get(host_name) return host.apt_update()
def host_debug(host_name, user=None): """ Returns debug information about the host. This operation needs admin access. Parameters: string host_name: the host name Returns: Debug information Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) host = hosts.get(host_name) return host.debugInfo()
def external_network_bridge_remove(host_name, type, group, user=None): """ Removes an external network bridge to a host. This operation needs admin access. Parameters: string host_name: name of the host string type: type of the external network string group: group of the external network Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) host = hosts.get(host_name) host.externalNetworksRemove(type, group)
def external_network_remove(type, group, user=None): """ Removes an external network. This operation needs admin access. Parameters: string type: type of the external network string group: name of the external network Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) en = hosts.ExternalNetwork.objects.get(type=type, group=group) fault.check(not len(en.externalnetworkbridge_set.all()), "External network still has bridges: %s", en) en.delete()
def resource_usage_by_topology(user=None): """ Returns a map of resource usage summed up by topology. This method requires admin access. Returns: map of resource use by topology """ _admin_access(user) usage={} for top in topology.all(): d = top.resources() if d: d.update(top_id=top.id) usage[top.name]=d return usage
def host_check(host_name, user=None): """ Performs a sanity check on the host. This method will return a task id that can be used to obtain the results. This operation needs admin access. Parameters: string host_name: the host name Returns: task id Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) host = hosts.get(host_name) return host.check()
def external_network_bridge_add(host_name, type, group, bridge, user=None): """ Adds an external network bridge to a host. This operation needs admin access. Parameters: string host_name: name of the host string type: type of the external network string group: group of the external network string bridge: bridge to connect interfaces to Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) host = hosts.get(host_name) host.externalNetworksAdd(type, group, bridge)
def host_change(host_name, group_name, enabled, attrs, user=None): """ Changes a host. The new values will only apply to new topologies or on state change. This operation needs admin access. Parameters: string host_name: the host name string group_name: the name of the host group boolean enabled: whether the host should be enabled dict attrs: dictionary with host attributes Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) hosts.change(host_name, group_name, enabled, attrs)
def external_network_add(type, group, params, user=None): """ Adds an external network. This operation needs admin access. Parameters: string type: type of the external network string group: group of the external network dict params: dict of all additional parameters Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) if not params.has_key("max_devices"): params["max_devices"] = None if not params.has_key("avoid_duplicates"): params["avoid_duplicates"] = False hosts.ExternalNetwork.objects.create(type=type, group=group, max_devices=params["max_devices"], avoid_duplicates=params["avoid_duplicates"])
def host_add(host_name, group_name, enabled, attrs, user=None): """ Adds a host to the list of available hosts. First host will be checked, then all templates will be uploaded and then finally the host will be available. The result of this method is a task id that can be used to observe the check and upload progress. This operation needs admin access. Parameters: string host_name: the host name string group_name: the name of the host group boolean enabled: whether the host should be enabled dict attrs: dictionary with host attributes Returns: task id of the task Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) return hosts.create(host_name, group_name, enabled, attrs)
def resource_usage_by_user(user=None): """ Returns a map of resource usage summed up by user (topology owner). This method requires admin access. Returns: map of resource use by user """ _admin_access(user) usage={} for top in topology.all(): if not top.owner.name in usage: usage[top.owner.name] = top.resources() else: d = top.resources() for key in d: if usage[top.owner.name].has_key(key): usage[top.owner.name][key] = float(usage[top.owner.name][key]) + float(d[key]) else: usage[top.owner.name][key] = float(d[key]) return usage
def resource_usage_by_user(user=None): """ Returns a map of resource usage summed up by user (topology owner). This method requires admin access. Returns: map of resource use by user """ _admin_access(user) usage={} for top in topology.all(): if not str(top.owner) in usage: usage[str(top.owner)] = top.resources() else: d = top.resources() if d: for key in d: if usage[str(top.owner)].has_key(key): usage[str(top.owner)][key] = float(usage[str(top.owner)][key]) + float(d[key]) else: usage[str(top.owner)][key] = float(d[key]) return util.xml_rpc_sanitize(usage)
def host_change(host_name, group_name, attrs, user=None): """ Changes a host. The new values will only apply to new topologies or on state change. This operation needs admin access. Parameters: string host_name: the host name string group_name: the name of the host group dict attrs: dictionary with host attributes Host attributes in "attrs": int vmid_start: begin of the VM id range for ToMaTo int vmid_count: number of the VM ids for ToMaTo int port_start: begin of the port range for ToMaTo int port_count: number of the ports for ToMaTo int bridge_start: begin of the bridge id range for ToMaTo int bridge_count: number of the bridge ids for ToMaTo Errors: fault.Error: if the user does not have enough privileges """ _admin_access(user) hosts.change(host_name, group_name, attrs)