/// <summary>
        /// Crea archivo /etc/netplan/50-cloud-init.yam"
        /// </summary>
        /// <param name="networkInterfaceName"></param>
        /// <param name="ip"></param>
        /// <param name="mask"></param>
        /// <param name="gateway"></param>
        /// <param name="nameServersAddresses"></param>
        /// <returns></returns>
        public static async Task <CommandResult> CreateYamlAsync(string networkInterfaceName, string ip, string mask, string gateway, string nameServersAddresses, string password, bool backup = true)
        {
            var content = GetYamlTemplate(networkInterfaceName, ip, mask, gateway, nameServersAddresses);

            var outputfile = YAML_FILE;

            var currentdir = Directory.GetCurrentDirectory();
            var tmpfile    = Path.Combine(currentdir, System.IO.Path.GetFileName(outputfile));

            await tmpfile.WriteAllTextAsync(content);

            await Bash.ExecuteAsync($"chmod 640 {tmpfile}");

            if (backup && File.Exists(YAML_FILE))
            {
                var backupfilename = $"{YAML_FILE}-{DateTimeExtensions.NowToFilenameString()}.backup";
                await Bash.ExecuteAsync($"cp {YAML_FILE} {backupfilename}", password : password);
            }

            var result = await Bash.ExecuteAsync($"mv {tmpfile} {outputfile}", password : password);

            await Bash.ExecuteAsync($"chmod 640 {outputfile}");

            return(result);
        }
Exemplo n.º 2
0
        public static async Task <List <NetworkInteface> > GetNetworkInterfacesAsync()
        {
            var cards = await GetNetworkCardsAsync();

            var interfaces = (await Bash.ExecuteAsync("ifconfig -a")).OutputList;

            return(ExtractNetworkInterfaces(cards, interfaces));
        }
 public static async Task <CommandResult> ApplyAsync(string password)
 {
     return(await Bash.ExecuteAsync("netplan apply", password));
 }
Exemplo n.º 4
0
        /// <summary>
        /// ls /sys/class/net -1"
        /// </summary>
        /// <returns></returns>
        ///
        public static async Task <List <string> > GetNetworkCardsAsync()
        {
            var result = await Bash.ExecuteAsync("ls /sys/class/net -1");

            return(result.OutputList);
        }