From 7fa547a3c1a70a767e7978db9e2847030659c88f Mon Sep 17 00:00:00 2001 From: Sahdev Zala Date: Mon, 24 Feb 2014 16:58:25 -0600 Subject: [PATCH] First code drop on data modeling. This is the first code drop for the project. Covers basis project structure and reading tosca profile into a memory model. --- heat-translator/exit.py | 2 + heat-translator/exit.pyc | Bin 0 -> 331 bytes heat-translator/heat/__init__.py | 0 heat-translator/heat/__init__.pyc | Bin 0 -> 147 bytes heat-translator/main.py | 38 ++++++ heat-translator/source.py | 18 +++ heat-translator/source.pyc | Bin 0 -> 1459 bytes heat-translator/tosca/__init__.py | 0 heat-translator/tosca/__init__.pyc | Bin 0 -> 161 bytes heat-translator/tosca/inputs.py | 66 ++++++++++ heat-translator/tosca/inputs.pyc | Bin 0 -> 4060 bytes .../tosca/nodetemplates/__init__.py | 0 .../tosca/nodetemplates/__init__.pyc | Bin 0 -> 157 bytes .../tosca/nodetemplates/capabilitytype.py | 0 .../tosca/nodetemplates/capabilitytype.pyc | Bin 0 -> 168 bytes .../tosca/nodetemplates/constraints.py | 87 +++++++++++++ .../tosca/nodetemplates/constraints.pyc | Bin 0 -> 5161 bytes .../tosca/nodetemplates/node_template.py | 117 ++++++++++++++++++ .../tosca/nodetemplates/node_template.pyc | Bin 0 -> 6852 bytes .../tosca/nodetemplates/node_templates.py | 19 +++ .../tosca/nodetemplates/node_templates.pyc | Bin 0 -> 1545 bytes .../tosca/nodetemplates/nodetype.py | 29 +++++ .../tosca/nodetemplates/nodetype.pyc | Bin 0 -> 1798 bytes .../tosca/nodetemplates/nodetypeschema.yaml | 49 ++++++++ .../tosca/nodetemplates/nodetypesdef.yaml | 46 +++++++ .../tosca/nodetemplates/properties.py | 35 ++++++ .../tosca/nodetemplates/properties.pyc | Bin 0 -> 2387 bytes .../tosca/nodetemplates/relationshiptype.py | 6 + .../tosca/nodetemplates/relationshiptype.pyc | Bin 0 -> 746 bytes .../tosca/nodetemplates/requirementtype.py | 0 .../tosca/nodetemplates/requirementtype.pyc | Bin 0 -> 169 bytes .../tosca/nodetemplates/rootnodetype.py | 31 +++++ .../tosca/nodetemplates/rootnodetype.pyc | Bin 0 -> 1927 bytes heat-translator/tosca/nodetemplates/schema.py | 88 +++++++++++++ .../tosca/nodetemplates/schema.pyc | Bin 0 -> 4298 bytes heat-translator/tosca/outputs.py | 4 + heat-translator/tosca/outputs.pyc | Bin 0 -> 525 bytes heat-translator/tosca/tests/__init__.py | 0 heat-translator/tosca/tests/__init__.pyc | Bin 0 -> 167 bytes heat-translator/tosca/tests/squaretest.pyc | Bin 0 -> 2148 bytes heat-translator/tosca/tests/test2.pyc | Bin 0 -> 1347 bytes heat-translator/tosca/tests/test3.pyc | Bin 0 -> 3142 bytes heat-translator/tosca/tests/test4.pyc | Bin 0 -> 521 bytes heat-translator/tosca/tests/testattrs.pyc | Bin 0 -> 1093 bytes heat-translator/tosca/tests/tosca.yaml | 30 +++++ heat-translator/tosca/tosca_profile.py | 24 ++++ heat-translator/tosca/tosca_profile.pyc | Bin 0 -> 1767 bytes heat-translator/tosca/translate.py | 34 +++++ heat-translator/tosca/translate.pyc | Bin 0 -> 1733 bytes heat-translator/tosca/validate.py | 20 +++ heat-translator/tosca/validate.pyc | Bin 0 -> 1257 bytes heat-translator/utils.py | 26 ++++ heat-translator/yaml_loader.py | 20 +++ heat-translator/yaml_loader.pyc | Bin 0 -> 1118 bytes 54 files changed, 789 insertions(+) create mode 100644 heat-translator/exit.py create mode 100644 heat-translator/exit.pyc create mode 100644 heat-translator/heat/__init__.py create mode 100644 heat-translator/heat/__init__.pyc create mode 100644 heat-translator/main.py create mode 100644 heat-translator/source.py create mode 100644 heat-translator/source.pyc create mode 100644 heat-translator/tosca/__init__.py create mode 100644 heat-translator/tosca/__init__.pyc create mode 100644 heat-translator/tosca/inputs.py create mode 100644 heat-translator/tosca/inputs.pyc create mode 100644 heat-translator/tosca/nodetemplates/__init__.py create mode 100644 heat-translator/tosca/nodetemplates/__init__.pyc create mode 100644 heat-translator/tosca/nodetemplates/capabilitytype.py create mode 100644 heat-translator/tosca/nodetemplates/capabilitytype.pyc create mode 100644 heat-translator/tosca/nodetemplates/constraints.py create mode 100644 heat-translator/tosca/nodetemplates/constraints.pyc create mode 100644 heat-translator/tosca/nodetemplates/node_template.py create mode 100644 heat-translator/tosca/nodetemplates/node_template.pyc create mode 100644 heat-translator/tosca/nodetemplates/node_templates.py create mode 100644 heat-translator/tosca/nodetemplates/node_templates.pyc create mode 100644 heat-translator/tosca/nodetemplates/nodetype.py create mode 100644 heat-translator/tosca/nodetemplates/nodetype.pyc create mode 100644 heat-translator/tosca/nodetemplates/nodetypeschema.yaml create mode 100644 heat-translator/tosca/nodetemplates/nodetypesdef.yaml create mode 100644 heat-translator/tosca/nodetemplates/properties.py create mode 100644 heat-translator/tosca/nodetemplates/properties.pyc create mode 100644 heat-translator/tosca/nodetemplates/relationshiptype.py create mode 100644 heat-translator/tosca/nodetemplates/relationshiptype.pyc create mode 100644 heat-translator/tosca/nodetemplates/requirementtype.py create mode 100644 heat-translator/tosca/nodetemplates/requirementtype.pyc create mode 100644 heat-translator/tosca/nodetemplates/rootnodetype.py create mode 100644 heat-translator/tosca/nodetemplates/rootnodetype.pyc create mode 100644 heat-translator/tosca/nodetemplates/schema.py create mode 100644 heat-translator/tosca/nodetemplates/schema.pyc create mode 100644 heat-translator/tosca/outputs.py create mode 100644 heat-translator/tosca/outputs.pyc create mode 100644 heat-translator/tosca/tests/__init__.py create mode 100644 heat-translator/tosca/tests/__init__.pyc create mode 100644 heat-translator/tosca/tests/squaretest.pyc create mode 100644 heat-translator/tosca/tests/test2.pyc create mode 100644 heat-translator/tosca/tests/test3.pyc create mode 100644 heat-translator/tosca/tests/test4.pyc create mode 100644 heat-translator/tosca/tests/testattrs.pyc create mode 100644 heat-translator/tosca/tests/tosca.yaml create mode 100644 heat-translator/tosca/tosca_profile.py create mode 100644 heat-translator/tosca/tosca_profile.pyc create mode 100644 heat-translator/tosca/translate.py create mode 100644 heat-translator/tosca/translate.pyc create mode 100644 heat-translator/tosca/validate.py create mode 100644 heat-translator/tosca/validate.pyc create mode 100644 heat-translator/utils.py create mode 100644 heat-translator/yaml_loader.py create mode 100644 heat-translator/yaml_loader.pyc diff --git a/heat-translator/exit.py b/heat-translator/exit.py new file mode 100644 index 0000000..acc3fb2 --- /dev/null +++ b/heat-translator/exit.py @@ -0,0 +1,2 @@ +def write_output(output): + pass \ No newline at end of file diff --git a/heat-translator/exit.pyc b/heat-translator/exit.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b9e0d337c050000ee6bb6c37dedff208108ab078 GIT binary patch literal 331 zcmb`B&kDjY48}7R6>;yeix%`MB6#1y-Moy_6*l&#rOlXn_APx3U%+Hj_5ucyetb#u z%k&+t9DWZZ^y%5xa3j1$v2dQl>@Q;$U*e z^B0kuS_@-!<58+objFq5N~Hxl+4xGLap`U^yi+3A5;vnQ^sT_Hz2lnpbgn?14hV*O cJ`jSq$6weP!M*w$eM!3ywaMB_AA2%`KPeMTfdBvi literal 0 HcmV?d00001 diff --git a/heat-translator/heat/__init__.py b/heat-translator/heat/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/heat-translator/heat/__init__.pyc b/heat-translator/heat/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..011e763e57bbf62a6436e313c70e3f2c6836fa41 GIT binary patch literal 147 zcmZSn%*(Yt{%=q+0~9av^yA|*^D;}~+R{~^2p literal 0 HcmV?d00001 diff --git a/heat-translator/main.py b/heat-translator/main.py new file mode 100644 index 0000000..e06beec --- /dev/null +++ b/heat-translator/main.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +import exit +import os +import sys +from source import Source +from tosca.translate import TOSCATranslator +from tosca.tosca_profile import Tosca +from tosca.validate import ToscaValidator + + +def main(): + sourcetype = sys.argv[1] + path = sys.argv[2] + #sourcetype = "tosca" + #path = "/heat-translator/tosca/tests/tosca.yaml" + if not sourcetype: + print("Translation type is needed. For example, 'tosca'") + if not path.endswith(".yaml"): + print "Only YAML file is supported at this time." + + if os.path.isdir(path): + print('Translation of directory is not supported at this time : %s' % path) + elif os.path.isfile(path): + heat_tpl = translate(sourcetype, path) + exit.write_output(heat_tpl) + else: + print('%s is not a valid file.' % path) + +def translate(sourcetype, path): + tpl = Source(path) + if sourcetype == "tosca": + tosca = Tosca(tpl) + ToscaValidator(tosca).validate() + return TOSCATranslator(tosca).translate() + +if __name__ == '__main__': + main() diff --git a/heat-translator/source.py b/heat-translator/source.py new file mode 100644 index 0000000..5a55aea --- /dev/null +++ b/heat-translator/source.py @@ -0,0 +1,18 @@ +from yaml_loader import Loader + +class Source(object): + def __init__(self, path): + self.profile = Loader(path).load() + + def __contains__(self, key): + return key in self.profile + + def __iter__(self): + return iter(self.profile) + + def __len__(self): + return len(self.profile) + + def __getitem__(self, key): + '''Get a section.''' + return self.profile[key] diff --git a/heat-translator/source.pyc b/heat-translator/source.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d2f832febf505cccdd0e5cacc3f8a16c98aa256f GIT binary patch literal 1459 zcmcgs!EVz)5FOiT3WcIxd+X6cqLx715JFUl3+ll+k;`bYH^hnUjl5f-O5Dmf@S}VH zythtL2~J1^J2RQxwdcKgJKpTa=}G(jcvi{w%JBaN=AXjV_$AVcbcxIpN$ON=DvLzw zOumWSiF}-AQcq--AK~%lC$2m}6sB+=oT=>)!6@TRE}qzu{8`p1rco10S&6Kt`%+j?$$BE|k~sp0 zYkPYT!jF+#wQ_whP488y+m1B3&{)G2=SiA-0n%|hcKYuHZh{>~_OTAKKM3os%s^8; zA+xQ_f5(`*wzmHtgej{kz*H&XjxTBNEGqm66Jt-HInGCY{S!>Sx8cHEcw2?W^_Q{l ze`}MH7za_Cq*OoKfbH#6&oCSdNONLto4z-lRSnz@)y~y7Erumejgs3{a-n3ql~mxK zXpH{dCs?uvxU-&s)8t_`-q(5jmRQTJ>00F}fo8>UJlfo+6~v8iABeZ;tYx0aT Ho~6G436ebo literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/__init__.py b/heat-translator/tosca/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/heat-translator/tosca/__init__.pyc b/heat-translator/tosca/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..78c4f95e03682cd1b08933352a6d08392aa88ebc GIT binary patch literal 161 zcmZSn%*(YreSJ_e0~9a1^fU5vQ}y!;QuB&S z5|gv_%kzt}iwhEyQ}r`a6H9bUiW2jRa}rDPi{dTyi;I%=OY)186XS~uQj;^&GL!Y= g<1_OzOXB183MxxDfX3P6=BJeAq}qWjEe2u+0EPG`I{*Lx literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/inputs.py b/heat-translator/tosca/inputs.py new file mode 100644 index 0000000..d532290 --- /dev/null +++ b/heat-translator/tosca/inputs.py @@ -0,0 +1,66 @@ +from tosca.nodetemplates.schema import Schema +from tosca.nodetemplates.constraints import Constraint + +class InputParameters(object): + def __init__(self, inputs): + self.inputs = inputs + + def __contains__(self, key): + return key in self.inputs + + def __iter__(self): + return iter(self.inputs) + + def __len__(self): + return len(self.inputs) + + def __getitem__(self, key): + '''Get a input value.''' + return self.inputs[key] + +class Input(object): + + def __init__(self, name, schema): + self.name = name + self.schema = schema + + def get_type(self): + return self.schema['type'] + + def get_description(self): + if self.has_default(): + return self.schema['description'] + return '' + + def get_default(self): + if self.has_default(): + return self.schema['default'] + return '' + + def get_constraints(self): + return self.schema['constraints'] + + def has_default(self): + '''Return whether the parameter has a default value.''' + return Schema.DEFAULT in self.schema + + def has_description(self): + '''Return whether the parameter has a default value.''' + return Schema.DESCRIPTION in self.schema + + def validate(self): + self.validate_type(self.get_type()) + self.validate_constraints(self.get_constraints()) + + def validate_type(self, input_type): + if input_type not in Schema.TYPES: + raise ValueError('Invalid type %s' % type) + + def validate_constraints(self, constraints): + for constraint in constraints: + for key in constraint.keys(): + if key not in Constraint.CONSTRAINTS: + raise ValueError('Invalid constraint %s' % constraint) + if isinstance(key, dict): #and is_required to have a min or max or in certain range or equal to something etc. + pass + \ No newline at end of file diff --git a/heat-translator/tosca/inputs.pyc b/heat-translator/tosca/inputs.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5697c2f5518ee695fb6e5edd2505e9018cf5035e GIT binary patch literal 4060 zcmcIn?QR=I6us+B>^NyiN+4B>1Pc|F1yU@E5E39n;{=F=+;kkMVyT*LcPGS&z3c8w zXd|V62(QKy@c?koowXe`5Q)aNGn3iz?##Jo&i&Z%ujR$1KWm+Y%1_AuzvE_ixl8#k zpgz$cpl(0`t}E29&>*C4$k!p6IXVa^oufa9&WZNB^OVkyW~<}bDy22*G!}T#-rxLb z1Uzz8?mEe#8N~j2k*`~MW?d2YGUrzKawi*}xZSvj2gaGgj&b7oO>XuJ?hFAQqhk== z3NT|30xSk|#6U4%Yyz}fCDm!n^OH%1yHRUly=Css0y-noLO@5LwI_gkKx7+u$j#vi z(?3w4t-;NA_G=zB5A%U(=0n5w#L02Uk&P^ z|2ph1VJ6{$e4xKgZuS{>h6Bg{3@#i25pHUfN(AgKAo^jZPU(US7AdXEU^gVjNOV?_kR(7xPL4Yz1c6rxrq%~jEF=D-Rx!e9Ovt=8kKpSTHw!W;s0Ya< zU!SOxV==1}NZSI{oeqr`q@bFWr?V0@wt5dZu{#IPODOT9_n~v5;#L`&1TklhP6ITy z9c)RBO^V*o^*Ge=CHd%&Uk+odQ*#iX^quE<78W59!lDZ>-sdR`C#K*=u=K{p!RumduBFDb?Lo#?Ay(&O#Xy_EHkbzVYuMsn%JK&`Va*$ zrc$nI%Q_4p(xIf}RNPBrXCx}AHB7&Aar%O=6ylQCGajE_O$#zlXg+j^VgN{&zOenRB@H9Qs)d#%rm)uH|SG>vC6VSxur#yJM539GHJfc?> zdif)9+C7pNo2@5b(W{WoLUMsPG*hyPnwrxE-!!3wvm9=kr}GLGcj&qNJ$_!J$0=mt z$wH{z$vjz;lLuu8>5?e9Qnw1pL=sTzVY{=Z9_+ODI_fSag(%Baw~MpH$P;NVah`JF z{m$sN$p%xd`c%YQ;8n+>T%%w)SPNF9H87!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y_=WOSGOmNp@9u3lO#@`D*I@B^|be3uPNs>0sO!)KqXn~o}9kL?wF;v zl%*ErTsdjPQnB6%kQ~vldJa^VOFB0C5k?RV zP^nvzDYTnwokTz2Wj|y^|9IIz_#U45D-=sclJZip2Cv*0`D8+|S?G}piRb6LJXMXD zsB6H(S0V2mGwgH({}^&kCn1bWM7^r^5RC&wYA}i(rY?Nc237%l#q@){hGG?92kLQ( z4m4zL(n)}KxB{>m3^oPd9gIyM2M&AIc@lUN&rz%(c8kP)oFY?CE_6N}1zf3f2&p!+6Yoo@0(n@j_;F9OY6w2^w}&}M_5Vb2X4H^;3Ps3xz9IX!1Va)N z4kM=6#|yzL5elgmz2j1q8tyE8w`G}!3NT^+1Dx& z{YsneT-Yup^U;?;}x_=Z)W)}x!u6PYpcunUDVHLuGvt_ z@IM}Uv~`Sx`ZE0POp<-q>i>yW1fWy+1bVMx^IX>E3!~^8DqH7`!8kT|6A~M5bCw%@HCG2Ge_wEzOWXOP?i@43 zi~_(823Gr8cqs?bM$wJh3&4hu^xB&tD#5v+y}HLgpb1X%BbdNo*YVR9?O_epbxTqO-9nXJ3lu!puW+{nb_){dw?;fGqPT zM213fx1QA0|Hmz3ye< literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/nodetemplates/nodetype.py b/heat-translator/tosca/nodetemplates/nodetype.py new file mode 100644 index 0000000..93a02aa --- /dev/null +++ b/heat-translator/tosca/nodetemplates/nodetype.py @@ -0,0 +1,29 @@ +from rootnodetype import RootNodeType + +class NodeType(RootNodeType): + def __init__(self, nodetype): + super(NodeType, self).__init__() + self.nodetype = nodetype + + ''' get properties for a given node type''' + def get_properties(self): + properties = [] + nodetype = self.get_nodetype() + for prop_key, prop_vale in nodetype.iteritems(): + if prop_key == 'properties': + properties = prop_vale + return properties + + ''' get capabilities for a given node type''' + def get_capabilities(self): + pass + + def derived_from(self): + pass + + def set_requirements(self): + pass + + def get_requirements(self): + return self.requirements() + \ No newline at end of file diff --git a/heat-translator/tosca/nodetemplates/nodetype.pyc b/heat-translator/tosca/nodetemplates/nodetype.pyc new file mode 100644 index 0000000000000000000000000000000000000000..387641a2d9035940c24668a1830b0e1775178faa GIT binary patch literal 1798 zcmd5-!EVz)5S_J?(3A#MAS4in!p-71X>w;Q{33Gv%4uoN>1>{ zd;q)|CrwYB2x{V)>`v^N_ulS~!(W5L-n=);X!8m2`wHfs!{xXXl|+@Iu_BcRWE4#l z)gCwHpU+yu$^2N<6B?D+!>r9u7Q%s z%vqHTLPAlFbT&oDT`tIx9_3vb+@WL?^^hV9;MkbOIm|tU^SBhPfH$DafKjWJ%r%k| zurrKd)Zts1hFdhoCPITzYhBC=ueDH^fsY5Dh^u&h#F=uE@F0S<&b`AZ{#sWit{XFR zKFy}_x7to!lV&FNHl4XL^|jTfr?InH>}!{$vE(*YgTIVxXQ=d|Std+JYOy2rKxK@M zv0f8>i^&DiT8LfB+N=Zm9@7e>6_bAR`5Ao*XdTkJLn}~MG!4j}(5l0a%}@CH0A)r( zZs-q@vaw)bePLY7nAi2fc)iuZ_Yo+(v9QX?E=U+x!pkADh-{ojPt8(pm&sLHn*Ax} z?`?4I@H0@y@JaR5k$Mapv^uhuZ09h?3g^2`ff>pE5LSBxe2hXYY?e0Zm!d3K^81K6 z-e`1-fU<-+*89rjdSdJ9;cW!TYC5QC&3sWMsgRigz+Z>c6=rhR%W-2W%SS673;>0 tNse1j^}GFkKjiN);;_6NEM5-VCXygX(s1{TOeA~Rigd;(<#Zhfe*ji0o45b~ literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/nodetemplates/nodetypeschema.yaml b/heat-translator/tosca/nodetemplates/nodetypeschema.yaml new file mode 100644 index 0000000..ebbc7b1 --- /dev/null +++ b/heat-translator/tosca/nodetemplates/nodetypeschema.yaml @@ -0,0 +1,49 @@ +tosca_nodes_Compute: + num_cpus: + required: no + type: integer + constraints: + - greater_or_equal: 1 + description: > + Number of (actual or virtual) CPUs associated with the Compute node. + disk_size: + required: no + type: integer + constraints: + - greater_or_equal: 0 + description: > + Size of the local disk, in Gigabytes (GB), available to applications running on the Compute node. + mem_size: + required: no + type: integer + constraints: + - greater_or_equal: 0 + description: > + Size of memory, in Megabytes (MB), available to applications running on the Compute node. + os_arch: + required: no + default: x86_64 + type: string + description: > + The host Operating System (OS) architecture. + os_type: + required: yes + type: string + description: > + The host Operating System (OS) type. + os_distribution: + required: no + type: string + description: > + The host Operating System (OS) distribution. Examples of valid values for an “os_type” of “Linux” would include: + debian, fedora, rhel and ubuntu. + os_version: + required: no + type: integer + description: > + The host Operating System version. + ip_address: + required: no + type: string + description: > + The primary IP address assigned by the cloud provider that applications may use to access the Compute node. diff --git a/heat-translator/tosca/nodetemplates/nodetypesdef.yaml b/heat-translator/tosca/nodetemplates/nodetypesdef.yaml new file mode 100644 index 0000000..003349c --- /dev/null +++ b/heat-translator/tosca/nodetemplates/nodetypesdef.yaml @@ -0,0 +1,46 @@ +tosca_nodes_Root: + properties: + - property + capabilities: + - capability1: somecapbility + interfaces: + - create + - start + - stop + - install + - delete + +tosca_nodes_Compute: + derived_from: tosca_nodes_Root + properties: + - num_cpus + - disk_size + - mem_size + - os_arch + - os_type + - os_version + - ip_address + requirements: + - host: none + - database: none + capabilities: + container: + type: Container + containee_types: [tosca_nodes_SoftwareComponent] + +tosca_nodes_SoftwareComponent: + derived_from: tosca_nodes_Root + requirements: + - host: tosca.nodes.Compute + capabilities: + containee: + type: Containee + container_types: [tosca.nodes.Compute] + +tosca.nodes.MySQL: + derived_from: tosca_nodes_SoftwareComponent + properties: + - db_user + - db_pwd + - db_root_pwd + \ No newline at end of file diff --git a/heat-translator/tosca/nodetemplates/properties.py b/heat-translator/tosca/nodetemplates/properties.py new file mode 100644 index 0000000..190e185 --- /dev/null +++ b/heat-translator/tosca/nodetemplates/properties.py @@ -0,0 +1,35 @@ +from tosca.nodetemplates.schema import Schema +from tosca.nodetemplates.constraints import Constraint + +class Property(object): + def __init__(self, name, nodetype, value): + self.name = name + self.nodetype = nodetype + self.value = value + + def is_required(self): + return Schema(self.nodetype).is_required(self.name) + + def get_name(self): + return self.name + + def validate(self): + self.validate_data_type() + self.validate_constraints() + + def validate_data_type(self): + data_type = Schema(self.nodetype).get_type(self.name) + if data_type == Schema.STRING: + return Constraint.validate_string(self.value) + elif data_type == Schema.INTEGER: + return Constraint.validate_integer(self.value) + elif data_type == Schema.NUMBER: + return Constraint.validate_number(self.value) + + def validate_constraints(self): + constraints = Schema(self.nodetype).get_constraints(self.name) + if constraints: + for constraint in constraints: + Constraint(self.name, self.value, constraint).validate() + pass + diff --git a/heat-translator/tosca/nodetemplates/properties.pyc b/heat-translator/tosca/nodetemplates/properties.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1b446c01d244a66092281cde6f191ae770719ac8 GIT binary patch literal 2387 zcmc&$O;6iE5S_J?Ktd@|)k8m2RcbH3fTgM@RG|ur5Qj#s0aZjoma(_s5Zl4KX+eTh z`tSO4`UBc|<9wl(V%5~OyiHs|KD>n>)a*$r>IYqDe5Xx z7(3K=D08Xn^4KL^qpymR8vP&|5gm5xl+&GoI=5ao7~I>cbb5J0q{9p2e4qczyqU3j0FZCFIc(_;K0lR1r?mQ z#_vIMxNUJWFS)x?bVU@h;fTRQR}4OcF$>&|2e()}n@5=zxOtIidpXdy&a>a5{!n{Z zmrX|ZzXo_Dz*K-89=ED9M{N10MW%fw%r1!HGyi*0o|!=uYo9%mn|@@AGJNyaH)ZUf z>d3CnrhQwOIP&Fuoeg-aHvXV;UaHO7;8O5~VVb8l3~{)D`$;wV8^fz;Qzty-fo1wc zJw+o$J@G@&g*~A!GkAdxR{}Ing$Rl$IIGt$ z``bI)fd%*JCN6&ZgsUF%rgQLdlh<#&Bp+tSy7b@~$t~MtYZ~G^%`{{gBxN3QN9ws+ zQSEV)qJnydVk231z{YJwrHWwrnJ!il$`41c=-NTyguZ$tpw&>6^ae0Ov+hXwVgku CV<`{- literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/nodetemplates/relationshiptype.py b/heat-translator/tosca/nodetemplates/relationshiptype.py new file mode 100644 index 0000000..11a9634 --- /dev/null +++ b/heat-translator/tosca/nodetemplates/relationshiptype.py @@ -0,0 +1,6 @@ +from rootnodetype import RootRelationshipType + +class RelatonshipType(RootRelationshipType): + def __init__(self, relatointype): + super(RelatonshipType, self).__init__() + self.nodetype = relatointype \ No newline at end of file diff --git a/heat-translator/tosca/nodetemplates/relationshiptype.pyc b/heat-translator/tosca/nodetemplates/relationshiptype.pyc new file mode 100644 index 0000000000000000000000000000000000000000..08a031dc3b6e85b8780fbcf84a982c25c3c375e2 GIT binary patch literal 746 zcmcJM!A`?442GR{Ludj40&zp)SaBfI&Ilp6@6d8#m#Atpt*mXTCKH;p8@w?O0KdIK zpI}kq#&#Tk`5S+qPOfjpSwZ^|pWDh^~}RVOKg!Mtqb({kpS#Dxk-3jj7ry7!%lOU1?l@fs(%)#(j nJ_hnE)RCI)=tL*{_&*s_BuS(mkPa%F=<~2szbil0~$f literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/nodetemplates/requirementtype.py b/heat-translator/tosca/nodetemplates/requirementtype.py new file mode 100644 index 0000000..e69de29 diff --git a/heat-translator/tosca/nodetemplates/requirementtype.pyc b/heat-translator/tosca/nodetemplates/requirementtype.pyc new file mode 100644 index 0000000000000000000000000000000000000000..92d223e0ae6e4a5c132c31a5f492ddf89d03dfe5 GIT binary patch literal 169 zcmZ9Fu?hk~3`AG75W!EdzskVXB7T9zSz5@l8&K|c6O$Zr-)$|J11kgb24*0$d~Y|q z>!(ZMcMJEEOIMB@!ljv$bK?kq(9ScsQ$ZlcsuoiZFOpt4CIpjMb%;iCYgIH8|)}JP12j znlf%4yulfU-GiAEjU|0JT6P*pg8h(}xw|mh8m9#=19a<{T1G7yyuCHWD8x63v9I9$ zD=7`qUz~JU&m5OP>%7dJ);;)^&n30(NoqcP9+KJ#oC~5$MGjfOqWT^+$Mo$fhph}= zeAuH)kLHLwG#7oS&rj%W30f3N&Sdq&F09*t$!*TnEmI@KSs>FWnPVhbo;typJJU?e z%!){o8luQTMi%p`m_5e^OIAx*%q6^oVHrNDKy9l%wXag1XDp2348xwo!=CCE?(x&PB-xvs9kWo zrTQWFg&U!k$<$~q($RWaWnT(}F{78l#C*46zJs^u#aqSQiMarb&9Vv9dS|`o_Th4i zi4B@iUX}J!UjNZ*_@z^R=^o5qtp;6%A1}KK2cjjeEF`qJK8Q$GN(FCIT}hTq?jsD# z3MbXxI!W_BV&VQ4!Rp99z+n$D1V#W=tRZlG6S=kPLVh=5gyfjnh5Wgb=uuu6X(zl& l^e=6s`ZzYJlQPD<{eMV9WPIET_c@o>avD1x#O@s&`~tfyyjlPN literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/nodetemplates/schema.py b/heat-translator/tosca/nodetemplates/schema.py new file mode 100644 index 0000000..4e0c2d8 --- /dev/null +++ b/heat-translator/tosca/nodetemplates/schema.py @@ -0,0 +1,88 @@ +from yaml_loader import Loader +import os + +schema_file = os.path.dirname(os.path.abspath(__file__)) + os.sep + "nodetypeschema.yaml" +schema = Loader(schema_file).load() + +class Schema(object): + + TYPES = ( + INTEGER, + STRING, NUMBER, BOOLEAN, + LIST + ) = ( + 'integer', + 'string', 'number', 'boolean', + 'list' + ) + + KEYS = ( + TYPE, DESCRIPTION, DEFAULT, CONSTRAINTS, + ) = ( + 'type', 'description', 'default', 'constraints' + ) + + def __init__(self, nodetype): + self.nodetype = nodetype + self.nodes = self._set_nodes() + + '''set a list of node names from the schema''' + def _set_nodes(self): + sections = [] + if isinstance(schema, dict): + for key in schema.iterkeys(): + sections.append(key) + return sections + + def _get_section(self, section_name): + section = {} + if section_name in self.nodes: + return schema[section_name] + return section + + ''' return true if property is a required for a given node ''' + def is_required(self, property_name): + return property_name in self.required() + + ''' get schemata for a given node type''' + def get_schemata(self): + ntype = self.nodetype + ntype = ntype.replace(".", "_") + return self._get_section(ntype) + + ''' get schema for a given property''' + def get_schema(self, property_name): + schema = {} + schemata = self.get_schemata() + for prop_key, prop_vale in schemata.iteritems(): + if prop_key == property_name: + for attr, value in prop_vale.iteritems(): + schema[attr] = value + return schema + + def get_type(self, property_name): + return self.get_schema(property_name)['type'] + + def get_constraints(self, property_name): + s = self.get_schema(property_name) + if 'constraints' in s: + s['constraints'] + + def get_description(self, property_name): + return self.get_schema(property_name)['description'] + + def get_greater_or_equal(self, property_name): + pass + + def get_equal(self, property_name): + pass + + ''' list all the required properties for a given nodetype ''' + def required(self): + required = [] + schemata = self.get_schemata() + for prop_key, prop_vale in schemata.iteritems(): + for attr, value in prop_vale.iteritems(): + if attr == 'required' and value: + required.append(prop_key) + return required \ No newline at end of file diff --git a/heat-translator/tosca/nodetemplates/schema.pyc b/heat-translator/tosca/nodetemplates/schema.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5c558477f781f709358b519b6f3085420df6b279 GIT binary patch literal 4298 zcmdT{>rxy=6h5;zST2D8fuPZ7jLAj~Ygv|+ACx9sOkv1^v!p1tlA0QJ8W`9c(}P0Q z?k{`*-@(W6aeM&%zB4Ed)G}f+a-5apT*~Cd6y(z3!>JKj2(q$J8x@0rQ4Sv$+1+gWfr%=17JRE6nE0Y&Z2ibI{iO@P+0Zpr z?O!R8$I=xv`x}VCp4jS^b%C^p$`xxbl{dT)y{8pR;-w1823~dsRVsZsC(Ywy^aK)~0P0yuAa`b)+lefe|@|CzbIs41=orqf*LZSv(4odLkY} z$FnB(IAUX(UbzxKufkc=IB+Rk2`wRZ4_x`E-8AKP$3QH|m*}<$h3fE>u9z3tM6Ad5hS|GLFP4I#ZcC zhZwXS=EAEAk@snd@(rl?ptEc3Y& z*zZFMK;Mc}aHgDDXU@@}p)B;Qn(kvTAxx)+VbDO%fWPtekI47e}8Wnwp;&@T~sd#Kv)z}hUi`jLpMktF+$FRrJ)_ z+^Fs-^J0CkstmuR_nEcz>Z-f3y|b}Z(bv}2zkl{>b4TY^w<`GdGwfA$313>%Y60Tj zVOJeW|G1AxJ||&8x@$La|t6FN^{#kIeWYZk_d!=85#s*`xaSkuujCO0Xa s(Xa61Nx{L3RD1szHxrlAUPricL%7y0CsFk+ch>@a+L_2aa%M7r0kMI{T>t<8 literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/outputs.py b/heat-translator/tosca/outputs.py new file mode 100644 index 0000000..94a6a04 --- /dev/null +++ b/heat-translator/tosca/outputs.py @@ -0,0 +1,4 @@ + +class Outputs(object): + def __init__(self): + pass diff --git a/heat-translator/tosca/outputs.pyc b/heat-translator/tosca/outputs.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c702c9b74e66e6cde98ca4653f35a1a61a3222b4 GIT binary patch literal 525 zcmb_YOKQU~5FI(i4S_DQ?Fqc9AnOo9x=+AfH5;MI3Q7Et@r)^5w>RzuIwSRSfL1V1 znt5-2ntj|YnsZ(`_&PJbw`_RNPy={?lY&~oJHQ*j(~+GFszP*h%W#-zm%SFKxcJGV?GS8H0J`wT>1+cBWqyB04lAN$li9|7+OSS7wV~H sw-nv)Ao2C*X-erWh2s>t+85$b&Jdoj-cc0%ch~p_>$KP=cISTZ37D~Q`~Uy| literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/tests/__init__.py b/heat-translator/tosca/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/heat-translator/tosca/tests/__init__.pyc b/heat-translator/tosca/tests/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2b03e287e0dd0a4cb32b16030bc398de8281ccab GIT binary patch literal 167 zcmZ9FO9}!(3`ARWA%gdqjb<%~c!ELn03q~5rfgc5Z%pJn|?r1OA$98Kr$D6?ExXwfm_fYUZ zgg-(5@Q3ijHscOEP0(SN(YOk5U2kj=C}*}sw&jh!P;s~ocPUe%v>;~?dkl3W#f=aN zjFvZiz&Iq3LCBqs=C#-JkgvNAlr`fE#TCUpA*5FJHLPeDosI10nXU}&=hL|(o%Fj&}%#E|puyatJm)YF!O2;~%V9AxiL|>V}EuCO@%5*4; z`rN|+#ks7t6i2IdS;^klffzSY2d0g(Xx76Lnve^mjCsa+b`t!k!5%dh06&U-4+pvL z64n2L-AAmcsZeicsvTl%u=8;z9{WBf7A(wgA{z3ss%{sm?&;L!W#O|?Oxv^2nQOO+ znzPn-OxlC}Z`gZyQ_tL}td_79U2g(1OI!yV=!qe7{|NdC78_cFBF*Us&B32${M#k4 z!WvH^-vM4x@Gngb5%^M4>irrKN&1#(Ri$C)IVl-X>Iq2f-(8&+{a z5vO7^6rCzkN|AI+*xp*()urIuQ`{1FPxjkA3Eir{j!0sE)ur6X52=0%u@9hrx%P2; zb2+^`GkpH_-1vU2u#O&<>8>wRR+@KD!!`f^ph!M-pNh-NuxqX|i~A7bWA|jvUJvSM nzT+4Q#ZCUd%hojDrcEL8oP1HU@Fm-18SU`!xVtC2a##KYt>VJ| literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/tests/test2.pyc b/heat-translator/tosca/tests/test2.pyc new file mode 100644 index 0000000000000000000000000000000000000000..78e3b9fe24aeba749ad50531426da140e8a1388b GIT binary patch literal 1347 zcmb_b&2G~`5T3Quq)A%>2SDYNqa|ol^@Jh>lpg^CdT=D5xvaMKCfH59(e4Clsaz0+6JXU7cr7he<@o8HRj{2XSKMHe`**Jl`=5zt$t)LjN$3i{3A`|36{ zP{C0Ld;&@-jNq$+O2G$e#zj#v`K4T+qClZVd2Z0+4N@~l zjPZ*M^~}uYMKwt{lk{J>R=M2LaEYK-^)7{R%>I9puahA#I*6KTO@*7Jp_vS7Gn;NZ zKe@NNv$H!Ol;IVfbjWvHOa`4^Z>v}2gWlLV(Rpfv-l6e)18s$8SNx(H^p1~@<&L*A z_la)Rb={#}(kyw%QZHwd9=XHPW+)R$nWfkzVe(vGf+qU%m=5;dz7b{WOpe?=a+MHg l5b1ZIiT%~SrO`!r`rwS24|zs`d$=CmYPVb0+s&vO{Q-pNDSH3_ literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/tests/test3.pyc b/heat-translator/tosca/tests/test3.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4c63b884a203b15b6588a6a103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567`qA~v-ad2CP{%{)9< jzL^%)7%po0QsSw-P4@|1*LS*3`1iOyC-NfKcXyp1lP_lD literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/tests/testattrs.pyc b/heat-translator/tosca/tests/testattrs.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9b018f2b4b77ce2af65d2c326243dbbc8fc78cbe GIT binary patch literal 1093 zcmcJO!EO^V5QfLQp)@TyAtCh&mp!o(NEHW!5FoV&l!J3XL_(Ic>%b27y?e(K&-T@4FG5{~&UjbynO%*py|J zua_(%ZnzD6GCtu#{ioCX{g(wuybU zF2BWYop!zoC3k+CTFF$P)k;l1a+pu#&n*@bSCEd_; z-=~1kJbc?MqD zlJfEiJS6I_eR~ypofZE8;Cqcx%sEkLPpx-ke*jy*3C<~$bDLOSwHR7iXa&?hfVm@6 z?|)qZi`075NzU=ejI(iOMW?C0B`Z2>jJ~S2e^q)V<%S*zN@aQ33-L-|l4$Yhcx=XI GV*Uax1MJ-Z literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/tests/tosca.yaml b/heat-translator/tosca/tests/tosca.yaml new file mode 100644 index 0000000..c342aed --- /dev/null +++ b/heat-translator/tosca/tests/tosca.yaml @@ -0,0 +1,30 @@ +tosca_definitions_version: tosca_simple_1_0 + +description: > + TOSCA simple profile that just defines a single compute instance. Note, this example does not include inputs values. + +inputs: + cpus: + type: integer + description: cpu + constraints: + - valid_values: [ 1, 2, 4, 8 ] + +node_templates: + my_server: + type: tosca.nodes.Compute + properties: + # compute properties (flavor) + disk_size: 10 + num_cpus: { get_input: cpus } + mem_size: 4096 + # host image properties + os_arch: x86_64 + os_type: Linux + os_distribution: Ubuntu + os_version: 12 + +outputs: + instance_ip: + description: The IP address of the deployed instance. + value: { get_property: [my_server, ip_address ] } \ No newline at end of file diff --git a/heat-translator/tosca/tosca_profile.py b/heat-translator/tosca/tosca_profile.py new file mode 100644 index 0000000..d702ccc --- /dev/null +++ b/heat-translator/tosca/tosca_profile.py @@ -0,0 +1,24 @@ +SECTIONS = (VERSION, DESCRIPTION, INPUTS, + NODE_TEMPLATES, OUTPUTS) = \ + ('tosca_definitions_version', 'description', 'inputs', + 'node_templates', 'outputs') + +class Tosca(object): + + def __init__(self, sourcedata): + self.sourcedata = sourcedata + + def get_version(self): + return self.sourcedata[VERSION] + + def get_description(self): + return self.sourcedata[DESCRIPTION] + + def get_inputs(self): + return self.sourcedata[INPUTS] + + def get_nodetemplates(self): + return self.sourcedata[NODE_TEMPLATES] + + def get_outputs(self): + return self.sourcedata[OUTPUTS] \ No newline at end of file diff --git a/heat-translator/tosca/tosca_profile.pyc b/heat-translator/tosca/tosca_profile.pyc new file mode 100644 index 0000000000000000000000000000000000000000..03b1d4b318303a0804ea73100f21c20ef7f1b187 GIT binary patch literal 1767 zcmcJP+iuf95QfKb4sD^FgoN@2zQR(uMHP_xB2r1BwTpy>v@+fexJ|s4cLPG|9Xtf@ z$qO+5CTVlsHi>pTd;Vs2X2O5RN9TVBX-S)3kH7D@**7fI0d;etFFncw$~%;Yly@ob zk?N7|(>x&6r$0o$i9Y88QUgk(L*D0x5XP2;RC-?3m8(o`#>4JKTl z`&HenoOMrFt&P&s>1DGhoVISjLuTdtH0Uy%d&3*>$Omrrl!YdMDgqPZs=zBDsg75= zq(ZN-0bQ^3VF?xwNTd-s$_|Td8{yz%7S{n?6G_GypKh>s0u{k|XLJO^crv@l)(^2KXCofr>~%UlzYj31olMUX znI#`*=kK#*ui!uhIFkP+_g~(JAJII$$oB2=ZFp}=)T>+M2-&$w*Sc70DSf$+a%t3R z!Cip`0#7C$L%`$W8N>?~x0&d*2Pz)|B^0q}ab>@A7;gWQ2vdR^Ss1kw_`(;B5HmZ~ x_}0EO86h20f#NT)S)ghPfgc5S_L2QHN9&a6lj-_2>h^B~@>zqJ&CtX(cD?5_KLyZ7T;H%e)Fx%_^^rq9@A{0Pd4Vg?Syf|Nsw zu}jwuH3Q(8OL2=z&*C=ll;?LSYmw^GL{QeIuSC~GALA{Ai~J6Up8n+PME4jD_g?J} z_6`Qaee-~uqbQlEck`lFjoIP$_%s?Fjhm#@d19(&#Z>UvTQ+^jj)^ck=F7i|9sCBs z1#5s7Cgl=4rGWc+m;-hSPW>K_$^Fr zv(t0t9ir20v6FIIPK}gy%v3r}eEh;-zE=4p1n}7w&T0wHt3m};tx9c@^dk6DH5a;0 zQWcn07UXak=q3$p$W_03Szm^rzs;r*n#5y~g3XOtVK2CYCCzME1dv!LW3<$03k$W` z9g&atTX{o7$E zh%4Tpt5F~lJ$wI|B&2UmJm&r*Y9Thn6E=;tL4PUOf8^3-2G8yZ7Zm9EJ>i1ov-_Ki z4{pmXUM7X&EsnEH%A(5VIXCS-4AE!H8zQeEJ_-@ZXIpcd*!S4seKrl(5njvdcrI?= zu6!(^%cRH+&W88LM`L+*97Z2bPa*?q=ZQ{?X+nl%k73M}+2R<6inUW2D(tYSbAz>8 geVVD%*i&!w!fcXXFVcDlkyc>e={P&0?|A(F1)^GW;s5{u literal 0 HcmV?d00001 diff --git a/heat-translator/tosca/validate.py b/heat-translator/tosca/validate.py new file mode 100644 index 0000000..fdcfeee --- /dev/null +++ b/heat-translator/tosca/validate.py @@ -0,0 +1,20 @@ +from tosca.inputs import Input +from tosca.nodetemplates.node_template import NodeTemplate + +class ToscaValidator(): + def __init__(self, Tosca): + self.inputs = Tosca.get_inputs() + self.nodetemplates = Tosca.get_nodetemplates() + self.tosca = Tosca + + def validate(self): + #validate inputs + for name, attrs in self.inputs.iteritems(): + if not isinstance(attrs, dict): + print ("The input %s has no attributes", name) + Input(name, attrs).validate() + + #validate node templates + for nodetemplate, value in self.nodetemplates.iteritems(): + NodeTemplate(nodetemplate, value, self.tosca).validate() + \ No newline at end of file diff --git a/heat-translator/tosca/validate.pyc b/heat-translator/tosca/validate.pyc new file mode 100644 index 0000000000000000000000000000000000000000..155f723aa18631a1e06e013c2865905125fca55d GIT binary patch literal 1257 zcmb_bPjAyu4EKBKpKW4WIU%75mBXY+NR6}u2x%Y$NWg&}(u#=+6hiVw(=|znT^Le( zDpx)cABztFw$qkzW=WrGzxQna{Ilcz+TT0;*&ZaYemwqv!V4d;Ncm@A3XmHZ88Bj7 zm|Dm^7xn8a`5X_m%RR$DmY|CATrX5m0kFbGaJvI0#M55j?O`8W}=S)^l44bW9cyp_KxY;KaQamp8x;= literal 0 HcmV?d00001 diff --git a/heat-translator/utils.py b/heat-translator/utils.py new file mode 100644 index 0000000..edce3fc --- /dev/null +++ b/heat-translator/utils.py @@ -0,0 +1,26 @@ +import numbers + +def validate_integer(value): + if not isinstance(value, (int, long)): + raise TypeError('value is not an integer for %s' %value) + return validate_number(value) + +def validate_number(value): + return str_to_num(value) + +def validate_string(value): + if not isinstance(value, basestring): + raise ValueError(_('Value must be a string')) + return value + +def validate_list(self, value): + pass + +def str_to_num(value): + '''Convert a string representation of a number into a numeric type.''' + if isinstance(value, numbers.Number): + return value + try: + return int(value) + except ValueError: + return float(value) \ No newline at end of file diff --git a/heat-translator/yaml_loader.py b/heat-translator/yaml_loader.py new file mode 100644 index 0000000..4f06886 --- /dev/null +++ b/heat-translator/yaml_loader.py @@ -0,0 +1,20 @@ +import yaml + +if hasattr(yaml, 'CSafeLoader'): + yaml_loader = yaml.CSafeLoader +else: + yaml_loader = yaml.SafeLoader + + +class Loader(object): + def __init__(self, file_name): + self.file_name = file_name + + def load(self): + f = open(self.file_name, 'r') + profile = f.read() # string + try: + doc = yaml.load(profile, Loader=yaml_loader) + except yaml.YAMLError as error: + raise ValueError(error) + return doc \ No newline at end of file diff --git a/heat-translator/yaml_loader.pyc b/heat-translator/yaml_loader.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6f023fae0fea201908a30eea69bcc034cf948f82 GIT binary patch literal 1118 zcmcIjO^?$s5Pgo*E-hU^+?FF3a)C&2MTlj^1uZ?K60qf9Oya5^X;Rs)P^I=l`3w9~ zegMo&7m7G9Q9XH1oS8T8P4$n{{`&jLsKoW9>Hd;dctfG0pF$0c0jJ<-n_!>7KVm#j zFxF^#f>XwohU;LWP^I_=?18Isms5y z{>asng0p0_4nZWyr|r_^?aDPF+H#S9Y5gLsZ0YjoZ4+u6TW_8|%Y!fTsk8C%@o~Pf z%i7e^GS|Ew3Z^er5s2# zd5SIRksx-kS8Av6zIlk0-*mC)!+(U@rBLw%+mue=t3spjVXMgyO+|*0Yx{y@#`HuA zZdRm_op-hpz}*Poj>N>j`V(2N&fi|X_P+Iz+k0p0wUe!wUvNRGHz7X2%C~F-ktL7X zl3F0A`Q!g)K*84YY=k=$pzf=I(&~)v_f*C+aP1HehB4BEG0V1E)3BI=4@ib1KS4J< zCE^7W4P3CRdOBmZ3UPf2a2I+?Da*D<3>^zG1o|+4F-)FL;as M6CEUX)gbBVUnAr5%K!iX literal 0 HcmV?d00001