def create_node(vm_): """ Build and submit the XML to create a node """ # Start the tree content = ET.Element("ve") # Name of the instance name = ET.SubElement(content, "name") name.text = vm_["name"] # Description, defaults to name desc = ET.SubElement(content, "description") desc.text = config.get_cloud_config_value( "desc", vm_, __opts__, default=vm_["name"], search_global=False ) # How many CPU cores, and how fast they are cpu = ET.SubElement(content, "cpu") cpu.attrib["number"] = config.get_cloud_config_value( "cpu_number", vm_, __opts__, default="1", search_global=False ) cpu.attrib["power"] = config.get_cloud_config_value( "cpu_power", vm_, __opts__, default="1000", search_global=False ) # How many megabytes of RAM ram = ET.SubElement(content, "ram-size") ram.text = config.get_cloud_config_value( "ram", vm_, __opts__, default="256", search_global=False ) # Bandwidth available, in kbps bandwidth = ET.SubElement(content, "bandwidth") bandwidth.text = config.get_cloud_config_value( "bandwidth", vm_, __opts__, default="100", search_global=False ) # How many public IPs will be assigned to this instance ip_num = ET.SubElement(content, "no-of-public-ip") ip_num.text = config.get_cloud_config_value( "ip_num", vm_, __opts__, default="1", search_global=False ) # Size of the instance disk disk = ET.SubElement(content, "ve-disk") disk.attrib["local"] = "true" disk.attrib["size"] = config.get_cloud_config_value( "disk_size", vm_, __opts__, default="10", search_global=False ) # Attributes for the image vm_image = config.get_cloud_config_value( "image", vm_, __opts__, search_global=False ) image = show_image({"image": vm_image}, call="function") platform = ET.SubElement(content, "platform") template = ET.SubElement(platform, "template-info") template.attrib["name"] = vm_image os_info = ET.SubElement(platform, "os-info") os_info.attrib["technology"] = image[vm_image]["technology"] os_info.attrib["type"] = image[vm_image]["osType"] # Username and password admin = ET.SubElement(content, "admin") admin.attrib["login"] = config.get_cloud_config_value( "ssh_username", vm_, __opts__, default="root" ) admin.attrib["password"] = config.get_cloud_config_value( "password", vm_, __opts__, search_global=False ) data = ET.tostring(content, encoding="UTF-8") __utils__["cloud.fire_event"]( "event", "requesting instance", "salt/cloud/{0}/requesting".format(vm_["name"]), args={ "kwargs": __utils__["cloud.filter_event"]("requesting", data, list(data)), }, sock_dir=__opts__["sock_dir"], transport=__opts__["transport"], ) node = query(action="ve", method="POST", data=data) return node
def create_node(vm_): ''' Build and submit the XML to create a node ''' # Start the tree content = ET.Element('ve') # Name of the instance name = ET.SubElement(content, 'name') name.text = vm_['name'] # Description, defaults to name desc = ET.SubElement(content, 'description') desc.text = config.get_cloud_config_value('desc', vm_, __opts__, default=vm_['name'], search_global=False) # How many CPU cores, and how fast they are cpu = ET.SubElement(content, 'cpu') cpu.attrib['number'] = config.get_cloud_config_value('cpu_number', vm_, __opts__, default='1', search_global=False) cpu.attrib['power'] = config.get_cloud_config_value('cpu_power', vm_, __opts__, default='1000', search_global=False) # How many megabytes of RAM ram = ET.SubElement(content, 'ram-size') ram.text = config.get_cloud_config_value('ram', vm_, __opts__, default='256', search_global=False) # Bandwidth available, in kbps bandwidth = ET.SubElement(content, 'bandwidth') bandwidth.text = config.get_cloud_config_value('bandwidth', vm_, __opts__, default='100', search_global=False) # How many public IPs will be assigned to this instance ip_num = ET.SubElement(content, 'no-of-public-ip') ip_num.text = config.get_cloud_config_value('ip_num', vm_, __opts__, default='1', search_global=False) # Size of the instance disk disk = ET.SubElement(content, 've-disk') disk.attrib['local'] = 'true' disk.attrib['size'] = config.get_cloud_config_value('disk_size', vm_, __opts__, default='10', search_global=False) # Attributes for the image vm_image = config.get_cloud_config_value('image', vm_, __opts__, search_global=False) image = show_image({'image': vm_image}, call='function') platform = ET.SubElement(content, 'platform') template = ET.SubElement(platform, 'template-info') template.attrib['name'] = vm_image os_info = ET.SubElement(platform, 'os-info') os_info.attrib['technology'] = image[vm_image]['technology'] os_info.attrib['type'] = image[vm_image]['osType'] # Username and password admin = ET.SubElement(content, 'admin') admin.attrib['login'] = config.get_cloud_config_value('ssh_username', vm_, __opts__, default='root') admin.attrib['password'] = config.get_cloud_config_value( 'password', vm_, __opts__, search_global=False) data = ET.tostring(content, encoding='UTF-8') salt.utils.cloud.fire_event( 'event', 'requesting instance', 'salt/cloud/{0}/requesting'.format(vm_['name']), {'kwargs': data}, ) node = query(action='ve', method='POST', data=data) return node