Class: UCSDestroy

Inherits:
Object
  • Object
show all
Defined in:
lib/ucslib/destroy.rb

Overview

Author

Murali Raju (<[email protected]>)

Copyright

Copyright © 2012 Murali Raju.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Instance Method Summary collapse

Constructor Details

#initialize(tokenjson) ⇒ UCSDestroy

Returns a new instance of UCSDestroy.



20
21
22
23
24
25
26
# File 'lib/ucslib/destroy.rb', line 20

def initialize(tokenjson)
   
    @cookie  = "#{JSON.parse(tokenjson)['cookie']}"
    ip       = "#{JSON.parse(tokenjson)['ip']}"
    @url 	 = "https://#{ip}/nuova"

end

Instance Method Details

#delete_org(json) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ucslib/destroy.rb', line 29

def delete_org(json)

	org = JSON.parse(json)['org']

xml_builder = Nokogiri::XML::Builder.new do |xml|
xml.configConfMos('cookie' => "#{@cookie}", 'inHierarchical' => 'false') {
  xml.inConfigs{
    xml.pair('key' => "org-root/org-#{org}") {
      xml.orgOrg('dn' => "org-root/org-#{org}", 'status' => 'deleted')
    }
  }
}
end

#Create XML
delete_org_XML= xml_builder.to_xml.to_s

#Post
begin
	RestClient.post(@url, delete_org_XML, :content_type => 'text/xml').body
rescue Exception => e
	raise "Error #{e}"
end
		
end

#delete_vlan(json) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ucslib/destroy.rb', line 55

def delete_vlan(json)

	vlan_id     = JSON.parse(json)['vlan_id']
	vlan_name   = JSON.parse(json)['vlan_name']

	xml_builder = Nokogiri::XML::Builder.new do |xml|
	  xml.configConfMos('cookie' => "#{@cookie}", 'inHierarchical' => 'false'){
	    xml.inConfigs{
	      xml.pair('key' => "fabric/lan/net-#{vlan_name}"){
	        xml.fabricVlan('dn' => "fabric/lan/net-#{vlan_name}", 'id' => "#{vlan_id}",
	                       'name' => "#{vlan_name}", 'status' => 'deleted')
	      }
	    }
	  }
	end

	#Create XML
	delete_vlan_XML = xml_builder.to_xml.to_s

	#Post
	begin
		RestClient.post(@url, delete_vlan_XML, :content_type => 'text/xml').body
	rescue Exception => e
		raise "Error #{e}"
	end

end