def to_wsme(self): name = self.region.name type = self.region.type quota = [] quotas = {} for region_quota in self.customer_region_quotas: quotas[region_quota.quota_type] = {} for quota_field in region_quota.quota_field_details: quotas[region_quota.quota_type][ quota_field. field_key] = quota_field.field_value or wsme.Unset if quotas: compute = None storage = None network = None if 'compute' in quotas: compute = [WsmeModels.Compute(**quotas['compute'])] if 'storage' in quotas: storage = [WsmeModels.Storage(**quotas['storage'])] if 'network' in quotas: network = [WsmeModels.Network(**quotas['network'])] quota = [ WsmeModels.Quota(compute=compute, storage=storage, network=network) ] users = [] user = None for user_role in self.customer_region_user_roles: if user and user.id != user_role.user.name: users.append(user) user = WsmeModels.User(id=user_role.user.name, role=[user_role.role.name]) elif user is None: user = WsmeModels.User(id=user_role.user.name, role=[user_role.role.name]) else: user.role.append(user_role.role.name) if user: users.append(user) region = WsmeModels.Region(name=name, type=type, quotas=quota, users=users) return region
def to_wsme(self): compute = {} storage = {} network = {} for quota_field in self.quota_field_details: if self.quota_type == "compute": if not quota_field.field_value: quota_field.field_value = wsme.Unset compute[quota_field.field_key] = quota_field.field_value elif self.quota_type == "storage": if not quota_field.field_value: quota_field.field_value = wsme.Unset storage[quota_field.field_key] = quota_field.field_value elif self.quota_type == "network": if not quota_field.field_value: quota_field.field_value = wsme.Unset network[quota_field.field_key] = quota_field.field_value quota = WsmeModels.Quota(compute=[WsmeModels.Compute(**compute)], storage=[WsmeModels.Storage(**storage)], network=[WsmeModels.Network(**network)]) return quota
} RET_CUSTOMER_JSON = { "description": "Customer description", "enabled": True, "name": "myDomain", "metadata": { "my_server_name": "Apache1", "ocx_cust": "123456889" }, "regions": [Models.Region(**{"name": "SAN1", "type": "single", "quotas": [Models.Quota(**{ "compute": [Models.Compute(instances='1', injected_files='1', key_pairs='1', ram='1', vcpus='1', metadata_items='1', injected_file_content_bytes='1', floating_ips='1', fixed_ips='1', injected_file_path_bytes='1', server_groups='1', server_group_members='1')], "storage": [Models.Storage(gigabytes='1', snapshots='1', volumes='1')], "network": [Models.Network(floating_ips='1', networks='1', ports='1', routers='1', subnets='1', security_groups='1', security_group_rules='1', health_monitor='1', member='1', pool='1', nat_instance='1', route_table='1', vip='1')] })]})], "users": [Models.User(** {"id": "userId1", "role": ["admin", "other"]}) ], "defaultQuotas": [Models.Quota(**{ "compute": [Models.Compute(instances='1', injected_files='1', key_pairs='1', ram='1', vcpus='1', metadata_items='1', injected_file_content_bytes='1', floating_ips='1', fixed_ips='1', injected_file_path_bytes='1', server_groups='1', server_group_members='1')], "storage": [Models.Storage(gigabytes='1', snapshots='1', volumes='1')], "network": [Models.Network(floating_ips='1', networks='1', ports='1', routers='1', subnets='1', security_groups='1', security_group_rules='1', health_monitor='1',