将设为首页浏览此站
开启辅助访问 天气与日历 收藏本站联系我们切换到窄版

易陆发现论坛

 找回密码
 开始注册
查看: 271|回复: 2
收起左侧

openstack使用ansible nova配置

[复制链接]
发表于 2021-9-3 15:45:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?开始注册

x
/usr/lib/python2.7/site-packages/openstack/compute/v28 {  q( h0 |/ G$ Q
server.py* s% j% }, M8 V, f. Z5 W/ N
文件内容:
6 u, N. H  J8 t: ]$ q0 j3 A9 E, {, R5 |1 K6 W8 [4 S5 L" e
# Licensed under the Apache License, Version 2.0 (the "License"); you may' p4 [( S- |' Y3 l+ \, s1 X
# not use this file except in compliance with the License. You may obtain
. d- s" D5 H' R& w- f1 T# a copy of the License at
% B4 B5 C) j$ i+ m  l#
' r8 a: t8 z$ t; U2 `' j#      http://www.apache.org/licenses/LICENSE-2.0! L% _# n- z3 m" z
#3 l% [; A$ p# ?
# Unless required by applicable law or agreed to in writing, software
; v3 _$ D  a2 x9 z: y3 n9 X# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
8 ?; o& X' `- K) d& }$ j' L# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
, f# _& f8 a  I# License for the specific language governing permissions and limitations2 e1 D  `9 g: p+ E* N* {0 l
# under the License.
2 d2 B, @$ N) l8 u" y0 S6 j4 u9 afrom openstack.compute.v2 import metadata( u+ u5 J2 W" l8 p" O
from openstack.image.v2 import image
7 O5 k+ r0 G0 b. o1 s+ d2 F& S" J: I( Qfrom openstack import exceptions! Z9 {8 q3 r- z' ?6 v  r# F
from openstack import resource
; K9 a: e- l7 t* B" [from openstack import utils
2 O. Z1 o3 V0 J- h% v/ gCONSOLE_TYPE_ACTION_MAPPING = {
3 ~$ H3 R: s1 ^& W8 ^' o4 Q    'novnc': 'os-getVNCConsole',
1 K6 a5 w& H' K" d# k, B1 g    'xvpvnc': 'os-getVNCConsole',0 I# ^7 d+ N' E
    'spice-html5': 'os-getSPICEConsole',
+ Z0 \6 k$ s8 o. o3 x. }9 \1 L    'rdp-html5': 'os-getRDPConsole',1 G8 `, I8 T* J' l$ z  v' Q
    'serial': 'os-getSerialConsole'
) R$ o2 r0 A$ |% n8 T}
  }+ |" L0 ], J* r8 v* C% J4 f& Nclass Server(resource.Resource, metadata.MetadataMixin, resource.TagMixin):- x. G* l5 E2 b2 {8 ]
    resource_key = 'server'9 t' W. a2 \! C! I- _% B) N
    resources_key = 'servers'# E3 I% ~+ }3 x
    base_path = '/servers'( y" f: ^+ a2 d; V/ V; _
    # capabilities
6 o; [+ q* S- a" S: X( Y4 D& `# Z4 @    allow_create = True
; y# w- m. i% f    allow_fetch = True
: w- n, \. U) z/ e$ a    allow_commit = True; L3 Y. J. G/ z- M
    allow_delete = True# s6 ^7 s. n' L
    allow_list = True$ U/ `: l( X) e9 I
    _query_mapping = resource.QueryParameters(/ y0 m- ~2 \6 ~% \+ B5 Q- ^8 b
        "auto_disk_config", "availability_zone",
) v, h, R% B  k' k0 O' q) d        "created_at", "description", "flavor",: R3 b" {2 u6 ?/ h: q( m
        "hostname", "image", "kernel_id", "key_name",
( m, B! K' \' {8 }0 O8 A* ]- s; k        "launch_index", "launched_at", "locked_by", "name",+ V! p) p* \1 x6 l! P/ r. q& h
        "node", "power_state", "progress", "project_id", "ramdisk_id",/ n4 T, N1 c$ `! m; \+ I) ~
        "reservation_id", "root_device_name",7 O* G$ l0 P( @3 o- u3 ?; Q  h
        "status", "task_state", "terminated_at", "user_id",
1 C2 V6 G5 n4 p        "vm_state",3 _4 p( o* Q: t) l$ ^0 r
        "sort_key", "sort_dir",9 R; _1 F$ g3 @4 |' `0 m
        access_ipv4="access_ip_v4",
4 r$ I" G9 k$ c" r4 Z6 [        access_ipv6="access_ip_v6",
6 b$ b0 q# B7 k2 h- r        has_config_drive="config_drive",
7 i' z% v6 B" r! g7 ?        deleted_only="deleted",1 s4 B. {4 O+ e- m! c
        compute_host="host",- T$ Y  R' |+ W! _# u
        is_soft_deleted="soft_deleted",/ ?4 }* _. l+ I
        ipv4_address="ip",
2 _" |+ A! K% D/ }" s0 ]        ipv6_address="ip6",
" w1 B# ?+ k6 p6 y: J        changes_since="changes-since",
* H$ Z; D* X$ G7 L$ p4 R: `% w        changes_before="changes-before",6 H2 \9 }2 K0 B; z
        id="uuid",
& _7 z$ e% b+ E3 J1 }  m0 C        all_projects="all_tenants",( }  J2 A6 d5 `5 V! K/ @+ x) [
        **resource.TagMixin._tag_query_parameters
: Z+ r6 ?6 T- z3 i4 t, b0 S" s( F    )
, X. ^* u6 ~! H; g) R( N3 `    _max_microversion = '2.72'" p* k, i# P$ }6 |0 r1 u
    #: A list of dictionaries holding links relevant to this server.! L6 G8 u( ?( A6 ?: F. ]
    links = resource.Body('links')0 ^+ {' T: u9 Z1 e8 q
    access_ipv4 = resource.Body('accessIPv4'): T  R" T: J; s! b9 R8 V
    access_ipv6 = resource.Body('accessIPv6')- U5 w: q; ]! a) A. K! d5 r5 N1 f
    #: A dictionary of addresses this server can be accessed through.: b* N+ x: K) o9 I2 l9 f/ H
    #: The dictionary contains keys such as ``private`` and ``public``,, b* }' Z2 K, h  I: \
    #: each containing a list of dictionaries for addresses of that type.. ~# _- R+ Y+ I  `: l0 I' t
    #: The addresses are contained in a dictionary with keys ``addr``
0 v! J7 Q: g- z& E    #: and ``version``, which is either 4 or 6 depending on the protocol! f! C8 W* Q2 F. k& h$ D. W
    #: of the IP address. *Type: dict*$ V) W& E6 t5 v# ^% Z/ j, t1 I
    addresses = resource.Body('addresses', type=dict)
6 h) K1 d. Y, v0 k; E) H    #: When a server is first created, it provides the administrator password.' V3 D8 k. h" W( |
    admin_password = resource.Body('adminPass')9 `/ x8 p' N8 ?. b. T& a, q0 p& n
    #: A list of an attached volumes. Each item in the list contains at least* r/ H3 p  z/ P0 \8 C) [
    #: an "id" key to identify the specific volumes.8 `% o3 B. m) o8 O$ M) y
    attached_volumes = resource.Body(
, i+ ~  t: K/ B9 u        'os-extended-volumes:volumes_attached')
& ~4 c6 m" B6 j    #: The name of the availability zone this server is a part of.
+ y! e, e3 O2 g1 v    availability_zone = resource.Body('OS-EXT-AZ:availability_zone')0 g6 y1 L) j2 @, u( x
    #: Enables fine grained control of the block device mapping for an& U) I( o  y- c
    #: instance. This is typically used for booting servers from volumes.# z" ?/ h" D/ O
    block_device_mapping = resource.Body('block_device_mapping_v2')+ f+ d3 W) ?5 g1 A0 }( C
    #: Indicates whether or not a config drive was used for this server.8 t8 M, q) {( B) D4 n7 S7 n/ `
    config_drive = resource.Body('config_drive')# l1 q7 q# u: p2 U( Q2 L
    #: The name of the compute host on which this instance is running.& G0 S0 W3 y% {! s( F% \$ T- W
    #: Appears in the response for administrative users only.7 y6 b0 W9 V0 V
    compute_host = resource.Body('OS-EXT-SRV-ATTR:host'): k, O  l' e0 w) @( t5 V- w
    #: Timestamp of when the server was created.1 L9 f2 g2 o2 U& G4 i
    created_at = resource.Body('created')
: a1 l9 c" F1 q    #: The description of the server. Before microversion
4 x! w/ s9 a! z( D2 h: A- r' h    #: 2.19 this was set to the server name.* Y% Y) p6 f6 x# V7 k+ m! b# M
    description = resource.Body('description')
- G0 H+ R( j5 G$ `7 S- i& e    #: The disk configuration. Either AUTO or MANUAL.
# a/ a+ Z, s3 `9 S    disk_config = resource.Body('OS-DCF:diskConfig')  \. K, t8 j1 Y3 C1 s& ?
    #: The flavor reference, as a ID or full URL, for the flavor to use for- x: |7 \) S* L! t" Z
    #: this server./ a7 S( P% c3 r6 _% v% @7 V
    flavor_id = resource.Body('flavorRef')
" O9 w6 m# s5 |* y    #: The flavor property as returned from server.
3 `9 p: T' J' Q1 {9 i4 s: t# x    # TODO(gtema): replace with flavor.Flavor addressing flavor.original_name  B# _. k8 K0 x9 r) R1 L
    flavor = resource.Body('flavor', type=dict)7 m6 e4 r2 Q! S) e
    #: Indicates whether a configuration drive enables metadata injection.+ W8 S0 l! `. i3 S' G; L3 T
    #: Not all cloud providers enable this feature.
! P" h+ d& {2 i; f4 E    has_config_drive = resource.Body('config_drive')
0 ~$ U7 E6 Y+ {9 ^5 g1 t  i) O    #: An ID representing the host of this server.& v7 ^" T: F- ?) c. C3 v  g& F
    host_id = resource.Body('hostId')
3 A' f/ X. b% ~: t2 W! c0 `    #: The host status.
  u5 o7 S3 h$ Z7 z$ E4 {) s$ u* J    host_status = resource.Body('host_status')
* n: J( I; x4 e3 F7 c- m    #: The hostname set on the instance when it is booted.' A/ i1 }& G8 l& M4 ^& f; O" P
    #: By default, it appears in the response for administrative users only.$ Q9 P+ X! X% X( s$ H/ e  x
    hostname = resource.Body('OS-EXT-SRV-ATTR:hostname')
2 q. j+ j8 ^' G* r! d- j    #: The hypervisor host name. Appears in the response for administrative6 q& T4 M( ?8 A3 b3 s, B
    #: users only.
/ c: G0 @* R' [8 ~$ u    hypervisor_hostname = resource.Body('OS-EXT-SRV-ATTR:hypervisor_hostname')/ t0 J4 n- O6 B/ ^* R# N) f
    #: The image reference, as a ID or full URL, for the image to use for
. Q: X0 [( K% a    #: this server.
1 g  N1 D& E+ A! X: A    image_id = resource.Body('imageRef')
' E( P5 j4 C' F) z  W    #: The image property as returned from server.) {, S! U% }4 Y' k8 T( G
    image = resource.Body('image', type=image.Image)
. P6 ?: r, ~. F: p" R% k( h' B' s    #: The instance name. The Compute API generates the instance name from the+ m0 x! S8 v5 c7 ~; x
    #: instance name template. Appears in the response for administrative users
4 ]0 ^7 e. |) S    #: only.
) D8 k! I/ M5 b* c# [4 U- Q$ E    instance_name = resource.Body('OS-EXT-SRV-ATTR:instance_name')
- \% H# K* X/ Q- ]' i" [    # The locked status of the server' t# w4 v. m+ [
    is_locked = resource.Body('locked', type=bool)
  V: C0 e  z& K5 ?  _: c    #: The UUID of the kernel image when using an AMI. Will be null if not.* k- p8 [* k, K2 ~1 y6 A/ S/ k" J1 y& ^7 @
    #: By default, it appears in the response for administrative users only.
" }* |0 R1 I- t+ j    kernel_id = resource.Body('OS-EXT-SRV-ATTR:kernel_id')2 l4 Y+ N, y3 e
    #: The name of an associated keypair
( r' u2 `2 e/ S- w    key_name = resource.Body('key_name')
4 B% \7 E+ H: H5 F5 ~- h    #: When servers are launched via multiple create, this is the
* ^) Z! l( W1 f: K$ n5 q    #: sequence in which the servers were launched. By default, it
) K5 u- ~9 j. a% w. S- X) x- x    #: appears in the response for administrative users only.6 [  F7 J. C( {! m
    launch_index = resource.Body('OS-EXT-SRV-ATTR:launch_index', type=int)2 j7 I% i3 [) f& k. @
    #: The timestamp when the server was launched.
( H0 h- h1 _4 ^+ }/ X& @' s( E0 b2 }    launched_at = resource.Body('OS-SRV-USG:launched_at')& e; A! K$ E, z' z& k
    #: Metadata stored for this server. *Type: dict*
. e' D! J/ J' i6 D  E& O$ o0 o( _    metadata = resource.Body('metadata', type=dict)3 d$ h) w) F0 y
    #: A networks object. Required parameter when there are multiple
' T  D" H0 _! n# ^0 s+ ^( D    #: networks defined for the tenant. When you do not specify the. m% e* F, X& y" A8 {1 {) p+ [
    #: networks parameter, the server attaches to the only network2 X! S0 g" Q2 A/ @/ K/ L
    #: created for the current tenant.$ g' j( U  C+ E1 l3 O9 o& O
    networks = resource.Body('networks')
+ h: D; N. w6 w; j5 T( P    #: The file path and contents, text only, to inject into the server at0 m! k" Z, z3 G2 P+ }+ {
    #: launch. The maximum size of the file path data is 255 bytes.. O6 J: E- K9 O! }: i. V6 E9 h
    #: The maximum limit is The number of allowed bytes in the decoded,
+ V' H* Z4 A& Z; M5 ]3 n3 |; L- M( L    #: rather than encoded, data.7 T  c8 A5 J2 q( p5 Z& k5 N7 `: K2 {
    personality = resource.Body('personality'), f  T8 X; I- Q& b' x
    #: The power state of this server.
  A6 z( `. f0 N1 m    power_state = resource.Body('OS-EXT-STS:power_state')
6 \6 y9 Y& `% o% W2 N$ Q    #: While the server is building, this value represents the percentage' a- m" {  C8 d0 f# z7 F
    #: of completion. Once it is completed, it will be 100.  *Type: int*% S5 o3 t. y- }
    progress = resource.Body('progress', type=int)* f' T0 V: Q; D8 ~7 O9 d
    #: The ID of the project this server is associated with.- {1 a& U  u  [3 I
    project_id = resource.Body('tenant_id')
, t% }2 W4 \9 ~( f9 t# o& l& _1 I    #: The UUID of the ramdisk image when using an AMI. Will be null if not.
* ?9 o6 x( H4 B7 Y$ L, P    #: By default, it appears in the response for administrative users only.# H( X1 _2 ~! N
    ramdisk_id = resource.Body('OS-EXT-SRV-ATTR:ramdisk_id')
  {, C: ~6 C$ }$ w6 }# s* K: ~    #: The reservation id for the server. This is an id that can be  X- _7 ^2 Y3 ^1 B8 E' Y6 J% d( Z8 u1 H
    #: useful in tracking groups of servers created with multiple create,
0 Y( H9 U" [7 s' W, @    #: that will all have the same reservation_id. By default, it appears
- |( {4 q1 Q/ @    #: in the response for administrative users only.+ Y8 g6 U. T* [% f$ E2 b8 v, @
    reservation_id = resource.Body('OS-EXT-SRV-ATTR:reservation_id')
( q6 Y" Z) g! G) L' {    #: The root device name for the instance By default, it appears in the
! j& J5 |$ {; Y) f  J# c6 {9 A: ~    #: response for administrative users only." i0 Z# Z% t$ b0 @: l- @* \& N
    root_device_name = resource.Body('OS-EXT-SRV-ATTR:root_device_name')
, A6 _% d' Z4 g! E    #: The dictionary of data to send to the scheduler.
. b3 M' K  k. A* J$ C' s# Q" n    scheduler_hints = resource.Body('OS-SCH-HNT:scheduler_hints', type=dict)
# {4 d( V# v) i- D    #: A list of applicable security groups. Each group contains keys for
$ m; C& @  y9 S' m    #: description, name, id, and rules.
" G8 q8 @1 {7 D/ j! G9 x3 Z    security_groups = resource.Body('security_groups',0 U: t: ]; R( A, [2 p  D
                                    type=list, list_type=dict)6 I% f2 o: ]% ~: s# u. y9 a9 }
    #: The UUIDs of the server groups to which the server belongs.; C# t+ j* {- D; k* d2 S7 s
    #: Currently this can contain at most one entry.5 D- w) T2 ~5 Y, H( {
    server_groups = resource.Body('server_groups', type=list, list_type=dict)9 Y- @$ r% |  y# t5 e
    #: The state this server is in. Valid values include ``ACTIVE``,+ Y) r$ e. ]4 ~+ k
    #: ``BUILDING``, ``DELETED``, ``ERROR``, ``HARD_REBOOT``, ``PASSWORD``,
; H# U; N7 C( S5 f/ q3 c+ {    #: ``PAUSED``, ``REBOOT``, ``REBUILD``, ``RESCUED``, ``RESIZED``,$ m8 o' }& Q# ]) e
    #: ``REVERT_RESIZE``, ``SHUTOFF``, ``SOFT_DELETED``, ``STOPPED``,7 t# ~8 X4 G3 z  @( W% }; ~5 |
    #: ``SUSPENDED``, ``UNKNOWN``, or ``VERIFY_RESIZE``.: S) A3 |# O' O2 j, W! e
    status = resource.Body('status')
+ c. F# H+ v, e8 |    #: The task state of this server.
% w" [% F  }* c6 h8 ^* s) |% x1 U; n    task_state = resource.Body('OS-EXT-STS:task_state')
% U: m; ~& t3 G- z/ w! o6 O    #: The timestamp when the server was terminated (if it has been).
' ]4 }" C$ v( m: @    terminated_at = resource.Body('OS-SRV-USG:terminated_at')5 B# j2 U+ i- z  p
    #: A list of trusted certificate IDs, that were used during image1 e8 i. G5 `: k2 n. E& m
    #: signature verification to verify the signing certificate.
3 z. q' e8 h8 N- g' t2 a( M    trusted_image_certificates = resource.Body(
7 P. A, c" Q* n4 v$ {5 J        'trusted_image_certificates', type=list). l8 s2 m0 I9 x; o& k
    #: Timestamp of when this server was last updated.
4 s6 S9 r3 ?) \3 L5 @    updated_at = resource.Body('updated')
" T9 q1 @( K( a    #: Configuration information or scripts to use upon launch.) n2 l' R% H0 u3 G1 O4 a
    #: Must be Base64 encoded.& Z8 i5 _/ Y1 C& H
    user_data = resource.Body('OS-EXT-SRV-ATTR:user_data')1 T9 t' N5 T' J, s1 m9 z+ N/ q
    #: The ID of the owners of this server.
  R3 A0 S  Y' I  f* r2 @) h2 X    user_id = resource.Body('user_id')9 E% Q2 v8 P" C# c3 w9 [2 Q: N7 Z
    #: The VM state of this server.
# H/ I5 H4 M; {9 n, N7 u6 h    vm_state = resource.Body('OS-EXT-STS:vm_state')
5 K+ u6 X3 G3 Y, J4 @/ e    def _prepare_request(self, requires_id=True, prepend_key=True,
# c( z  R8 V+ E  C' r                         base_path=None, **kwargs):1 K. i% p7 n% @) R
        request = super(Server, self)._prepare_request(requires_id=requires_id,
, P: y) Q5 m& p: m: b' h/ k                                                       prepend_key=prepend_key,1 O% v+ p, H# G9 N$ C/ {, ?5 u! [
                                                       base_path=base_path)
* K1 j) L/ [* ?' j. M) |        server_body = request.body[self.resource_key]
0 T0 g" G# y! I& k* l! `! f        # Some names exist without prefix on requests but with a prefix: E9 z, n! `. E  c
        # on responses. If we find that we've populated one of these) C, W) S. m1 {7 S3 o/ x- @; q
        # attributes with something and then go to make a request, swap out( c# v5 ~8 m& ~; ]
        # the name to the bare version.- o' N- n9 s! J# V+ R0 l
        # Availability Zones exist with a prefix on response, but not request) k' k$ V, {( j2 B
        az_key = "OS-EXT-AZ:availability_zone"+ D. ~- @5 a) ]% Q/ `
        if az_key in server_body:) ^4 o/ u! Z4 N, E7 n% p4 w# I
            server_body["availability_zone"] = server_body.pop(az_key)
# `2 ]: A) O( @1 I, _  ?        # User Data exists with a prefix on response, but not request
4 _3 {7 ]% |/ w: E0 w8 |) i        ud_key = "OS-EXT-SRV-ATTR:user_data") k& @! N& d1 w. }
        if ud_key in server_body:
/ f* P7 g% t" \0 {, e0 P  D            server_body["user_data"] = server_body.pop(ud_key)4 W1 j" e  F* p) I
        # Scheduler hints are sent in a top-level scope, not within the
1 A$ @) N2 L7 f- `  L        # resource_key scope like everything else. If we try to send
, d' h- d. O) \. Z* \8 U6 m4 d        # scheduler_hints, pop them out of the resource_key scope and into% R% ^. X+ R# Y3 h( x
        # their own top-level scope.. g* }0 s. k; d' n: I4 r
        hint_key = "OS-SCH-HNT:scheduler_hints"
8 m; D( r  X% M# s! z        if hint_key in server_body:* R. U* y- A7 x2 }' a' V
            request.body[hint_key] = server_body.pop(hint_key)
& v- d; [! Y" ^' X        return request
) F3 D2 i1 [! u( j& \% U' }    def _action(self, session, body, microversion=None):0 h# U( Q  [% q2 E' ?2 O! ^: m8 ]
        """Preform server actions given the message body."""4 i" \+ y, q/ {# U' j7 }4 s
        # NOTE: This is using Server.base_path instead of self.base_path$ f( c2 g1 Y8 i1 G9 z8 }
        # as both Server and ServerDetail instances can be acted on, but( l3 _! D9 z( a
        # the URL used is sans any additional /detail/ part.
6 v8 r% N+ o* C8 ^/ Z        url = utils.urljoin(Server.base_path, self.id, 'action'): y1 P8 b& {) |
        headers = {'Accept': ''}
* w, q5 Y! Y& C4 k# l        response = session.post($ k' F: F- F! U
            url, json=body, headers=headers, microversion=microversion)9 [+ B( e8 X6 v0 _& n. j
        exceptions.raise_from_response(response)
; ^( F  i3 {. c4 F4 F* Z# p) S! T. R        return response- T$ h: Z% c8 G# b
    def change_password(self, session, new_password):
' j% Q$ j0 ]# r+ r3 N# d* q        """Change the administrator password to the given password."""$ e' j3 X" j: J
        body = {'changePassword': {'adminPass': new_password}}$ n. O) ?8 \; b& h4 H
        self._action(session, body)
, L% ]# q& H2 j) `. m# |! J    def get_password(self, session):
* \! T# S' I8 h, ~3 p2 ~) _        """Get the encrypted administrator password."""  e5 i5 {. p. N% P- x$ d0 X' s
        url = utils.urljoin(Server.base_path, self.id, 'os-server-password')
! m: S; `+ v/ x9 s; Z        return session.get(url)+ ~8 d2 Q5 v: m- Q
    def reboot(self, session, reboot_type):+ H- H# @3 t7 c- }3 O4 b) Q
        """Reboot server where reboot_type might be 'SOFT' or 'HARD'."""
3 W6 R( t- L6 c5 `0 Q9 T1 Q        body = {'reboot': {'type': reboot_type}}+ B8 F7 G7 L9 L/ o' K  {- e
        self._action(session, body)
) D! w" O  p4 \    def force_delete(self, session):' o, a7 ^( {: T5 y% {& h- ]) N
        """Force delete a server."""3 G4 k$ w( X7 {) P+ M2 }% k! J
        body = {'forceDelete': None}7 K+ L% Z; d; U7 H: E# D
        self._action(session, body)
6 g+ \+ D. g& U7 w5 l! {    def rebuild(self, session, name, admin_password,
8 u* b- N! A1 p) G4 G: f                preserve_ephemeral=False, image=None,
6 G3 @+ g9 e1 f7 N5 i9 K                access_ipv4=None, access_ipv6=None,
* _& [* y# y; c' Z                metadata=None, personality=None):
( {1 w) R: k8 G/ G2 G  r9 G        """Rebuild the server with the given arguments."""
, Z9 y+ o1 U8 h& o) ]        action = {0 T. s7 a1 N$ c! O$ M
            'name': name,2 H+ \$ ]0 j! r! [6 n' ~
            'adminPass': admin_password,
1 M: W) \1 J, g% @% x9 l8 K) F            'preserve_ephemeral': preserve_ephemeral: z0 q8 R2 ]3 W% S) R( s
        }
9 @( b% d% m6 k* a        if image is not None:
- Q1 j0 y2 z* d6 B8 Z: f            action['imageRef'] = resource.Resource._get_id(image)
! [2 \+ f! I& Y# Y        if access_ipv4 is not None:
$ a! \4 t3 f  i" P            action['accessIPv4'] = access_ipv44 |& A% y" n: S; x
        if access_ipv6 is not None:- @" D# U% {' H1 U
            action['accessIPv6'] = access_ipv6
$ u7 u; p# ]3 P9 c$ m: ]        if metadata is not None:8 J. G1 i" ]! R' W
            action['metadata'] = metadata( a; l' |5 ?' Q2 B9 Q
        if personality is not None:
/ l3 Y, b3 i  `2 z" y            action['personality'] = personality
$ j1 P, j$ \! n: K* I; s1 x        body = {'rebuild': action}- j1 r) t8 h8 I, B- L
        response = self._action(session, body)
; @! |1 P* L' p3 Z8 G        self._translate_response(response)
' P9 M) {) D7 G* ^2 P! }. n        return self
: F0 }  I9 l- @4 x, R    def resize(self, session, flavor):
5 I1 \( k' d: _9 O: \- e( ~        """Resize server to flavor reference."""
3 j3 A! _" P/ ^, P, O        body = {'resize': {'flavorRef': flavor}}
4 C: `$ t8 d, H/ y; P        self._action(session, body)
0 f. n$ ?1 T; ~+ {+ |) B8 @    def confirm_resize(self, session):
" a  ^4 D' }9 Z7 J; t% q: D        """Confirm the resize of the server."""5 Y; y" W# s, @9 y; l7 g8 n
        body = {'confirmResize': None}) a* ]4 Q: N4 c+ m& M% u
        self._action(session, body)
) I1 t# G' o6 i' b+ s! Z# b    def revert_resize(self, session):
( W9 {5 N$ |$ c6 X4 b+ p        """Revert the resize of the server."""  }* [0 n$ C. R% A; l+ @
        body = {'revertResize': None}% }2 ~. }  E. B7 b7 d
        self._action(session, body)- I7 F/ ]0 a. i( w- q9 \
    def create_image(self, session, name, metadata=None):9 F8 g2 S9 s: F" t, E* ]6 L
        """Create image from server."""! _7 f* m, V# ]% J! U
        action = {'name': name}. S# |5 s( E7 i! i
        if metadata is not None:$ M3 z8 H- c! ?$ ^* Q3 \+ q
            action['metadata'] = metadata
5 U, x/ \; i, _# a6 A+ G6 p        body = {'createImage': action}
3 Q' @) u( f" @        # You won't believe it - wait, who am I kidding - of course you will!8 h6 X( u. R" ]: r. V) d2 r* d5 b2 [
        # Nova returns the URL of the image created in the Location! u: z4 N) A9 x
        # header of the response. (what?) But, even better, the URL it responds
6 N! ~' M. L4 O2 Z        # with has a very good chance of being wrong (it is built from" _' d1 m. D: i$ c* w! M, `/ J* p# u
        # nova.conf values that point to internal API servers in any cloud( [5 Z# K/ S( v' y  w) t
        # large enough to have both public and internal endpoints.3 I! b/ s/ ]% d# l$ S0 w
        # However, nobody has ever noticed this because novaclient doesn't
# f8 q, m0 v) W! Y9 d4 b        # actually use that URL - it extracts the id from the end of" V, a/ i& e: q) r' S
        # the url, then returns the id. This leads us to question:
$ a. r6 a# M: L        #   a) why Nova is going to return a value in a header
, C* S4 {; m1 |5 @+ e0 }  o( d# @        #   b) why it's going to return data that probably broken
$ A7 o% E, T% Y3 r        #   c) indeed the very nature of the fabric of reality
1 S2 [' M: P, r0 N2 m9 L        # Although it fills us with existential dread, we have no choice but
" ~8 `% W" s, @        # to follow suit like a lemming being forced over a cliff by evil
& D9 H5 U; L3 m# V* e- F* g* t        # producers from Disney.
) P/ f* L6 S( J) o2 i: F8 ?  @$ U        microversion = None& j7 [0 R8 U5 r1 K3 w; F
        if utils.supports_microversion(session, '2.45'):6 Z& f  w& |6 L- T5 c+ h
            microversion = '2.45'+ Z. E" P, ?+ L* c2 ]
        response = self._action(session, body, microversion)1 D5 ^+ o4 T( y/ t. c. J8 E/ O/ ~
        body = None$ v/ W8 _& h; \
        try:
* F2 ^7 b, D& s& j4 G            # There might be body, might be not
$ S8 \/ \$ W! i2 a" m            body = response.json()$ [/ j3 ^& R8 }$ T/ ?
        except Exception:
# K1 |* g/ m- q# |! L            pass
2 {3 }1 s5 R& \0 y3 D1 b8 {/ W        if body and 'image_id' in body:  S3 ?2 n8 W2 g! k0 o
            image_id = body['image_id']
+ _; M: J( l2 ^2 Y! m/ U" K( A. v        else:
- ^" F" ]3 Y& a- u) _            image_id = response.headers['Location'].rsplit('/', 1)[1]
  E4 H+ T+ o5 [% s& R' i        return image_id
. Q7 Y  }0 J, q. p    def add_security_group(self, session, security_group_name):
$ a* ?6 {& F! t; U* h* t+ c        body = {"addSecurityGroup": {"name": security_group_name}}
9 m, u+ R5 y  O( p- J* c3 F6 k        self._action(session, body)
# a' W+ K6 _  B! G    def remove_security_group(self, session, security_group_name):
4 E6 \5 n- C$ }2 B1 f0 L        body = {"removeSecurityGroup": {"name": security_group_name}}& R" G5 g; N) j6 S9 N' R) S1 H
        self._action(session, body)
7 s" a. ?; [$ @. g. S- r    def reset_state(self, session, state):
. b# y  k0 F  w: R        body = {"os-resetState": {"state": state}}
7 n- i9 T& g  q- k% s        self._action(session, body)
9 j4 t; s1 {5 _5 z" f+ ~! p    def add_fixed_ip(self, session, network_id):
  @- Y3 Z1 _+ e$ }2 }. N: W        body = {"addFixedIp": {"networkId": network_id}}
, N! c, v9 H/ n# O; z4 J  @        self._action(session, body)+ k4 i7 x8 ^/ L  F9 Z
    def remove_fixed_ip(self, session, address):- j. r2 t) H# B0 N9 y. Q% i! J1 K# F
        body = {"removeFixedIp": {"address": address}}; i# v' w# m0 @4 ?2 d
        self._action(session, body)
! H4 X! Z& ]* g$ O, H5 k( b    def add_floating_ip(self, session, address, fixed_address=None):5 \3 j3 y4 b9 ?5 l: w
        body = {"addFloatingIp": {"address": address}}
* d& |# |+ e/ Q( Q8 q8 j% b        if fixed_address is not None:
+ d/ k. O" s6 g            body['addFloatingIp']['fixed_address'] = fixed_address3 C8 y9 c/ a' m4 }- Z$ i
        self._action(session, body)
& B. o5 V9 h3 m    def remove_floating_ip(self, session, address):
9 u5 E0 U* z8 i        body = {"removeFloatingIp": {"address": address}}
% {$ z* T2 @2 q        self._action(session, body)  h9 e  S2 n, H. q# [: _) N
    def backup(self, session, name, backup_type, rotation):
+ K% T5 b. V$ t; y6 D$ K; j% W        body = {) y  \/ t& k3 P+ z- E
            "createBackup": {
" i' k9 N  g0 i                "name": name,
% d5 W0 N# r; g' ~# N# t                "backup_type": backup_type,$ E+ [2 R- T! [, D- [' x5 u0 m
                "rotation": rotation
4 d  W% o+ M5 t            }
8 S# `5 k, u; T7 L1 e        }; U. N8 V+ _1 J5 l* P9 N3 f8 j
        self._action(session, body)% X0 O; |1 y5 e+ e) F" I
    def pause(self, session):
7 L( w) X! S: i        body = {"pause": None}% Y- M7 P% O7 k9 X+ _
        self._action(session, body)
& i& f8 z. U: a  |    def unpause(self, session):( ^3 `/ f. y5 l
        body = {"unpause": None}$ p7 ]  f8 H' e* s- `
        self._action(session, body); |& g: k4 j. r+ ]
    def suspend(self, session):3 e4 x5 v  ?" l
        body = {"suspend": None}9 ^# v% X, j. Y1 e1 E
        self._action(session, body)
8 T7 z/ L' G# ]# u    def resume(self, session):4 J0 j0 h2 z2 C5 ?0 B
        body = {"resume": None}
% ^' J; S' y4 [        self._action(session, body)
+ i( r5 x; h% q  \    def lock(self, session):. V* t9 s& f+ R. C
        body = {"lock": None}
  Z3 {3 E2 y3 i8 w/ R        self._action(session, body)1 G" ^  u+ K5 i- f" U; X8 Q
    def unlock(self, session):. w8 J6 e& C+ W( q( i0 K
        body = {"unlock": None}
' J9 N( d( b/ f) @        self._action(session, body)# z) o4 o9 n# x3 `6 ?
    def rescue(self, session, admin_pass=None, image_ref=None):
: p( D- ~% M. K- n        body = {"rescue": {}}
. g. X: f, z$ F, x4 U        if admin_pass is not None:6 ^/ |& T( v" S1 g: u
            body["rescue"]["adminPass"] = admin_pass$ [, O+ `5 Z  W- a8 @
        if image_ref is not None:3 Y' A: s2 i; h" X  U5 b
            body["rescue"]["rescue_image_ref"] = image_ref* Y% g; e7 y( U3 \* E" b% |" m& Q
        self._action(session, body)* u5 ]0 H; v8 y; M" m
    def unrescue(self, session):
+ g8 n6 n- ?; e5 J9 `$ @        body = {"unrescue": None}
% ^7 \2 w7 e1 K' ~+ Y( n9 G( o, D2 u        self._action(session, body)7 F2 C' ]0 b* X" m5 x# C. }; S
    def evacuate(self, session, host=None, admin_pass=None, force=None):
6 L7 J# f# g8 l9 v+ K        body = {"evacuate": {}}6 V$ [, c3 V$ o' U; w# q2 z& U  s
        if host is not None:
: C; R7 X# t, H, p+ w5 `            body["evacuate"]["host"] = host
  Z6 Z+ X3 t9 {2 }4 ^; Q& u        if admin_pass is not None:0 M4 ^, W* [8 p9 d; b
            body["evacuate"]["adminPass"] = admin_pass
+ D9 H+ B8 Y+ A! C$ N4 |        if force is not None:
1 G1 D9 v- [9 i/ J& L; G" I- m- h. {/ e& T            body["evacuate"]["force"] = force
( i$ E/ V$ A  X' u        self._action(session, body)* y- j# `1 D6 S5 P0 i  {
    def start(self, session):
( A% o& ~  x5 |# c* ^" f7 a        body = {"os-start": None}
% i  S+ t; M# `$ m2 o, q# m3 O, c        self._action(session, body)
( B& p/ t) j  b( ^6 ]4 L# i  ]    def stop(self, session):
$ N& g8 @5 j4 \* W        body = {"os-stop": None}, w, G- E) P7 K# Q
        self._action(session, body): E2 \# T$ X: n9 G3 A
    def shelve(self, session):
9 }: G1 D4 i6 ?' ~5 X; a        body = {"shelve": None}
* X5 e3 F1 }/ Y% @5 G        self._action(session, body)  o. D: F; M; T8 H7 h5 _
    def unshelve(self, session):/ D- E7 t0 R. ]; F& ?" {
        body = {"unshelve": None}( V" y9 P( c' k0 j7 h
        self._action(session, body)
& ~" J% @, l% c! ^4 o8 D& f# P: |" R% Y    def migrate(self, session):
# E' m5 P: A' b4 B        body = {"migrate": None}" B* B# o5 e& a
        self._action(session, body)
' G- ?* {& ^/ v  E3 s/ L    def get_console_output(self, session, length=None):$ L9 M. r! ]0 j) b
        body = {"os-getConsoleOutput": {}}& u$ m$ n, p7 J
        if length is not None:
6 j" {: t" U. F" Q* {$ W            body["os-getConsoleOutput"]["length"] = length  y0 }7 e4 L+ I, g' e/ @
        resp = self._action(session, body)
+ Q1 k" v# [" i# W, Q% G& L) N        return resp.json()* ~4 m; h1 S+ H% L, u
    def get_console_url(self, session, console_type):/ k4 q1 D- S$ O# ^# l; O# T
        action = CONSOLE_TYPE_ACTION_MAPPING.get(console_type)
9 s* e, F9 E5 O- O$ V& `) A/ W3 X        if not action:
2 G: i) q% j# f( l, u            raise ValueError("Unsupported console type %s" % console_type)* }: }8 w  ^, n9 H
        body = {action: {'type': console_type}}* J! q9 }& W, W. K
        resp = self._action(session, body)
5 U( U& x1 B6 [, e: y4 q        return resp.json().get('console')
! R+ O! F) `# W6 v8 u; C    def live_migrate(self, session, host, force, block_migration,( ]9 @! ?1 W4 T
                     disk_over_commit=False):
7 A: p, l1 T) H, C& j# G3 @        if utils.supports_microversion(session, '2.30'):
( B+ P7 A/ {5 [; o% z1 D: N            return self._live_migrate_30(. S: ~% @1 g2 ]. T
                session, host,1 f1 D! P- s3 c8 v6 {; k3 s
                force=force,
+ s* ~1 O( V+ B- B9 h5 a                block_migration=block_migration)# D2 m6 p# l5 m* {; e
        elif utils.supports_microversion(session, '2.25'):' t8 }' L* R% X
            return self._live_migrate_25(
, M# ]+ K4 R5 W# R" q                session, host,
9 ]5 a9 K3 s1 ^                force=force,5 v; G, ^. J2 T. H0 X
                block_migration=block_migration)
: w9 J4 F& j- z0 c+ P1 q; }        else:
: ]( r% @6 @+ w$ t, ?/ M, |# k1 [$ V            return self._live_migrate(
+ D# m6 t7 [2 [, z8 l  @                session, host,! X$ I# U& |" b8 G0 O! u) G
                force=force,' l+ i; b! r! Z5 w  t
                block_migration=block_migration,
  \% R0 \( J1 ?' ?. \6 c                disk_over_commit=disk_over_commit)
  Z+ g2 `. s2 T' U, x# I    def _live_migrate_30(self, session, host, force, block_migration):! }$ k5 x! E/ P. B4 E& W
        microversion = '2.30'
/ M- S: i' k! H& ]( n        body = {'host': None}
) n% E2 P* w: \9 h% O$ L        if block_migration is None:
! d8 ?1 X# E2 O7 _+ h            block_migration = 'auto'
9 \$ a( o. Y& X" K  p9 r& F# \. w0 @        body['block_migration'] = block_migration/ O- j" E, W9 x) f' e7 {% n& ^
        if host:
# r& ^4 z3 @! o9 j; F) d( ~' H            body['host'] = host7 Y& H% g9 [! l. L: T
            if force:! J# u- p7 k+ h, R) j+ O
                body['force'] = force
0 S6 l3 T- C* s        self._action(
  Z- M8 U  O2 A: a. n$ q            session, {'os-migrateLive': body}, microversion=microversion)( v: a' K( N( E5 p! m& o' W
    def _live_migrate_25(self, session, host, force, block_migration):1 [5 c* M. ~  c- H3 X' A
        microversion = '2.25'
* F4 X$ o: k2 N# ?# a        body = {'host': None}% u# s3 V0 o, q
        if block_migration is None:
- n. A. ]- J: v0 p: N1 g% U+ x1 f% l            block_migration = 'auto'4 j. v- Q2 X" T( _- ?
        body['block_migration'] = block_migration
5 o# G( k6 t2 y/ l- T: d; ^7 L        if host:
3 ?' |" u- T6 C8 f( ~" p            body['host'] = host
5 z  ]. ^( [( K3 I            if not force:+ X1 b1 d% }/ P. B
                raise ValueError(
) u. d' k! L8 L" c5 |                    "Live migration on this cloud implies 'force'"
  c0 w# U6 _1 @+ R, n                    " if the 'host' option has been given and it is not"" V+ }2 a5 X# z; J( k
                    " possible to disable. It is recommended to not use 'host'"
" g: H' C5 q7 U9 U. m% Y; [                    " at all on this cloud as it is inherently unsafe, but if"
! k3 X, n) ^- S                    " it is unavoidable, please supply 'force=True' so that it"
9 i  j: A1 |2 x+ ~2 S                    " is clear you understand the risks."): P/ ^6 t5 z# _& z2 _, o
        self._action(
7 {' J0 u1 n' a. B            session, {'os-migrateLive': body}, microversion=microversion): b5 D# a. a0 m
    def _live_migrate(self, session, host, force, block_migration,
+ K" v- j! p, M3 \; q# v7 {                      disk_over_commit):- ^: X0 b3 _6 E3 L% v' x
        microversion = None
" X- W2 I8 q+ y# N        body = {1 j' i0 S4 `1 P3 S  [
            'host': None,
, X# R9 R# \6 Y        }, p  R1 K  @% ~/ q( S" h
        if block_migration == 'auto':6 _+ c: h7 H; }7 I4 A# @8 G* g& x# A
            raise ValueError(
: e  j4 k0 Z4 a6 f                "Live migration on this cloud does not support 'auto' as"
: {9 q  |2 ~# ?6 r& @; J# g+ l3 V5 r                " a parameter to block_migration, but only True and False.")
: L7 q0 g; |9 q/ Y        body['block_migration'] = block_migration or False5 I& C1 Q3 g3 C/ N" K4 L$ F% }
        body['disk_over_commit'] = disk_over_commit or False# c4 p: Z' ~1 b5 a
        if host:0 o% s" V/ o( r1 H; O
            body['host'] = host4 @" C. H3 _# a' l9 V
            if not force:: i9 `0 }9 F/ {! [! m. R$ |. V9 P
                raise ValueError(1 ~6 g" `7 E0 ~2 ^/ f2 h
                    "Live migration on this cloud implies 'force'") M0 X- W# g$ K7 d9 n
                    " if the 'host' option has been given and it is not"
% w% ]* P% r# V, d+ F1 N3 P                    " possible to disable. It is recommended to not use 'host'"
- `& k6 L) E* V, s0 W- y                    " at all on this cloud as it is inherently unsafe, but if"
! L5 ]  T+ P( D' }5 Z0 \8 B# l9 i                    " it is unavoidable, please supply 'force=True' so that it"
9 g1 S; K1 S" i                    " is clear you understand the risks.")8 A2 X$ D, Z2 }& x( v; M; c
        self._action(; w' f1 _) w8 {( }$ I4 K% C0 U( y
            session, {'os-migrateLive': body}, microversion=microversion)# {* p1 C1 D0 u
    def fetch_security_groups(self, session):
7 c5 N$ r3 L9 S4 M0 X, y7 f        """Fetch security groups of a server.1 J, \" \, W$ i) t' X1 s
        :returns: Updated Server instance.' s0 S8 r4 V+ L- k
        """4 @2 v" N, H+ G+ q) |% m% T
        url = utils.urljoin(Server.base_path, self.id, 'os-security-groups')
2 c- q- ?, \5 V; k- v6 Z3 e: w        response = session.get(url)
& L$ l* _& B  Z* Q        exceptions.raise_from_response(response)
! E- N4 R8 Y, r( `! _        try:0 y' w+ o2 G5 {& {% U) p
            data = response.json()9 X( G* Y3 J/ x3 N
            if 'security_groups' in data:* P. x8 k" d! {# ~
                self.security_groups = data['security_groups']2 ]* W* H/ ^% A. o  E
        except ValueError:$ q- g8 e# g! f  l: C0 W( v
            pass
$ ]- L  [3 |+ i0 b2 X7 r3 g        return self( O& v2 I5 A* `. q) R
) {; ^/ J3 U; }/ Z1 [
ServerDetail = Server
: g/ N  ]7 Y3 n! |: F
* ~* ^, N- M; f# L2 ~8 Y6 S" r5 ]- Y4 g$ l0 n. v1 `
 楼主| 发表于 2021-9-3 15:49:26 | 显示全部楼层
openstack.tar.gz (1.68 MB, 下载次数: 0, 售价: 5 金钱)
 楼主| 发表于 2021-9-3 15:52:54 | 显示全部楼层
ansible task 9 b$ U) e- T, w) Y, L1 ]$ K
ansible-playbook xxxx.yml; c" L9 }3 l8 W* W% y9 n% k6 i

instence.tar.gz

2.22 KB, 下载次数: 0

售价: 5 金钱  [记录]  [购买]

您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

如有购买积分卡请联系497906712

QQ|返回首页|Archiver|手机版|小黑屋|易陆发现 点击这里给我发消息

GMT+8, 2021-10-28 16:42 , Processed in 0.061329 second(s), 25 queries .

Powered by LR.LINUX.cloud bbs168x X3.2 Licensed

© 2012-2022 Comsenz Inc.

快速回复 返回顶部 返回列表