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/ports/"
236 "%s/flavors?name=m1.tiny" % (self.nova_hostname,
239 headers = {"Accept": "application/json", "Content-Type":
240 "application/json", "X-Auth-Token": self.token_id}
241 response = requests.get(url, headers=headers)
243 if (response.status_code == OK):
244 self.logger.debug(response.status_code)
245 self.logger.debug(response.content)
246 self.logger.info("Flavor is available")
247 json1_data = json.loads(response.content)
248 self.logger.debug(json1_data)
249 self.flavorRef = json1_data['flavors'][0]['id']
251 return(response.status_code)
253 for y in range(0, 3):
256 org_nw_port.append({'port': self.port_num[y]})
257 if self.vm_name != '':
258 Dicdata['name'] = "vm" + str(y)
259 if self.imageRef != '':
260 Dicdata['imageRef'] = self.image_id
261 if self.flavorRef != '':
262 Dicdata['flavorRef'] = self.flavorRef
263 if self.max_count != '':
264 Dicdata['max_count'] = self.max_count
265 if self.min_count != '':
266 Dicdata['min_count'] = self.min_count
267 if self.org_nw_port != '':
268 Dicdata['networks'] = org_nw_port
269 Dicdata = {'server': Dicdata}
270 data = json.dumps(Dicdata, indent=4)
271 url = 'http://%s:8774/v2.1/%s/servers' % (self.nova_hostname,
273 headers = {"Accept": "application/json", "Content-Type":
274 "application/json", "X-Auth-Token": self.token_id}
275 response = requests.post(url, headers=headers, data=data)
276 if (response.status_code == ACCEPTED):
277 self.logger.debug(response.status_code)
278 self.logger.debug(response.content)
279 info = "Creation of VM" + str(y) + " is successfull"
280 self.logger.debug(info)
282 json1_data = json.loads(response.content)
283 self.logger.debug(json1_data)
284 self.vm_id = json1_data['server']['id']
285 self.vm.append(json1_data['server']['id'])
287 return(response.status_code)
289 return(response.status_code)
291 def checkVmState(self):
292 """Checking the Status of the Instance."""
294 for y in range(0, 3):
295 url = ("http://%s:8774/v2.1/servers/"
296 "detail?name=vm" + str(y)) % (self.neutron_hostname)
297 headers = {"Accept": "application/json", "X-Auth-Token":
299 response = requests.get(url, headers=headers)
300 if (response.status_code == OK):
301 self.logger.debug(response.status_code)
302 self.logger.debug(response.content)
303 json1_data = json.loads(response.content)
304 self.logger.debug(json1_data)
305 self.vm_active = json1_data['servers'][0]['status']
306 if (self.vm_active == "ACTIVE"):
307 info = "VM" + str(y) + " is Active : " + self.vm_active
309 info = "VM" + str(y) + " is NOT Active : " + self.vm_active
310 self.logger.debug(info)
312 return(response.status_code)
313 return(response.status_code)
316 def createPortPair(self):
317 """Creation of Port Pair."""
318 for p in range(1, 2):
320 if self.port_pair_ingress != '':
321 Dicdata['ingress'] = self.port_num[p]
322 if self.port_pair_egress != '':
324 Dicdata['egress'] = self.port_num[egress]
325 if self.port_pair_name != '':
326 Dicdata['name'] = "PP" + str(p)
328 Dicdata = {'port_pair': Dicdata}
329 data = json.dumps(Dicdata, indent=4)
330 url = 'http://%s:9696/%s/sfc/port_pairs' % (self.neutron_hostname,
332 headers = {"Accept": "application/json", "X-Auth-Token":
334 response = requests.post(url, headers=headers, data=data)
335 if (response.status_code == CREATED):
336 info = ("Creation of Port Pair PP" + str(p) +
338 self.logger.debug(info)
340 return(response.status_code)
342 return(response.status_code)
344 def getPortPair(self):
345 """Query the Portpair id value."""
346 for p in range(0, 1):
347 url = ("http://%s:9696/%s/ports/"
348 "sfc/port_pairs?name=PP1" % (self.neutron_hostname,
350 headers = {"Accept": "application/json",
351 "X-Auth-Token": self.token_id}
352 response = requests.get(url, headers=headers)
354 if (response.status_code == OK):
355 self.logger.debug(response.status_code)
356 self.logger.debug(response.content)
357 json1_data = json.loads(response.content)
358 self.logger.debug(json1_data)
359 self.port_pair_id.append(json1_data['port_pairs'][0]['id'])
361 return(response.status_code)
362 return(response.status_code)
364 def createPortGroup(self):
365 """Creation of PortGroup."""
366 for p in range(0, 1):
369 port_pair_list.append(self.port_pair_id[p])
370 if self.port_group_name != '':
371 Dicdata['name'] = "PG" + str(p)
372 if self.port_pair_id != '':
373 Dicdata['port_pairs'] = port_pair_list
375 Dicdata = {'port_pair_group': Dicdata}
376 data = json.dumps(Dicdata, indent=4)
377 url = ("http://%s:9696/%s/"
378 "sfc/port_pair_groups" % (self.neutron_hostname,
380 headers = {"Accept": "application/json", "X-Auth-Token":
382 response = requests.post(url, headers=headers, data=data)
383 if (response.status_code == CREATED):
384 info = ("Creation of Port Group PG" + str(p) +
386 self.logger.debug(info)
388 return(response.status_code)
390 return(response.status_code)
392 def getPortGroup(self):
393 """Query the PortGroup id."""
394 for p in range(0, 1):
395 url = ("http://%s:9696/%s/sfc/port_pair_groups"
396 "?name=PG" + str(p)) % (self.neutron_hostname,
398 headers = {"Accept": "application/json", "X-Auth-Token":
400 response = requests.get(url, headers=headers)
402 if (response.status_code == OK):
403 self.logger.debug(response.status_code)
404 self.logger.debug(response.content)
405 json1_data = json.loads(response.content)
406 self.port_grp_id.append(json1_data['port_pair_groups']
409 return(response.status_code)
410 return(response.status_code)
412 def createFlowClassifier(self):
413 """Creation of Flow Classifier."""
415 if self.source_ip_prefix != '':
416 Dicdata['source_ip_prefix'] = self.source_ip_prefix
417 if self.destination_ip_prefix != '':
418 Dicdata['destination_ip_prefix'] = self.destination_ip_prefix
419 if self.logical_source_port != '':
420 Dicdata['logical_source_port'] = self.port_num[0]
421 if self.fcname != '':
422 Dicdata['name'] = "FC1"
423 if self.ethertype != '':
424 Dicdata['ethertype'] = self.ethertype
426 Dicdata = {'flow_classifier': Dicdata}
427 data = json.dumps(Dicdata, indent=4)
428 url = ("http://%s:9696/%s/"
429 "sfc/flow_classifiers" % (self.neutron_hostname,
431 headers = {"Accept": "application/json",
432 "X-Auth-Token": self.token_id}
433 response = requests.post(url, headers=headers, data=data)
434 if (response.status_code == CREATED):
435 json1_data = json.loads(response.content)
436 self.flow_class_if = json1_data['flow_classifier']['id']
437 self.logger.debug("Creation of Flow Classifier is successful")
438 return(response.status_code)
440 return(response.status_code)
442 def createPortChain(self):
443 """Creation of PortChain."""
446 flow_class_list.append(self.flow_class_if)
447 port_pair_groups_list = []
448 port_pair_groups_list.append(self.port_grp_id[0])
450 if flow_class_list != '':
451 Dicdata['flow_classifiers'] = flow_class_list
452 if self.pcname != '':
453 Dicdata['name'] = "PC1"
454 if port_pair_groups_list != '':
455 Dicdata['port_pair_groups'] = port_pair_groups_list
457 Dicdata = {'port_chain': Dicdata}
458 data = json.dumps(Dicdata, indent=4)
459 url = 'http://%s:9696/%s/sfc/port_chains' % (self.neutron_hostname,
461 headers = {"Accept": "application/json",
462 "Content-Type": "application/json",
463 "X-Auth-Token": self.token_id}
464 response = requests.post(url, headers=headers, data=data)
465 if (response.status_code == CREATED):
466 self.logger.debug("Creation of PORT CHAIN is successful")
467 json1_data = json.loads(response.content)
468 self.PC_id = json1_data['port_chain']['id']
469 return(response.status_code)
471 return(response.status_code)
473 def checkFlowAdded(self):
474 """Check whether the Flows are downloaded successfully."""
476 response = requests.get('http://' + self.onos_hostname +
477 ':8181/onos/v1/flows',
478 auth=("karaf", "karaf"))
479 if (response.status_code == OK):
480 self.logger.debug("Flow is successfully Queries")
481 json1_data = json.loads(response.content)
482 self.flowadd = json1_data['flows'][0]['state']
484 if (self.flowadd == "ADDED"):
485 self.logger.info("Flow is successfully added to OVS")
486 return(response.status_code)
490 return(response.status_code)
491 ####################################################################
493 def createRouter(self):
494 """Creation of Router."""
496 if self.routername != '':
497 Dicdata['name'] = "router1"
498 if self.admin_state_up != '':
499 Dicdata['admin_state_up'] = self.admin_state_up
501 Dicdata = {'router': Dicdata}
502 data = json.dumps(Dicdata, indent=4)
503 url = 'http://%s:9696/%s/routers.json' % (self.neutron_hostname,
505 headers = {"Accept": "application/json",
506 "X-Auth-Token": self.token_id}
507 response = requests.post(url, headers=headers, data=data)
508 if (response.status_code == CREATED):
509 self.logger.debug(response.status_code)
510 self.logger.debug(response.content)
511 self.logger.debug("Creation of Router is successfull")
512 json1_data = json.loads(response.content)
513 self.logger.debug(json1_data)
514 self.router_id = json1_data['router']['id']
515 return(response.status_code)
517 return(response.status_code)
519 def attachInterface(self):
520 """Attachment of instance ports to the Router."""
521 url = ("http://%s:9696/%s/networks"
522 "?name=admin_floating_net" % (self.neutron_hostname,
524 headers = {"Accept": "application/json", "X-Auth-Token": self.token_id}
525 response = requests.get(url, headers=headers)
526 if (response.status_code == OK):
527 self.logger.debug(response.status_code)
528 self.logger.debug(response.content)
529 json1_data = json.loads(response.content)
530 self.logger.debug(json1_data)
531 self.net_name = json1_data['networks'][0]['name']
532 if (self.net_name == "admin_floating_net"):
533 self.pub_net_id = json1_data['networks'][0]['id']
535 return(response.status_code)
536 ############################################################
538 self.logger.info("Attachment of Instance interface to Router")
540 if self.subnetId != '':
541 Dicdata['subnet_id'] = self.subnetId
543 data = json.dumps(Dicdata, indent=4)
544 url = ("http://%s:9696/%s/routers"
545 "/%s/add_router_interface" % (self.neutron_hostname,
548 headers = {"Accept": "application/json",
549 "X-Auth-Token": self.token_id}
550 response = requests.put(url, headers=headers, data=data)
551 if (response.status_code == OK):
552 self.logger.debug(response.status_code)
553 self.logger.debug(response.content)
554 self.logger.info("Interface attached successfull")
556 return(response.status_code)
557 ############################################################
558 self.logger.info("Attachment of Gateway to Router")
561 if self.pub_net_id != 0:
562 Dicdata1['network_id'] = self.pub_net_id
564 Dicdata1 = {'external_gateway_info': Dicdata1}
565 Dicdata1 = {'router': Dicdata1}
566 data = json.dumps(Dicdata1, indent=4)
567 url = 'http://%s:9696/%s/routers/%s' % (self.neutron_hostname,
570 headers = {"Accept": "application/json",
571 "X-Auth-Token": self.token_id}
572 response = requests.put(url, headers=headers, data=data)
573 if (response.status_code == OK):
574 self.logger.debug(response.status_code)
575 self.logger.debug(response.content)
576 self.logger.info("Gateway Interface attached successfull")
577 return(response.status_code)
579 return(response.status_code)
581 def addFloatingIp(self):
582 """Attachment of Floating Ip to the Router."""
583 for ip_num in range(0, 2):
585 Dicdata['pool'] = "admin_floating_net"
587 data = json.dumps(Dicdata, indent=4)
588 url = ("http://%s:8774/v2.1/"
589 "os-floating-ips" % (self.nova_hostname))
590 headers = {"Accept": "application/json",
591 "X-Auth-Token": self.token_id}
592 response = requests.post(url, headers=headers, data=data)
593 if (response.status_code == OK):
594 self.logger.debug(response.status_code)
595 self.logger.debug(response.content)
596 self.logger.info("Floating ip created successfully")
597 json1_data = json.loads(response.content)
598 self.logger.debug(json1_data)
599 self.vm_public_ip.append(json1_data['floating_ip']['ip'])
600 self.vm_public_id.append(json1_data['floating_ip']['id'])
602 self.logger.error("Floating ip NOT created successfully")
605 if self.address != '':
606 Dicdata1['address'] = self.vm_public_ip[ip_num]
608 Dicdata1 = {'addFloatingIp': Dicdata1}
609 data = json.dumps(Dicdata1, indent=4)
610 url = ("http://%s:8774/v2.1/"
611 "servers/%s/action" % (self.nova_hostname,
614 headers = {"Accept": "application/json",
615 "X-Auth-Token": self.token_id}
616 response = requests.post(url, headers=headers, data=data)
617 if(response.status_code == ACCEPTED):
618 self.logger.debug(response.status_code)
619 self.logger.debug(response.content)
620 self.logger.info("Public Ip successfully added to VM")
622 return(response.status_code)
623 return(response.status_code)
626 """Login to the VM to check NSH packets are received."""
632 hostname = self.vm_public_ip[0]
634 password = "cubswin:)"
635 s.login(hostname, username, password)
636 s.sendline("ping -c 5 " + str(self.port_ip[2]))
637 s.prompt() # match the prompt
639 ping_re = re.search("transmitted.*received", s.before).group()
640 x = re.split('\s+', ping_re)
642 self.logger.info("Ping is Successfull")
644 self.logger.info("Ping is NOT Successfull")
648 hostname = self.vm_public_ip[1]
650 password = "cubswin:)"
651 s.login(hostname, username, password)
652 s.sendline('sudo ./firewall')
654 output_pack = s.before
656 if(output_pack.find("nshc") != -1):
657 self.logger.info("The packet has reached VM2 Instance")
660 self.logger.info("Packet not received in Instance")
663 def ping(ip, timeout=300):
666 self.logger.debug("Pinging %s. Waiting for response..." % ip)
667 response = os.system("ping -c 1 " + ip + " >/dev/null 2>&1")
669 self.logger.info("Ping " + ip + " detected!")
673 self.logger.info("Ping " + ip + " timeout reached.")
677 result0 = ping(self.vm_public_ip[0])
678 result1 = ping(self.vm_public_ip[1])
679 if result0 == 0 and result1 == 0:
682 p1 = Process(target=vm1, args=(queue1, ))
684 p2 = Process(target=vm0)
687 return (queue1.get())
689 self.logger.error("Thread didnt run")
691 """##################################################################"""
692 """ ######################## Stats Functions ################# #####"""
694 def portChainDeviceMap(self):
695 """Check the PC Device Stats in the ONOS."""
696 response = requests.get('http://' + self.onos_hostname +
697 ':8181/onos/vtn/portChainDeviceMap/' +
698 self.PC_id, auth=("karaf", "karaf"))
699 if (response.status_code == OK):
700 self.logger.info("PortChainDeviceMap is successfully Queries")
701 return(response.status_code)
703 return(response.status_code)
705 def portChainSfMap(self):
706 """Check the PC SF Map Stats in the ONOS."""
707 response = requests.get('http://' + self.onos_hostname +
708 ':8181/onos/vtn/portChainSfMap/' +
709 self.PC_id, auth=("karaf", "karaf"))
710 if (response.status_code == OK):
711 self.logger.info("portChainSfMap is successfully Queries")
712 return(response.status_code)
714 return(response.status_code)
716 """###################################################################"""
718 def deletePortChain(self):
719 """Deletion of PortChain."""
720 url = ('http://' + self.neutron_hostname + ':9696/' +
721 self.osver + '/sfc/port_chains/' + self.PC_id)
722 headers = {"Accept": "application/json", "Content-Type":
723 "application/json", "X-Auth-Token": self.token_id}
724 response = requests.delete(url, headers=headers)
725 if (response.status_code == OK):
726 self.logger.debug(response.status_code)
727 self.logger.debug(response.content)
728 return(response.status_code)
730 return(response.status_code)
732 def deleteFlowClassifier(self):
733 """Deletion of Flow Classifier."""
734 url = ("http://%s:9696/%s/sfc/"
735 "flow_classifiers/%s" % (self.neutron_hostname,
738 headers = {"Accept": "application/json",
739 "X-Auth-Token": self.token_id}
740 response = requests.delete(url, headers=headers)
741 if (response.status_code == OK):
742 self.logger.debug(response.status_code)
743 self.logger.debug(response.content)
744 return(response.status_code)
746 return(response.status_code)
748 def deletePortGroup(self):
749 """Deletion of PortGroup."""
750 for p in range(0, 1):
751 url = ("http://%s:9696/%s/sfc/"
752 "port_pair_groups/%s" % (self.neutron_hostname,
754 self.port_grp_id[p]))
755 headers = {"Accept": "application/json", "X-Auth-Token":
757 response = requests.delete(url, headers=headers)
758 if (response.status_code == NO_CONTENT):
759 self.logger.debug(response.status_code)
760 self.logger.debug(response.content)
762 return(response.status_code)
763 return(response.status_code)
765 def deletePortPair(self):
766 """Deletion of Portpair."""
767 for p in range(1, 2):
768 url = ("http://%s:9696/%s/sfc/"
769 "port_pairs/%s" % (self.neutron_hostname,
771 self.port_pair_id[0]))
772 headers = {"Accept": "application/json",
773 "X-Auth-Token": self.token_id}
774 response = requests.delete(url, headers=headers)
775 if (response.status_code == NO_CONTENT):
776 self.logger.debug(response.status_code)
777 self.logger.debug(response.content)
779 return(response.status_code)
780 return(response.status_code)
784 self.logger.info("Deleting VMs")
785 for y in range(0, 3):
786 url = ("http://%s:8774/v2.1/"
787 "/servers/%s" % (self.nova_hostname,
789 headers = {"Accept": "application/json",
790 "X-Auth-Token": self.token_id}
791 response = requests.delete(url, headers=headers)
792 if (response.status_code == NO_CONTENT):
793 self.logger.debug(response.status_code)
794 self.logger.debug(response.content)
795 self.logger.debug("VM" + str(y) + " is Deleted : ")
798 return(response.status_code)
799 self.logger.info("Deleting Ports")
800 for x in range(self.i, self.numTerms):
801 url = ('http://' + self.neutron_hostname + ':9696/' +
802 self.osver + '/ports/' + self.port_num[x])
803 headers = {"Accept": "application/json", "X-Auth-Token":
805 response = requests.delete(url, headers=headers)
807 if (response.status_code == NO_CONTENT):
808 self.logger.debug(response.status_code)
809 self.logger.debug(response.content)
810 self.logger.debug("Port" + str(x) + " Deleted")
812 return(response.status_code)
813 self.logger.info("Deleting Router")
816 Dicdata['external_gateway_info'] = {}
817 Dicdata = {'router': Dicdata}
818 data = json.dumps(Dicdata, indent=4)
819 url = ("http://%s:9696/%s/"
820 "/routers/%s" % (self.neutron_hostname,
823 headers = {"Accept": "application/json",
824 "X-Auth-Token": self.token_id}
825 response = requests.put(url, headers=headers, data=data)
826 if (response.status_code == OK):
827 self.logger.debug(response.status_code)
828 self.logger.debug(response.content)
830 if self.subnetId != '':
831 Dicdata1['subnet_id'] = self.subnetId
832 data = json.dumps(Dicdata1, indent=4)
833 url = ("http://%s:9696/%s/routers/%s"
834 "/remove_router_interface.json" % (self.neutron_hostname,
837 headers = {"Accept": "application/json",
838 "X-Auth-Token": self.token_id}
839 response = requests.put(url, headers=headers, data=data)
840 if (response.status_code == OK):
841 url = ("http://%s:9696/%s/"
842 "routers/%s" % (self.neutron_hostname,
845 headers = {"Accept": "application/json", "X-Auth-Token":
847 response = requests.delete(url, headers=headers)
848 if (response.status_code == NO_CONTENT):
849 self.logger.debug(response.status_code)
850 self.logger.debug(response.content)
852 return(response.status_code)
854 return(response.status_code)
856 return(response.status_code)
858 self.logger.info("Deleting Network")
859 url = "http://%s:9696/%s/networks/%s" % (self.neutron_hostname,
863 headers = {"Accept": "application/json",
864 "X-Auth-Token": self.token_id}
865 response = requests.delete(url, headers=headers)
866 if (response.status_code == NO_CONTENT):
867 self.logger.debug(response.status_code)
868 self.logger.debug(response.content)
870 return(response.status_code)
872 self.logger.info("Deleting Floating ip")
873 for ip_num in range(0, 2):
874 url = ("http://%s:9696/%s/floatingips"
875 "/%s" % (self.neutron_hostname,
877 self.vm_public_id[ip_num]))
879 headers = {"Accept": "application/json", "X-Auth-Token":
881 response = requests.delete(url, headers=headers)
882 if (response.status_code == NO_CONTENT):
883 self.logger.debug(response.status_code)
884 self.logger.debug(response.content)
886 return(response.status_code)
887 return(response.status_code)