2.Openstack基本操作

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 ] [--image ]
                 [--image-with ] [--boot-volume ]
                 [--snapshot ] [--min-count ]
                 [--max-count ] [--meta ]
                 [--key-name ] [--user-data ]
                 [--availability-zone ]
                 [--security-groups ]
                 [--block-device-mapping ]
                 [--block-device key1=value1[,key2=value2...]]
                 [--swap ]
                 [--ephemeral size=[,format=]]
                 [--hint ]
                 [--nic ]
                 [--config-drive ] [--poll] [--admin-pass ]
                 [--access-ip-v4 ] [--access-ip-v6 ]
                 [--description ] [--tags ]
                 [--return-reservation-id]
                 

Boot a new server.

Positional arguments:
                          Name for the new server.

Optional arguments:
  --flavor              Name or ID of flavor (see 'nova flavor-list').
  --image                Name or ID of image (see 'glance image-list').
  --image-with       Image metadata property (see 'glance image-
                                show').
  --boot-volume      Volume ID to boot from.
  --snapshot       Snapshot ID to boot from (will create a
                                volume).
  --min-count           Boot at least  servers (limited by
                                quota).
  --max-count           Boot up to  servers (limited by
                                quota).
  --meta             Record arbitrary key/value metadata to
                                /meta_data.json on the metadata server. Can be
                                specified multiple times.
  --key-name          Key name of keypair that should be created
                                earlier with the command keypair-add.
  --user-data        user data file to pass to be exposed by the
                                metadata server.
  --availability-zone 
                                The availability zone for server placement.
  --security-groups 
                                Comma separated list of security group names.
  --block-device-mapping 
                                Block device mapping in the format =:::.
  --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             Create and attach a local swap block device of
                                 MB.
  --ephemeral size=[,format=]
                                Create and attach a local ephemeral block
                                device of  GiB and format it to
                                .
  --hint             Send arbitrary key/value pairs to the
                                scheduler for custom use.
  --nic 
                                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         Enable config drive.
  --poll                        Report the new server boot progress until it
                                completes.
  --admin-pass           Admin password for the instance.
  --access-ip-v4         Alternative access IPv4 of the instance.
  --access-ip-v6         Alternative access IPv6 of the instance.
  --description    Description for the server. (Supported by API
                                versions '2.19' - '2.latest')
  --tags                  Tags for the server.Tags must be separated by
                                commas: --tags  (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                                |
+--------------------------------------+-----------------------------------------------------------------+

你可能感兴趣的:(2.Openstack基本操作)