예제 #1
0
 def get_vm(self, component_key, component_value, vm_config,
            network_interface_name, index):
     vm = dict_to_objdict(deepcopy(vm_config))
     vm.specification.name = resource_name(self.cluster_prefix,
                                           self.cluster_name,
                                           'vm' + '-' + str(index),
                                           component_key)
     vm.specification.admin_username = self.cluster_model.specification.admin_user.name
     vm.specification.network_interface_name = network_interface_name
     vm.specification.tags.append(
         {'cluster': cluster_tag(self.cluster_prefix, self.cluster_name)})
     vm.specification.tags.append({component_key: ''})
     if vm.specification.os_type == 'linux':
         # For linux we dont need a PW since we only support SSH. We add something random for Terraform
         # to run and later disable password access in Ansible.
         vm.specification.admin_password = str(uuid.uuid4())
     if vm_config.specification.os_type == 'windows':
         raise NotImplementedError('Windows VMs not supported jet.')
     pub_key_path = self.cluster_model.specification.admin_user.key_path + '.pub'
     if os.path.isfile(pub_key_path):
         vm.specification.public_key = pub_key_path
     else:
         raise Exception(
             f'SSH key path "{pub_key_path}" is not valid. Ansible run will fail.'
         )
     return vm
예제 #2
0
 def get_ips_for_feature(self, component_key):
     look_for_public_ip = self.cluster_model.specification.cloud.use_public_ips
     cluster = cluster_tag(self.cluster_prefix, self.cluster_name)
     running_instances = self.run(self, f'az vm list-ip-addresses --ids $(az resource list --query "[?type==\'Microsoft.Compute/virtualMachines\' && tags.{component_key} == \'\' && tags.cluster == \'{cluster}\'].id" --output tsv)')
     result = []
     for instance in running_instances:
         if isinstance(instance, list):
             instance = instance[0]   
         name = instance['virtualMachine']['name']
         if look_for_public_ip:
             ip = instance['virtualMachine']['network']['publicIpAddresses'][0]['ipAddress']
         else:
             ip = instance['virtualMachine']['network']['privateIpAddresses'][0]
         result.append(AnsibleHostModel(name, ip))
     return result
예제 #3
0
 def get_vm(self, component_key, component_value, vm_config, availability_set, network_interface_name, index):
     vm = dict_to_objdict(deepcopy(vm_config))
     vm.specification.name = resource_name(self.cluster_prefix, self.cluster_name, 'vm' + '-' + str(index), component_key)
     vm.specification.admin_username = self.cluster_model.specification.admin_user.name
     vm.specification.network_interface_name = network_interface_name
     vm.specification.tags.append({'cluster': cluster_tag(self.cluster_prefix, self.cluster_name)})
     vm.specification.tags.append({component_key: ''})
     if vm_config.specification.os_type == 'windows':
         raise NotImplementedError('Windows VMs not supported jet.')
     pub_key_path = self.cluster_model.specification.admin_user.key_path + '.pub'
     if os.path.isfile(pub_key_path):
         vm.specification.public_key = pub_key_path
     else:
         raise Exception(f'SSH key path "{pub_key_path}" is not valid. Ansible run will fail.')
     if availability_set is not None:
         vm.specification.availability_set_name = availability_set.specification.name
     return vm
예제 #4
0
def test_cluster_tag():
    actual = cluster_tag('prefix', 'Cluster')
    assert actual == "prefix-cluster"
예제 #5
0
def test_cluster_tag_no_prefix3():
    actual = cluster_tag(None, 'Cluster')
    assert actual == "cluster"
예제 #6
0
def test_cluster_tag_no_prefix2():
    actual = cluster_tag('', 'Cluster')
    assert actual == "cluster"
예제 #7
0
def test_cluster_tag_no_prefix1():
    actual = cluster_tag('default', 'Cluster')
    assert actual == "cluster"