def _k8s_get_credentials_internal(name, acs_info, path, ssh_key_file): if ssh_key_file is not None and not os.path.isfile(ssh_key_file): raise CLIError( 'Private key file {} does not exist'.format(ssh_key_file)) dns_prefix = acs_info.master_profile.dns_prefix # pylint: disable=no-member location = acs_info.location # pylint: disable=no-member user = acs_info.linux_profile.admin_username # pylint: disable=no-member _mkdir_p(os.path.dirname(path)) path_candidate = path ix = 0 while os.path.exists(path_candidate): ix += 1 path_candidate = '{}-{}-{}'.format(path, name, ix) # TODO: this only works for public cloud, need other casing for national clouds acs_client.SecureCopy(user, '{}.{}.cloudapp.azure.com'.format( dns_prefix, location), '.kube/config', path_candidate, key_filename=ssh_key_file) # merge things if path_candidate != path: try: merge_kubernetes_configurations(path, path_candidate) except yaml.YAMLError as exc: logger.warning( 'Failed to merge credentials to kube config file: %s', exc) logger.warning('The credentials have been saved to %s', path_candidate)
def k8s_get_credentials(name=None, resource_group_name=None, dns_prefix=None, location=None, user=None, path=None): if not dns_prefix or not location: acs_info = _get_acs_info(name, resource_group_name) if not dns_prefix: dns_prefix = acs_info.master_profile.dns_prefix # pylint: disable=no-member if not location: location = acs_info.location # pylint: disable=no-member if not user: user = acs_info.linux_profile.admin_username # pylint: disable=no-member _mkdir_p(os.path.dirname(path)) path_candidate = path ix = 0 while os.path.exists(path_candidate): ix += 1 path_candidate = '{}-{}-{}'.format(path, name, ix) # TODO: this only works for public cloud, need other casing for national clouds acs_client.SecureCopy(user, '{}.{}.cloudapp.azure.com'.format(dns_prefix, location), '.kube/config', path_candidate) # merge things if path_candidate != path: try: merge_kubernetes_configurations(path, path_candidate) except yaml.YAMLError as exc: logger.warning('Failed to merge credentials to kube config file: %s', exc) logger.warning('The credentials have been saved to %s', path_candidate)
def acs_get_credentials(dns_prefix, location): # TODO: once we get the right swagger in here, update this to actually pull location and dns_prefix #acs_info = _get_acs_info(name, resource_group_name) home = os.path.expanduser('~') path = os.path.join(home, '.kube', 'config') # TODO: this only works for public cloud, need other casing for national clouds acs_client.SecureCopy('azureuser', '{}-k8s-masters.{}.cloudapp.azure.com'.format(dns_prefix, location), '.kube/config', path)