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)
35 def prepare_vm_after_boot(drv
,argument
):
36 vm_inst
= drv
.get_instance(argument
.server_id
)
37 logger
.info("Waiting for VM instance to get to running state")
38 vm_inst
.wait_until_running()
39 logger
.info("VM instance is now in running state")
41 vm_inst
.create_tags(Tags
=[{'Key': 'Name','Value':argument
.vdu_name
}])
42 if argument
.vdu_node_id
is not None:
43 vm_inst
.create_tags(Tags
=[{'Key':'node_id','Value':argument
.vdu_node_id
}])
45 for index
,port_id
in enumerate(argument
.vdu_port_list
):
46 logger
.info("Attaching network interface with id %s to VDU instance %s",port_id
,vm_inst
.id)
47 drv
.attach_network_interface(NetworkInterfaceId
= port_id
,InstanceId
= vm_inst
.id,DeviceIndex
=index
+1)
54 parser
= argparse
.ArgumentParser(description
='Script to create AWS resources')
55 parser
.add_argument('--aws_key',
61 parser
.add_argument('--aws_secret',
67 parser
.add_argument('--aws_region',
73 parser
.add_argument('--server_id',
77 help = "Server ID on which boot operations needs to be performed")
79 parser
.add_argument('--vdu_name',
85 parser
.add_argument('--vdu_node_id',
88 help = "Node id for vdu")
90 parser
.add_argument('--vdu_port_list',
92 dest
= "vdu_port_list",
94 help = "Port id list for vdu")
96 argument
= parser
.parse_args()
98 if not argument
.aws_key
:
99 logger
.error("ERROR: AWS key is not configured")
102 logger
.debug("Using AWS key: %s" %(argument
.aws_key
))
104 if not argument
.aws_secret
:
105 logger
.error("ERROR: AWS Secret is not configured")
108 logger
.debug("Using AWS Secret: %s" %(argument
.aws_secret
))
110 if not argument
.aws_region
:
111 logger
.error("ERROR: AWS Region is not configured")
114 logger
.debug("Using AWS Region: %s" %(argument
.aws_region
))
116 if not argument
.server_id
:
117 logger
.error("ERROR: Server ID is not configured")
120 logger
.debug("Using Server ID : %s" %(argument
.server_id
))
128 logger
.error("fork failed: %d (%s)\n" % (e
.errno
, e
.strerror
))
131 drv
= aws_drv
.AWSDriver(key
= argument
.aws_key
,
132 secret
= argument
.aws_secret
,
133 region
= argument
.aws_region
)
134 prepare_vm_after_boot(drv
, argument
)
137 if __name__
== "__main__":