mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-27 03:21:29 +03:00
feature #200: Adding VN publish/unpublish methods
This commit is contained in:
parent
a55391ece7
commit
b3fd7ef2d1
@ -543,6 +543,32 @@ private:
|
||||
VirtualNetworkPool * vnpool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class VirtualNetworkPublish: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
VirtualNetworkPublish(
|
||||
VirtualNetworkPool * _vnpool,
|
||||
UserPool * _upool):
|
||||
vnpool(_vnpool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:sib";
|
||||
_help="Enables/Disables a virtual network";
|
||||
};
|
||||
|
||||
~VirtualNetworkPublish(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
VirtualNetworkPool * vnpool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
@ -489,7 +489,12 @@ when "show"
|
||||
value=Time.at(value).strftime("%m/%d %H:%M:%S")
|
||||
end
|
||||
puts str % ["REGISTER TIME", value]
|
||||
puts str % ["PUBLIC", image[:public]]
|
||||
if image[:public].to_i == 1
|
||||
public_str = "Y"
|
||||
else
|
||||
public_str = "N"
|
||||
end
|
||||
puts str % ["PUBLIC", public_str]
|
||||
|
||||
puts str % ["STATE", image.short_state_str]
|
||||
puts str % ["RUNNING_VMS", image[:runningvms]]
|
||||
|
@ -79,6 +79,12 @@ ShowTableVN={
|
||||
:size => 6,
|
||||
:proc => lambda {|d,e| d["bridge"] }
|
||||
},
|
||||
:public => {
|
||||
:name => "PUBLIC",
|
||||
:desc => "Whether the Image is public or not",
|
||||
:size => 1,
|
||||
:proc => lambda {|d,e| if d["PUBLIC"].to_i == 1 then "Y" else "N" end}
|
||||
},
|
||||
:totalleases => {
|
||||
:name => "#LEASES",
|
||||
:desc => "Number of this virtual network's given leases",
|
||||
@ -86,7 +92,7 @@ ShowTableVN={
|
||||
:proc => lambda {|d,e| d["TOTAL_LEASES"] }
|
||||
},
|
||||
|
||||
:default => [:id, :user, :name, :type, :bridge, :totalleases]
|
||||
:default => [:id, :user, :name, :type, :bridge, :public, :totalleases]
|
||||
}
|
||||
|
||||
class VNShow
|
||||
@ -159,6 +165,12 @@ Commands:
|
||||
* show (Gets info from a virtual network)
|
||||
onevnet show <network_id>
|
||||
|
||||
* publish (Publish a virtual network)
|
||||
onevnet publish <network_id>
|
||||
|
||||
* unpublish (Unpublish a virtual network)
|
||||
onevnet unpublish <network_id>
|
||||
|
||||
* delete (Removes a virtual network)
|
||||
onevnet delete <network_id>
|
||||
|
||||
@ -223,6 +235,12 @@ when "show"
|
||||
|
||||
puts str % ["ID: ",vn.id.to_s]
|
||||
puts str % ["UID: ",vn["UID"]]
|
||||
if vn[:public].to_i == 1
|
||||
public_str = "Y"
|
||||
else
|
||||
public_str = "N"
|
||||
end
|
||||
puts str % ["PUBLIC", public_str]
|
||||
puts
|
||||
print_header(str_h1,"VIRTUAL NETWORK TEMPLATE",false)
|
||||
|
||||
@ -244,6 +262,28 @@ when "show"
|
||||
end
|
||||
end
|
||||
|
||||
when "publish"
|
||||
check_parameters("publish", 1)
|
||||
vn_id=get_vn_id(ARGV[0])
|
||||
|
||||
vn=OpenNebula::VirtualNetwork.new_with_id(vn_id, get_one_client)
|
||||
|
||||
result=vn.publish
|
||||
if is_successful?(result)
|
||||
puts "VirtualNetwork published" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "unpublish"
|
||||
check_parameters("unpublish", 1)
|
||||
vn_id=get_vn_id(ARGV[0])
|
||||
|
||||
vn=OpenNebula::VirtualNetwork.new_with_id(vn_id, get_one_client)
|
||||
|
||||
result=vn.unpublish
|
||||
if is_successful?(result)
|
||||
puts "VirtualNetwork unpublished" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "delete"
|
||||
check_parameters("delete", 1)
|
||||
args=expand_args(ARGV)
|
||||
|
@ -8,6 +8,7 @@ module OpenNebula
|
||||
VN_METHODS = {
|
||||
:info => "vn.info",
|
||||
:allocate => "vn.allocate",
|
||||
:publish => "vn.publish",
|
||||
:delete => "vn.delete"
|
||||
}
|
||||
|
||||
@ -46,9 +47,28 @@ module OpenNebula
|
||||
def allocate(description)
|
||||
super(VN_METHODS[:allocate],description)
|
||||
end
|
||||
|
||||
def publish
|
||||
set_publish(true)
|
||||
end
|
||||
|
||||
def unpublish
|
||||
set_publish(false)
|
||||
end
|
||||
|
||||
def delete()
|
||||
super(VN_METHODS[:delete])
|
||||
end
|
||||
|
||||
private
|
||||
def set_publish(published)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(VN_METHODS[:publish], @pe_id, published)
|
||||
rc = nil if !OpenNebula.is_error?(rc)
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -254,6 +254,9 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
xmlrpc_c::methodPtr vnpool_info(new
|
||||
RequestManager::VirtualNetworkPoolInfo(vnpool,upool));
|
||||
|
||||
xmlrpc_c::methodPtr vn_publish(new
|
||||
RequestManager::VirtualNetworkPublish(vnpool, upool));
|
||||
|
||||
xmlrpc_c::methodPtr vn_delete(new
|
||||
RequestManager::VirtualNetworkDelete(vnpool, upool));
|
||||
@ -317,6 +320,7 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate);
|
||||
RequestManagerRegistry.addMethod("one.vn.info", vn_info);
|
||||
RequestManagerRegistry.addMethod("one.vn.publish", vn_publish);
|
||||
RequestManagerRegistry.addMethod("one.vn.delete", vn_delete);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.vnpool.info", vnpool_info);
|
||||
|
@ -45,6 +45,7 @@ source_files=[
|
||||
'RequestManagerVirtualNetworkAllocate.cc',
|
||||
'RequestManagerVirtualNetworkInfo.cc',
|
||||
'RequestManagerVirtualNetworkPoolInfo.cc',
|
||||
'RequestManagerVirtualNetworkPublish.cc',
|
||||
'RequestManagerVirtualNetworkDelete.cc',
|
||||
'RequestManagerUserAllocate.cc',
|
||||
'RequestManagerUserInfo.cc',
|
||||
|
@ -93,7 +93,7 @@ int VirtualNetworkPool::allocate (
|
||||
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
||||
// Information about the VN needs to be extracted from the template
|
||||
vn->get_template_attribute("TYPE",s_type);
|
||||
|
||||
@ -121,10 +121,16 @@ int VirtualNetworkPool::allocate (
|
||||
|
||||
vn->get_template_attribute("BRIDGE",bridge);
|
||||
vn->bridge = bridge;
|
||||
|
||||
// ------------ PUBLIC --------------------
|
||||
|
||||
vn->get_template_attribute("PUBLIC", public_attr);
|
||||
vn->vn_template.erase("PUBLIC");
|
||||
vn->public_vnet = (public_attr == "YES");
|
||||
|
||||
transform (public_attr.begin(), public_attr.end(), public_attr.begin(),
|
||||
(int(*)(int))toupper);
|
||||
|
||||
vn->public_vnet = (public_attr == "YES");
|
||||
vn->vn_template.erase("PUBLIC");
|
||||
|
||||
// Insert the VN in the pool so we have a valid OID
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user