Skip to content

Instantly share code, notes, and snippets.

@ccamacho
Created April 25, 2020 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccamacho/9eb7f3f21ba4fe5fc84c634cb09364d1 to your computer and use it in GitHub Desktop.
Save ccamacho/9eb7f3f21ba4fe5fc84c634cb09364d1 to your computer and use it in GitHub Desktop.
asdf
class Server(resource.Resource):
resource_type = const.RES_TYPE_SERVER
sdk_class = openstack.compute.v2.server.Server
info_from_sdk = [
'addresses',
'id',
'status',
]
params_from_sdk = [
'name',
]
params_from_refs = [
'flavor_name',
'security_group_names',
]
# TODO: Check there is no flavor_id only 'original_name'
# @classmethod
# def from_sdk(cls, conn, sdk_resource):
# obj = super(Server, cls).from_sdk(conn, sdk_resource)
# obj.info()['flavor_id'] = sdk_resource['flavor']['id']
# return obj
@staticmethod
def _find_sdk_res(conn, name_or_id):
return conn.compute.find_server(name_or_id)
@staticmethod
def _refs_from_sdk(conn, sdk_res):
refs = {}
# TODO: Check, sometimes there is no ID, only 'original_name'
refs['flavor_name'] = reference.server_flavor_name(
conn, sdk_res['flavor']['original_name'])
# conn, sdk_res['flavor']['id'])
# TODO: Check fetching the flavor ID from the SDK
refs['flavor_id'] = reference.server_flavor_id(
conn, sdk_res['flavor']['original_name'])
refs['security_group_names'] = [security_group['name'] for
security_group in
sdk_res['security_groups']]
return refs
def _refs_from_ser(self, conn):
refs = {}
refs['flavor_name'] = self.params()['flavor_name']
refs['flavor_id'] = reference.server_flavor_id(
conn, self.params()['flavor_name'])
return refs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment