def machine_actions(request): # TODO: We shouldn't return list_machines, just 200. Save the API! backend_id = request.matchdict['backend'] machine_id = request.matchdict['machine'] user = user_from_request(request) params = request.json_body action = params.get('action', '') plan_id = params.get('plan_id', '') #plan_id is the id of the plan to resize name = params.get('name', '') if action in ('start', 'stop', 'reboot', 'destroy', 'resize', 'rename'): if action == 'start': methods.start_machine(user, backend_id, machine_id) elif action == 'stop': methods.stop_machine(user, backend_id, machine_id) elif action == 'reboot': methods.reboot_machine(user, backend_id, machine_id) elif action == 'destroy': methods.destroy_machine(user, backend_id, machine_id) elif action == 'resize': methods.resize_machine(user, backend_id, machine_id, plan_id) elif action == 'rename': methods.rename_machine(user, backend_id, machine_id, name) ## return OK return methods.list_machines(user, backend_id) raise BadRequestError()
def execute(self, email, backend_id): log.warn('Running list machines for user %s backend %s' % (email, backend_id)) from mist.io import methods user = user_from_email(email) machines = methods.list_machines(user, backend_id) log.warn('Returning list machines for user %s backend %s' % (email, backend_id)) return {'backend_id': backend_id, 'machines': machines}
def execute(self, email, cloud_id): log.warn('Running list machines for user %s cloud %s' % (email, cloud_id)) from mist.io import methods user = user_from_email(email) machines = methods.list_machines(user, cloud_id) if multi_user: for machine in machines: kwargs = {} kwargs['cloud_id'] = cloud_id kwargs['machine_id'] = machine.get('id') from mist.core.methods import list_tags mistio_tags = list_tags(user, resource_type='machine', **kwargs) # optimized for js for tag in mistio_tags: for key, value in tag.items(): tag_dict = {'key': key, 'value': value} if tag_dict not in machine['tags']: machine['tags'].append(tag_dict) # FIXME: optimize! log.warn('Returning list machines for user %s cloud %s' % (email, cloud_id)) return {'cloud_id': cloud_id, 'machines': machines}
def machine_actions(request): # TODO: We shouldn't return list_machines, just 200. Save the API! backend_id = request.matchdict['backend'] machine_id = request.matchdict['machine'] user = user_from_request(request) params = request.json_body action = params.get('action', '') plan_id = params.get('plan_id', '') # plan_id is the id of the plan to resize name = params.get('name', '') if action in ('start', 'stop', 'reboot', 'destroy', 'resize', 'rename'): if action == 'start': methods.start_machine(user, backend_id, machine_id) elif action == 'stop': methods.stop_machine(user, backend_id, machine_id) elif action == 'reboot': methods.reboot_machine(user, backend_id, machine_id) elif action == 'destroy': methods.destroy_machine(user, backend_id, machine_id) elif action == 'resize': methods.resize_machine(user, backend_id, machine_id, plan_id) elif action == 'rename': methods.rename_machine(user, backend_id, machine_id, name) # return OK return methods.list_machines(user, backend_id) raise BadRequestError()
def execute(self, email, backend_id): log.warn('Running list machines for user %s backend %s' % (email, backend_id)) from mist.io import methods user = user_from_email(email) machines = methods.list_machines(user, backend_id) if multi_user: for machine in machines: kwargs = {} kwargs['backend_id'] = backend_id kwargs['machine_id'] = machine.get('id') from mist.core.methods import list_tags mistio_tags = list_tags(user, resource_type='machine', **kwargs) # optimized for js for tag in mistio_tags: for key, value in tag.items(): tag_dict = {'key': key, 'value': value} if tag_dict not in machine['tags']: machine['tags'].append(tag_dict) # FIXME: optimize! log.warn('Returning list machines for user %s backend %s' % (email, backend_id)) return {'backend_id': backend_id, 'machines': machines}
def execute(self, email, backend_id): log.warn("Running list machines for user %s backend %s" % (email, backend_id)) from mist.io import methods user = user_from_email(email) machines = methods.list_machines(user, backend_id) if multi_user: for machine in machines: kwargs = {} kwargs["backend_id"] = backend_id kwargs["machine_id"] = machine.get("id") from mist.core.methods import list_tags mistio_tags = list_tags(user, resource_type="machine", **kwargs) # optimized for js for tag in mistio_tags: for key, value in tag.items(): tag_dict = {"key": key, "value": value} if tag_dict not in machine["tags"]: machine["tags"].append(tag_dict) # FIXME: optimize! log.warn("Returning list machines for user %s backend %s" % (email, backend_id)) return {"backend_id": backend_id, "machines": machines}
def list_machines(request): """Gets machines and their metadata from a backend.""" user = user_from_request(request) backend_id = request.matchdict['backend'] return methods.list_machines(user, backend_id)
def list_machines(request): """Gets machines and their metadata from a cloud.""" user = user_from_request(request) cloud_id = request.matchdict['cloud'] return methods.list_machines(user, cloud_id)