mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-24 02:03:52 +03:00
Feature #1223: Basic xmlrpc method one.vm.attach, needs to be finished
This commit is contained in:
parent
8071e5ca0d
commit
e5b2f84f4c
@ -166,6 +166,23 @@ public:
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineAttach : public RequestManagerVirtualMachine
|
||||
{
|
||||
public:
|
||||
VirtualMachineAttach():
|
||||
RequestManagerVirtualMachine("VirtualMachineAttach",
|
||||
"Attaches a new disk to the virtual machine",
|
||||
"A:sis"){};
|
||||
|
||||
~VirtualMachineAttach(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -249,6 +249,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr vm_action(new VirtualMachineAction());
|
||||
xmlrpc_c::methodPtr vm_savedisk(new VirtualMachineSaveDisk());
|
||||
xmlrpc_c::methodPtr vm_monitoring(new VirtualMachineMonitoring());
|
||||
xmlrpc_c::methodPtr vm_attach(new VirtualMachineAttach());
|
||||
xmlrpc_c::methodPtr vm_pool_acct(new VirtualMachinePoolAccounting());
|
||||
xmlrpc_c::methodPtr vm_pool_monitoring(new VirtualMachinePoolMonitoring());
|
||||
|
||||
@ -357,6 +358,7 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.vm.chown", vm_chown);
|
||||
RequestManagerRegistry.addMethod("one.vm.chmod", vm_chmod);
|
||||
RequestManagerRegistry.addMethod("one.vm.monitoring", vm_monitoring);
|
||||
RequestManagerRegistry.addMethod("one.vm.attach", vm_attach);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);
|
||||
RequestManagerRegistry.addMethod("one.vmpool.accounting", vm_pool_acct);
|
||||
|
@ -620,3 +620,75 @@ void VirtualMachineMonitoring::request_execute(
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
|
||||
VirtualMachine * vm;
|
||||
VirtualMachineTemplate * tmpl;
|
||||
PoolObjectAuth host_perms;
|
||||
|
||||
int rc;
|
||||
string error_str;
|
||||
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
string str_tmpl = xmlrpc_c::value_string(paramList.getString(2));
|
||||
|
||||
VirtualMachinePool * vmpool = static_cast<VirtualMachinePool *>(pool);
|
||||
|
||||
tmpl = new VirtualMachineTemplate();
|
||||
|
||||
rc = tmpl->parse_str_or_xml(str_tmpl, error_str);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL, "", att); // TODO: error message
|
||||
delete tmpl;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: auth & quotas
|
||||
|
||||
// TODO: set vm state HOTPLUG & vm->set_resched(false); // Cancel re-scheduling actions
|
||||
|
||||
vm = get_vm(id, att);
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(auth_object),id),
|
||||
att);
|
||||
delete tmpl;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
rc = vm->attach_disk(tmpl, error_str);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL, "", att); // TODO: error message
|
||||
|
||||
vm->unlock();
|
||||
delete tmpl;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
dm->attach(id);
|
||||
|
||||
|
||||
delete tmpl;
|
||||
success_response(id, att);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
Loading…
x
Reference in New Issue
Block a user