def _platform_create_new_instance(self, instance_name, image, instance_type, monitor_cmd_queue=None): """ Create a new instance using the Google Cloud Platform API Args: instance_name (str): The name of the instance image (<image_type>): The image to be used as a base system instance_type (<instance_type>): The VM flavor monitor_cmd_queue: the monitor commands Quue """ # Creation summary print("\n--- Creating a new instance with the following properties:") print("- %-20s %-30s" % ("Name", instance_name)) print("- %-20s %-30s" % ("Image", image.name)) print("- %-20s %-30s" % ("Instance Type", instance_type.name)) # ask for confirm print("") if (SimpleTUI.user_yn("Are you sure?")): instance = self.gcp_client.create_node(name=instance_name, size=instance_type, image=image) if instance is None: return False if monitor_cmd_queue is not None and self.is_monitor_running(): monitor_cmd_queue.put({ "command": "add", "instance_id": instance.id }) return True
def _platform_create_new_instance(self, instance_name, image, instance_type, monitor_cmd_queue=None): """ Create a new instance using the Amazon Web Services API Some specific steps are performed here: - Ask for security group - Ask for key pair - Instance creation summary Args: instance_name (str): The name of the instance image (<image_type>): The image to be used as a base system instance_type (<instance_type>): The VM flavor monitor_cmd_queue: the monitor commands Quue """ # 5. Security Group security_group_index = SimpleTUI.list_dialog( "Security Groups available", self.print_all_security_groups, question="Select security group") if security_group_index is None: return security_group = self.security_groups[security_group_index - 1] # 6. Key Pair key_pair_index = SimpleTUI.list_dialog("Key Pairs available", self.print_all_key_pairs, question="Select key pair") if key_pair_index is None: return key_pair = self.key_pairs[key_pair_index - 1] # Creation summary print("\n--- Creating a new instance with the following properties:") print("- %-20s %-30s" % ("Name", instance_name)) print("- %-20s %-30s" % ("Image", image.name)) print("- %-20s %-30s" % ("Instance Type", instance_type.name)) print("- %-20s %-30s" % ("Key Pair", key_pair.name)) print("- %-20s %-30s" % ("Security Group", security_group)) # ask for confirm print("") if (SimpleTUI.user_yn("Are you sure?")): instance = self.ec2_client.create_node( name=instance_name, image=image, size=instance_type, ex_keyname=key_pair.name, ex_security_groups=[security_group], ex_monitoring=True, ex_mincount=1, ex_maxcount=1) if instance is None: return False if monitor_cmd_queue is not None and self.is_monitor_running(): monitor_cmd_queue.put({ "command": "add", "instance_id": instance.id }) return True