Browsing:

Author: Jacqueline

My predictions for 2016 and beyond

For the first time a post not about coding or information technology, but about my predictions for 2016 and beyond. Here goes. These are going to get huge in 2016:

  • Blockchain is going to get momentum. Blockchain helps us solve the problem of the trusted third parties (like banks), which have created an inefficient society with has led to inequality. Blockchain is a technology which allows us to keep a ledger together. The authority to control, to divide and to conquer belongs to us!

 

  • Soylent, the food replacement. When I first read about Soylent it was still a crowdfunding initiative from Rob Rhinehart at Kickstarter in 2013. Soylent is open source, so you can create your own. But you can also buy it from several suppliers (mostly in the Netherlands funny enough). I have tried Joylent myself and I must admit it is rather tasty. Now I'm eagerly awaiting my Jakefood Light shipment. What is so disruptive about Soylent? Well, it is a food drink that contains only what the body needs. Better than pizzas and hamburgers for sure. For just 9 euros per day.
    Imagine, this can decrease our ecological footprint. It might be a solution for world hunger as well.

 

  • Blue Origin and Spacex. Well, they are inventing rockets that can be re-used. Space travel will be cheaper. It allows us to dream about a future where we can colonize Mars. And this dream can become reality.

  • Ok, I have to admit. Microsofts Continuum is pretty cool. Imagine the situation where you only need to own a smartphone. It will become a desktop computer if you attach it to a dock.  Now we only have to wait until applications become Continuum aware. (But I'm not sure if I would ditch my Macbook).

 

So, there you have it. These are my predictions for the future. They will be big. Maybe not so in 2016, but we are well on our way.

 


ASP.NET 5 getting started from scratch

Let's see how ASP.NET 5 works and discover how we can build a basic website with an API and an Angularjs frontend. Just like we're used to doing with Node.js. Let's see how the Microsoft way compares. Maybe I'm a little late because the current release seems to be 1.0.0.-rc2 on Github. So there's tons of info on the Internet already. And here is my bit as well. 🙂

I will use the Visual Studio Community Edition and I've got a VirtualBox VM running. And let's also host the app in Azure and see how we can collaborate using the Visual Studio Online tools.

First, select File, New, Project and select the Empty ASP.NET 5 template:

aspnet5_1

 

 

 

 

 

 

 

Let's debug and run it immediately!

aspnet5_2

 

 

 

 

Cool! Now where did that came from?

Startup.cs

Startup.cs is the entrypoint for an ASP.NET 5 application. I feel it compares to the app.js or index.js in an Express application which requires all the dependencies needed for the application. It is what the Global.asax was before. There are 2 sections: ConfigureServices and Configure. I think the comments describes their purposes really well:

public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {

           
            app.UseIISPlatformHandler();
              
            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });             
        }

        // Entry point for the application.
        public static void Main(string[] args) => WebApplication.Run(args);
    }

Adding a static page

If we follow along the Express.js workflow, I would now need to add the possibility to add a static file (index.html). And I would need to plug that in to the Startup.cs. And I would need to install the dependencies in a package.json sort of file:

And that is correct. There is a project.json file in the solution and I need to add a dependency to Microsoft.AspNet.StaticFiles. Add it like I did at line 10. (It has intellisense, cool!)

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

Now I can add an index.html file in wwwroot and edit Startup.cs. Delete everything in the Configure method and add 'app.UseStaticFiles();'.

 public void Configure(IApplicationBuilder app)
        {
            app.UseStaticFiles();
        }

Run the app and now this page is served:
aspnet5_3

 

 

 

 

But of course I don't want to type in the URI. I want the web app to server default files.
Then it seems I still need to add middleware to serve the index.html. Add 'app.UseDefaultFiles(); to the Configure method in Startup.cs:

public void Configure(IApplicationBuilder app)
        {
            app.UseDefaultFiles();
            app.UseStaticFiles();
        }

You can find a great explanation here.

So great! That means I can go ahead and add Bootstrap and Angular and that I can write some serious api in C#.

BTW, if you want to know how Microsoft (and the community I must add) has envisioned an ASP.NET 5 web project, please try the MVC web app template.


Vagrant, Parallels and Windows guests

For all of you running a Mac, this is how to create a Windows guest with Vagrant and Packer.

packer
Packer

Vagrant supports Parallels 8 and higher, but please be aware that Vagrant only supports the Pro version of Parallels 11.

First install the plugin:

vagrant plugin install vagrant-parallels

Second, get the Parallels virtualization SDK here

Third, get Packer and unzip it in your Vagrant dir.

Fourth, clone packer-windows from Github.

git clone https://github.com/joefitzgerald/packer-windows

Now make sure the packer and the packer-windows executables are in the same folder. This makes the command easier because you don't need to think hard to make sure the paths to all the files and commands are right.

Fifth, download the Windows server iso upfront. I usually download the Windows Server iso first from here so that I don't have to wait for the download to finish during the packer build process.

Sixth, get this json config file for Parallels. You see that I put the iso from the fifth step on the desktop and reference it in the file.

Seventh, start building and grab coffee

./packer build -var iso_url=~/Desktop/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO windows_2012_r2_parallels.json 

And another coffee..

Screen Shot 2015-10-07 at 07.02.50

Step eight: add the template to vagrant

vagrant box add --name windows_2012_r2 windows_2012_r2_parallels.box

Step nine: create a Vagrant file

Create a folder named lab01 and put a Vagrantfile in it:

Vagrant.require_version ">= 1.6.2"

$root_provision_script = <<'ROOT_PROVISION_SCRIPT'
& $env:windir\system32\tzutil /s "W. Europe Standard Time"

ROOT_PROVISION_SCRIPT

Vagrant.configure("2") do |config|
    config.vm.define "lab01"
    config.vm.box = "windows_2012_r2"
    config.vm.hostname = "lab01" 
    config.vm.provider :virtualbox do |v, override|
        v.gui = false
        #v.customize ["modifyvm", :id, "--memory", 2048]
        #v.customize ["modifyvm", :id, "--cpus", 2]
    end


    config.vm.network :forwarded_port, guest: 3389, host: 3391, id: "rdp", auto_correct: true
    config.vm.network :forwarded_port, guest: 22, host: 2223, id: "ssh", auto_correct: true
    #config.vm.network "private_network", ip: "192.168.56.11"
    config.vm.provision "shell", inline: $root_provision_script
    #config.vm.provision "shell", path: "sysprep.ps1"
    

end

Then issue a 'vagrant up' and we're done.


Build a Windows lab with VirtualBox, Packer and Vagrant, adding sysprep (part 2)

In my former article I elaborated on how to create a lab with Windows servers quickly using Vagrant, Packer and Virtualbox. What I did not realize at that time is that the box I created had 2 issues:

  • The box is not sysprepped. The sysprep is mandatory if you want to create a Domain Controller and are adding boxes to the domain. You'll end up with 2 boxes with the same SID.
  • The MAC address is cloned for every Vagrant machine that is based on the box. This becomes a problem if you want to place the hosts in a bridged network.

Sysprep

Then I went and Googled (after trying in vain myself) and found this repository: https://github.com/mefellows/packer-community-templates. Someone has already done it.

Step 1:
Here is a link to the json file: https://gist.github.com/jacqinthebox/cd3dcbf4b220c70de956.
Copy this file to the packer-windows folder and save it as 'windows_2012_r2_sysprep.json'

Step 2
Make sure you copy the Autounattend_sysprep.xml file from \packer-community-templates\answer_files\2012_r2 to the \packer-windows\answer_files\2012_r2 folder.

Now you can run packer build -only virtualbox-iso windows_2012_r2_sysprep.json. And grab a coffee.

MAC address

The MAC address can be set in the Vagrant file for each machine. First you need to know what the name is of the network interface for the bridge.

2015-09-17_22-02-19

Then you can insert the name of the nic in the Vagrantfile like this (see the marked lines):

Vagrant.require_version ">= 1.6.2"

$root_provision_script = <<'ROOT_PROVISION_SCRIPT'
& $env:windir\system32\tzutil /s "W. Europe Standard Time"

ROOT_PROVISION_SCRIPT

Vagrant.configure("2") do |config|
    config.vm.define "dsc01"
    config.vm.box = "windows_2012_r2"
    config.vm.hostname = "dsc01" 
    config.vm.provider :virtualbox do |v, override|
        v.gui = true
    end
end

	config.vm.network :forwarded_port, guest: 3389, host: 3391, id: "rdp", auto_correct: true
	config.vm.network :forwarded_port, guest: 22, host: 2223, id: "ssh", auto_correct: true
   	config.vm.network "public_network", :bridge => 'Qualcomm Atheros AR8151 PCI-E Gigabit Ethernet Controller (NDIS 6.30)', :mac => "5CA1AB1E0001"
        config.vm.provision "shell", inline: $root_provision_script
    
end

So there it is.




Create a lab on Azure with Vagrant and Powershell

If you want to spin up a lab quickly to test things in a Windows environment, you can use an Azure trial account. It is possible to create trial accounts indefinitely so it will cost you nothing. So, let's go.

For this scenario, I am assuming you are on Windows. By the way, I did the same on a Macbook but instead of Powershell I used the Azure CLI for Mac (runs on Node.js). Check this.

Step 1. Create an Azure trial account

Create a trial account on Azure here.
You will need to supply your credit card info and you should use an mail address that has not been used before for a trial. I am on Google Apps, so I can create mail addresses as much as I like.

Step 2. Install Azure Powershell

You'll need Azure Powershell to query the available images.
Install the Azure Powershell with the msi (or Web Platform Installer).
I've been trying to install the SDK with OneGet, but it seems to be not available.

This gives you a brand new shell.
2015-08-12_09-47-21
 
 
 
 
Not happy with it because it doen't have a cursor. Let's fix that:

[Console]::CursorSize = 25

Step 3. Add your Azure credentials

Type

add-AzureAccount

and enter your credentials

add-azure

Next, get the publishsettings.

Get-AzurePublishSettingsFile

add-azure4.

Save your publishsettings (e.g. on c:\temp) and import them:

Import-AzurePublishSettingsFile c:\temp\%your trial account%-credentials.publishsettings

Step 4. Generate certificates

I would advise to use Cmder with msysgit integration, if you don't already. Cmder is my go to terminal emulator. I use it for Powershell, Git Bash and ordinary DOS. So install Cmder with Chocolatey.

  • First create a pem certificate which is conveniently valid for 10 years. This contains a public key and private key.
  • Then create a pfx certicate based on this pem certifcate.
  • From the pfx, generate a cer to upload to Azure.

openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout azurecert.pem -out azurecert.pem

openssl pkcs12 -export -out azurecert.pfx -in azurecert.pem -name "Vagrant Azure Cert"

openssl x509 -inform pem -in azurecert.pem -outform der -out azurecert.cer

Thanks to this article.

Step 5. Upload the cer file to Azure

I can't figure out how this works with Powershell, so log on to your subscription and add the .cer file:

2015-08-13_06-49-41

First go to settings, then to Management Certificates and upload your .cer file.

cert-blur-bla

Step 6. Install the Vagrant Plugin for Azure

https://github.com/MSOpenTech/vagrant-azure

vagrant plugin install vagrant-azure
vagrant box add azure https://github.com/msopentech/vagrant-azure/raw/master/dummy.box

Now take a look at the Vagrant file for this box. It is located here: C:\Users\yourname\.vagrant.d\boxes\azure\0\azure\Vagrantfile.
In this file you can define some constants that will be applied to every Azure box you create. I've changed 'azure.vm.size' from 'Small' to 'Medium' and added 'azure.vm.location' = West Europe.

#
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = '2'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # All Vagrant configuration is done here. The most common configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.

  config.vm.provider :azure do |azure|
    azure.vm_size = 'Medium'
    azure.vm_location = 'West Europe' # e.g., West US
  end
end

Step 7. Create a new Vagrant file for your Azure box

Now it's time to create the Azure Vagrant box. Without much further ado, this is my Vagrantfile:

# --
Vagrant.configure('2') do |config|
    config.vm.box = 'azure'

    config.vm.provider :azure do |azure, override|
        azure.mgmt_certificate = 'insert path to you pem certifcate'
        azure.mgmt_endpoint = 'https://management.core.windows.net'
        azure.subscription_id = 'insert your Azure subscription ID'
        azure.vm_image = 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-20150726-en.us-127GB.vhd'
        azure.vm_name = 'box01' # max 15 characters. contains letters, number and hyphens. can start with letters and can end with letters and numbers

        azure.vm_password = 'Vagrant!' # min 8 characters. should contain a lower case letter, an uppercase letter, a number and a special character

        azure.storage_acct_name = 'azureboxesstorage2015' # optional. A new one will be generated if not provided.
        azure.cloud_service_name = 'azureboxes' # same as vm_name. leave blank to auto-generate
        azure.vm_location = 'West Europe' # e.g., West US

    azure.tcp_endpoints = '3389:53390' # opens the Remote Desktop internal port that listens on public port 53389. Without this, you cannot RDP to a Windows VM.
    end
end

The Vagrantfile is of based on the Vagrantfile supplied by https://github.com/MSOpenTech/vagrant-azure.

You can get a list of available Azure VM images by logging on to your Azure subscription with Powershell and issue the following command:


Get-AzureVMImage | where-object { $_.Label -like "Windows Server 2012 R2 *" }| select imagename,imagefamily

Step 8. Vagrant up

Now it's time to issue a Vagrant up.

This is will generate some error messages because the vm needs to initialize (I assume).

azure-2015-fout

Just issue an vagrant up again until it says: The machine is already created.

Then you can go ahead and RDP into your new VM:

vagrant-rdp-werkt

So there you go, now you are all set to deploy Azure images until the cloud bursts.