c49b03e5fc250222046ef8bc0dbed68c04b5b151
[snaps.git] / snaps / domain / vm_inst.py
1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 #                    and others.  All rights reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16
17 class VmInst:
18     """
19     SNAPS domain object for Images. Should contain attributes that
20     are shared amongst cloud providers
21     """
22     def __init__(self, name, inst_id, image_id, flavor_id, ports,
23                  keypair_name, sec_grp_names, volume_ids):
24         """
25         Constructor
26         :param name: the image's name
27         :param inst_id: the instance's id
28         :param image_id: the instance's image id
29         :param flavor_id: the ID used to spawn this instance
30         :param ports: list of SNAPS-OO Port domain objects associated with this
31                       server instance
32         :param keypair_name: the name of the associated keypair
33         :param sec_grp_names: list of security group names
34         :param volume_ids: list of attached volume IDs
35         """
36         self.name = name
37         self.id = inst_id
38         self.image_id = image_id
39         self.flavor_id = flavor_id
40         self.ports = ports
41         self.keypair_name = keypair_name
42         self.sec_grp_names = sec_grp_names
43         self.volume_ids = volume_ids
44
45     def __eq__(self, other):
46         return (self.name == other.name and
47                 self.id == other.id and
48                 self.image_id == other.image_id and
49                 self.flavor_id == other.flavor_id and
50                 self.ports == other.ports and
51                 self.keypair_name == other.keypair_name and
52                 self.sec_grp_names == other.sec_grp_names and
53                 self.volume_ids == other.volume_ids)
54
55
56 class FloatingIp:
57     """
58     SNAPS domain object for Images. Should contain attributes that
59     are shared amongst cloud providers
60     """
61     def __init__(self, **kwargs):
62         """
63         Constructor
64         :param id: the floating ip's id
65         :param description: the description
66         :param ip|floating_ip_address: the Floating IP address mapped to the
67                                        'ip' attribute
68         :param fixed_ip_address: the IP address of the tenant network
69         :param floating_network_id: the ID of the external network
70         :param port_id: the ID of the associated port
71         :param router_id: the ID of the associated router
72         :param project_id|tenant_id: the ID of the associated project mapped to
73                                      the attribute 'project_id'
74         :param
75         """
76         self.id = kwargs.get('id')
77         self.description = kwargs.get('description')
78         self.ip = kwargs.get('ip', kwargs.get('floating_ip_address'))
79         self.fixed_ip_address = kwargs.get('fixed_ip_address')
80         self.floating_network_id = kwargs.get('floating_network_id')
81         self.port_id = kwargs.get('port_id')
82         self.router_id = kwargs.get('router_id')
83         self.project_id = kwargs.get('project_id', kwargs.get('tenant_id'))