8 from multiprocessing import Process
9 from multiprocessing import Queue
10 from pexpect import pxssh
12 from functest.utils.constants import CONST
20 class SfcOnos(object):
21 """Defines all the def function of SFC."""
24 """Initialization of variables."""
25 self.logger = logging.getLogger(__name__)
30 self.keystone_hostname = 'keystone_ip'
31 self.neutron_hostname = 'neutron_ip'
32 self.nova_hostname = 'nova_ip'
33 self.glance_hostname = 'glance_ip'
34 self.onos_hostname = 'onos_ip'
35 # Network variables #######
36 self.netname = "test_nw"
37 self.admin_state_up = True
40 # #########################
41 # SubNet variables#########
43 self.cidr = "20.20.20.0/24"
44 self.subnetname = "test_nw_subnets"
45 # ###############################
54 self.security_groups = []
55 self.port_security_enabled = False
56 # ###############################
57 # VM creation variable
58 self.container_format = "bare"
59 self.disk_format = "qcow2"
60 self.imagename = "TestSfcVm"
61 self.createImage = ("/home/root1/devstack/files/images/"
62 "firewall_block_image.img")
65 self.imageRef = "test"
71 self.routername = "router1"
73 # #####################################
75 self.port_pair_ingress = 0
76 self.port_pair_egress = 0
77 self.port_pair_name = "PP"
78 self.port_pair_id = []
79 # ####################################
81 self.port_group_name = "PG"
83 # ####################################
85 self.source_ip_prefix = "20.20.20.0/24"
86 self.destination_ip_prefix = "20.20.20.0/24"
87 self.logical_source_port = 0
89 self.ethertype = "IPv4"
90 # #####################################
91 self.flow_class_if = 0
92 # #####################################
93 # Port Chain variables
96 # #####################################
97 # Port Chain variables
99 # #####################################
101 self.vm_public_ip = []
102 self.vm_public_id = []
103 self.cirros_username = CONST.__getattribute__(
104 'openstack_image_username')
105 self.cirros_password = CONST.__getattribute__(
106 'openstack_image_password')
114 """Get the keystone token value from Openstack ."""
115 url = 'http://%s:5000/%s/tokens' % (self.keystone_hostname,
117 data = ('{"auth": {"tenantName": "admin", "passwordCredentials":'
118 '{ "username": "admin", "password": "console"}}}')
119 headers = {"Accept": "application/json"}
120 response = requests.post(url, headers=headers, data=data)
121 if (response.status_code == OK):
122 json1_data = json.loads(response.content)
123 self.logger.debug(response.status_code)
124 self.logger.debug(response.content)
125 self.logger.debug(json1_data)
126 self.token_id = json1_data['access']['token']['id']
127 self.tenant_id = json1_data['access']['token']['tenant']['id']
128 return(response.status_code)
130 return(response.status_code)
132 def createNetworks(self):
133 """Creation of networks."""
135 if self.netname != '':
136 Dicdata['name'] = self.netname
137 if self.admin_state_up != '':
138 Dicdata['admin_state_up'] = self.admin_state_up
139 Dicdata = {'network': Dicdata}
140 data = json.dumps(Dicdata, indent=4)
141 url = 'http://%s:9696/%s/networks' % (self.neutron_hostname,
143 headers = {"Accept": "application/json",
144 "X-Auth-Token": self.token_id}
145 response = requests.post(url, headers=headers, data=data)
146 if (response.status_code == CREATED):
147 self.logger.debug(response.status_code)
148 self.logger.debug(response.content)
150 json1_data = json.loads(response.content)
151 self.logger.debug(json1_data)
152 self.net_id = json1_data['network']['id']
153 return(response.status_code)
155 return(response.status_code)
157 def createSubnets(self):
158 """Creation of SubNets."""
161 Dicdata['network_id'] = self.net_id
162 if self.ip_version != '':
163 Dicdata['ip_version'] = self.ip_version
165 Dicdata['cidr'] = self.cidr
166 if self.subnetname != '':
167 Dicdata['name'] = self.subnetname
169 Dicdata = {'subnet': Dicdata}
170 data = json.dumps(Dicdata, indent=4)
171 url = 'http://%s:9696/%s/subnets' % (self.neutron_hostname,
173 headers = {"Accept": "application/json",
174 "X-Auth-Token": self.token_id}
175 response = requests.post(url, headers=headers, data=data)
177 if (response.status_code == CREATED):
178 self.logger.debug(response.status_code)
179 self.logger.debug(response.content)
180 json1_data = json.loads(response.content)
181 self.logger.debug(json1_data)
182 self.subnetId = json1_data['subnet']['id']
183 return(response.status_code)
185 return(response.status_code)
187 def createPorts(self):
188 """Creation of Ports."""
189 for x in range(self.i, self.numTerms):
191 if self.net_id != '':
192 Dicdata['network_id'] = self.net_id
194 Dicdata['name'] = "port" + str(x)
195 if self.admin_state_up != '':
196 Dicdata['admin_state_up'] = self.admin_state_up
197 if self.security_groups != '':
198 Dicdata['security_groups'] = self.security_groups
199 # if self.port_security_enabled != '':
200 # Dicdata['port_security_enabled'] = self.port_security_enabled
202 Dicdata = {'port': Dicdata}
203 data = json.dumps(Dicdata, indent=4)
204 url = 'http://%s:9696/%s/ports' % (self.neutron_hostname,
206 headers = {"Accept": "application/json",
207 "X-Auth-Token": self.token_id}
208 response = requests.post(url, headers=headers, data=data)
210 if (response.status_code == CREATED):
211 self.logger.debug(response.status_code)
212 self.logger.debug(response.content)
214 json1_data = json.loads(response.content)
215 self.logger.debug(json1_data)
216 self.port_num.append(json1_data['port']['id'])
217 self.port_ip.append(json1_data['port']['fixed_ips'][0]
220 return(response.status_code)
221 return(response.status_code)
224 """Creation of Instance, using firewall image."""
225 url = ("http://%s:9292/v2/images?"
226 "name=TestSfcVm" % (self.glance_hostname))
227 headers = {"Accept": "application/json",
228 "Content-Type": "application/octet-stream",
229 "X-Auth-Token": self.token_id}
230 response = requests.get(url, headers=headers)
231 if (response.status_code == OK):
232 self.logger.debug(response.status_code)
233 self.logger.debug(response.content)
234 self.logger.info("FireWall Image is available")
235 json1_data = json.loads(response.content)
236 self.logger.debug(json1_data)
237 self.image_id = json1_data['images'][0]['id']
239 return(response.status_code)
241 url = ("http://%s:8774/v2.1/%s/flavors?"
242 "name=m1.tiny" % (self.nova_hostname, self.tenant_id))
243 headers = {"Accept": "application/json", "Content-Type":
244 "application/json", "X-Auth-Token": self.token_id}
245 response = requests.get(url, headers=headers)
247 if (response.status_code == OK):
248 self.logger.debug(response.status_code)
249 self.logger.debug(response.content)
250 self.logger.info("Flavor is available")
251 json1_data = json.loads(response.content)
252 self.logger.debug(json1_data)
253 self.flavorRef = json1_data['flavors'][0]['id']
255 return(response.status_code)
257 for y in range(0, 3):
260 org_nw_port.append({'port': self.port_num[y]})
261 if self.vm_name != '':
262 Dicdata['name'] = "vm" + str(y)
263 if self.imageRef != '':
264 Dicdata['imageRef'] = self.image_id
265 if self.flavorRef != '':
266 Dicdata['flavorRef'] = self.flavorRef
267 if self.max_count != '':
268 Dicdata['max_count'] = self.max_count
269 if self.min_count != '':
270 Dicdata['min_count'] = self.min_count
271 if self.org_nw_port != '':
272 Dicdata['networks'] = org_nw_port
273 Dicdata = {'server': Dicdata}
274 data = json.dumps(Dicdata, indent=4)
275 url = 'http://%s:8774/v2.1/%s/servers' % (self.nova_hostname,
277 headers = {"Accept": "application/json", "Content-Type":
278 "application/json", "X-Auth-Token": self.token_id}
279 response = requests.post(url, headers=headers, data=data)
280 if (response.status_code == ACCEPTED):
281 self.logger.debug(response.status_code)
282 self.logger.debug(response.content)
283 info = "Creation of VM" + str(y) + " is successfull"
284 self.logger.debug(info)
286 json1_data = json.loads(response.content)
287 self.logger.debug(json1_data)
288 self.vm_id = json1_data['server']['id']
289 self.vm.append(json1_data['server']['id'])
291 return(response.status_code)
293 return(response.status_code)
295 def checkVmState(self):
296 """Checking the Status of the Instance."""
298 for y in range(0, 3):
299 url = ("http://%s:8774/v2.1/servers/"
300 "detail?name=vm" + str(y)) % (self.neutron_hostname)
301 headers = {"Accept": "application/json",
302 "X-Auth-Token": self.token_id}
303 response = requests.get(url, headers=headers)
304 if (response.status_code == OK):
305 self.logger.debug(response.status_code)
306 self.logger.debug(response.content)
307 json1_data = json.loads(response.content)
308 self.logger.debug(json1_data)
309 self.vm_active = json1_data['servers'][0]['status']
310 if (self.vm_active == "ACTIVE"):
311 info = "VM" + str(y) + " is Active : " + self.vm_active
313 info = "VM" + str(y) + " is NOT Active : " + self.vm_active
314 self.logger.debug(info)
316 return(response.status_code)
317 return(response.status_code)
320 def createPortPair(self):
321 """Creation of Port Pair."""
322 for p in range(1, 2):
324 if self.port_pair_ingress != '':
325 Dicdata['ingress'] = self.port_num[p]
326 if self.port_pair_egress != '':
328 Dicdata['egress'] = self.port_num[egress]
329 if self.port_pair_name != '':
330 Dicdata['name'] = "PP" + str(p)
332 Dicdata = {'port_pair': Dicdata}
333 data = json.dumps(Dicdata, indent=4)
334 url = 'http://%s:9696/%s/sfc/port_pairs' % (self.neutron_hostname,
336 headers = {"Accept": "application/json", "X-Auth-Token":
338 response = requests.post(url, headers=headers, data=data)
339 if (response.status_code == CREATED):
340 info = ("Creation of Port Pair PP" + str(p) +
342 self.logger.debug(info)
344 return(response.status_code)
346 return(response.status_code)
348 def getPortPair(self):
349 """Query the Portpair id value."""
350 for p in range(0, 1):
351 url = ("http://%s:9696/%s/"
352 "sfc/port_pairs?name=PP1" % (self.neutron_hostname,
354 headers = {"Accept": "application/json",
355 "X-Auth-Token": self.token_id}
356 response = requests.get(url, headers=headers)
358 if (response.status_code == OK):
359 self.logger.debug(response.status_code)
360 self.logger.debug(response.content)
361 json1_data = json.loads(response.content)
362 self.logger.debug(json1_data)
363 self.port_pair_id.append(json1_data['port_pairs'][0]['id'])
365 return(response.status_code)
366 return(response.status_code)
368 def createPortGroup(self):
369 """Creation of PortGroup."""
370 for p in range(0, 1):
373 port_pair_list.append(self.port_pair_id[p])
374 if self.port_group_name != '':
375 Dicdata['name'] = "PG" + str(p)
376 if self.port_pair_id != '':
377 Dicdata['port_pairs'] = port_pair_list
379 Dicdata = {'port_pair_group': Dicdata}
380 data = json.dumps(Dicdata, indent=4)
381 url = ("http://%s:9696/%s/"
382 "sfc/port_pair_groups" % (self.neutron_hostname,
384 headers = {"Accept": "application/json", "X-Auth-Token":
386 response = requests.post(url, headers=headers, data=data)
387 if (response.status_code == CREATED):
388 info = ("Creation of Port Group PG" + str(p) +
390 self.logger.debug(info)
392 return(response.status_code)
394 return(response.status_code)
396 def getPortGroup(self):
397 """Query the PortGroup id."""
398 for p in range(0, 1):
399 url = ("http://%s:9696/%s/sfc/port_pair_groups"
400 "?name=PG" + str(p)) % (self.neutron_hostname,
402 headers = {"Accept": "application/json", "X-Auth-Token":
404 response = requests.get(url, headers=headers)
406 if (response.status_code == OK):
407 self.logger.debug(response.status_code)
408 self.logger.debug(response.content)
409 json1_data = json.loads(response.content)
410 self.port_grp_id.append(json1_data['port_pair_groups']
413 return(response.status_code)
414 return(response.status_code)
416 def createFlowClassifier(self):
417 """Creation of Flow Classifier."""
419 if self.source_ip_prefix != '':
420 Dicdata['source_ip_prefix'] = self.source_ip_prefix
421 if self.destination_ip_prefix != '':
422 Dicdata['destination_ip_prefix'] = self.destination_ip_prefix
423 if self.logical_source_port != '':
424 Dicdata['logical_source_port'] = self.port_num[0]
425 if self.fcname != '':
426 Dicdata['name'] = "FC1"
427 if self.ethertype != '':
428 Dicdata['ethertype'] = self.ethertype
430 Dicdata = {'flow_classifier': Dicdata}
431 data = json.dumps(Dicdata, indent=4)
432 url = ("http://%s:9696/%s/"
433 "sfc/flow_classifiers" % (self.neutron_hostname,
435 headers = {"Accept": "application/json",
436 "X-Auth-Token": self.token_id}
437 response = requests.post(url, headers=headers, data=data)
438 if (response.status_code == CREATED):
439 json1_data = json.loads(response.content)
440 self.flow_class_if = json1_data['flow_classifier']['id']
441 self.logger.debug("Creation of Flow Classifier is successful")
442 return(response.status_code)
444 return(response.status_code)
446 def createPortChain(self):
447 """Creation of PortChain."""
450 flow_class_list.append(self.flow_class_if)
451 port_pair_groups_list = []
452 port_pair_groups_list.append(self.port_grp_id[0])
454 if flow_class_list != '':
455 Dicdata['flow_classifiers'] = flow_class_list
456 if self.pcname != '':
457 Dicdata['name'] = "PC1"
458 if port_pair_groups_list != '':
459 Dicdata['port_pair_groups'] = port_pair_groups_list
461 Dicdata = {'port_chain': Dicdata}
462 data = json.dumps(Dicdata, indent=4)
463 url = 'http://%s:9696/%s/sfc/port_chains' % (self.neutron_hostname,
465 headers = {"Accept": "application/json",
466 "Content-Type": "application/json",
467 "X-Auth-Token": self.token_id}
468 response = requests.post(url, headers=headers, data=data)
469 if (response.status_code == CREATED):
470 self.logger.debug("Creation of PORT CHAIN is successful")
471 json1_data = json.loads(response.content)
472 self.PC_id = json1_data['port_chain']['id']
473 return(response.status_code)
475 return(response.status_code)
477 def checkFlowAdded(self):
478 """Check whether the Flows are downloaded successfully."""
480 response = requests.get('http://' + self.onos_hostname +
481 ':8181/onos/v1/flows',
482 auth=("karaf", "karaf"))
483 if (response.status_code == OK):
484 self.logger.debug("Flow is successfully Queries")
485 json1_data = json.loads(response.content)
486 self.flowadd = json1_data['flows'][0]['state']
488 if (self.flowadd == "ADDED"):
489 self.logger.info("Flow is successfully added to OVS")
490 return(response.status_code)
494 return(response.status_code)
495 ####################################################################
497 def createRouter(self):
498 """Creation of Router."""
500 if self.routername != '':
501 Dicdata['name'] = "router1"
502 if self.admin_state_up != '':
503 Dicdata['admin_state_up'] = self.admin_state_up
505 Dicdata = {'router': Dicdata}
506 data = json.dumps(Dicdata, indent=4)
507 url = 'http://%s:9696/%s/routers.json' % (self.neutron_hostname,
509 headers = {"Accept": "application/json",
510 "X-Auth-Token": self.token_id}
511 response = requests.post(url, headers=headers, data=data)
512 if (response.status_code == CREATED):
513 self.logger.debug(response.status_code)
514 self.logger.debug(response.content)
515 self.logger.debug("Creation of Router is successfull")
516 json1_data = json.loads(response.content)
517 self.logger.debug(json1_data)
518 self.router_id = json1_data['router']['id']
519 return(response.status_code)
521 return(response.status_code)
523 def attachInterface(self):
524 """Attachment of instance ports to the Router."""
525 url = ("http://%s:9696/%s/networks"
526 "?name=admin_floating_net" % (self.neutron_hostname,
528 headers = {"Accept": "application/json", "X-Auth-Token": self.token_id}
529 response = requests.get(url, headers=headers)
530 if (response.status_code == OK):
531 self.logger.debug(response.status_code)
532 self.logger.debug(response.content)
533 json1_data = json.loads(response.content)
534 self.logger.debug(json1_data)
535 self.net_name = json1_data['networks'][0]['name']
536 if (self.net_name == "admin_floating_net"):
537 self.pub_net_id = json1_data['networks'][0]['id']
539 return(response.status_code)
540 ############################################################
542 self.logger.info("Attachment of Instance interface to Router")
544 if self.subnetId != '':
545 Dicdata['subnet_id'] = self.subnetId
547 data = json.dumps(Dicdata, indent=4)
548 url = ("http://%s:9696/%s/routers"
549 "/%s/add_router_interface" % (self.neutron_hostname,
552 headers = {"Accept": "application/json",
553 "X-Auth-Token": self.token_id}
554 response = requests.put(url, headers=headers, data=data)
555 if (response.status_code == OK):
556 self.logger.debug(response.status_code)
557 self.logger.debug(response.content)
558 self.logger.info("Interface attached successfull")
560 return(response.status_code)
561 ############################################################
562 self.logger.info("Attachment of Gateway to Router")
565 if self.pub_net_id != 0:
566 Dicdata1['network_id'] = self.pub_net_id
568 Dicdata1 = {'external_gateway_info': Dicdata1}
569 Dicdata1 = {'router': Dicdata1}
570 data = json.dumps(Dicdata1, indent=4)
571 url = 'http://%s:9696/%s/routers/%s' % (self.neutron_hostname,
574 headers = {"Accept": "application/json",
575 "X-Auth-Token": self.token_id}
576 response = requests.put(url, headers=headers, data=data)
577 if (response.status_code == OK):
578 self.logger.debug(response.status_code)
579 self.logger.debug(response.content)
580 self.logger.info("Gateway Interface attached successfull")
581 return(response.status_code)
583 return(response.status_code)
585 def addFloatingIp(self):
586 """Attachment of Floating Ip to the Router."""
587 for ip_num in range(0, 2):
589 Dicdata['pool'] = "admin_floating_net"
591 data = json.dumps(Dicdata, indent=4)
592 url = ("http://%s:8774/v2.1/"
593 "os-floating-ips" % (self.nova_hostname))
594 headers = {"Accept": "application/json",
595 "X-Auth-Token": self.token_id}
596 response = requests.post(url, headers=headers, data=data)
597 if (response.status_code == OK):
598 self.logger.debug(response.status_code)
599 self.logger.debug(response.content)
600 self.logger.info("Floating ip created successfully")
601 json1_data = json.loads(response.content)
602 self.logger.debug(json1_data)
603 self.vm_public_ip.append(json1_data['floating_ip']['ip'])
604 self.vm_public_id.append(json1_data['floating_ip']['id'])
606 self.logger.error("Floating ip NOT created successfully")
609 if self.address != '':
610 Dicdata1['address'] = self.vm_public_ip[ip_num]
612 Dicdata1 = {'addFloatingIp': Dicdata1}
613 data = json.dumps(Dicdata1, indent=4)
614 url = ("http://%s:8774/v2.1/"
615 "servers/%s/action" % (self.nova_hostname,
618 headers = {"Accept": "application/json",
619 "X-Auth-Token": self.token_id}
620 response = requests.post(url, headers=headers, data=data)
621 if(response.status_code == ACCEPTED):
622 self.logger.debug(response.status_code)
623 self.logger.debug(response.content)
624 self.logger.info("Public Ip successfully added to VM")
626 return(response.status_code)
627 return(response.status_code)
630 """Login to the VM to check NSH packets are received."""
636 hostname = self.vm_public_ip[0]
637 s.login(hostname, self.cirros_username, self.cirros_password)
638 s.sendline("ping -c 5 " + str(self.port_ip[2]))
639 s.prompt() # match the prompt
641 ping_re = re.search("transmitted.*received", s.before).group()
642 x = re.split('\s+', ping_re)
644 self.logger.info("Ping is Successfull")
646 self.logger.info("Ping is NOT Successfull")
650 hostname = self.vm_public_ip[1]
651 s.login(hostname, self.cirros_username, self.cirros_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",
846 "X-Auth-Token": self.token_id}
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)