05d744b9a4349ccb8df939db506c298dae3a8178
4 # Copyright 2016 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
19 import rift
.rwcal
.aws
as aws_drv
25 logging
.basicConfig(level
=logging
.DEBUG
)
27 logger
= logging
.getLogger()
28 rwlog_handler
= rwlogger
.RwLogger(category
="rw-cal-log",
30 logger
.addHandler(rwlog_handler
)
31 #logger.setLevel(logging.DEBUG)
34 def cleanup_vm(drv
,argument
):
35 vm_inst
= drv
.get_instance(argument
.server_id
)
36 logger
.info("Waiting for VM instance to get to terminating state")
37 vm_inst
.wait_until_terminated()
38 logger
.info("VM inst is now in terminating state")
40 for port_id
in argument
.vdu_port_list
:
41 logger
.info("Deleting network interface with id %s",port_id
)
42 port
= drv
.get_network_interface(port_id
)
44 if port
.association
and 'AssociationId' in port
.association
:
45 drv
.disassociate_public_ip_from_network_interface(NetworkInterfaceId
=port
.id)
46 drv
.delete_network_interface(port
.id)
48 logger
.error("Newtork interface with id %s not found when deleting interface",port_id
)
55 parser
= argparse
.ArgumentParser(description
='Script to create AWS resources')
56 parser
.add_argument('--aws_key',
62 parser
.add_argument('--aws_secret',
68 parser
.add_argument('--aws_region',
74 parser
.add_argument('--server_id',
78 help = "Server ID on which delete operations needs to be performed")
80 parser
.add_argument('--vdu_port_list',
82 dest
= "vdu_port_list",
84 help = "Port id list for vdu")
86 argument
= parser
.parse_args()
88 if not argument
.aws_key
:
89 logger
.error("ERROR: AWS key is not configured")
92 logger
.debug("Using AWS key: %s" %(argument
.aws_key
))
94 if not argument
.aws_secret
:
95 logger
.error("ERROR: AWS Secret is not configured")
98 logger
.debug("Using AWS Secret: %s" %(argument
.aws_secret
))
100 if not argument
.aws_region
:
101 logger
.error("ERROR: AWS Region is not configured")
104 logger
.debug("Using AWS Region: %s" %(argument
.aws_region
))
106 if not argument
.server_id
:
107 logger
.error("ERROR: Server ID is not configured")
110 logger
.debug("Using Server ID : %s" %(argument
.server_id
))
118 logger
.error("fork failed: %d (%s)\n" % (e
.errno
, e
.strerror
))
121 drv
= aws_drv
.AWSDriver(key
= argument
.aws_key
,
122 secret
= argument
.aws_secret
,
123 region
= argument
.aws_region
)
124 cleanup_vm(drv
, argument
)
127 if __name__
== "__main__":