7 from multiprocessing import Process
8 from multiprocessing import Queue
9 from pexpect import pxssh
11 import functest.utils.functest_logger as ft_logger
20 """Defines all the def function of SFC."""
23 """Initialization of variables."""
24 self.logger = ft_logger.Logger("sfc_fun").getLogger()
29 self.keystone_hostname = 'keystone_ip'
30 self.neutron_hostname = 'neutron_ip'
31 self.nova_hostname = 'nova_ip'
32 self.glance_hostname = 'glance_ip'
33 self.onos_hostname = 'onos_ip'
34 # Network variables #######
35 self.netname = "test_nw"
36 self.admin_state_up = True
39 # #########################
40 # SubNet variables#########
42 self.cidr = "20.20.20.0/24"
43 self.subnetname = "test_nw_subnets"
44 # ###############################
53 self.security_groups = []
54 self.port_security_enabled = False
55 # ###############################
56 # VM creation variable
57 self.container_format = "bare"
58 self.disk_format = "qcow2"
59 self.imagename = "TestSfcVm"
60 self.createImage = ("/home/root1/devstack/files/images/"
61 "firewall_block_image.img")
64 self.imageRef = "test"
70 self.routername = "router1"
72 # #####################################
74 self.port_pair_ingress = 0
75 self.port_pair_egress = 0
76 self.port_pair_name = "PP"
77 self.port_pair_id = []
78 # ####################################
80 self.port_group_name = "PG"
82 # ####################################
84 self.source_ip_prefix = "20.20.20.0/24"
85 self.destination_ip_prefix = "20.20.20.0/24"
86 self.logical_source_port = 0
88 self.ethertype = "IPv4"
89 # #####################################
90 self.flow_class_if = 0
91 # #####################################
92 # Port Chain variables
95 # #####################################
96 # Port Chain variables
98 # #####################################
100 self.vm_public_ip = []
101 self.vm_public_id = []
109 """Get the keystone token value from Openstack ."""
110 url = 'http://%s:5000/%s/tokens' % (self.keystone_hostname,
112 data = ('{"auth": {"tenantName": "admin", "passwordCredentials":'
113 '{ "username": "admin", "password": "console"}}}')
114 headers = {"Accept": "application/json"}
115 response = requests.post(url, headers=headers, data=data)
116 if (response.status_code == OK):
117 json1_data = json.loads(response.content)
118 self.logger.debug(response.status_code)
119 self.logger.debug(response.content)
120 self.logger.debug(json1_data)
121 self.token_id = json1_data['access']['token']['id']
122 self.tenant_id = json1_data['access']['token']['tenant']['id']
123 return(response.status_code)
125 return(response.status_code)
127 def createNetworks(self):
128 """Creation of networks."""
130 if self.netname != '':
131 Dicdata['name'] = self.netname
132 if self.admin_state_up != '':
133 Dicdata['admin_state_up'] = self.admin_state_up
134 Dicdata = {'network': Dicdata}
135 data = json.dumps(Dicdata, indent=4)
136 url = 'http://%s:9696/%s/networks' % (self.neutron_hostname,
138 headers = {"Accept": "application/json",
139 "X-Auth-Token": self.token_id}
140 response = requests.post(url, headers=headers, data=data)
141 if (response.status_code == CREATED):
142 self.logger.debug(response.status_code)
143 self.logger.debug(response.content)
145 json1_data = json.loads(response.content)
146 self.logger.debug(json1_data)
147 self.net_id = json1_data['network']['id']
148 return(response.status_code)
150 return(response.status_code)
152 def createSubnets(self):
153 """Creation of SubNets."""
156 Dicdata['network_id'] = self.net_id
157 if self.ip_version != '':
158 Dicdata['ip_version'] = self.ip_version
160 Dicdata['cidr'] = self.cidr
161 if self.subnetname != '':
162 Dicdata['name'] = self.subnetname
164 Dicdata = {'subnet': Dicdata}
165 data = json.dumps(Dicdata, indent=4)
166 url = 'http://%s:9696/%s/subnets' % (self.neutron_hostname,
168 headers = {"Accept": "application/json",
169 "X-Auth-Token": self.token_id}
170 response = requests.post(url, headers=headers, data=data)
172 if (response.status_code == CREATED):
173 self.logger.debug(response.status_code)
174 self.logger.debug(response.content)
175 json1_data = json.loads(response.content)
176 self.logger.debug(json1_data)
177 self.subnetId = json1_data['subnet']['id']
178 return(response.status_code)
180 return(response.status_code)
182 def createPorts(self):
183 """Creation of Ports."""
184 for x in range(self.i, self.numTerms):
186 if self.net_id != '':
187 Dicdata['network_id'] = self.net_id
189 Dicdata['name'] = "port" + str(x)
190 if self.admin_state_up != '':
191 Dicdata['admin_state_up'] = self.admin_state_up
192 if self.security_groups != '':
193 Dicdata['security_groups'] = self.security_groups
194 # if self.port_security_enabled != '':
195 # Dicdata['port_security_enabled'] = self.port_security_enabled
197 Dicdata = {'port': Dicdata}
198 data = json.dumps(Dicdata, indent=4)
199 url = 'http://%s:9696/%s/ports' % (self.neutron_hostname,
201 headers = {"Accept": "application/json",
202 "X-Auth-Token": self.token_id}
203 response = requests.post(url, headers=headers, data=data)
205 if (response.status_code == CREATED):
206 self.logger.debug(response.status_code)
207 self.logger.debug(response.content)
209 json1_data = json.loads(response.content)
210 self.logger.debug(json1_data)
211 self.port_num.append(json1_data['port']['id'])
212 self.port_ip.append(json1_data['port']['fixed_ips'][0]
215 return(response.status_code)
216 return(response.status_code)
219 """Creation of Instance, using firewall image."""
220 url = ("http://%s:9292/v2/images?"
221 "name=TestSfcVm" % (self.glance_hostname))
222 headers = {"Accept": "application/json", "Content-Type": "application/\
223 octet-stream", "X-Auth-Token": self.token_id}
224 response = requests.get(url, headers=headers)
225 if (response.status_code == OK):
226 self.logger.debug(response.status_code)
227 self.logger.debug(response.content)
228 self.logger.info("FireWall Image is available")
229 json1_data = json.loads(response.content)
230 self.logger.debug(json1_data)
231 self.image_id = json1_data['images'][0]['id']
233 return(response.status_code)
235 url = ("http://%s:8774/v2.1/%s/flavors?"
236 "name=m1.tiny" % (self.nova_hostname, self.tenant_id))
237 headers = {"Accept": "application/json", "Content-Type":
238 "application/json", "X-Auth-Token": self.token_id}
239 response = requests.get(url, headers=headers)
241 if (response.status_code == OK):
242 self.logger.debug(response.status_code)
243 self.logger.debug(response.content)
244 self.logger.info("Flavor is available")
245 json1_data = json.loads(response.content)
246 self.logger.debug(json1_data)
247 self.flavorRef = json1_data['flavors'][0]['id']
249 return(response.status_code)
251 for y in range(0, 3):
254 org_nw_port.append({'port': self.port_num[y]})
255 if self.vm_name != '':
256 Dicdata['name'] = "vm" + str(y)
257 if self.imageRef != '':
258 Dicdata['imageRef'] = self.image_id
259 if self.flavorRef != '':
260 Dicdata['flavorRef'] = self.flavorRef
261 if self.max_count != '':
262 Dicdata['max_count'] = self.max_count
263 if self.min_count != '':
264 Dicdata['min_count'] = self.min_count
265 if self.org_nw_port != '':
266 Dicdata['networks'] = org_nw_port
267 Dicdata = {'server': Dicdata}
268 data = json.dumps(Dicdata, indent=4)
269 url = 'http://%s:8774/v2.1/%s/servers' % (self.nova_hostname,
271 headers = {"Accept": "application/json", "Content-Type":
272 "application/json", "X-Auth-Token": self.token_id}
273 response = requests.post(url, headers=headers, data=data)
274 if (response.status_code == ACCEPTED):
275 self.logger.debug(response.status_code)
276 self.logger.debug(response.content)
277 info = "Creation of VM" + str(y) + " is successfull"
278 self.logger.debug(info)
280 json1_data = json.loads(response.content)
281 self.logger.debug(json1_data)
282 self.vm_id = json1_data['server']['id']
283 self.vm.append(json1_data['server']['id'])
285 return(response.status_code)
287 return(response.status_code)
289 def checkVmState(self):
290 """Checking the Status of the Instance."""
292 for y in range(0, 3):
293 url = ("http://%s:8774/v2.1/servers/"
294 "detail?name=vm" + str(y)) % (self.neutron_hostname)
295 headers = {"Accept": "application/json", "X-Auth-Token":
297 response = requests.get(url, headers=headers)
298 if (response.status_code == OK):
299 self.logger.debug(response.status_code)
300 self.logger.debug(response.content)
301 json1_data = json.loads(response.content)
302 self.logger.debug(json1_data)
303 self.vm_active = json1_data['servers'][0]['status']
304 if (self.vm_active == "ACTIVE"):
305 info = "VM" + str(y) + " is Active : " + self.vm_active
307 info = "VM" + str(y) + " is NOT Active : " + self.vm_active
308 self.logger.debug(info)
310 return(response.status_code)
311 return(response.status_code)
314 def createPortPair(self):
315 """Creation of Port Pair."""
316 for p in range(1, 2):
318 if self.port_pair_ingress != '':
319 Dicdata['ingress'] = self.port_num[p]
320 if self.port_pair_egress != '':
322 Dicdata['egress'] = self.port_num[egress]
323 if self.port_pair_name != '':
324 Dicdata['name'] = "PP" + str(p)
326 Dicdata = {'port_pair': Dicdata}
327 data = json.dumps(Dicdata, indent=4)
328 url = 'http://%s:9696/%s/sfc/port_pairs' % (self.neutron_hostname,
330 headers = {"Accept": "application/json", "X-Auth-Token":
332 response = requests.post(url, headers=headers, data=data)
333 if (response.status_code == CREATED):
334 info = ("Creation of Port Pair PP" + str(p) +
336 self.logger.debug(info)
338 return(response.status_code)
340 return(response.status_code)
342 def getPortPair(self):
343 """Query the Portpair id value."""
344 for p in range(0, 1):
345 url = ("http://%s:9696/%s/"
346 "sfc/port_pairs?name=PP1" % (self.neutron_hostname,
348 headers = {"Accept": "application/json",
349 "X-Auth-Token": self.token_id}
350 response = requests.get(url, headers=headers)
352 if (response.status_code == OK):
353 self.logger.debug(response.status_code)
354 self.logger.debug(response.content)
355 json1_data = json.loads(response.content)
356 self.logger.debug(json1_data)
357 self.port_pair_id.append(json1_data['port_pairs'][0]['id'])
359 return(response.status_code)
360 return(response.status_code)
362 def createPortGroup(self):
363 """Creation of PortGroup."""
364 for p in range(0, 1):
367 port_pair_list.append(self.port_pair_id[p])
368 if self.port_group_name != '':
369 Dicdata['name'] = "PG" + str(p)
370 if self.port_pair_id != '':
371 Dicdata['port_pairs'] = port_pair_list
373 Dicdata = {'port_pair_group': Dicdata}
374 data = json.dumps(Dicdata, indent=4)
375 url = ("http://%s:9696/%s/"
376 "sfc/port_pair_groups" % (self.neutron_hostname,
378 headers = {"Accept": "application/json", "X-Auth-Token":
380 response = requests.post(url, headers=headers, data=data)
381 if (response.status_code == CREATED):
382 info = ("Creation of Port Group PG" + str(p) +
384 self.logger.debug(info)
386 return(response.status_code)
388 return(response.status_code)
390 def getPortGroup(self):
391 """Query the PortGroup id."""
392 for p in range(0, 1):
393 url = ("http://%s:9696/%s/sfc/port_pair_groups"
394 "?name=PG" + str(p)) % (self.neutron_hostname,
396 headers = {"Accept": "application/json", "X-Auth-Token":
398 response = requests.get(url, headers=headers)
400 if (response.status_code == OK):
401 self.logger.debug(response.status_code)
402 self.logger.debug(response.content)
403 json1_data = json.loads(response.content)
404 self.port_grp_id.append(json1_data['port_pair_groups']
407 return(response.status_code)
408 return(response.status_code)
410 def createFlowClassifier(self):
411 """Creation of Flow Classifier."""
413 if self.source_ip_prefix != '':
414 Dicdata['source_ip_prefix'] = self.source_ip_prefix
415 if self.destination_ip_prefix != '':
416 Dicdata['destination_ip_prefix'] = self.destination_ip_prefix
417 if self.logical_source_port != '':
418 Dicdata['logical_source_port'] = self.port_num[0]
419 if self.fcname != '':
420 Dicdata['name'] = "FC1"
421 if self.ethertype != '':
422 Dicdata['ethertype'] = self.ethertype
424 Dicdata = {'flow_classifier': Dicdata}
425 data = json.dumps(Dicdata, indent=4)
426 url = ("http://%s:9696/%s/"
427 "sfc/flow_classifiers" % (self.neutron_hostname,
429 headers = {"Accept": "application/json",
430 "X-Auth-Token": self.token_id}
431 response = requests.post(url, headers=headers, data=data)
432 if (response.status_code == CREATED):
433 json1_data = json.loads(response.content)
434 self.flow_class_if = json1_data['flow_classifier']['id']
435 self.logger.debug("Creation of Flow Classifier is successful")
436 return(response.status_code)
438 return(response.status_code)
440 def createPortChain(self):
441 """Creation of PortChain."""
444 flow_class_list.append(self.flow_class_if)
445 port_pair_groups_list = []
446 port_pair_groups_list.append(self.port_grp_id[0])
448 if flow_class_list != '':
449 Dicdata['flow_classifiers'] = flow_class_list
450 if self.pcname != '':
451 Dicdata['name'] = "PC1"
452 if port_pair_groups_list != '':
453 Dicdata['port_pair_groups'] = port_pair_groups_list
455 Dicdata = {'port_chain': Dicdata}
456 data = json.dumps(Dicdata, indent=4)
457 url = 'http://%s:9696/%s/sfc/port_chains' % (self.neutron_hostname,
459 headers = {"Accept": "application/json",
460 "Content-Type": "application/json",
461 "X-Auth-Token": self.token_id}
462 response = requests.post(url, headers=headers, data=data)
463 if (response.status_code == CREATED):
464 self.logger.debug("Creation of PORT CHAIN is successful")
465 json1_data = json.loads(response.content)
466 self.PC_id = json1_data['port_chain']['id']
467 return(response.status_code)
469 return(response.status_code)
471 def checkFlowAdded(self):
472 """Check whether the Flows are downloaded successfully."""
474 response = requests.get('http://' + self.onos_hostname +
475 ':8181/onos/v1/flows',
476 auth=("karaf", "karaf"))
477 if (response.status_code == OK):
478 self.logger.debug("Flow is successfully Queries")
479 json1_data = json.loads(response.content)
480 self.flowadd = json1_data['flows'][0]['state']
482 if (self.flowadd == "ADDED"):
483 self.logger.info("Flow is successfully added to OVS")
484 return(response.status_code)
488 return(response.status_code)
489 ####################################################################
491 def createRouter(self):
492 """Creation of Router."""
494 if self.routername != '':
495 Dicdata['name'] = "router1"
496 if self.admin_state_up != '':
497 Dicdata['admin_state_up'] = self.admin_state_up
499 Dicdata = {'router': Dicdata}
500 data = json.dumps(Dicdata, indent=4)
501 url = 'http://%s:9696/%s/routers.json' % (self.neutron_hostname,
503 headers = {"Accept": "application/json",
504 "X-Auth-Token": self.token_id}
505 response = requests.post(url, headers=headers, data=data)
506 if (response.status_code == CREATED):
507 self.logger.debug(response.status_code)
508 self.logger.debug(response.content)
509 self.logger.debug("Creation of Router is successfull")
510 json1_data = json.loads(response.content)
511 self.logger.debug(json1_data)
512 self.router_id = json1_data['router']['id']
513 return(response.status_code)
515 return(response.status_code)
517 def attachInterface(self):
518 """Attachment of instance ports to the Router."""
519 url = ("http://%s:9696/%s/networks"
520 "?name=admin_floating_net" % (self.neutron_hostname,
522 headers = {"Accept": "application/json", "X-Auth-Token": self.token_id}
523 response = requests.get(url, headers=headers)
524 if (response.status_code == OK):
525 self.logger.debug(response.status_code)
526 self.logger.debug(response.content)
527 json1_data = json.loads(response.content)
528 self.logger.debug(json1_data)
529 self.net_name = json1_data['networks'][0]['name']
530 if (self.net_name == "admin_floating_net"):
531 self.pub_net_id = json1_data['networks'][0]['id']
533 return(response.status_code)
534 ############################################################
536 self.logger.info("Attachment of Instance interface to Router")
538 if self.subnetId != '':
539 Dicdata['subnet_id'] = self.subnetId
541 data = json.dumps(Dicdata, indent=4)
542 url = ("http://%s:9696/%s/routers"
543 "/%s/add_router_interface" % (self.neutron_hostname,
546 headers = {"Accept": "application/json",
547 "X-Auth-Token": self.token_id}
548 response = requests.put(url, headers=headers, data=data)
549 if (response.status_code == OK):
550 self.logger.debug(response.status_code)
551 self.logger.debug(response.content)
552 self.logger.info("Interface attached successfull")
554 return(response.status_code)
555 ############################################################
556 self.logger.info("Attachment of Gateway to Router")
559 if self.pub_net_id != 0:
560 Dicdata1['network_id'] = self.pub_net_id
562 Dicdata1 = {'external_gateway_info': Dicdata1}
563 Dicdata1 = {'router': Dicdata1}
564 data = json.dumps(Dicdata1, indent=4)
565 url = 'http://%s:9696/%s/routers/%s' % (self.neutron_hostname,
568 headers = {"Accept": "application/json",
569 "X-Auth-Token": self.token_id}
570 response = requests.put(url, headers=headers, data=data)
571 if (response.status_code == OK):
572 self.logger.debug(response.status_code)
573 self.logger.debug(response.content)
574 self.logger.info("Gateway Interface attached successfull")
575 return(response.status_code)
577 return(response.status_code)
579 def addFloatingIp(self):
580 """Attachment of Floating Ip to the Router."""
581 for ip_num in range(0, 2):
583 Dicdata['pool'] = "admin_floating_net"
585 data = json.dumps(Dicdata, indent=4)
586 url = ("http://%s:8774/v2.1/"
587 "os-floating-ips" % (self.nova_hostname))
588 headers = {"Accept": "application/json",
589 "X-Auth-Token": self.token_id}
590 response = requests.post(url, headers=headers, data=data)
591 if (response.status_code == OK):
592 self.logger.debug(response.status_code)
593 self.logger.debug(response.content)
594 self.logger.info("Floating ip created successfully")
595 json1_data = json.loads(response.content)
596 self.logger.debug(json1_data)
597 self.vm_public_ip.append(json1_data['floating_ip']['ip'])
598 self.vm_public_id.append(json1_data['floating_ip']['id'])
600 self.logger.error("Floating ip NOT created successfully")
603 if self.address != '':
604 Dicdata1['address'] = self.vm_public_ip[ip_num]
606 Dicdata1 = {'addFloatingIp': Dicdata1}
607 data = json.dumps(Dicdata1, indent=4)
608 url = ("http://%s:8774/v2.1/"
609 "servers/%s/action" % (self.nova_hostname,
612 headers = {"Accept": "application/json",
613 "X-Auth-Token": self.token_id}
614 response = requests.post(url, headers=headers, data=data)
615 if(response.status_code == ACCEPTED):
616 self.logger.debug(response.status_code)
617 self.logger.debug(response.content)
618 self.logger.info("Public Ip successfully added to VM")
620 return(response.status_code)
621 return(response.status_code)
624 """Login to the VM to check NSH packets are received."""
630 hostname = self.vm_public_ip[0]
632 password = "cubswin:)"
633 s.login(hostname, username, password)
634 s.sendline("ping -c 5 " + str(self.port_ip[2]))
635 s.prompt() # match the prompt
637 ping_re = re.search("transmitted.*received", s.before).group()
638 x = re.split('\s+', ping_re)
640 self.logger.info("Ping is Successfull")
642 self.logger.info("Ping is NOT Successfull")
646 hostname = self.vm_public_ip[1]
648 password = "cubswin:)"
649 s.login(hostname, username, password)
650 s.sendline('sudo ./firewall')
652 output_pack = s.before
654 if(output_pack.find("nshc") != -1):
655 self.logger.info("The packet has reached VM2 Instance")
658 self.logger.info("Packet not received in Instance")
661 def ping(ip, timeout=300):
664 self.logger.debug("Pinging %s. Waiting for response..." % ip)
665 response = os.system("ping -c 1 " + ip + " >/dev/null 2>&1")
667 self.logger.info("Ping " + ip + " detected!")
671 self.logger.info("Ping " + ip + " timeout reached.")
675 result0 = ping(self.vm_public_ip[0])
676 result1 = ping(self.vm_public_ip[1])
677 if result0 == 0 and result1 == 0:
680 p1 = Process(target=vm1, args=(queue1, ))
682 p2 = Process(target=vm0)
685 return (queue1.get())
687 self.logger.error("Thread didnt run")
689 """##################################################################"""
690 """ ######################## Stats Functions ################# #####"""
692 def portChainDeviceMap(self):
693 """Check the PC Device Stats in the ONOS."""
694 response = requests.get('http://' + self.onos_hostname +
695 ':8181/onos/vtn/portChainDeviceMap/' +
696 self.PC_id, auth=("karaf", "karaf"))
697 if (response.status_code == OK):
698 self.logger.info("PortChainDeviceMap is successfully Queries")
699 return(response.status_code)
701 return(response.status_code)
703 def portChainSfMap(self):
704 """Check the PC SF Map Stats in the ONOS."""
705 response = requests.get('http://' + self.onos_hostname +
706 ':8181/onos/vtn/portChainSfMap/' +
707 self.PC_id, auth=("karaf", "karaf"))
708 if (response.status_code == OK):
709 self.logger.info("portChainSfMap is successfully Queries")
710 return(response.status_code)
712 return(response.status_code)
714 """###################################################################"""
716 def deletePortChain(self):
717 """Deletion of PortChain."""
718 url = ('http://' + self.neutron_hostname + ':9696/' +
719 self.osver + '/sfc/port_chains/' + self.PC_id)
720 headers = {"Accept": "application/json", "Content-Type":
721 "application/json", "X-Auth-Token": self.token_id}
722 response = requests.delete(url, headers=headers)
723 if (response.status_code == OK):
724 self.logger.debug(response.status_code)
725 self.logger.debug(response.content)
726 return(response.status_code)
728 return(response.status_code)
730 def deleteFlowClassifier(self):
731 """Deletion of Flow Classifier."""
732 url = ("http://%s:9696/%s/sfc/"
733 "flow_classifiers/%s" % (self.neutron_hostname,
736 headers = {"Accept": "application/json",
737 "X-Auth-Token": self.token_id}
738 response = requests.delete(url, headers=headers)
739 if (response.status_code == OK):
740 self.logger.debug(response.status_code)
741 self.logger.debug(response.content)
742 return(response.status_code)
744 return(response.status_code)
746 def deletePortGroup(self):
747 """Deletion of PortGroup."""
748 for p in range(0, 1):
749 url = ("http://%s:9696/%s/sfc/"
750 "port_pair_groups/%s" % (self.neutron_hostname,
752 self.port_grp_id[p]))
753 headers = {"Accept": "application/json", "X-Auth-Token":
755 response = requests.delete(url, headers=headers)
756 if (response.status_code == NO_CONTENT):
757 self.logger.debug(response.status_code)
758 self.logger.debug(response.content)
760 return(response.status_code)
761 return(response.status_code)
763 def deletePortPair(self):
764 """Deletion of Portpair."""
765 for p in range(1, 2):
766 url = ("http://%s:9696/%s/sfc/"
767 "port_pairs/%s" % (self.neutron_hostname,
769 self.port_pair_id[0]))
770 headers = {"Accept": "application/json",
771 "X-Auth-Token": self.token_id}
772 response = requests.delete(url, headers=headers)
773 if (response.status_code == NO_CONTENT):
774 self.logger.debug(response.status_code)
775 self.logger.debug(response.content)
777 return(response.status_code)
778 return(response.status_code)
782 self.logger.info("Deleting VMs")
783 for y in range(0, 3):
784 url = ("http://%s:8774/v2.1/"
785 "/servers/%s" % (self.nova_hostname,
787 headers = {"Accept": "application/json",
788 "X-Auth-Token": self.token_id}
789 response = requests.delete(url, headers=headers)
790 if (response.status_code == NO_CONTENT):
791 self.logger.debug(response.status_code)
792 self.logger.debug(response.content)
793 self.logger.debug("VM" + str(y) + " is Deleted : ")
796 return(response.status_code)
797 self.logger.info("Deleting Ports")
798 for x in range(self.i, self.numTerms):
799 url = ('http://' + self.neutron_hostname + ':9696/' +
800 self.osver + '/ports/' + self.port_num[x])
801 headers = {"Accept": "application/json", "X-Auth-Token":
803 response = requests.delete(url, headers=headers)
805 if (response.status_code == NO_CONTENT):
806 self.logger.debug(response.status_code)
807 self.logger.debug(response.content)
808 self.logger.debug("Port" + str(x) + " Deleted")
810 return(response.status_code)
811 self.logger.info("Deleting Router")
814 Dicdata['external_gateway_info'] = {}
815 Dicdata = {'router': Dicdata}
816 data = json.dumps(Dicdata, indent=4)
817 url = ("http://%s:9696/%s/"
818 "/routers/%s" % (self.neutron_hostname,
821 headers = {"Accept": "application/json",
822 "X-Auth-Token": self.token_id}
823 response = requests.put(url, headers=headers, data=data)
824 if (response.status_code == OK):
825 self.logger.debug(response.status_code)
826 self.logger.debug(response.content)
828 if self.subnetId != '':
829 Dicdata1['subnet_id'] = self.subnetId
830 data = json.dumps(Dicdata1, indent=4)
831 url = ("http://%s:9696/%s/routers/%s"
832 "/remove_router_interface.json" % (self.neutron_hostname,
835 headers = {"Accept": "application/json",
836 "X-Auth-Token": self.token_id}
837 response = requests.put(url, headers=headers, data=data)
838 if (response.status_code == OK):
839 url = ("http://%s:9696/%s/"
840 "routers/%s" % (self.neutron_hostname,
843 headers = {"Accept": "application/json", "X-Auth-Token":
845 response = requests.delete(url, headers=headers)
846 if (response.status_code == NO_CONTENT):
847 self.logger.debug(response.status_code)
848 self.logger.debug(response.content)
850 return(response.status_code)
852 return(response.status_code)
854 return(response.status_code)
856 self.logger.info("Deleting Network")
857 url = "http://%s:9696/%s/networks/%s" % (self.neutron_hostname,
861 headers = {"Accept": "application/json",
862 "X-Auth-Token": self.token_id}
863 response = requests.delete(url, headers=headers)
864 if (response.status_code == NO_CONTENT):
865 self.logger.debug(response.status_code)
866 self.logger.debug(response.content)
868 return(response.status_code)
870 self.logger.info("Deleting Floating ip")
871 for ip_num in range(0, 2):
872 url = ("http://%s:9696/%s/floatingips"
873 "/%s" % (self.neutron_hostname,
875 self.vm_public_id[ip_num]))
877 headers = {"Accept": "application/json", "X-Auth-Token":
879 response = requests.delete(url, headers=headers)
880 if (response.status_code == NO_CONTENT):
881 self.logger.debug(response.status_code)
882 self.logger.debug(response.content)
884 return(response.status_code)
885 return(response.status_code)