2.Openstack基本操作

2018-05-03  本文已影响0人  qianlong21st

1 使用OpenStack CLI

1.1 配置OpenStack CLI的环境变量

步骤一:source /opt/stack/nova/tools/nova-manage.bash_completion
步骤二:source /opt/devstack/openrc admin admin,其中第一个admin代表租户,第二个admin代表用户;也可以使用demo demo来执行上述命令。

stack@henry-desktop:/opt/devstack$ source /opt/stack/nova/tools/nova-manage.bash_completion 
stack@henry-desktop:/opt/devstack$ ls -l openrc
-rw-r--r-- 1 stack stack 4033 5月   1 23:16 openrc
stack@henry-desktop:/opt/devstack$ source openrc admin admin
WARNING: setting legacy OS_TENANT_NAME to support cli tools.

执行一条命令测试设置是否成功

stack@henry-desktop:~$ glance image-list
+--------------------------------------+--------------------------+
| ID                                   | Name                     |
+--------------------------------------+--------------------------+
| 298a9699-0ac3-4ad1-a026-905250d2aeb4 | cirros-0.3.5-x86_64-disk |
+--------------------------------------+--------------------------+

1.2 使用nova boot启动一个新实例

stack@henry-desktop:~$ nova help boot
usage: nova boot [--flavor <flavor>] [--image <image>]
                 [--image-with <key=value>] [--boot-volume <volume_id>]
                 [--snapshot <snapshot_id>] [--min-count <number>]
                 [--max-count <number>] [--meta <key=value>]
                 [--key-name <key-name>] [--user-data <user-data>]
                 [--availability-zone <availability-zone>]
                 [--security-groups <security-groups>]
                 [--block-device-mapping <dev-name=mapping>]
                 [--block-device key1=value1[,key2=value2...]]
                 [--swap <swap_size>]
                 [--ephemeral size=<size>[,format=<format>]]
                 [--hint <key=value>]
                 [--nic <auto,none,net-id=net-uuid,net-name=network-name,port-id=port-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,tag=tag>]
                 [--config-drive <value>] [--poll] [--admin-pass <value>]
                 [--access-ip-v4 <value>] [--access-ip-v6 <value>]
                 [--description <description>] [--tags <tags>]
                 [--return-reservation-id]
                 <name>

Boot a new server.

Positional arguments:
  <name>                        Name for the new server.

Optional arguments:
  --flavor <flavor>             Name or ID of flavor (see 'nova flavor-list').
  --image <image>               Name or ID of image (see 'glance image-list').
  --image-with <key=value>      Image metadata property (see 'glance image-
                                show').
  --boot-volume <volume_id>     Volume ID to boot from.
  --snapshot <snapshot_id>      Snapshot ID to boot from (will create a
                                volume).
  --min-count <number>          Boot at least <number> servers (limited by
                                quota).
  --max-count <number>          Boot up to <number> servers (limited by
                                quota).
  --meta <key=value>            Record arbitrary key/value metadata to
                                /meta_data.json on the metadata server. Can be
                                specified multiple times.
  --key-name <key-name>         Key name of keypair that should be created
                                earlier with the command keypair-add.
  --user-data <user-data>       user data file to pass to be exposed by the
                                metadata server.
  --availability-zone <availability-zone>
                                The availability zone for server placement.
  --security-groups <security-groups>
                                Comma separated list of security group names.
  --block-device-mapping <dev-name=mapping>
                                Block device mapping in the format <dev-
                                name>=<id>:<type>:<size(GiB)>:<delete-on-
                                terminate>.
  --block-device key1=value1[,key2=value2...]
                                Block device mapping with the keys: id=UUID
                                (image_id, snapshot_id or volume_id only if
                                using source image, snapshot or volume)
                                source=source type (image, snapshot, volume or
                                blank), dest=destination type of the block
                                device (volume or local), bus=device's bus
                                (e.g. uml, lxc, virtio, ...; if omitted,
                                hypervisor driver chooses a suitable default,
                                honoured only if device type is supplied)
                                type=device type (e.g. disk, cdrom, ...;
                                defaults to 'disk') device=name of the device
                                (e.g. vda, xda, ...; if omitted, hypervisor
                                driver chooses suitable device depending on
                                selected bus; note the libvirt driver always
                                uses default device names), size=size of the
                                block device in MB(for swap) and in GiB(for
                                other formats) (if omitted, hypervisor driver
                                calculates size), format=device will be
                                formatted (e.g. swap, ntfs, ...; optional),
                                bootindex=integer used for ordering the boot
                                disks (for image backed instances it is equal
                                to 0, for others need to be specified),
                                shutdown=shutdown behaviour (either preserve
                                or remove, for local destination set to
                                remove) and tag=device metadata tag
                                (optional). (Supported by API versions '2.42'
                                - '2.latest')
  --swap <swap_size>            Create and attach a local swap block device of
                                <swap_size> MB.
  --ephemeral size=<size>[,format=<format>]
                                Create and attach a local ephemeral block
                                device of <size> GiB and format it to
                                <format>.
  --hint <key=value>            Send arbitrary key/value pairs to the
                                scheduler for custom use.
  --nic <auto,none,net-id=net-uuid,net-name=network-name,port-id=port-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,tag=tag>
                                Create a NIC on the server. Specify option
                                multiple times to create multiple nics unless
                                using the special 'auto' or 'none' values.
                                auto: automatically allocate network resources
                                if none are available. This cannot be
                                specified with any other nic value and cannot
                                be specified multiple times. none: do not
                                attach a NIC at all. This cannot be specified
                                with any other nic value and cannot be
                                specified multiple times. net-id: attach NIC
                                to network with a specific UUID. net-name:
                                attach NIC to network with this name (either
                                port-id or net-id or net-name must be
                                provided), v4-fixed-ip: IPv4 fixed address for
                                NIC (optional), v6-fixed-ip: IPv6 fixed
                                address for NIC (optional), port-id: attach
                                NIC to port with this UUID tag: interface
                                metadata tag (optional) (either port-id or
                                net-id must be provided). (Supported by API
                                versions '2.42' - '2.latest')
  --config-drive <value>        Enable config drive.
  --poll                        Report the new server boot progress until it
                                completes.
  --admin-pass <value>          Admin password for the instance.
  --access-ip-v4 <value>        Alternative access IPv4 of the instance.
  --access-ip-v6 <value>        Alternative access IPv6 of the instance.
  --description <description>   Description for the server. (Supported by API
                                versions '2.19' - '2.latest')
  --tags <tags>                 Tags for the server.Tags must be separated by
                                commas: --tags <tag1,tag2> (Supported by API
                                versions '2.52' - '2.latest')
  --return-reservation-id       Return a reservation id bound to created
                                servers.
stack@henry-desktop:~$ nova flavor-list
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+
| ID | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public | Description |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+
| 1  | m1.tiny   | 512       | 1    | 0         |      | 1     | 1.0         | True      | -           |
| 2  | m1.small  | 2048      | 20   | 0         |      | 1     | 1.0         | True      | -           |
| 3  | m1.medium | 4096      | 40   | 0         |      | 2     | 1.0         | True      | -           |
| 4  | m1.large  | 8192      | 80   | 0         |      | 4     | 1.0         | True      | -           |
| 42 | m1.nano   | 64        | 0    | 0         |      | 1     | 1.0         | True      | -           |
| 5  | m1.xlarge | 16384     | 160  | 0         |      | 8     | 1.0         | True      | -           |
| 84 | m1.micro  | 128       | 0    | 0         |      | 1     | 1.0         | True      | -           |
| c1 | cirros256 | 256       | 0    | 0         |      | 1     | 1.0         | True      | -           |
| d1 | ds512M    | 512       | 5    | 0         |      | 1     | 1.0         | True      | -           |
| d2 | ds1G      | 1024      | 10   | 0         |      | 1     | 1.0         | True      | -           |
| d3 | ds2G      | 2048      | 10   | 0         |      | 2     | 1.0         | True      | -           |
| d4 | ds4G      | 4096      | 20   | 0         |      | 4     | 1.0         | True      | -           |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+
stack@henry-desktop:~$ glance image-list
+--------------------------------------+--------------------------+
| ID                                   | Name                     |
+--------------------------------------+--------------------------+
| 298a9699-0ac3-4ad1-a026-905250d2aeb4 | cirros-0.3.5-x86_64-disk |
+--------------------------------------+--------------------------+
stack@henry-desktop:~$ nova boot --flavor 1 --image 298a9699-0ac3-4ad1-a026-905250d2aeb4 test-instance
+--------------------------------------+-----------------------------------------------------------------+
| Property                             | Value                                                           |
+--------------------------------------+-----------------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                          |
| OS-EXT-AZ:availability_zone          |                                                                 |
| OS-EXT-SRV-ATTR:host                 | -                                                               |
| OS-EXT-SRV-ATTR:hostname             | test-instance                                                   |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                                               |
| OS-EXT-SRV-ATTR:instance_name        |                                                                 |
| OS-EXT-SRV-ATTR:kernel_id            |                                                                 |
| OS-EXT-SRV-ATTR:launch_index         | 0                                                               |
| OS-EXT-SRV-ATTR:ramdisk_id           |                                                                 |
| OS-EXT-SRV-ATTR:reservation_id       | r-t6n7cxny                                                      |
| OS-EXT-SRV-ATTR:root_device_name     | -                                                               |
| OS-EXT-SRV-ATTR:user_data            | -                                                               |
| OS-EXT-STS:power_state               | 0                                                               |
| OS-EXT-STS:task_state                | scheduling                                                      |
| OS-EXT-STS:vm_state                  | building                                                        |
| OS-SRV-USG:launched_at               | -                                                               |
| OS-SRV-USG:terminated_at             | -                                                               |
| accessIPv4                           |                                                                 |
| accessIPv6                           |                                                                 |
| adminPass                            | dRGbLFjWfy7B                                                    |
| config_drive                         |                                                                 |
| created                              | 2018-05-03T04:47:24Z                                            |
| description                          | -                                                               |
| flavor:disk                          | 1                                                               |
| flavor:ephemeral                     | 0                                                               |
| flavor:extra_specs                   | {}                                                              |
| flavor:original_name                 | m1.tiny                                                         |
| flavor:ram                           | 512                                                             |
| flavor:swap                          | 0                                                               |
| flavor:vcpus                         | 1                                                               |
| hostId                               |                                                                 |
| host_status                          |                                                                 |
| id                                   | 54ec6256-edff-46cf-84c8-73322f373c64                            |
| image                                | cirros-0.3.5-x86_64-disk (298a9699-0ac3-4ad1-a026-905250d2aeb4) |
| key_name                             | -                                                               |
| locked                               | False                                                           |
| metadata                             | {}                                                              |
| name                                 | test-instance                                                   |
| os-extended-volumes:volumes_attached | []                                                              |
| progress                             | 0                                                               |
| security_groups                      | default                                                         |
| status                               | BUILD                                                           |
| tags                                 | []                                                              |
| tenant_id                            | 3acd3cdedc3148d9970a0259b399105b                                |
| updated                              | 2018-05-03T04:47:28Z                                            |
| user_id                              | 2a18d1b3de8548a7b0f19a3a21ebf877                                |
+--------------------------------------+-----------------------------------------------------------------+
上一篇下一篇

猜你喜欢

热点阅读