Skip to content

Homework 2. DevStack Manipulation Through CLI

life1347 edited this page Nov 7, 2013 · 20 revisions

Nova

create instance through CLI

#creds
#Paste the following:
export OS_TENANT_NAME=xxx
export OS_USERNAME=xxx
export OS_PASSWORD=xxx
export OS_AUTH_URL="http://10.211.55.38:5000/v2.0/"

load creds

$ source creds

create instance

$ nova --os-cache boot --image 91547919-76f5-4fa8-b447-67e940b28aae --flavor 1 my_first_vm

nova-create-instance nova-launch-instance

$ nova pause 83dfe637-943c-45aa-956d-2481e53139d0

nova-launch-instance

Neutron

create network

$ neutron net-create --tenant-id 873298b5fbff44b4b13a41270296af0f demo

neutron-create-network

create subnet

$ neutron subnet-create --tenant-id 873298b5fbff44b4b13a41270296af0f demo 10.50.1.0/24 --dns_nameservers list=true 8.8.8.7 8.8.8.8

neutron-create-subnet

create router

$ neutron router-create --tenant-id 873298b5fbff44b4b13a41270296af0f R_test

neutron-create-router

get l3 agent id

must ensure that user in creds has admin permission, otherwise neutron will show nothing

$ neutron agent-list

neutron-agent-list

add router to l3 agent

$ neutron l3-agent-router-add 91c26035-5d98-4cf9-b4e3-4d1d61f7c7a2 R_test

add router to the subnet

$ neutron router-interface-add 674d9ed8-99be-47d6-8793-a857a564838c 79b488aa-2f5c-4542-8aae-f9ce145a02f5

add subnet to external network

$ neutron router-gateway-set 674d9ed8-99be-47d6-8793-a857a564838c 0ad3b25a-86a9-4710-af52-ee1269f7a6e0

neutron-sub-to-ext

allocate a floating ip

$ neutron floatingip-create public

neutron-allocate-ip

bind ip with instance

$ neutron port-list

neutron-port-list

create instance & attatch it to subnet just create

$ nova --os-cache --debug boot --image 91547919-76f5-4fa8-b447-67e940b28aae --flavor 1 my_first_vm --nic net-id=5c84b865-99cf-4b56-b233-206a9288c43e

neutron-attatch-network-to-instance nova-instance-in-newsubnet nova-neutron-cli-working

Cinder

create volume through CLI

$ cinder create --display_name testV 1

cinder-create-volume

show volumes

$ cinder list

cinder-list

attatch volume to instance

$ nova volume-attach 6fc38207-94f8-43a2-ba3a-0624dfedb696 6617d80a-7893-458a-9d46-975b3832d6bc auto

nova-attatch-volume-to-instance

show volume which attatch to instance

//command on instance
$ find /dev/ -type b | grep vd

cinder-volumes-attatch-to-instance

Heat

first create image for creating heat templates

$ glance image-create --name F17-x86_64-cfntools --is-public true --container-format bare --disk-format qcow2 --location http://fedorapeople.org/groups/heat/prebuilt-jeos-images/F17-x86_64-cfntools.qcow2,http://fedorapeople.org/groups/heat/prebuilt-jeos-images/F17-i386-cfntools.qcow2

glance-create-img

create key pair

$ nova keypair-add heat_key > heat_key.priv
$ chmod 600 heat_key.priv

create heat template

$ heat stack-create teststack -u https://raw.github.com/openstack/heat-templates/master/cfn/F17/WordPress_Single_Instance.template -P "InstanceType=m1.large;DBUsername=wp;DBPassword=verybadpassword;KeyName=heat_key;LinuxDistribution=F17"

heat-create-templates

show current template

$ heat stack-list

heat-stack-list

heat stacks failed :( heat-stacks-1 heat-stacks-2 heat-stacks-3 heat-stacks-4 heat-stacks-5

Ceilometer

show types that can be statistic

$ ceilometer meter-list

ceilometer-meter-list

meter network

$ ceilometer statistics -m network

ceilometer-statistics ceilometer-on-dashboard

ISSUES

  • 在操作過程中會使用到不同身分(e.g demo or admin),creds也要做相對應更動才能正常使用CLI。(權限管理)

Reference

  1. http://yansu.org/2013/05/01/terminal-command-of-ceilometer.html
  2. https://github.com/mseknibilel/OpenStack-Grizzly-Install-Guide
  3. http://docs.openstack.org/user-guide/content/

Heat template

https://raw.github.com/openstack/heat-templates/master/cfn/F17/WordPress_Single_Instance.template

{
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description" : "AWS CloudFormation Sample Template WordPress_Single_Instance: WordPress is web software you can use to create a beautiful website or blog. This template installs a single-instance WordPress deployment using a local MySQL database to store the data.",

  "Parameters" : {

    "KeyName" : {
      "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
      "Type" : "String"
    },

    "InstanceType" : {
      "Description" : "WebServer EC2 instance type",
      "Type" : "String",
      "Default" : "m1.small",
      "AllowedValues" : [ "m1.tiny", "m1.small", "m1.medium", "m1.large", "m1.xlarge" ],
      "ConstraintDescription" : "must be a valid EC2 instance type."
    },

    "DBName": {
      "Default": "wordpress",
      "Description" : "The WordPress database name",
      "Type": "String",
      "MinLength": "1",
      "MaxLength": "64",
      "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
      "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
    },

    "DBUsername": {
      "Default": "admin",
      "NoEcho": "true",
      "Description" : "The WordPress database admin account username",
      "Type": "String",
      "MinLength": "1",
      "MaxLength": "16",
      "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*",
      "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters."
    },

    "DBPassword": {
      "Default": "admin",
      "NoEcho": "true",
      "Description" : "The WordPress database admin account password",
      "Type": "String",
      "MinLength": "1",
      "MaxLength": "41",
      "AllowedPattern" : "[a-zA-Z0-9]*",
      "ConstraintDescription" : "must contain only alphanumeric characters."
    },

    "DBRootPassword": {
      "Default": "admin",
      "NoEcho": "true",
      "Description" : "Root password for MySQL",
      "Type": "String",
      "MinLength": "1",
      "MaxLength": "41",
      "AllowedPattern" : "[a-zA-Z0-9]*",
      "ConstraintDescription" : "must contain only alphanumeric characters."
    },
    "LinuxDistribution": {
      "Default": "F17",
      "Description" : "Distribution of choice",
      "Type": "String",
      "AllowedValues" : [ "F18", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ]
    }
  },

  "Mappings" : {
    "AWSInstanceType2Arch" : {
      "m1.tiny"    : { "Arch" : "32" },
      "m1.small"    : { "Arch" : "64" },
      "m1.medium"    : { "Arch" : "64" },
      "m1.large"   : { "Arch" : "64" },
      "m1.xlarge"   : { "Arch" : "64" }
    },
    "DistroArch2AMI": {
      "F18"      : { "32" : "F18-i386-cfntools", "64" : "F18-x86_64-cfntools" },
      "F17"      : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" },
      "U10"      : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" },
      "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" },
      "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" },
      "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" }
    }
  },

  "Resources" : {
    "WikiDatabase": {
      "Type": "AWS::EC2::Instance",
      "Metadata" : {
        "AWS::CloudFormation::Init" : {
          "config" : {
            "packages" : {
              "yum" : {
                "mysql"        : [],
                "mysql-server" : [],
                "httpd"        : [],
                "wordpress"    : []
              }
            },
            "services" : {
              "systemd" : {
                "mysqld"   : { "enabled" : "true", "ensureRunning" : "true" },
                "httpd"    : { "enabled" : "true", "ensureRunning" : "true" }
              }
            }
          }
        }
      },
      "Properties": {
        "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" },
                          { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
        "InstanceType"   : { "Ref" : "InstanceType" },
        "KeyName"        : { "Ref" : "KeyName" },
        "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
          "#!/bin/bash -v\n",
          "/opt/aws/bin/cfn-init\n",
          "# Setup MySQL root password and create a user\n",
          "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n",
          "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n",
          "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n",
          "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"localhost\"\n",
          "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n",
          "FLUSH PRIVILEGES;\n",
          "EXIT\n",
          "EOF\n",
          "sed -i \"/Deny from All/d\" /etc/httpd/conf.d/wordpress.conf\n",
          "sed -i \"s/Require local/Require all granted/\" /etc/httpd/conf.d/wordpress.conf\n",
          "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ /usr/share/wordpress/wp-config.php\n",
          "systemctl restart httpd.service\n"
        ]]}}
      }
    }
  },

  "Outputs" : {
    "WebsiteURL" : {
      "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/wordpress"]] },
      "Description" : "URL for Wordpress wiki"
    }
  }
}