Ejemplo n.º 1
0
 def instantiate_role(self, role):
     delegate = self._delegate['delegate']
     ec2 = self._delegate['ec2']
     rd = self._delegate['role_defs'][role]
     log.info("Instantiating role {} from role-def {!r}".format(role, rd))
     private_ip = derive_ip_address(
         self._delegate['subnet_obj'].cidr_block,
         self._delegate['delegate'],
         rd['last-octet'],
     )
     # kwargs we use always
     our_kwargs = {
         "key_name": self._delegate['keyname'],
         "subnet_id": self._delegate['subnet_obj'].id,
         "instance_type": rd['type'],
         "private_ip_address": private_ip,
         "placement": self.availability_zone()
     }
     # conditional kwargs
     if rd['user-data']:
         u = get_file_as_string(rd['user-data'])
         log.info("Read {} characters of user-data from file {}".format(
             len(u), rd['user-data']))
         # FIXME master IP address is hardcoded
         # FIXME template_token_subst() calls are hardcoded
         u = template_token_subst(u, '@@MASTER_IP@@', '10.0.0.10')
         u = template_token_subst(u, '@@DELEGATE@@', delegate)
         u = template_token_subst(u, '@@ROLE@@', role)
         u = template_token_subst(u, '@@NODE_NO@@', rd['node-no'])
         u = template_token_subst(u, '@@REGION@@', self.region())
         our_kwargs['user_data'] = u
     reservation = ec2.run_instances(rd['ami-id'], **our_kwargs)
     i_obj = reservation.instances[0]
     self.apply_tags(i_obj, role=role)
     v_obj = None
     if rd['volume']:
         vol_size = int(rd['volume'])
         log.info("Role {} requires {}GB volume".format(role, vol_size))
         if vol_size > 0:
             v_obj = ec2.create_volume(vol_size, i_obj.placement)
             self.apply_tags(v_obj, role=role)
     return (i_obj, v_obj)
Ejemplo n.º 2
0
 def instantiate_role(self, role):
     delegate = self._delegate["delegate"]
     ec2 = self._delegate["ec2"]
     rd = self._delegate["role_defs"][role]
     log.info("Instantiating role {} from role-def {!r}".format(role, rd))
     private_ip = derive_ip_address(
         self._delegate["subnet_obj"].cidr_block, self._delegate["delegate"], rd["last-octet"]
     )
     # kwargs we use always
     our_kwargs = {
         "key_name": self._delegate["keyname"],
         "subnet_id": self._delegate["subnet_obj"].id,
         "instance_type": rd["type"],
         "private_ip_address": private_ip,
         "placement": self.availability_zone(),
     }
     # conditional kwargs
     if rd["user-data"]:
         u = get_file_as_string(rd["user-data"])
         log.info("Read {} characters of user-data from file {}".format(len(u), rd["user-data"]))
         # FIXME master IP address is hardcoded
         # FIXME template_token_subst() calls are hardcoded
         u = template_token_subst(u, "@@MASTER_IP@@", "10.0.0.10")
         u = template_token_subst(u, "@@DELEGATE@@", delegate)
         u = template_token_subst(u, "@@ROLE@@", role)
         u = template_token_subst(u, "@@NODE_NO@@", rd["node-no"])
         u = template_token_subst(u, "@@REGION@@", self.region())
         our_kwargs["user_data"] = u
     reservation = ec2.run_instances(rd["ami-id"], **our_kwargs)
     i_obj = reservation.instances[0]
     self.apply_tags(i_obj, role=role)
     v_obj = None
     if rd["volume"]:
         vol_size = int(rd["volume"])
         log.info("Role {} requires {}GB volume".format(role, vol_size))
         if vol_size > 0:
             v_obj = ec2.create_volume(vol_size, i_obj.placement)
             self.apply_tags(v_obj, role=role)
     return (i_obj, v_obj)
Ejemplo n.º 3
0
 def get_key_material(self, keyname):
     fn = "keys/{}.pub".format(keyname)
     return get_file_as_string(fn)
Ejemplo n.º 4
0
 def get_key_material(self, keyname):
     fn = "keys/{}.pub".format(keyname)
     return get_file_as_string(fn)